示例#1
0
    # 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)
    sim_model = builder.create_pyomo_model(0.0, 50.0)

    #################################################################################
    #: non absorbing species.

    non_abs = ['C']
    builder.set_non_absorbing_species(sim_model, non_abs)
    #################################################################################
    #=========================================================================
    #USER INPUT SECTION - SIMULATOR - See user guide for how this section functions
    #=========================================================================

    # create instance of simulator
    simulator = PyomoSimulator(sim_model)
    simulator.apply_discretization('dae.collocation',
                                   nfe=20,
                                   ncp=3,
                                   scheme='LAGRANGE-RADAU')

    # simulate with fixed variances
    sigmas = {'device': 1e-8, 'A': 1e-6, 'B': 1e-7}
    results_sim = simulator.run_sim('ipopt',
            exprs[c] = gammas[c][0] * m.Y[t, '0'] + gammas[c][1] * m.Y[t, '1']+gammas[c][2] * m.Y[t, '2']+gammas[c][3] * m.Y[t, '3']+ gammas[c][4] * m.Y[t, '4'] - exprs['V'] / V * m.Z[t, c]
            if c == 'C':
                exprs[c] += 0.02247311828 / (m.X[t, 'V'] * 210) * step
        return exprs


    builder.set_odes_rule(rule_odes)
    
    #Add time points where feed as discrete jump should take place:
    feed_times=[101.035, 303.126]#, 400.
    builder.add_feed_times(feed_times)

    model = builder.create_pyomo_model(0, 600)

    non_abs = ['F']
    builder.set_non_absorbing_species(model, non_abs)
    
    #Load data:
    dataDirectory = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets'))

    filenameD =  os.path.join(dataDirectory,'FeCaseexamplewithoutTemp_D_data_input_noiselesspoints2.csv')
    D_frame = read_spectral_data_from_csv(filenameD)
    builder.add_spectral_data(D_frame)
    model = builder.create_pyomo_model(0., 600.) 
    
    #Absorbing Simulation for Initialization:
    #=========================================================================
    #USER INPUT SECTION - FE Factory
    #=========================================================================
     
    #call FESimulator