u = prob.addControllerInputs(1, [0.0], [1.0]) rhs = Expression(SX.zeros(3)) rhs[0] = x[0] - x[0] * x[1] + w[0] rhs[1] = -x[1] + x[0] * x[1] + u * x[2] * x[1] + w[1] rhs[2] = -x[2] + 0.50 + w[2] m = SX.zeros(2, 2) m[0, 0] = 2 + 1.414 m[1, 0] = 1 + 1.414 m[0, 1] = 1 + 1.414 m[1, 1] = 1 + 1.414 prob.addControllerODEs(x, rhs) f = sum((1 - x[0]('coll')) * (1 - x[0]('coll')) + (1 - x[1]('coll')) * (1 - x[1]('coll')) + u('coll') * u('coll')) + (mul((mul( (x[0:2](-1).T, m)), x[0:2](-1)))) prob.addControlObjective(f) #prob.addConstraints(x(0),[1,1,0.50]) x1 = prob.addPlantStates(3) u1 = prob.addPlantInputs(1) rhs1 = SX.zeros(3) rhs1[0] = x1[0] - x1[0] * x1[1] rhs1[1] = -x1[1] + x1[0] * x1[1] + u1 * x1[2] * x1[1] rhs1[2] = -x1[2] + 0.50 prob.addPlantODEs(x1, rhs1) x0 = NP.array([1, 1, 0.50]) prob.setInitCondition(x0) solver = MPCsolve(prob, printlevel=0) solver.solve() solver.plotStates() # solver.plotControls() #
rhs[14] = stream_6_flow * (stream_6_conc[5]) - stream_7_flow * (stream_7_conc[5]) + reactor_conv_rate[5]; rhs[15] = stream_6_flow * (stream_6_conc[6]) - stream_7_flow * (stream_7_conc[6]) + reactor_conv_rate[6]; rhs[16] = stream_6_flow * (stream_6_conc[7]) - stream_7_flow * (stream_7_conc[7]) + reactor_conv_rate[7]; rhs[17] = ((1/1000.0) * stream_6_flow * stream_6_cp * (mixing[8] - reactor[8]) - Qr - reactor_exoth_heat)/reactor_Ncp; MPC.addControllerODEs(x,rhs) r = NP.array([393.5,2.745,25.93,114.5/3600.0,98.0/3600.0,11.2/3600.0,]) h = NP.array([reactor[8],pr_MPa,u[0],u[1],u[2],u[3]]) H = h - r S = [9.8657122193156304e-01,0.1428778068436973e-01,0.01,0.01,0.01,0.01] ff = sum(S[0]*H[0]('coll')*H[0]('coll')+S[1]*H[1]('coll')*H[1]('coll')+S[2]*H[2]('coll')*H[2]('coll')+S[3]*H[3]('coll')*H[3]('coll')+S[4]*H[4]('coll')*H[4]('coll')+S[5]*H[5]('coll')*H[5]('coll')) MPC.addControlObjective(ff) x1 = MPC.addPlantStates(18) u1 = MPC.addPlantInputs(4) mixing = x1[0:9] #mixing(8) is temperature reactor = x1[9:18] #reactor(8) is temperature mixing_zone_N = (mixing[0] + mixing[1] + mixing[2] + mixing[3] + mixing[4] + mixing[5] + mixing[6] + mixing[7]) pm_MPa = mixing_zone_N * (RkJ * mixing[8] / Vm) / 1000.0 stream_6_conc = SX.zeros(8) for i in range(8): stream_6_conc[i] = mixing[i]/mixing_zone_N # Energy balance for the mixing zone mixing_zone_Ncp = (mixing[0]*cp_vap_A + mixing[1]*cp_vap_B + mixing[2]*cp_vap_C
98.0 / 3600.0, 11.2 / 3600.0, ]) h = NP.array([reactor[8], pr_MPa, u[0], u[1], u[2], u[3]]) H = h - r S = [9.8657122193156304e-01, 0.1428778068436973e-01, 0.01, 0.01, 0.01, 0.01] ff = sum(S[0] * H[0]('coll') * H[0]('coll') + S[1] * H[1]('coll') * H[1]('coll') + S[2] * H[2]('coll') * H[2]('coll') + S[3] * H[3]('coll') * H[3]('coll') + S[4] * H[4]('coll') * H[4]('coll') + S[5] * H[5]('coll') * H[5]('coll')) MPC.addControlObjective(ff) x1 = MPC.addPlantStates(18) u1 = MPC.addPlantInputs(4) mixing = x1[0:9] #mixing(8) is temperature reactor = x1[9:18] #reactor(8) is temperature mixing_zone_N = (mixing[0] + mixing[1] + mixing[2] + mixing[3] + mixing[4] + mixing[5] + mixing[6] + mixing[7]) pm_MPa = mixing_zone_N * (RkJ * mixing[8] / Vm) / 1000.0 stream_6_conc = SX.zeros(8) for i in range(8): stream_6_conc[i] = mixing[i] / mixing_zone_N # Energy balance for the mixing zone
#w.fix() w.plot() u = prob.addControllerInputs(1,[0.0],[1.0]) rhs = Expression(SX.zeros(3)) rhs[0] = x[0] - x[0]*x[1] + w[0] rhs[1] = -x[1] + x[0]*x[1] + u*x[2]*x[1] + w[1] rhs[2] = -x[2] + 0.50 + w[2] m = SX.zeros(2,2) m[0,0] = 2 + 1.414 m[1,0] = 1 + 1.414 m[0,1] = 1 + 1.414 m[1,1] = 1 + 1.414 prob.addControllerODEs(x,rhs) f = sum((1 - x[0]('coll'))*(1 - x[0]('coll')) + (1 - x[1]('coll'))*(1-x[1]('coll')) + u('coll')*u('coll')) + (mul((mul((x[0:2](-1).T,m)),x[0:2](-1)))) prob.addControlObjective(f) #prob.addConstraints(x(0),[1,1,0.50]) x1 = prob.addPlantStates(3) u1 = prob.addPlantInputs(1) rhs1 = SX.zeros(3) rhs1[0] = x1[0] - x1[0]*x1[1] rhs1[1] = -x1[1] + x1[0]*x1[1] + u1*x1[2]*x1[1] rhs1[2] = -x1[2] + 0.50 prob.addPlantODEs(x1,rhs1) x0 = NP.array([1,1,0.50]) prob.setInitCondition(x0) solver = MPCsolve(prob,printlevel=0) solver.solve() solver.plotStates()# solver.plotControls()#