コード例 #1
0
ファイル: ode_conditional_sim.py プロジェクト: schenkch/kipet
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
        exprs = dict()
        exprs['A'] = r
        exprs['B'] = r
        exprs['C'] = -r
コード例 #2
0
    params = dict()
    params['k0'] = 49.7796
    params['k1'] = 8.93156
    params['k2'] = 1.31765
    params['k3'] = 0.310870
    params['k4Tr'] = 3.87809
    params['E'] = 20.

    builder.add_parameter(params)

    # add additional state variables
    extra_states = dict()
    extra_states['V'] = 0.0629418

    builder.add_complementary_state_variable(extra_states)

    # stoichiometric coefficients
    gammas = dict()
    gammas['AH'] = [-1, 0, 0, -1, 0]
    gammas['B'] = [-1, 0, 0, 0, 1]
    gammas['C'] = [0, -1, 1, 0, 0]
    gammas['BH+'] = [1, 0, 0, 0, -1]
    gammas['A-'] = [1, -1, 1, 1, 0]
    gammas['AC-'] = [0, 1, -1, -1, -1]
    gammas['P'] = [0, 0, 0, 1, 1]

    def rule_algebraics(m, t):
        r = list()
        r.append(m.Y[t, '0'] - m.P['k0'] * m.Z[t, 'AH'] * m.Z[t, 'B'])
        r.append(m.Y[t, '1'] - m.P['k1'] * m.Z[t, 'A-'] * m.Z[t, 'C'])
コード例 #3
0
    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()
    extra_states1['A'] = 1e-3
    builder.add_complementary_state_variable(extra_states1)

    extra_states2 = dict()
    extra_states2['A2'] = 1e-3
    builder2.add_complementary_state_variable(extra_states2)

    # If you have multiple experiments, you need to add your experimental datasets to a dictionary:
    datasets = {'Exp1': C_frame1, 'Exp2': C_frame2}

    #Notice that we do not add the data to the model as we did in the past, rather we pass this as
    #an argument into the function later on.

    # define explicit system of ODEs
    def rule_odes(m, t):
        exprs = dict()
        exprs['A'] = -m.P['k1'] * m.X[t, 'A']