Ejemplo n.º 1
0
            (328.0 - m.X[t, 'T'])**2 + 1e-5**2)**0.5
        exprs = dict()
        exprs['A'] = r
        exprs['B'] = r
        exprs['C'] = -r
        exprs['T'] = T1 + T2

        return exprs

    builder.set_odes_rule(rule_odes)

    # create an instance of a casadi model template
    casadi_model = builder.create_casadi_model(0.0, 20.0)

    # create instance of simulator
    sim = CasadiSimulator(casadi_model)
    # defines the discrete points wanted in the concentration profile
    sim.apply_discretization('integrator', nfe=200)
    # simulate
    results_casadi = sim.run_sim("cvodes")

    # display concentration results
    if with_plots:
        results_casadi.Z.plot.line(legend=True)
        plt.xlabel("time (s)")
        plt.ylabel("Concentration (mol/L)")
        plt.title("Concentration Profile")

        results_casadi.X.plot.line(legend=True)
        plt.xlabel("time (s)")
        plt.ylabel("Temperature (K)")
Ejemplo n.º 2
0
        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
    # the template includes
    #   - Z variables indexed over time and components names e.g. m.Z[t,'A']
    #   - C variables indexed over measurement t_i and components names e.g. m.C[t_i,'A']
    #   - P parameters indexed over the parameter names m.P['k']
    #   - D spectra data indexed over the t_i, l_j measurement points m.D[t_i,l_j]
    casadi_model = builder.create_casadi_model(0.0, 200.0)

    # create instance of simulator
    sim = CasadiSimulator(casadi_model)
    # defines the discrete points wanted in the profiles (does not include measurement points)
    sim.apply_discretization('integrator', nfe=500)
    # simulate

    sigmas = {'device': 1e-6, 'A': 1e-5, 'B': 1e-5}
    results_casadi = sim.run_sim("cvodes", variances=sigmas, seed=123453256)

    if with_plots:
        # displary concentrations and absorbances results
        results_casadi.C.plot.line(legend=True)
        plt.xlabel("time (s)")
        plt.ylabel("Concentration (mol/L)")
        plt.title("Concentration Profile")

        # take a look at the data