def _og_inequality(self, prob, obj): """ define inequality conditions """ s = [prob.states_all_section(i) for i in range(5)] result = Condition() u_m = prob.controls(0, 0) u_a = prob.controls(1, 0) result.lower_bound(u_m, 0) result.upper_bound(u_m, 1) result.lower_bound(u_a, (-np.pi/2)) #thrust force to the left result.upper_bound(u_a, (+np.pi/2)) #thrust force to the right #bound states for i in range(5): result.lower_bound(s[i], obj.ranges[i][0]) result.upper_bound(s[i], obj.ranges[i][1]) #cone constraint result.lower_bound(s[1], 1.*s[0]) # z > (1/tan(th)) * x return result()
def equality(prob, obj): R = prob.states_all_section(0) v = prob.states_all_section(1) m = prob.states_all_section(2) T = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # event condition result.equal(R[0], obj.Re) result.equal(v[0], 0.0) result.equal(m[0], obj.M0) result.equal(v[-1], 0.0) result.equal(m[-1], obj.M0_2nd * obj.Mc) # knotting condition R1 = prob.states(0, 0) v1 = prob.states(1, 0) m1 = prob.states(2, 0) R2 = prob.states(0, 1) v2 = prob.states(1, 1) m2 = prob.states(2, 1) result.equal(R1[-1], R2[0]) result.equal(v1[-1], v2[0]) result.equal(m1[-1], m2[0] - 1200) return result()
def inequality(prob, obj): r = prob.states_all_section(0) vr = prob.states_all_section(1) vt = prob.states_all_section(2) ur1 = prob.controls_all_section(0) ur2 = prob.controls_all_section(1) ut1 = prob.controls_all_section(2) ut2 = prob.controls_all_section(3) tf = prob.time_final(-1) result = Condition() # lower bounds result.lower_bound(r, obj.r0) result.lower_bound(ur1, 0.0) result.lower_bound(ut1, 0.0) result.lower_bound(ur2, 0.0) result.lower_bound(ut2, 0.0) result.lower_bound(tf, 0.0) # upper bounds result.upper_bound(r, obj.rf) result.upper_bound(ur1, obj.u_max) result.upper_bound(ut1, obj.u_max) result.upper_bound(ur2, obj.u_max) result.upper_bound(ut2, obj.u_max) result.upper_bound(tf, obj.tf_max) return result()
def cost_derivative(prob, obj): jac = Condition(prob.number_of_variables) index_m0 = prob.index_states(4, 0, 0) index_mf = prob.index_states(4, 0, -1) m = prob.states_all_section(4) # jac.change_value(index_m0, - m[-1] / m[0]**2) # jac.change_value(index_mf, - 1.0 / m[0]) jac.change_value(index_mf, -1.0) return jac()
def equality(prob, obj): R = prob.states_all_section(0) theta = prob.states_all_section(1) Vr = prob.states_all_section(2) Vt = prob.states_all_section(3) m = prob.states_all_section(4) Tr = prob.controls_all_section(0) Tt = prob.controls_all_section(1) tf = prob.time_final(-1) R0 = prob.states(0, 0) R1 = prob.states(0, 1) theta0 = prob.states(1, 0) theta1 = prob.states(1, 1) Vr0 = prob.states(2, 0) Vr1 = prob.states(2, 1) Vt0 = prob.states(3, 0) Vt1 = prob.states(3, 1) m0 = prob.states(4, 0) m1 = prob.states(4, 1) Tr0 = prob.controls(0, 0) Tr1 = prob.controls(0, 1) Tt0 = prob.controls(1, 0) Tt1 = prob.controls(1, 1) unit_R = prob.unit_states[0][0] unit_V = prob.unit_states[0][2] unit_m = prob.unit_states[0][4] result = Condition() # event condition result.equal(R0[0], obj.Re + obj.H0, unit=unit_R) # 初期地表 result.equal(theta0[0], 0.0) result.equal(Vr0[0], 0.0, unit=unit_V) result.equal(Vt0[0], obj.V0, unit=unit_V) result.equal(m0[0], obj.Minit, unit=unit_m) # (1st stage and 2nd stage and Payload) initial # knotting condition result.equal(m1[0], obj.M0[1], unit=unit_m) # (2nd stage + Payload) initial result.equal(R1[0], R0[-1], unit=unit_R) result.equal(theta1[0], theta0[-1]) result.equal(Vr1[0], Vr0[-1], unit=unit_V) result.equal(Vt1[0], Vt0[-1], unit=unit_V) # Target Condition result.equal(R1[-1], obj.Rtarget, unit=unit_R) # Radius result.equal(Vr[-1], 0.0, unit=unit_V) # Radius Velocity result.equal(Vt[-1], obj.Vtarget, unit=unit_V) return result()
def _og_equality(self, prob, obj): """ define the equality conditions to be met. in theory the user should be able to provide/modify this""" result = Condition() for i in range(5): result.equal(prob.states_all_section(i)[0], obj.s_0[i]), #r, v, m = [r,v,m](0) for i in range(4): result.equal(prob.states_all_section(i)[-1], 0.) #r, v = 0 return result()
def equality(prob, obj): x = prob.states_all_section(0) y = prob.states_all_section(1) v = prob.states_all_section(2) theta = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # event condition result.equal(x[0], 0.0) result.equal(y[0], 0.0) result.equal(v[0], 0.0) result.equal(x[-1], obj.l) return result()
def equality(prob, obj): h = prob.states_all_section(0) v = prob.states_all_section(1) m = prob.states_all_section(2) T = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # event condition result.equal(h[0], obj.H0) result.equal(v[0], obj.V0) result.equal(m[0], obj.M0) result.equal(v[-1], 0.0) result.equal(m[-1], obj.Mf) return result()
def inequality(prob, obj): R = prob.states_all_section(0) theta = prob.states_all_section(1) Vr = prob.states_all_section(2) Vt = prob.states_all_section(3) m = prob.states_all_section(4) Tr = prob.controls_all_section(0) Tt = prob.controls_all_section(1) tf = prob.time_final(-1) rho = obj.air_density(R - obj.Re) Dr = 0.5 * rho * Vr * np.sqrt(Vr**2 + Vt**2) \ * obj.Cd * obj.A # [N] Dt = 0.5 * rho * Vt * np.sqrt(Vr**2 + Vt**2) \ * obj.Cd * obj.A # [N] g = obj.g0 * (obj.Re / R)**2 # [m/s2] # dynamic pressure q = 0.5 * rho * (Vr**2 + Vt**2) # [Pa] # accelaration a_r = (Tr - Dr) / m a_t = (Tt - Dt) / m a_mag = np.sqrt(a_r**2 + a_t**2) # [m/s2] # Thrust T = np.sqrt(Tr**2 + Tt**2) result = Condition() # lower bounds result.lower_bound(R, obj.Re, unit=prob.unit_states[0][0]) # result.lower_bound(Vr, 0.0, unit=prob.unit_states[0][2]) # result.lower_bound(Vt, 0.0, unit=prob.unit_states[0][3]) result.lower_bound(m[1:], (obj.M0 - obj.Mp), unit=prob.unit_states[0][4]) result.lower_bound(Tr, 0.0, unit=prob.unit_controls[0][0]) # result.lower_bound(Tt, obj.Tmax / obj.unit_T, unit=prob.unit_controls[0][0]) result.lower_bound(Tt, 0.0, unit=prob.unit_controls[0][0]) # upper bounds result.upper_bound(m, obj.M0, unit=prob.unit_states[0][4]) result.upper_bound(Tr, obj.Tmax, unit=prob.unit_controls[0][0]) result.upper_bound(Tt, obj.Tmax, unit=prob.unit_controls[0][0]) result.upper_bound(T, obj.Tmax, unit=prob.unit_controls[0][0]) # result.upper_bound(q, obj.MaxQ, unit = prob.unit_states[0][0]) result.upper_bound(a_mag, obj.MaxG * obj.g0) return result()
def inequality(prob, obj): x = prob.states_all_section(0) y = prob.states_all_section(1) v = prob.states_all_section(2) theta = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # lower bounds result.lower_bound(x, 0) result.lower_bound(y, 0) result.lower_bound(theta, 0) # upper bounds result.upper_bound(theta, np.pi) result.upper_bound(x, obj.l) return result()
def inequality(prob, obj): u = prob.states_all_section(0) v = prob.states_all_section(1) x = prob.states_all_section(2) y = prob.states_all_section(3) beta = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # lower bounds result.lower_bound(beta, -np.pi / 2) # upper bounds result.upper_bound(beta, np.pi / 2) return result()
def inequality(prob, obj): h = prob.states_all_section(0) v = prob.states_all_section(1) m = prob.states_all_section(2) T = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # lower bounds result.lower_bound(h, obj.H0) result.lower_bound(v, 0.0) result.lower_bound(m, obj.Mf) result.lower_bound(T, 0.0) result.lower_bound(tf, 0.1) # upper bounds result.upper_bound(m, obj.M0) result.upper_bound(T, obj.T_max) return result()
def inequality(prob, obj): R = prob.states_all_section(0) v = prob.states_all_section(1) m = prob.states_all_section(2) T = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # lower bounds result.lower_bound(R, obj.Re) result.lower_bound(v, 0.0) result.lower_bound(m, obj.M0 * obj.Mc) result.lower_bound(T, 0.0) result.lower_bound(tf, 10) # upper bounds result.upper_bound(m, obj.M0) result.upper_bound(T, obj.max_thrust * obj.M0 * obj.g0) return result()
def inequality(prob, obj): x = prob.states_all_section(0) y = prob.states_all_section(1) v = prob.states_all_section(2) theta = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # lower bounds result.lower_bound(tf, 0.1) result.lower_bound(y, 0) result.lower_bound(theta, 0) # upper bounds # result.upper_bound(theta, np.pi/2) # result.upper_bound(y, x * np.tan(obj.theta0) + obj.h) return result()
def equality(prob, obj): u = prob.states_all_section(0) v = prob.states_all_section(1) x = prob.states_all_section(2) y = prob.states_all_section(3) beta = prob.controls_all_section(0) tf = prob.time_final(-1) result = Condition() # event condition result.equal(u[0], 0.0) result.equal(v[0], 0.0) result.equal(x[0], 0.0) result.equal(y[0], 0.0) result.equal(u[-1], 1.0) result.equal(v[-1], 0.0) result.equal(y[-1], 1.0) return result()
def equality(prob, obj): r = prob.states_all_section(0) vr = prob.states_all_section(1) vt = prob.states_all_section(2) ur1 = prob.controls_all_section(0) ur2 = prob.controls_all_section(1) ut1 = prob.controls_all_section(2) ut2 = prob.controls_all_section(3) tf = prob.time_final(-1) result = Condition() # event condition result.equal(r[0], obj.r0) result.equal(vr[0], obj.vr0) result.equal(vt[0], obj.vt0) result.equal(r[-1], obj.rf) result.equal(vr[-1], obj.vrf) result.equal(vt[-1], obj.vtf) return result()
def equality(prob, obj): R = prob.states_all_section(0) theta = prob.states_all_section(1) Vr = prob.states_all_section(2) Vt = prob.states_all_section(3) m = prob.states_all_section(4) Tr = prob.controls_all_section(0) Tt = prob.controls_all_section(1) tf = prob.time_final(-1) result = Condition() # event condition result.equal(R[0], obj.Re, unit=prob.unit_states[0][0]) result.equal(theta[0], 0.0, unit=prob.unit_states[0][1]) result.equal(Vr[0], 0.0, unit=prob.unit_states[0][2]) result.equal(Vt[0], 0.0, unit=prob.unit_states[0][3]) result.equal(m[0], obj.M0, unit=prob.unit_states[0][4]) result.equal(R[-1], obj.Rtarget, unit=prob.unit_states[0][1]) result.equal(Vr[-1], 0.0, unit=prob.unit_states[0][2]) result.equal(Vt[-1], obj.Vtarget, unit=prob.unit_states[0][3]) return result()
def cost_derivative(prob, obj): jac = Condition(prob.number_of_variables) index_R_end = prob.index_states(0, 0, -1) jac.change_value(index_R_end, -1) return jac()
def inequality(prob, obj): R = prob.states_all_section(0) theta = prob.states_all_section(1) Vr = prob.states_all_section(2) Vt = prob.states_all_section(3) m = prob.states_all_section(4) Tr = prob.controls_all_section(0) Tt = prob.controls_all_section(1) tf = prob.time_final(-1) R0 = prob.states(0, 0) R1 = prob.states(0, 1) theta0 = prob.states(1, 0) theta1 = prob.states(1, 1) Vr0 = prob.states(2, 0) Vr1 = prob.states(2, 1) Vt0 = prob.states(3, 0) Vt1 = prob.states(3, 1) m0 = prob.states(4, 0) m1 = prob.states(4, 1) Tr0 = prob.controls(0, 0) Tr1 = prob.controls(0, 1) Tt0 = prob.controls(1, 0) Tt1 = prob.controls(1, 1) rho = obj.airDensity(R - obj.Re) Mach = np.sqrt(Vr**2 + Vt**2) / obj.airSound(R - obj.Re) Cd = obj.Cd(Mach) Dr0 = 0.5 * rho * Vr * np.sqrt(Vr**2 + Vt**2) * Cd * obj.A[0] # [N] Dt0 = 0.5 * rho * Vt * np.sqrt(Vr**2 + Vt**2) * Cd * obj.A[0] # [N] Dr1 = 0.5 * rho * Vr * np.sqrt(Vr**2 + Vt**2) * Cd * obj.A[1] # [N] Dt1 = 0.5 * rho * Vt * np.sqrt(Vr**2 + Vt**2) * Cd * obj.A[1] # [N] g = obj.g0 * (obj.Re / R)**2 # [m/s2] # dynamic pressure q = 0.5 * rho * (Vr**2 + Vt**2) # [Pa] # accelaration a_r0 = (Tr - Dr0) / m a_t0 = (Tt - Dt0) / m a_mag0 = np.sqrt(a_r0**2 + a_t0**2) # [m/s2] a_r1 = (Tr - Dr1) / m a_t1 = (Tt - Dt1) / m a_mag1 = np.sqrt(a_r1**2 + a_t1**2) # [m/s2] # Thrust T0 = np.sqrt(Tr0**2 + Tt0**2) T1 = np.sqrt(Tr1**2 + Tt1**2) dThrust0 = (obj.airPressure(obj.H0) - obj.airPressure(R0 - obj.Re)) * obj.Ae[0] dThrust1 = obj.airPressure(R1 - obj.Re) * obj.Ae[1] result = Condition() # lower bounds result.lower_bound(R, obj.Re, unit=prob.unit_states[0][0]) # 地表以下 result.lower_bound(m0, obj.Mdry[0] + obj.M0[1], unit=prob.unit_states[0][4]) # 乾燥質量以下 result.lower_bound(m1, obj.Mdry[1], unit=prob.unit_states[0][4]) result.lower_bound(Tr, -obj.ThrustMax[1], unit=prob.unit_controls[0][0]) result.lower_bound(Tt, -obj.ThrustMax[1], unit=prob.unit_controls[0][0]) # upper bounds result.upper_bound(m0, obj.Minit, unit=prob.unit_states[0][4]) # 初期質量以上 result.upper_bound(m1, obj.M0[1], unit=prob.unit_states[0][4]) result.upper_bound(Tr0, obj.ThrustMax[0] + dThrust0, unit=prob.unit_controls[0][0]) result.upper_bound(Tt0, obj.ThrustMax[0] + dThrust0, unit=prob.unit_controls[0][0]) result.upper_bound(T0, obj.ThrustMax[0] + dThrust0, unit=prob.unit_controls[0][0]) result.upper_bound(Tr1, obj.ThrustMax[1] + dThrust1, unit=prob.unit_controls[0][0]) result.upper_bound(Tt1, obj.ThrustMax[1] + dThrust1, unit=prob.unit_controls[0][0]) result.upper_bound(T1, obj.ThrustMax[1] + dThrust1, unit=prob.unit_controls[0][0]) result.upper_bound(q, obj.MaxQ, unit=prob.unit_states[0][0]) result.upper_bound(a_mag0, obj.MaxG * obj.g0) result.upper_bound(a_mag1, obj.MaxG * obj.g0) return result()
def cost_derivative(prob, obj): jac = Condition(prob.number_of_variables) # index_tf = prob.index_time_final(0) index_tf = prob.index_time_final(-1) jac.change_value(index_tf, 1) return jac()