def test_fuselage_aerodynamics_optimization(): opti = asb.Opti() alpha = opti.variable(init_guess=0, lower_bound=0, upper_bound=30) beta = opti.variable(init_guess=0) fuselage = asb.Fuselage(xsecs=[ asb.FuselageXSec(xyz_c=[xi, 0, 0], radius=asb.Airfoil("naca0010").local_thickness( 0.8 * xi)) for xi in np.cosspace(0, 1, 20) ], ) aero = asb.AeroBuildup(airplane=asb.Airplane(fuselages=[fuselage]), op_point=asb.OperatingPoint(velocity=10, alpha=alpha, beta=beta)).run() opti.minimize(-aero["L"] / aero["D"]) sol = opti.solve(verbose=False) print(sol.value(alpha)) assert sol.value(alpha) > 10 and sol.value(alpha) < 20 assert sol.value(beta) == pytest.approx(0, abs=1e-3) opti.minimize(aero["D"]) sol = opti.solve(verbose=False) assert sol.value(alpha) == pytest.approx(0, abs=1e-2) assert sol.value(beta) == pytest.approx(0, abs=1e-2)
def dynamics(t, y): dyn = asb.FreeBodyDynamics( *y, g=1, ) aero = asb.AeroBuildup( airplane=airplane, op_point=dyn.op_point ).run() dyn.X, dyn.Y, dyn.Z = aero["F_b"] dyn.L, dyn.M, dyn.N = aero["M_b"] derivatives = dyn.state_derivatives() derivatives["u"] = np.where( dyn.u < 0, 0, derivatives["u"] ) return np.array(list(dyn.state_derivatives().values()))
import aerosandbox as asb import aerosandbox.numpy as np from aerosandbox.aerodynamics.aero_3D.test_aero_3D.conventional import airplane analysis = asb.AeroBuildup( airplane=airplane, op_point=asb.OperatingPoint( atmosphere=asb.Atmosphere(altitude=0, method="ISA"), velocity=10, # m/s alpha=5, # In degrees beta=0, # In degrees p=0, # About the body x-axis, in rad/sec q=0, # About the body y-axis, in rad/sec r=0, # About the body z-axis, in rad/sec ), )
import matplotlib.pyplot as plt import aerosandbox.tools.pretty_plots as p fuselage = asb.Fuselage(xsecs=[ asb.FuselageXSec(xyz_c=[xi, 0, 0], radius=asb.Airfoil("naca0020").local_thickness(xi) / 2) for xi in np.cosspace(0, 1, 20) ], ) fig, ax = plt.subplots(figsize=(7, 6)) V = np.linspace(10, 1000, 1001) op_point = asb.OperatingPoint(velocity=V, ) aero = asb.AeroBuildup( airplane=asb.Airplane(fuselages=[fuselage]), op_point=op_point, ).run() plt.plot(op_point.mach(), aero["CD"], label="Full Model") aero = asb.AeroBuildup(airplane=asb.Airplane(fuselages=[fuselage]), op_point=op_point, include_wave_drag=False).run() plt.plot(op_point.mach(), aero["CD"], zorder=1.9, label="Model without Wave Drag") p.show_plot("Transonic Fuselage Drag", "Mach [-]", "Drag Area $C_D \cdot A$ [m$^2$]")
sol = integrate.solve_ivp( fun=dynamics, t_span=t_span, y0=np.array(list(init_state.values())), method="LSODA", vectorized=True, dense_output=True, atol=np.array(list(atols.values())), ) time = np.linspace(sol.t.min(), sol.t.max(), 300) dyn = asb.FreeBodyDynamics( time, *sol.sol(time), ) aero = asb.AeroBuildup( airplane=airplane, op_point=dyn.op_point ).run() dyn.X, dyn.Y, dyn.Z = aero["F_b"] dyn.L, dyn.M, dyn.N = aero["M_b"] from aerosandbox.tools.pretty_plots import plt, show_plot, equal vars_to_plot = { **dyn.state, "alpha" : dyn.alpha, "beta" : dyn.beta, "speed" : dyn.speed, "altitude": dyn.altitude, "CL" : aero["CL"], "CY" : aero["CY"], "CD" : aero["CD"],
af = xsec.airfoil af.generate_polars( cache_filename=f"cache/{af.name}.json", xfoil_kwargs=dict(xfoil_repanel="naca" in af.name.lower())) airplane.wings[i].xsecs[j].airfoil = af op_point = asb.OperatingPoint(velocity=25, alpha=3) vlm = asb.VortexLatticeMethod( airplane, op_point, align_trailing_vortices_with_wind=True, chordwise_resolution=12, spanwise_resolution=12, ) vlm_aero = vlm.run() ab = asb.AeroBuildup(airplane, op_point) ab_aero = ab.run() avl = asb.AVL( airplane, op_point, ) avl_aero = avl.run() for k, v in {"VLM": vlm_aero, "AVL": avl_aero, "AB": ab_aero}.items(): print(f"{k}:") for f in ["CL", "CD", "Cm"]: print(f"\t{f} : {v[f]}") print(f"\tL/D : {v['CL'] / v['CD']}")
def test_aero_buildup(): analysis = asb.AeroBuildup( airplane=airplane, op_point=asb.OperatingPoint(), ) return analysis.run()
import aerosandbox.numpy as np import matplotlib.pyplot as plt import aerosandbox.tools.pretty_plots as p fuselage = asb.Fuselage(xsecs=[ asb.FuselageXSec(xyz_c=[xi, 0, 0], radius=asb.Airfoil("naca0010").local_thickness(xi)) for xi in np.cosspace(0, 1, 20) ], ) fig, ax = plt.subplots(figsize=(7, 6)) Beta, Alpha = np.meshgrid(np.linspace(-90, 90, 500), np.linspace(-90, 90, 500)) aero = asb.AeroBuildup(airplane=asb.Airplane(fuselages=[fuselage]), op_point=asb.OperatingPoint( velocity=10, alpha=Alpha, beta=Beta, )).run() from aerosandbox.tools.string_formatting import eng_string p.contour( Beta, Alpha, aero["L"], colorbar_label="Lift $L$ [N]", # levels=100, linelabels_format=lambda s: eng_string(s, unit="N"), cmap=plt.get_cmap("coolwarm")) p.equal() p.show_plot("3D Fuselage Lift", r"$\beta$ [deg]", r"$\alpha$ [deg]")
def get_aero(xyz_ref): return asb.AeroBuildup(airplane=asb.Airplane(fuselages=[fuselage], xyz_ref=xyz_ref), op_point=asb.OperatingPoint(velocity=10, alpha=5, beta=5)).run()