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$ [-]")

    show_plot()

    ##### Test optimization
    opti = asb.Opti()
    alpha = opti.variable(init_guess=0, lower_bound=-20, upper_bound=20)
    LD = af.CL_function(alpha, 1e6) / af.CD_function(alpha, 1e6)
Пример #2
0
if __name__ == "__main__":
    # Make AeroSandbox Atmosphere
    altitude = np.linspace(-5e3, 100e3, 1000)
    atmo_diff = Atmosphere(altitude=altitude)
    atmo_isa = Atmosphere(altitude=altitude, method="isa")

    from aerosandbox.tools.pretty_plots import plt, sns, mpl, show_plot, set_ticks

    fig, ax = plt.subplots()

    plt.plot(
        ((atmo_diff.pressure() - atmo_isa.pressure()) / atmo_isa.pressure()) *
        100,
        altitude / 1e3,
    )
    set_ticks(0.2, 0.1, 20, 10)
    plt.xlim(-1, 1)
    show_plot("AeroSandbox Atmosphere vs. ISA Atmosphere",
              "Pressure, Relative Error [%]", "Altitude [km]")

    fig, ax = plt.subplots()
    plt.plot(
        atmo_diff.temperature() - atmo_isa.temperature(),
        altitude / 1e3,
    )
    set_ticks(1, 0.5, 20, 10)
    plt.xlim(-5, 5)
    show_plot("AeroSandbox Atmosphere vs. ISA Atmosphere",
              "Temperature, Absolute Error [K]", "Altitude [km]")
Пример #3
0
    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]")
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]")
Пример #5
0
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 [%]")