mCD = af.CD_function(alpha, Re) xf_run = asb.XFoil(af, Re=Re, max_iter=20).alpha(alpha_lowres) xa = xf_run["alpha"] xCL = xf_run["CL"] xCD = xf_run["CD"] plt.sca(ax[0, 0]) plt.plot(ma, mCL) plt.plot(xa, xCL, ".") plt.xlabel("Angle of Attack [deg]") plt.ylabel("Lift Coefficient $C_L$ [-]") plt.sca(ax[0, 1]) plt.plot(ma, mCD) plt.plot(xa, xCD, ".") plt.ylim(0, 0.05) plt.xlabel("Angle of Attack [deg]") plt.ylabel("Drag Coefficient $C_D$ [-]") plt.sca(ax[1, 0]) plt.plot(mCD, mCL) plt.plot(xCD, xCL, ".") plt.xlim(0, 0.05) plt.xlabel("Drag Coefficient $C_D$ [-]") plt.ylabel("Lift Coefficient $C_L$ [-]") plt.sca(ax[1, 1]) plt.plot(ma, mCL / mCD) plt.plot(xa, xCL / xCD, ".") plt.xlabel("Angle of Attack [deg]") plt.ylabel("Lift-to-Drag Ratio $C_L/C_D$ [-]")
from scipy import optimize fig, ax = plt.subplots() speeds = np.linspace(0, 30, 500) def get_mileage(speed): bike = Bike() try: perf = bike.steady_state_performance(speed=speed, ) except ValueError: return np.NaN motor = perf['motor state'] power = motor['voltage'] * motor['current'] return power / speed mileage = np.array([get_mileage(speed) for speed in speeds]) # J/m mileage_Wh_per_mile = mileage / 3600 * 1000 * 1.609 plt.plot(speeds * 2.24, mileage_Wh_per_mile) plt.xlim(left=0) plt.ylim(bottom=0, top=50) set_ticks(x_major=5, x_minor=1, y_major=5, y_minor=1) show_plot(f"Electric Bike: Mileage vs. Speed", xlabel="Speed [mph]", ylabel=f"Energy Mileage [Wh per mile]")
def simulate( self, t_eval, t_span=(0, 60), initial_position=0, initial_velocity=0, ): res = integrate.solve_ivp( fun=self.equations_of_motion, t_span=t_span, y0=np.array([initial_position, initial_velocity]), t_eval=t_eval, ) return res.y if __name__ == '__main__': bike = Bike() from aerosandbox.tools.pretty_plots import plt, show_plot, set_ticks fig, ax = plt.subplots() t = np.linspace(0, 60, 500) pos, vel = bike.simulate(t) plt.plot(t, vel * 2.24) set_ticks(2, 1, 4, 2) plt.xlim(0, 20) plt.ylim(0, 36) show_plot("Electric Bike", xlabel="Time [s]", ylabel="Speed [mph]")
airplane=airplane, op_point=OperatingPoint(velocity=100, alpha=alpha, beta=0), ).run() plt.sca(ax[0, 0]) plt.plot(alpha, aero["CL"]) plt.xlabel(r"$\alpha$ [deg]") plt.ylabel(r"$C_L$") set_ticks(5, 1, 0.5, 0.1) plt.sca(ax[0, 1]) plt.plot(alpha, aero["CD"]) plt.xlabel(r"$\alpha$ [deg]") plt.ylabel(r"$C_D$") set_ticks(5, 1, 0.05, 0.01) plt.ylim(bottom=0) plt.sca(ax[1, 0]) plt.plot(alpha, aero["Cm"]) plt.xlabel(r"$\alpha$ [deg]") plt.ylabel(r"$C_m$") set_ticks(5, 1, 0.5, 0.1) plt.sca(ax[1, 1]) plt.plot(alpha, aero["CL"] / aero["CD"]) plt.xlabel(r"$\alpha$ [deg]") plt.ylabel(r"$C_L/C_D$") set_ticks(5, 1, 10, 2) show_plot("`asb.AeroBuildup` Aircraft Aerodynamics")
from scipy import optimize speed = 24 / 2.24 fig, ax = plt.subplots() t = np.linspace(0, 10, 500) gear_ratios = np.geomspace(0.020 / 0.700, 0.700 / 0.700, 300) def get_efficiency(gear_ratio): bike = Bike(gear_ratio=gear_ratio) try: perf = bike.steady_state_performance(speed=speed) except ValueError: return np.NaN return perf['motor state']['efficiency'] eff = np.array([get_efficiency(gear_ratio) for gear_ratio in gear_ratios]) plt.plot(gear_ratios, eff * 100) plt.xlim(gear_ratios[0], gear_ratios[-1]) plt.ylim(0, 100) # plt.xscale('log') set_ticks(x_major=0.1, x_minor=0.025, y_major=10, y_minor=2.5) show_plot(f"Electric Bike: Gear Ratios at {speed * 2.24:.0f} mph", xlabel="Gear Ratio", ylabel=f"Efficiency [%]")