-
Notifications
You must be signed in to change notification settings - Fork 0
/
N10-Main_Code.py
123 lines (91 loc) · 5.27 KB
/
N10-Main_Code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# %% Code Version Numbers
vn_N6=1.0 #See meta-data at bottom for details
vn_Main_Code=1.0 #See meta-data fro details
# %% Current Machine Running Code with neccesary adjustments
"""Machine code feature is commented out as we aren't running the code on multiple machines for now, just my local machine Replaced with simple direct_export_path and internal_export_path variables"""
# %% Current Machine Running Code with neccesary adjustments
machine_number=1 #Input the machine you are running this code on
"""Machine codes:
Josh's Thinkpad- 1
"""
if machine_number == 1: #Code to assign the right export paths for each machine, since each is unique
direct_export_path=r'C:\Users\joshu\Box\Quantum Biofilms\Raw Data\N8_results\Direct Exports'
internal_export_path=r'C:\Users\joshu\Box\Quantum Biofilms\Raw Data\N8_results\Internal Exports'
# %% I don't remember what this is for but I'm scared to delete it
from IPython import get_ipython
get_ipython().magic('reset -sf')
# %% Imports
import time
import os
import numpy as np
from N8_RJ import *
from N8_method_of_lines import *
from N8_parameter_tester import *
from N8_parameter_matrix import *
from N8_report_generator import *
from N8_csv_generator import *
#from N8_linear_fitting import *
# %% Start Timer
t_start=time.time()
# %% Determine what run number this is then update run number
counter_file = open(f"counter_file_{machine_number}.txt",'r+')
old_count_number=int(counter_file.read())
new_count_number=str(old_count_number+1)
counter_file = open(f"counter_file_{machine_number}.txt",'w')
counter_file.write(new_count_number)
counter_file.close()
# %%Inputs Code Block
h=np.array([0.01]) #Define timesteps to test
tol=np.array([10**(-8)]) #Define the tolerance the code will run with when running Newton-Rhapson
t1=np.array([0]) #Define initialtime vector of values to test
t2=np.array([10]) #Final Time
nx=np.array([100]) #Mesh size
gamma=np.array([1]) #Define effective diffusivity
alpha=np.array([1]) #Define dimensionless and porosity adjusted binding rate constant
xi=np.array([1]) #Define dimensionless and porosity adjusted maximum binding site density
K=np.array([1]) #Define dimensionless and porosity adjusted equilibrium constant
a=np.array([8]) #Define shape paramter for binding site profile
b=np.array([2]) #Define shape paramter for intersitital porosity profile
c=np.array([1.5]) #Define shape paramter for traditional proosity profile
eps=np.array([0.2]) #Define dimensionless minimum interstital porosity
rho=np.array([0]) #Define dimensionless minimum traditional porosity
Kp=np.array([1]) #Define partition coeffecient
ci=10**(-10) #Define the inital concentration in the biofilm (Can't be zero, if one wants to be zero, set it to a very small number instead)
#Calculating the gamma, epsilon and rho corresponding to a certain minimu porosity is done below
# phi_i_min=0.2 #Minimum interstitial porosity
# phi_p_min=0.2 #Minimum pore volume porosity
# eps=np.array([phi_i_min*np.tanh(b)/(1-phi_i_min)]) #Define dimensionless minimum interstital porosity
# rho=np.array([[phi_p_min*np.tanh(c)/(1-phi_p_min)]]) #Define dimensionless minimum traditional porosity
# effective_diffusivity=1
#Note: will want to rpint out porosity profile everytime now.
# %% Generate Parameter Matrix for Testing
[parameter_matrix,parameter_combos_count,vn_parameter_matrix_generator]=parameter_matrix_generator(h,tol,t1,t2,nx,gamma,alpha,xi,eps,rho,K,a,b,c,Kp)
# %% Run parameters through numerical model (Heart of the Code)
[c_set,vn_parameter_checker,vn_method_of_lines,vn_RJ] = parameter_checker(parameter_matrix,ci) #output the set of concentration over time and space results for each set of parameters tested
# %% Export results to csv files
vn_csv_generator = csv_generator(c_set,parameter_combos_count,parameter_matrix,direct_export_path,new_count_number,machine_number)
# %% Fit model to first order approximation, plot approximation, and determine fit of approximation
#[perc_acc_matrix,vn_linear_fitting]=linear_fit(c_set,parameter_combos_count,parameter_matrix,internal_export_path)
# %% Report Generator: Exports Plots as Word Document to Seperate Directory (see file N2_report_generator.py)
#report=plot_generator(c_set,parameter_combos_count,parameter_matrix,new_count_number,vn_N6,vn_Main_Code,vn_parameter_matrix_generator,vn_parameter_checker,vn_csv_generator,vn_method_of_lines,vn_RJ,perc_acc_matrix,vn_linear_fitting,machine_number,internal_export_path)
report=plot_generator(c_set,parameter_combos_count,parameter_matrix,new_count_number,vn_N6,vn_Main_Code,vn_parameter_matrix_generator,vn_parameter_checker,vn_csv_generator,vn_method_of_lines,vn_RJ,machine_number,internal_export_path)
# %% Stop Timer
#End timer
t_end=time.time()
total_time=t_end-t_start
print('Total time is {} sec'.format(total_time))
#%% To export report, turn on this code block
#Finish Report
para5=report.add_paragraph(f'Time to Run (sec): {total_time} ')
report_filename_partial=f'N6_report{new_count_number}-{machine_number}.docx'
report_filename_full=os.path.join(direct_export_path,report_filename_partial)
report.save(report_filename_full)
"""
Created on Tue Jun 16 16:13:07 2020
@author: joshuaprince
Overall N2.1 Computer Model Meta-data
Version 0.2
The code runs again and exports the report.
"""