예제 #1
0
import aerosandbox as asb
import casadi as cas
from airplane import make_airplane

n_booms = 1
wing_span = 40
alpha = 5

airplane = make_airplane(n_booms=n_booms, wing_span=wing_span,)
op_point = asb.OperatingPoint(density=0.10, velocity=20, alpha=alpha,)

### LL
# Run an analysis
opti = cas.Opti()  # Initialize an analysis/optimization environment
# airplane.fuselages=[]
ap = asb.Casvlm1(airplane=airplane, op_point=op_point, opti=opti)
# Solver options
p_opts = {}
s_opts = {}
# s_opts["mu_strategy"] = "adaptive"
opti.solver("ipopt", p_opts, s_opts)
# Solve
try:
    sol = opti.solve()
except RuntimeError:
    sol = opti.debug
    raise Exception("An error occurred!")
# Postprocess
# ap.substitute_solution(sol)
ap.draw(show=False).show()
def display_geometry(
    display_geometry,
    run_ll_analysis,
    run_vlm_analysis,
    n_booms,
    wing_span,
    alpha,
):
    ### Figure out which button was clicked
    try:
        button_pressed = np.argmax(
            np.array([
                float(display_geometry),
                float(run_ll_analysis),
                float(run_vlm_analysis),
            ]))
        assert button_pressed is not None
    except:
        button_pressed = 0

    ### Make the airplane
    airplane = make_airplane(
        n_booms=n_booms,
        wing_span=wing_span,
    )
    op_point = asb.OperatingPoint(
        density=0.10,
        velocity=20,
        alpha=alpha,
    )
    if button_pressed == 0:
        # Display the geometry
        figure = airplane.draw(show=False, colorbar_title=None)
        output = "Please run an analysis to display the data."
    elif button_pressed == 1:
        # Run an analysis
        opti = cas.Opti()  # Initialize an analysis/optimization environment
        ap = asb.Casll1(airplane=airplane,
                        op_point=op_point,
                        opti=opti,
                        run_setup=False)
        ap.setup(verbose=False)
        # Solver options
        p_opts = {}
        s_opts = {}
        # s_opts["mu_strategy"] = "adaptive"
        opti.solver('ipopt', p_opts, s_opts)
        # Solve
        try:
            sol = opti.solve()
            output = make_table(
                pd.DataFrame({
                    "Figure": ["CL", "CD", "CDi", "CDp", "L/D"],
                    "Value": [
                        sol.value(ap.CL),
                        sol.value(ap.CD),
                        sol.value(ap.CDi),
                        sol.value(ap.CDp),
                        sol.value(ap.CL / ap.CD),
                    ]
                }))
        except:
            sol = opti.debug
            output = html.P(
                "Aerodynamic analysis failed! Most likely the airplane is stalled at this flight condition."
            )

        figure = ap.draw(show=False)  # Generates figure

    elif button_pressed == 2:
        # Run an analysis
        opti = cas.Opti()  # Initialize an analysis/optimization environment
        ap = asb.Casvlm1(airplane=airplane,
                         op_point=op_point,
                         opti=opti,
                         run_setup=False)
        ap.setup(verbose=False)
        # Solver options
        p_opts = {}
        s_opts = {}
        s_opts["max_iter"] = 50
        # s_opts["mu_strategy"] = "adaptive"
        opti.solver('ipopt', p_opts, s_opts)
        # Solve
        try:
            sol = opti.solve()
            output = make_table(
                pd.DataFrame({
                    "Figure": ["CL", "CDi", "L/Di"],
                    "Value": [
                        sol.value(ap.CL),
                        sol.value(ap.CDi),
                        sol.value(ap.CL / ap.CDi),
                    ]
                }))
        except:
            sol = opti.debug
            output = html.P(
                "Aerodynamic analysis failed! Most likely the airplane is stalled at this flight condition."
            )

        figure = ap.draw(show=False)  # Generates figure

    figure.update_layout(
        autosize=True,
        # width=1000,
        # height=700,
        margin=dict(
            l=0,
            r=0,
            b=0,
            t=0,
        ))

    return (figure, output)