Ejemplo n.º 1
0
    #=========================================================================

    # 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',
                  'Temp']  # the indices of the rate rxns
    # note the fifth, sixth and seventh components. Which basically work as inputs

    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')
Ejemplo n.º 2
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):
        algebraics = list()
Ejemplo n.º 3
0
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']) / (
            (328.0 - m.X[t, 'T'])**2 + 1e-5**2)**0.5
Ejemplo n.º 4
0
    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)

    # define explicit system of ODEs
Ejemplo n.º 5
0
        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)

    # create an instance of a casadi model template
Ejemplo n.º 6
0
    # 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

    # define explicit system of ODEs
    # DEFINE MODEL FOR ALL EXPERIMENTS
    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']
Ejemplo n.º 7
0
    #=========================================================================
       
    
    # 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']
        exprs['B'] = m.P['k1']*m.Z[t,'A']-m.P['k2']*m.Z[t,'B']-m.P['k3']*m.Z[t,'B']
Ejemplo n.º 8
0
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
        vo = 240