from pomodoro.discs.expression import Expression from casadi import * import matplotlib.pyplot as plt from SolACE.MPCproblem import MPCproblem from SolACE.MPCsolve import MPCsolve t = time.time() prob = MPCproblem(50, t_control=10, total_plant=15) x = prob.addControllerStates(3, [0.0, 0.0, 0.0], [15.0, 30.0, 1000.0, 20.0]) w = prob.addControllerInputs(3, [-.5, -.5, 0.0], [.5] * 3) #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])
stream_7_conc[5] = p_F_r / pr_MPa stream_7_conc[6] = p_G_r / pr_MPa stream_7_conc[7] = p_H_r / pr_MPa stream_7_conc = MPC.prob.makeExpression(stream_7_conc) Qr = u[0] * cp_cw * (T_CWSr_out - T_CWSr_in) / 1000.0 press_m_r_diff = sqrt(pm_MPa - pr_MPa) stream_6_flow = 0.8333711713 * (press_m_r_diff) ps_MPa = 2.70 press_r_s_diff = sqrt(pr_MPa - ps_MPa) stream_7_flow = 1.53546206685993 * press_r_s_diff rhs = Expression(SX.zeros(18)) rhs[0] = u[ 3] * stream_1_conc_A + stream_5_flow * stream_5_conc_A + stream_8_flow * stream_8_conc_A - stream_6_flow * ( mixing[0] / mixing_zone_N) rhs[1] = u[3] * stream_1_conc_B + u[ 1] * stream_2_conc_B + stream_5_flow * stream_5_conc_B + stream_8_flow * stream_8_conc_B - stream_6_flow * ( mixing[1] / mixing_zone_N) rhs[2] = stream_5_flow * stream_5_conc_C + stream_8_flow * stream_8_conc_C - stream_6_flow * ( mixing[2] / mixing_zone_N) rhs[3] = u[ 1] * stream_2_conc_D + stream_5_flow * stream_5_conc_D + stream_8_flow * stream_8_conc_D - stream_6_flow * ( mixing[3] / mixing_zone_N) rhs[4] = u[ 2] * stream_3_conc_E + stream_5_flow * stream_5_conc_E + stream_8_flow * stream_8_conc_E - stream_6_flow * ( mixing[4] / mixing_zone_N) rhs[5] = u[
MPC = MPCproblem(50, total_plant=1500.0) x = MPC.addControllerStates(6, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) u = MPC.addControllerInputs(2, [2.0, 50.0], [10, 150]) k1 = 1.6599e6 * exp(-6666.37 / (273.15 + u[1])) k2 = 7.2117e8 * exp(-8333.3 / (273.15 + u[1])) k3 = 2.6745e12 * exp(-11111.0 / (273.15 + u[1])) #Fa = prob1.addFixedParameters(1) #Fa.setPVals(NP.array([2.4])) r1 = k1 * x[0] * x[1] * W r2 = k2 * x[1] * x[2] * W r3 = k3 * x[2] * x[5] * W rhs = Expression(SX.zeros(6)) rhs[0] = Fa - (Fa + u[0]) * x[0] - r1 rhs[1] = u[0] - (Fa + u[0]) * x[1] - r1 - r2 rhs[2] = -(Fa + u[0]) * x[2] + 2 * r1 - 2 * r2 - r3 rhs[3] = -(Fa + u[0]) * x[3] + r2 rhs[4] = -(Fa + u[0]) * x[4] + 1.5 * r3 rhs[5] = -(Fa + u[0]) * x[5] + r2 - 0.5 * r3 MPC.addControllerODEs(x, rhs) f1 = -sum(5554.1 * (Fa + u[0]('coll')) * x[5]('coll') + 125.91 * (Fa + u[0]('coll')) * x[3]('coll') - 370.3 * Fa - 555.42 * u[0]('coll')) MPC.addControlObjective(f1) x1 = MPC.addPlantStates(6) u1 = MPC.addPlantInputs(2)
S55 = 0.0000005 r0 = NP.array([2.14, 1.09, 114.2, 112.9, 14.19, -1113.5]) r1 = NP.array([2.9805,0.9612,106.0,100.75,18.038,-4565.88]) r2 = NP.array([3.5176,0.7395,87.0,79.8,8.256,-6239.33]) tph = 3600.0 x0 = NP.array([1.0,0.5,100.0,100.0]) ##################### MPC = MPCproblem(50,total_plant=3000) x = MPC.addControllerStates(4,[0.0,0.0,50.0,50.0,-1.0e06],[10.0,10.0,250.0,250.0,1.0e06],[2.14,1.09,114.2,112.9,0.0]) u = MPC.addControllerInputs(2,[3.0,-9000.0],[35.0,0.0]) rhs = Expression(SX.zeros(4)) cA = x[0] cB = x[1] theta = x[2] thetaK = x[3] k1 = k10*exp(E1/(273.15 +theta)) k2 = k20*exp(E2/(273.15 +theta)) k3 = k30*exp(E3/(273.15 +theta)) r = r0 X0 = x[0]-r[0] X1 = x[1]-r[1] X2 = x[2]-r[2] X3 = x[3]-r[3] U1 = u[0]-r[4]
S55 = 0.0000005 r0 = NP.array([2.14, 1.09, 114.2, 112.9, 14.19, -1113.5]) r1 = NP.array([2.9805,0.9612,106.0,100.75,18.038,-4565.88]) r2 = NP.array([3.5176,0.7395,87.0,79.8,8.256,-6239.33]) tph = 3600.0 x0 = NP.array([1.0,0.5,100.0,100.0]) ##################### MPC = MPCproblem(300,total_plant=3000) x = MPC.addControllerStates(4,[0.0,0.0,50.0,50.0,-1.0e06],[10.0,10.0,250.0,250.0,1.0e06],[2.14,1.09,114.2,112.9,0.0]) u = MPC.addControllerInputs(2,[3.0,-9000.0],[35.0,0.0]) rhs = Expression(SX.zeros(4)) cA = x[0] cB = x[1] theta = x[2] thetaK = x[3] k1 = k10*exp(E1/(273.15 +theta)) k2 = k20*exp(E2/(273.15 +theta)) k3 = k30*exp(E3/(273.15 +theta)) r = r0 X0 = x[0]-r[0] X1 = x[1]-r[1] X2 = x[2]-r[2] X3 = x[3]-r[3] U1 = u[0]-r[4]