Ejemplo n.º 1
0
 def get_run_data(
     Re
 ):  # Get the data for an XFoil alpha sweep at one specific Re.
     run_data = XFoil(airfoil=self, Re=Re,
                      **xfoil_kwargs).alpha(alphas)
     run_data["Re"] = Re * np.ones_like(run_data["alpha"])
     return run_data  # Data is a dict where keys are figures of merit [str] and values are 1D ndarrays.
Ejemplo n.º 2
0
    def plot_winds_at_altitude(altitude=18000):
        fig, ax = plt.subplots()

        day_of_years = np.linspace(0, 365, 150)
        latitudes = np.linspace(-80, 80, 120)
        Day_of_years, Latitudes = np.meshgrid(day_of_years, latitudes)

        winds = wind_speed_world_95(
            altitude=altitude * np.ones_like(Latitudes.flatten()),
            latitude=Latitudes.flatten(),
            day_of_year=Day_of_years.flatten(),
        ).reshape(Latitudes.shape)

        args = [day_of_years, latitudes, winds]

        levels = np.arange(0, 80.1, 5)
        CS = plt.contour(*args,
                         levels=levels,
                         linewidths=0.5,
                         colors="k",
                         alpha=0.7)
        CF = plt.contourf(*args,
                          levels=levels,
                          cmap='viridis_r',
                          alpha=0.7,
                          extend="max")
        cbar = plt.colorbar(label="Wind Speed [m/s]", extendrect=True)
        ax.clabel(CS, inline=1, fontsize=9, fmt="%.0f m/s")

        plt.xticks(
            np.linspace(0, 365, 13)[:-1],
            ("Jan. 1", "Feb. 1", "Mar. 1", "Apr. 1", "May 1", "June 1",
             "July 1", "Aug. 1", "Sep. 1", "Oct. 1", "Nov. 1", "Dec. 1"),
            rotation=40)

        lat_label_vals = np.arange(-80, 80.1, 20)
        lat_labels = []
        for lat in lat_label_vals:
            if lat >= 0:
                lat_labels.append(f"{lat:.0f}N")
            else:
                lat_labels.append(f"{-lat:.0f}S")
        plt.yticks(lat_label_vals, lat_labels)

        show_plot(
            f"95th-Percentile Wind Speeds at {altitude / 1e3:.0f} km Altitude",
            xlabel="Day of Year",
            ylabel="Latitude",
        )
Ejemplo n.º 3
0
def spy(
    matrix,
    show=True,
):
    """
    Plots the sparsity pattern of a matrix.
    :param matrix: The matrix to plot the sparsity pattern of. [2D ndarray or CasADi array]
    :param show: Whether or not to show the sparsity plot. [boolean]
    :return: The figure to be plotted [go.Figure]
    """
    try:
        matrix = matrix.toarray()
    except:
        pass
    abs_m = np.abs(matrix)
    sparsity_pattern = abs_m >= 1e-16
    matrix[sparsity_pattern] = np.log10(abs_m[sparsity_pattern] + 1e-16)
    j_index_map, i_index_map = np.meshgrid(np.arange(matrix.shape[1]),
                                           np.arange(matrix.shape[0]))

    i_index = i_index_map[sparsity_pattern]
    j_index = j_index_map[sparsity_pattern]
    val = matrix[sparsity_pattern]
    val = np.ones_like(i_index)
    fig = go.Figure(
        data=go.Heatmap(
            y=i_index,
            x=j_index,
            z=val,
            # type='heatmap',
            colorscale='RdBu',
            showscale=False,
        ), )
    fig.update_layout(
        plot_bgcolor="black",
        xaxis=dict(showgrid=False, zeroline=False),
        yaxis=dict(showgrid=False,
                   zeroline=False,
                   autorange="reversed",
                   scaleanchor="x",
                   scaleratio=1),
        width=800,
        height=800 * (matrix.shape[0] / matrix.shape[1]),
    )
    if show:
        fig.show()
    return fig
