예제 #1
0
    #USER INPUT SECTION - SIMULATION
    #=========================================================================
  
    sim = PyomoSimulator(model)
    # defines the discrete points wanted in the concentration profile
    sim.apply_discretization('dae.collocation',nfe=100,ncp=3,scheme='LAGRANGE-RADAU')
    fe_l = sim.model.alltime.get_finite_elements()
    fe_list = [fe_l[i + 1] - fe_l[i] for i in range(0, len(fe_l) - 1)]
    nfe = len(fe_list)  #: Create a list with the step-size
    print(nfe)
    # sys.exit()
    # good initialization

    filename_initZ = os.path.join(dataDirectory, 'init_Z.csv')#Use absolute paths
    initialization = pd.read_csv(filename_initZ,index_col=0)
    sim.initialize_from_trajectory('Z',initialization)
    filename_initX = os.path.join(dataDirectory, 'init_X.csv')#Use absolute paths
    initialization = pd.read_csv(filename_initX,index_col=0)
    sim.initialize_from_trajectory('X',initialization)
    filename_initY = os.path.join(dataDirectory, 'init_Y.csv')#Use absolute paths
    initialization = pd.read_csv(filename_initY,index_col=0)
    sim.initialize_from_trajectory('Y',initialization)
            
    sim.fix_from_trajectory('Y','Csat',fixed_traj)
    sim.fix_from_trajectory('Y','f',fixed_traj)

    with open("f0.txt", "w") as f:
        for t in sim.model.alltime:
            val = value(sim.model.Y[t, 'f'])
            f.write('\t' + str(t) + '\t' + str(val) + '\n')
        f.close()
예제 #2
0
                                   nfe=30,
                                   ncp=1,
                                   scheme='LAGRANGE-RADAU')

    # simulate
    results_pyomo = simulator.run_sim('ipopt', tee=True)

    # second model to scale and initialize
    scaled_model = builder.create_pyomo_model(0.0, 200.0)
    scaled_sim = PyomoSimulator(scaled_model)
    scaled_sim.apply_discretization('dae.collocation',
                                    nfe=30,
                                    ncp=1,
                                    scheme='LAGRANGE-RADAU')

    scaled_sim.initialize_from_trajectory('Z', results_pyomo.Z)
    scaled_sim.initialize_from_trajectory('dZdt', results_pyomo.dZdt)

    scaled_sim.scale_variables_from_trajectory('Z', results_pyomo.Z)
    scaled_sim.scale_variables_from_trajectory('dZdt', results_pyomo.dZdt)

    solver_options = dict()
    solver_options['nlp_scaling_method'] = 'user-scaling'
    #solver_options['bound_relax_factor'] = 0.0
    #solver_options['mu_init'] =  1e-6
    #solver_options['bound_push'] = 1e-6

    # simulate scaled model
    results_scaled = scaled_sim.run_sim('ipopt',
                                        tee=True,
                                        solver_opts=solver_options)