os.path.join( os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))), 'data_sets')) filename = os.path.join(dataDirectory, 'Ex_1_C_data.txt') C_frame = read_concentration_data_from_txt(filename) # Then we build dae block for as described in the section 4.2.1. Note the addition # of the data using .add_spectral_data ################################################################################# builder = TemplateBuilder() components = {'A': 1e-3, 'B': 0, 'C': 0} builder.add_mixture_component(components) builder.add_parameter('k1', bounds=(0.0, 5.0)) builder.add_parameter('k2', bounds=(0.0, 1.0)) builder.add_concentration_data(C_frame) # 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) opt_model = builder.create_pyomo_model(0.0, 10.0) #opt_model.C.pprint() #========================================================================= #USER INPUT SECTION - VARIANCE GIVEN #=========================================================================
# create an instance of a pyomo model template # the template includes # - Z variables indexed over time and components names e.g. m.Z[t,'A'] # - P parameters indexed over the parameter names e.g. m.P['k'] feed_times=[2.51, 10.0, 15.0]#set with declared feeding points builder.add_feed_times(feed_times)#have to add feed times first! # Load concentration data ################################################################################# dataDirectory = os.path.abspath( os.path.join( os.path.dirname( os.path.abspath( inspect.getfile( inspect.currentframe() ) ) ), 'data_sets')) filename = os.path.join(dataDirectory,'Ad5_C_data_input_noise2.csv') C_frame = read_concentration_data_from_csv(filename) builder.add_concentration_data(C_frame) #has to be added here already to use for initialization as well pyomo_model = builder.create_pyomo_model(0.0,20.0) #========================================================================= #USER INPUT SECTION - FE Factory #========================================================================= # call FESimulator # FESimulator re-constructs the current TemplateBuilder into fe_factory syntax # there is no need to call PyomoSimulator any more as FESimulator is a child class sim = FESimulator(pyomo_model) # defines the discrete points wanted in the concentration profile sim.apply_discretization('dae.collocation', nfe=40, ncp=3, scheme='LAGRANGE-RADAU') #New Inputs for discrete feeds