Ejemplo n.º 4
0
    def plot_winds_at_day(day_of_year=0):
        fig, ax = plt.subplots()

        altitudes = np.linspace(0, 30000, 150)
        latitudes = np.linspace(-80, 80, 120)
        Altitudes, Latitudes = np.meshgrid(altitudes, latitudes)

        winds = wind_speed_world_95(
            altitude=Altitudes.flatten(),
            latitude=Latitudes.flatten(),
            day_of_year=day_of_year * np.ones_like(Altitudes.flatten()),
        ).reshape(Altitudes.shape)

        args = [altitudes / 1e3, latitudes, winds]

        levels = np.arange(0, 80.1, 5)
        CS = plt.contour(*args,
                         levels=levels,
                         linewidths=0.5,
                         colors="k",
                         alpha=0.7)
        CF = plt.contourf(*args,
                          levels=levels,
                          cmap='viridis_r',
                          alpha=0.7,
                          extend="max")
        cbar = plt.colorbar(label="Wind Speed [m/s]", extendrect=True)
        ax.clabel(CS, inline=1, fontsize=9, fmt="%.0f m/s")

        lat_label_vals = np.arange(-80, 80.1, 20)
        lat_labels = []
        for lat in lat_label_vals:
            if lat >= 0:
                lat_labels.append(f"{lat:.0f}N")
            else:
                lat_labels.append(f"{-lat:.0f}S")
        plt.yticks(lat_label_vals, lat_labels)

        show_plot(
            f"95th-Percentile Wind Speeds at Day {day_of_year:.0f}",
            xlabel="Altitude [km]",
            ylabel="Latitude",
        )
Ejemplo n.º 5
0
    data = {k: np.array([d[k] for d in data]) for k in data[0].keys()}

    order = np.argsort(data['mach'])

    data = {k: v[order] for k, v in data.items()}

    return data


machs = np.linspace(0, 1.3, 500)
airfoil = asb.Airfoil("rae2822")
airfoil.generate_polars(cache_filename="./cache/rae2822.json")
aerobuildup_data = {
    "mach": machs,
    "CL": airfoil.CL_function(1, 6.5e6, machs, 0) * np.ones_like(machs),
    "CD": airfoil.CD_function(1, 6.5e6, machs, 0) * np.ones_like(machs),
    "CM": airfoil.CM_function(1, 6.5e6, machs, 0) * np.ones_like(machs),
}

datas = {
    "XFoil v6 (P-G)": get_data(data_folder / "xfoil6.csv"),
    "MSES (Euler + IBL)": get_data(data_folder / "mses.csv"),
    "SU2 (RANS)": get_data(data_folder / "su2.csv"),
    "ASB AeroBuildup": aerobuildup_data,
}

import matplotlib.pyplot as plt
import aerosandbox.tools.pretty_plots as p

fig, ax = plt.subplots()
Ejemplo n.º 6
0
def beta(mach):
    return np.sqrt(1 - mach**2)


machs_to_fit = np.linspace(0.001, 0.999, 500)


def sigmoid(x):
    return 1 / (1 + np.exp(x))


def inv_sigmoid(x):
    return np.log(1 / x - 1)


weights = np.ones_like(machs_to_fit)
weights[0] = 1000
weights[machs_to_fit > 0.9] = 0.5
weights[machs_to_fit > 0.95] = 0.25


def model(x, p):
    return sigmoid(p["p5"] * (x - p["o5"])**5 + p["p3"] * (x - p["o3"])**4 +
                   p["p1"] * (x - p["o1"]))


fit = asb.FittedModel(
    model=model,
    x_data=machs_to_fit,
    y_data=beta(machs_to_fit),
    parameter_guesses={
Ejemplo n.º 7
0
    X, Y = np.meshgrid(
        np.linspace(-2, 2, 50),
        np.linspace(-2, 2, 50),
    )
    X = X.flatten()
    Y = Y.flatten()

    x_panels = np.array([1, -1, -1, 1, 1])
    y_panels = np.array([1, 1, -1, -1, 1])

    U, V = calculate_induced_velocity_line_singularities(
        x_field=X,
        y_field=Y,
        x_panels=x_panels,
        y_panels=y_panels,
        gamma=1 * np.ones_like(x_panels),
        sigma=1 * np.ones_like(x_panels))

    import matplotlib.pyplot as plt
    import seaborn as sns

    sns.set(palette=sns.color_palette("husl"))
    fig, ax = plt.subplots(1, 1, figsize=(6, 6), dpi=200)

    plt.quiver(X, Y, U, V, (U**2 + V**2)**0.5, scale=10)
    plt.axis("equal")
    plt.xlabel(r"$x$")
    plt.ylabel(r"$z$")
    plt.title(r"Linear-Strength Vortex: Induced Velocity")
    plt.tight_layout()
    # plt.savefig("C:/Users/User/Downloads/temp.svg")