with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # ========================================================================= # USER INPUT SECTION - MODEL BUILDING - See user guide for how this section functions # ========================================================================= # read S matrix wl_span = np.arange(180, 230, 1) #1599,1852, 5) S_parameters = Lorentzian_parameters() S_frame = generate_absorbance_data(wl_span, S_parameters) # create template model builder = TemplateBuilder() # components components = dict() components['A'] = 0.395555 components['B'] = 0.0351202 components['C'] = 0.0 components['D'] = 0.0 components['E'] = 0.0 components['F'] = 0.0 components['G'] = 0.0 builder.add_mixture_component(components) # add algebraics
#USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= # Load spectral data from the relevant file location. As described in section 4.3.1 ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath( inspect.getfile( inspect.currentframe() ) ) ), 'data_sets')) filename = os.path.join(dataDirectory,'Dij.txt') D_frame = read_spectral_data_from_txt(filename) # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_spectral_data ################################################################################# builder = TemplateBuilder() components = {'A':1e-3,'B':0,'C':0} builder.add_mixture_component(components) builder.add_parameter('k1', init=2.0, bounds=(1.0,5.0)) #There is also the option of providing initial values: Just add init=... as additional argument as above. builder.add_parameter('k2',init = 0.2, bounds=(0.0,1)) builder.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m,t): exprs = dict() exprs['A'] = -m.P['k1']*m.Z[t,'A'] exprs['B'] = m.P['k1']*m.Z[t,'A']-m.P['k2']*m.Z[t,'B'] exprs['C'] = m.P['k2']*m.Z[t,'B'] return exprs
if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # read 300x100 spectra matrix D_{i,j} # this defines the measurement points t_i and l_j as well dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), '..', '..', 'data_sets')) filename = os.path.join(dataDirectory, 'Dij.txt') D_frame = read_spectral_data_from_txt(filename) ###################################### builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) # note the parameter is not fixed builder.add_parameter('k1', bounds=(0.0, 5.0)) builder.add_parameter('k2', bounds=(0.0, 1.0)) builder.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs
from kipet.library.TemplateBuilder import * from kipet.library.CasadiSimulator import * import matplotlib.pyplot as plt import sys import os if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() components = {'A': 1, 'B': 0.8, 'C': 0, 'D': 0} builder.add_mixture_component(components) builder.add_parameter('k1', 2.0) builder.add_parameter('k2', 1.0) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] * m.Z[t, 'B'] exprs['B'] = -m.P['k1'] * m.Z[t, 'A'] * m.Z[t, 'B'] exprs['C'] = m.P['k1'] * m.Z[t, 'A'] * m.Z[ t, 'B'] - 2 * m.P['k2'] * m.Z[t, 'C']**2 exprs['D'] = m.P['k2'] * m.Z[t, 'C']**2 return exprs
#========================================================================= # Load spectral data from the relevant file location. As described in section 4.3.1 ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets')) filename = os.path.join(dataDirectory, 'Dij.txt') D_frame = read_spectral_data_from_txt(filename) # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_spectral_data ################################################################################# builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', 4.0) #init=4.0, bounds=(0.0,5.0)) #There is also the option of providing initial values: Just add init=... as additional argument as above. builder.add_parameter('k2', bounds=(0.0, 1.0)) builder.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs
filename2 = os.path.join(dataDirectory, 'Dij_exp3_reduced.txt') D_frame1 = read_spectral_data_from_txt(filename1) D_frame2 = read_spectral_data_from_txt(filename2) #This function can be used to remove a certain number of wavelengths from data # in this case only every 2nd wavelength is included D_frame1 = decrease_wavelengths(D_frame1, A_set=2) #Here we add noise to datasets in order to make our data differenct between experiments D_frame2 = add_noise_to_signal(D_frame2, 0.00001) D_frame2 = decrease_wavelengths(D_frame2, A_set=2) #D_frame3 = add_noise_to_signal(D_frame2, 0.0004) ################################################################################# builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', init=1.0, bounds=(0.00, 10)) #There is also the option of providing initial values: Just add init=... as additional argument as above. builder.add_parameter('k2', init=0.224, bounds=(0.0, 10)) # If you have multiple experiments, you need to add your experimental datasets to a dictionary: datasets = {'Exp1': D_frame1, 'Exp2': D_frame2} #, 'Exp3': D_frame3} # Additionally, we do not add the spectral data to the TemplateBuilder, rather supplying the # TemplateBuilder before data is added as an argument into the function # define explicit system of ODEs def rule_odes(m, t):
if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # read 500x2 S matrix wl_span = np.arange(180, 230, 10) S_parameters = Lorentzian_parameters() S_frame = generate_absorbance_data(wl_span, S_parameters) # components concentrations = {'A': 1, 'B': 0} # create template model builder = TemplateBuilder() builder.add_mixture_component(concentrations) builder.add_parameter('k', 0.1) builder.add_absorption_data(S_frame) builder.add_measurement_times([i for i in range(0, 50, 10)]) dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), '..', 'data_sets')) # filename = os.path.join(dataDirectory,'Dij_case52a.txt') filename = os.path.join(dataDirectory, 'Sij_small.txt') write_absorption_data_to_txt(filename, S_frame)
#USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= # Load spectral data from the relevant file location. As described in section 4.3.1 ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath( inspect.getfile( inspect.currentframe() ) ) ), 'data_sets')) filename = os.path.join(dataDirectory,'new_estim_problem_conc.csv') D_frame = read_concentration_data_from_csv(filename) # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_concentration_data ################################################################################# builder = TemplateBuilder() builder.add_mixture_component('A',0.3) builder.add_mixture_component('B',0.0) builder.add_mixture_component('C',0.0) builder.add_mixture_component('D',0.01) builder.add_mixture_component('E',0.0) #Following this we add the kinetic parameters builder.add_parameter('k1',bounds=(0.1,2)) builder.add_parameter('k2',bounds=(0.0,2)) builder.add_parameter('k3',bounds=(0.0,2)) builder.add_parameter('k4',bounds=(0.0,2)) # define explicit system of ODEs def rule_odes(m,t): exprs = dict() exprs['A'] = -m.P['k1']*m.Z[t,'A']-m.P['k4']*m.Z[t,'A']
with_plots = True if len(sys.argv)==2: if int(sys.argv[1]): with_plots = False #========================================================================= #USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= ###################################### # create template model species = {'A':6.7, 'B':20.2, 'C':0.0} params = {'k_p':3.734e7} builder = TemplateBuilder() builder = TemplateBuilder(concentrations=species, parameters=params) #extra_states=dict() #extra_states['T']=290.0 builder.add_complementary_state_variable('T',290.0) # define explicit system of ODEs def rule_odes(m,t): r = m.P['k_p']*exp(-15400.0/(1.987*m.X[t,'T']))*m.Z[t,'A']*m.Z[t,'B'] T1 = 45650.0*(r*0.01)/28.0 T2 = 1+(328.0-m.X[t,'T'])/((328.0-m.X[t,'T'])**2+1e-5**2)**0.5 exprs = dict() exprs['A'] = -r exprs['B'] = -r
from kipet.library.TemplateBuilder import * from kipet.library.PyomoSimulator import * import matplotlib.pyplot as plt from pyomo.core import * import sys if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() builder.add_mixture_component('A', 1.0) builder.add_mixture_component('B', 0.0) builder.add_mixture_component('C', 0.0) builder.add_complementary_state_variable('T', 290.0) builder.add_complementary_state_variable('V', 100.0) # define explicit system of ODEs def rule_odes(m, t): k1 = 1.25 * exp((9500 / 1.987) * (1 / 320.0 - 1 / m.X[t, 'T'])) k2 = 0.08 * exp((7000 / 1.987) * (1 / 290.0 - 1 / m.X[t, 'T'])) ra = -k1 * m.Z[t, 'A'] rb = 0.5 * k1 * m.Z[t, 'A'] - k2 * m.Z[t, 'B'] rc = 3 * k2 * m.Z[t, 'B'] cao = 4.0
# \frac{dZ_b}{dt} = k*Z_a Z_b(0) = 0 from kipet.library.TemplateBuilder import * from kipet.library.PyomoSimulator import * import matplotlib.pyplot as plt import sys if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() builder.add_mixture_component('A', 1) builder.add_mixture_component('B', 0) builder.add_parameter('k', 0.01) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k'] * m.Z[t, 'A'] exprs['B'] = m.P['k'] * m.Z[t, 'A'] return exprs builder.set_odes_rule(rule_odes) # create an instance of a pyomo model template # the template includes
import os from itertools import count, takewhile if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # ========================================================================= # USER INPUT SECTION - MODEL BUILDING - See user guide for how this section functions # ========================================================================= # create template model builder = TemplateBuilder() # components components = dict() components['A'] = 0.395555 components['B'] = 0.0351202 components['C'] = 0.0 components['D'] = 0.0 components['E'] = 0.0 components['F'] = 0.0 components['G'] = 0.0 builder.add_mixture_component(components) # add algebraics algebraics = ['0', '1', '2', '3', '4', '5']#, 'Temp'] # the indices of the rate rxns
#USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= # Load concentration data from the relevant file location. As described in section 4.3.1 ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets')) filename = os.path.join(dataDirectory, 'Ex_1_C_data_withoutA.csv') C_frame1 = read_concentration_data_from_csv(filename) C_frame2 = add_noise_to_signal(C_frame1, 0.0001) ################################################################################# builder = TemplateBuilder() builder2 = TemplateBuilder() components = {'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', init=1.0, bounds=(0.00, 10)) #There is also the option of providing initial values: Just add init=... as additional argument as above. builder.add_parameter('k2', init=0.224, bounds=(0.0, 10)) builder2.add_mixture_component(components) builder2.add_parameter('k1', init=1.0, bounds=(0.00, 10)) # There is also the option of providing initial values: Just add init=... as additional argument as above. builder2.add_parameter('k2', init=0.224, bounds=(0.0, 10)) #A and A2 are the states that we want to estimate the initial condition for, they are not measured: #add complementary state variable: extra_states1 = dict()
#========================================================================= # Load spectral data from the relevant file location. As described in section 4.3.1 ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets')) filename = os.path.join(dataDirectory, 'Dij.txt') D_frame = read_spectral_data_from_txt(filename) # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_spectral_data ################################################################################# builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', init=4.0, bounds=(0.0, 5.0)) #There is also the option of providing initial values: Just add init=... as additional argument as above. builder.add_parameter('k2', bounds=(0.0, 1.0)) builder.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs
with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # ========================================================================= # USER INPUT SECTION - MODEL BUILDING - See user guide for how this section functions # ========================================================================= # read S matrix wl_span = np.arange(180,230, 1)#1599,1852, 5) S_parameters = Lorentzian_parameters() S_frame = generate_absorbance_data(wl_span, S_parameters) # create template model builder = TemplateBuilder() # components components = dict() components['A'] = 1e-3 components['B'] = 0.0 components['C'] = 0.0 components['D'] = 1e-3 components['E'] = 0 builder.add_mixture_component(components) params = dict() params['k1'] = 1.5 params['k2'] = 0.2
with_plots = True if len(sys.argv)==2: if int(sys.argv[1]): with_plots = False # read 200x500 spectra matrix D_{i,j} # this defines the measurement points t_i and l_j as well dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath( inspect.getfile( inspect.currentframe() ) ) ), '..','..','data_sets')) filename = os.path.join(dataDirectory,'Dijsawall.txt') D_frame = read_spectral_data_from_txt(filename) ########################################################## builder2 = TemplateBuilder() builder2.add_mixture_component({'A':1,'B':0}) # note the parameter is not fixed builder2.add_parameter('k',bounds=(0.0,1)) builder2.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m,t): exprs = dict() exprs['A'] = -m.P['k']*m.Z[t,'A'] exprs['B'] = m.P['k']*m.Z[t,'A'] return exprs builder2.set_odes_rule(rule_odes)
if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # read 100x3 S matrix # this defines the measurement lambdas l_j but the t_i still need to be passed dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), '..', '..', 'data_sets')) filename = os.path.join(dataDirectory, 'Slk_case51a.txt') S_frame = read_absorption_data_from_txt(filename) # create template model builder = TemplateBuilder() builder.add_mixture_component('A', 1) builder.add_mixture_component('B', 0) builder.add_mixture_component('C', 0) builder.add_parameter('k1', 2.0) builder.add_parameter('k2', 0.2) # includes absorption data in the template and defines measurement sets builder.add_absorption_data(S_frame) builder.add_measurement_times([i * 0.0333 for i in range(300)]) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B']
if __name__ == "__main__": with_plots = True if len(sys.argv)==2: if int(sys.argv[1]): with_plots = False #========================================================================= #USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_spectral_data ################################################################################# builder = TemplateBuilder() components = {'A':1e-3,'B':0,'C':0} builder.add_mixture_component(components) algebraics=['1','2','3','k2T','Temp'] builder.add_algebraic_variable(algebraics) # Load Temp data: dataDirectory = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(inspect.getfile( inspect.currentframe()))), 'data_sets')) Ttraj = os.path.join(dataDirectory, 'Tempvalues.csv') fixed_Ttraj = read_absorption_data_from_csv(Ttraj) params = dict() params['k1'] = 1.0
# \frac{dZ_c}{dt} = k_2*Z_b Z_c(0) = 0 from kipet.library.TemplateBuilder import * from kipet.library.PyomoSimulator import * import matplotlib.pyplot as plt import sys if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() builder.add_mixture_component('A', 1) builder.add_mixture_component('B', 0) builder.add_mixture_component('C', 0) builder.add_parameter('k1', 2.0) builder.add_parameter('k2', 0.2) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs builder.set_odes_rule(rule_odes)
# \frac{dC_b}{dt} = k*C_a C_b(0) = 0 from kipet.library.TemplateBuilder import * from kipet.library.CasadiSimulator import * import matplotlib.pyplot as plt import sys if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() builder.add_mixture_component('A', 1) builder.add_mixture_component('B', 0) builder.add_algebraic_variable('ra') builder.add_parameter('k', 0.01) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.Y[t, 'ra'] exprs['B'] = m.Y[t, 'ra'] return exprs builder.set_odes_rule(rule_odes) def rule_algebraics(m, t):
#USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= # Load spectral data ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets')) filename = os.path.join(dataDirectory, 'Dij.txt') D_frame = read_spectral_data_from_txt(filename) # build dae block for optimization problems ################################################################################# builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', bounds=(0.1, 4.0)) builder.add_parameter('k2', bounds=(0.01, 1.0)) builder.add_spectral_data(D_frame) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs builder.set_odes_rule(rule_odes)
from kipet.library.TemplateBuilder import * from kipet.library.CasadiSimulator import * import matplotlib.pyplot as plt import casadi as ca import sys if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() builder.add_mixture_component('A', 6.7) builder.add_mixture_component('B', 20.0) builder.add_mixture_component('C', 0.0) builder.add_complementary_state_variable('T', 290.0) builder.add_parameter('k_p', 3.734e7) # define explicit system of ODEs def rule_odes(m, t): r = -m.P['k_p'] * ca.exp( -15400.0 / (1.987 * m.X[t, 'T'])) * m.Z[t, 'A'] * m.Z[t, 'B'] T1 = 45650.0 * (-r * 0.01) / 28.0 #T2 = ca.if_else(m.X[t,'T']>328.0,0.0,2.0) T2 = 1 + (328.0 - m.X[t, 'T']) / (
filename1 = os.path.join(dataDirectory, 'multexp4D.csv') filename2 = os.path.join(dataDirectory, 'multexp5D.csv') D_frame1 = read_spectral_data_from_csv(filename1, negatives_to_zero=True) D_frame2 = read_spectral_data_from_csv(filename2, negatives_to_zero=True) # We wish to add a third dataset that is just a more noisey version of 2 D_frame3 = add_noise_to_signal(D_frame2, 0.00001) # If you have multiple experiments, you need to add your experimental datasets to a dictionary: datasets = {'Exp1': D_frame1, 'Exp2': D_frame2, 'Exp3': D_frame3} #========================================================================= # EXPERIMENT 1 #========================================================================= #Initial conditions builder1 = TemplateBuilder() components1 = dict() components1['A'] = 1e-3 components1['B'] = 0.0 components1['C'] = 0.0 components1['D'] = 0.0 components1['E'] = 0 builder1.add_mixture_component(components1) builder1.add_parameter('k1', init=1.5, bounds=(0.001, 10)) builder1.add_parameter('k2', init=0.2, bounds=(0.0001, 5)) builder1.add_parameter('k3', init=0.4, bounds=(0.3, 2)) # Notice that, although we will not have any reaction for D and E, we still add this equation # This model acts as the main model for all experimental datasets
#========================================================================= # Load spectral data from the relevant file location. As described in section 4.3.1 ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets')) filename = os.path.join(dataDirectory, 'Ex_1_C_data.txt') C_frame = read_concentration_data_from_txt(filename) # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_spectral_data ################################################################################# builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', bounds=(0.0, 5.0)) builder.add_parameter('k2', bounds=(0.0, 1.0)) builder.add_concentration_data(C_frame) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] exprs['B'] = m.P['k1'] * m.Z[t, 'A'] - m.P['k2'] * m.Z[t, 'B'] exprs['C'] = m.P['k2'] * m.Z[t, 'B'] return exprs builder.set_odes_rule(rule_odes)
if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # read 200x500 D matrix # this defines the measurement points t_i and l_j as well dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), '..', '..', 'data_sets')) filename = os.path.join(dataDirectory, 'Slk_sawall.txt') S_frame = read_absorption_data_from_txt(filename) # create template model builder = TemplateBuilder() builder.add_mixture_component({'A': 1, 'B': 0}) builder.add_parameter('k', 0.01) # includes spectra data in the template and defines measurement sets builder.add_absorption_data(S_frame) builder.add_measurement_times([i for i in range(200)]) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k'] * m.Z[t, 'A'] exprs['B'] = m.P['k'] * m.Z[t, 'A'] return exprs builder.set_odes_rule(rule_odes)
from kipet.library.TemplateBuilder import * from kipet.library.PyomoSimulator import * import matplotlib.pyplot as plt import sys import os if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model builder = TemplateBuilder() components = {'A': 217.324e-3, 'B': 167.35e-3, 'C': 2.452e-3} builder.add_mixture_component(components) builder.add_parameter('k1', 0.00539048) # define explicit system of ODEs def rule_odes(m, t): exprs = dict() exprs['A'] = -m.P['k1'] * m.Z[t, 'A'] * m.Z[t, 'B'] exprs['B'] = -m.P['k1'] * m.Z[t, 'A'] * m.Z[t, 'B'] exprs['C'] = m.P['k1'] * m.Z[t, 'A'] * m.Z[t, 'B'] return exprs builder.set_odes_rule(rule_odes) # create an instance of a pyomo model template
import matplotlib.pyplot as plt from pyomo.core import * import sys if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False # create template model species = {'A': 6.7, 'B': 20.2, 'C': 0.0} params = {'k_p': 3.734e7} builder = TemplateBuilder(concentrations=species, parameters=params) builder.add_complementary_state_variable('T', 290.0) # define explicit system of ODEs def rule_odes(m, t): r = m.P['k_p'] * exp(-15400.0 / (1.987 * m.X[t, 'T'])) * m.Z[t, 'A'] * m.Z[t, 'B'] T1 = 45650.0 * (r * 0.01) / 28.0 #T2 = Expr_if(IF=m.X[t,'T']>328.0, THEN=0.0, ELSE=2.0) T2 = 1 + (328.0 - m.X[t, 'T']) / ( (328.0 - m.X[t, 'T'])**2 + 1e-5**2)**0.5 exprs = dict() exprs['A'] = -r exprs['B'] = -r exprs['C'] = r
import os import six if __name__ == "__main__": with_plots = True if len(sys.argv) == 2: if int(sys.argv[1]): with_plots = False #========================================================================= #USER INPUT SECTION - REQUIRED MODEL BUILDING ACTIONS #========================================================================= # create template model builder = TemplateBuilder() # components components = dict() components['AH'] = 0.395555 components['B'] = 0.0351202 components['C'] = 0.0 components['BH+'] = 0.0 components['A-'] = 0.0 components['AC-'] = 0.0 components['P'] = 0.0 builder.add_mixture_component(components) # add algebraics algebraics = ['0', '1', '2', '3', '4', '5', 'k4T',
import inspect import six import pandas as pd if __name__ == "__main__": with_plots = True if len(sys.argv)==2: if int(sys.argv[1]): with_plots = False #========================================================================= # SIMULATION MODEL #========================================================================= # First we will look to generate our data for each of our components in order # to build the C-matrix that we desire. We will look to give our species different # noise levels in order to also test whether the scaling for multiple levels works builder = TemplateBuilder() builder.add_mixture_component('A',0.5) builder.add_mixture_component('B',0.0) builder.add_mixture_component('C',0.0) builder.add_mixture_component('D',0.01) builder.add_mixture_component('E',0.0) builder.add_mixture_component('F',0.3) builder.add_mixture_component('G',0.5) builder.add_mixture_component('H',0.0) #Following this we add the kinetic parameters builder.add_parameter('k1',0.3) builder.add_parameter('k2',0.1) builder.add_parameter('k3',0.1) builder.add_parameter('k4',0.4) builder.add_parameter('k5',0.02)