def optimize_aircraft(m, substitutions, fixedBPR=False, pRatOpt=True, mutategparg=False, x0 = None): """ Optimizes an aircraft of a given configuration :param m: aircraft model with objective and configuration :param fixedBPR: boolean specifying whether or not BPR is fixed (depends on config) :param pRatOpt: boolean specifying whether or not pressure ratio is optimized (depends on config) :param mutategparg: boolean whether to keep each GP solve intact :return: solution of aircraft model """ if fixedBPR: substitutions.update({ '\\alpha_{max}': 6.97, #8.62, }) if pRatOpt: del substitutions['\pi_{f_D}'] del substitutions['\pi_{lc_D}'] del substitutions['\pi_{hc_D}'] m.substitutions.update(substitutions) m_relax = Model(m.cost, BCS(m)) m_relax = relaxed_constants(m_relax) sol = m_relax.localsolve(verbosity=4, iteration_limit=200, reltol=0.01, mutategp=mutategparg, x0 = x0) post_process(sol) return sol
def run_M072_737(objective, fixedBPR, pRatOpt, mutategparg): # User definitions Nclimb = 3 Ncruise = 2 Nmission = 1 aircraft = 'M072_737' m = Mission(Nclimb, Ncruise, objective, aircraft, Nmission) substitutions = get_M072_737_subs() if Nmission > 1: substitutions.update({ 'R_{req}': [3000. * units('nmi'), 2500. * units('nmi')], 'n_{pass}': [180., 180.], }) else: substitutions.update({ 'R_{req}': 3000. * units('nmi'), 'n_{pass}': 180., }) if fixedBPR: substitutions.update({ '\\alpha_{max}': 6.97, }) if pRatOpt: del substitutions['\pi_{f_D}'] ## del substitutions['\pi_{lc_D}'] ## del substitutions['\pi_{hc_D}'] m.substitutions.update(substitutions) m = Model(m.cost, BCS(m)) m_relax = relaxed_constants(m, None, ['M_{takeoff}', '\\theta_{db}']) sol = m_relax.localsolve(verbosity=4, iteration_limit=200, reltol=0.01, mutategp=mutategparg) post_process(sol) percent_diff(sol, aircraft, Nclimb) post_compute(sol, Nclimb) return sol
def test(): " test model for continuous integration " v = Aircraft(sp=False) m = Mission(v, latitude=[20]) m.cost = m[m.aircraft.Wtotal] m.solve() v = Aircraft(sp=True) m = Mission(v, latitude=[20]) m.cost = m[m.aircraft.Wtotal] m.localsolve() v = Aircraft(Npod=3, sp=True) m = Mission(v, latitude=[20]) m.cost = m[m.aircraft.Wtotal] f = relaxed_constants(M) s = f.localsolve() post_process(s)
def run_optimal_777(objective, fixedBPR, pRatOpt, mutategparg): # User definitions Nclimb = 3 Ncruise = 2 Nmission = 1 aircraft = 'optimal777' m = Mission(Nclimb, Ncruise, objective, aircraft, Nmission) substitutions = get_optimal_777300ER_subs() substitutions.update({ 'R_{req}': 6000., 'n_{pass}': 450., }) if fixedBPR: substitutions.update({ '\\alpha_{max}': 8.62, }) if pRatOpt: del substitutions['\pi_{f_D}'] ## del substitutions['\pi_{lc_D}'] ## del substitutions['\pi_{hc_D}'] m.substitutions.update(substitutions) m = Model(m.cost, BCS(m)) m_relax = relaxed_constants(m, None, ['M_{takeoff}', '\\theta_{db}']) sol = m_relax.localsolve(verbosity=4, iteration_limit=200, reltol=0.01, mutategp=mutategparg) post_process(sol) percent_diff(sol, 'b777300ER', Nclimb) post_compute(sol, Nclimb) return sol
def pods(N=[1, 3, 5, 7, 9, 0], Nplot=5): "trade number of pods" SP = True data = {} for i in N: print("\nN=%i" % i) from solar import Mission, Aircraft Vehicle = Aircraft(Npod=i, sp=SP) M = Mission(Vehicle, latitude=[20]) M.cost = M[M.aircraft.Wtotal] try: sol = M.localsolve() data[i] = sol("Wtotal").magnitude except RuntimeWarning as e: print("rw: %s" % e) try: V2 = Aircraft(Npod=i, sp=SP) M2 = Mission(V2, latitude=[20]) M2.cost = M2[M2.aircraft.Wtotal] feas = relaxed_constants(M2) sol2 = feas.localsolve() vks = post_process(sol2) data[i] = np.NaN if vks else sol2("Wtotal").magnitude M, sol = M2, sol2 except Exception as e: print("e: %s" % e) data[i] = np.NaN except CalledProcessError as e: print("cpe: %s" % e) data[i] = np.NaN # mosek_cli can't process certain Ns if Nplot == i: plot_shear(M, sol) df = pd.DataFrame(data, index=[0]) return df
v = Aircraft(sp=False) m = Mission(v, latitude=[20]) m.cost = m[m.aircraft.Wtotal] m.solve() v = Aircraft(sp=True) m = Mission(v, latitude=[20]) m.cost = m[m.aircraft.Wtotal] m.localsolve() v = Aircraft(Npod=3, sp=True) m = Mission(v, latitude=[20]) m.cost = m[m.aircraft.Wtotal] f = relaxed_constants(M) s = f.localsolve() post_process(s) if __name__ == "__main__": SP = True Vehicle = Aircraft(Npod=3, sp=SP) M = Mission(Vehicle, latitude=[20]) M.cost = M[M.aircraft.Wtotal] try: sol = (M.localsolve("mosek") if SP else M.solve("mosek")) except RuntimeWarning: V2 = Aircraft(Npod=3, sp=SP) M2 = Mission(V2, latitude=[20]) M2.cost = M2[M2.aircraft.Wtotal] feas = relaxed_constants(M2) sol = feas.localsolve("mosek") vks = post_process(sol)