def test_airfoil_multielement():
    a = asb.AirfoilInviscid(airfoil=[
        asb.Airfoil("e423").repanel(n_points_per_side=50),
        asb.Airfoil("naca6408").repanel(n_points_per_side=25).scale(
            0.4, 0.4).rotate(np.radians(-20)).translate(0.9, -0.05),
    ],
                            op_point=asb.OperatingPoint(velocity=1, alpha=5))
def test_airfoil_symmetric_NACA():
    a = asb.AirfoilInviscid(airfoil=[asb.Airfoil("naca0012").repanel(50)],
                            op_point=asb.OperatingPoint(
                                velocity=1,
                                alpha=0,
                            ))
    assert a.Cl == pytest.approx(0, abs=1e-8)
Esempio n. 3
0
def display_graph(n_clicks, alpha, height, streamline_density,
                  operating_checklist, *kulfan_inputs):
    ### Figure out if a button was pressed
    global n_clicks_last
    if n_clicks is None:
        n_clicks = 0

    analyze_button_pressed = n_clicks > n_clicks_last
    n_clicks_last = n_clicks

    ### Parse the checklist
    ground_effect = "ground_effect" in operating_checklist

    ### Start constructing the figure
    airfoil = asb.Airfoil(coordinates=asb.get_kulfan_coordinates(
        lower_weights=np.array(kulfan_inputs[n_kulfan_inputs_per_side:]),
        upper_weights=np.array(kulfan_inputs[:n_kulfan_inputs_per_side]),
        TE_thickness=0,
        enforce_continuous_LE_radius=False,
        n_points_per_side=200,
    ))

    ### Do coordinates output
    coordinates_output = "\n".join(
        ["```"] + ["AeroSandbox Airfoil"] +
        ["\t%f\t%f" % tuple(coordinate)
         for coordinate in airfoil.coordinates] + ["```"])

    ### Continue doing the airfoil things
    airfoil = airfoil.rotate(angle=-np.radians(alpha))
    airfoil = airfoil.translate(0, height + 0.5 * np.sind(alpha))
    fig = go.Figure()
    fig.add_trace(
        go.Scatter(
            x=airfoil.x(),
            y=airfoil.y(),
            mode="lines",
            name="Airfoil",
            fill="toself",
            line=dict(color="blue"),
        ))

    ### Default text output
    text_output = 'Click "Analyze" to compute aerodynamics!'

    xrng = (-0.5, 1.5)
    yrng = (-0.6, 0.6) if not ground_effect else (0, 1.2)

    if analyze_button_pressed:

        analysis = asb.AirfoilInviscid(
            airfoil=airfoil.repanel(50),
            op_point=asb.OperatingPoint(
                velocity=1,
                alpha=0,
            ),
            ground_effect=ground_effect,
        )

        x = np.linspace(*xrng, 100)
        y = np.linspace(*yrng, 100)
        X, Y = np.meshgrid(x, y)
        u, v = analysis.calculate_velocity(x_field=X.flatten(),
                                           y_field=Y.flatten())
        U = u.reshape(X.shape)
        V = v.reshape(Y.shape)

        streamline_fig = ff.create_streamline(
            x,
            y,
            U,
            V,
            arrow_scale=1e-16,
            density=streamline_density,
            line=dict(color="#ff82a3"),
            name="Streamlines",
        )

        fig = go.Figure(data=streamline_fig.data + fig.data)

        text_output = make_table(
            pd.DataFrame({
                "Engineering Quantity": ["C_L"],
                "Value": [f"{analysis.Cl:.3f}"]
            }))

    fig.update_layout(
        xaxis_title="x/c",
        yaxis_title="y/c",
        showlegend=False,
        yaxis=dict(scaleanchor="x", scaleratio=1),
        margin={"t": 0},
        title=None,
    )

    fig.update_xaxes(range=xrng)
    fig.update_yaxes(range=yrng)

    return fig, text_output, [coordinates_output]
def test_airfoil_with_TE_gap():
    a = asb.AirfoilInviscid(airfoil=asb.Airfoil("naca4408").repanel(100),
                            op_point=asb.OperatingPoint(velocity=1, alpha=5))
    assert a.Cl == pytest.approx(1.0754, abs=0.01)  # From XFoil
def test_airfoil_ground_effect():
    a = asb.AirfoilInviscid(
        airfoil=asb.Airfoil("naca4408").repanel(100).translate(0, 0.2),
        op_point=asb.OperatingPoint(velocity=1, alpha=0),
        ground_effect=True)
    assert a.calculate_velocity(0, 0)[1] == pytest.approx(0)