def test_api_eval(cleanup):
    results_folder_path = pth.join(RESULTS_FOLDER_PATH, "api_eval")
    configuration_file_path = pth.join(results_folder_path, "oad_process.toml")

    # Generation of configuration file ----------------------------------------
    api.generate_configuration_file(configuration_file_path, True)

    # Generation of inputs ----------------------------------------------------
    # We get the same inputs as in tutorial notebook
    source_xml = pth.join(root_folder_path, "src", "fastoad", "notebooks",
                          "tutorial", "data", "CeRAS01_baseline.xml")
    api.generate_inputs(configuration_file_path, source_xml, overwrite=True)

    # Run model ---------------------------------------------------------------
    problem = api.evaluate_problem(configuration_file_path, True)

    # Check that weight-performances loop correctly converged
    assert_allclose(
        problem["data:weight:aircraft:OWE"],
        problem["data:weight:airframe:mass"] +
        problem["data:weight:propulsion:mass"] +
        problem["data:weight:systems:mass"] +
        problem["data:weight:furniture:mass"] +
        problem["data:weight:crew:mass"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MZFW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:max_payload"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MTOW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:payload"] +
        problem["data:mission:sizing:needed_block_fuel"],
        atol=1,
    )

    assert_allclose(problem["data:handling_qualities:static_margin"],
                    -0.071146,
                    atol=1e-3)
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"],
                    16.0,
                    atol=1e-2)
    assert_allclose(problem["data:weight:aircraft:MTOW"], 76796, atol=1)
    assert_allclose(problem["data:geometry:wing:area"], 131.26, atol=1e-2)
    assert_allclose(problem["data:geometry:vertical_tail:area"],
                    27.49,
                    atol=1e-2)
    assert_allclose(problem["data:geometry:horizontal_tail:area"],
                    33.99,
                    atol=1e-2)
    assert_allclose(problem["data:mission:sizing:needed_block_fuel"],
                    20708,
                    atol=1)
def test_api_optim(cleanup):
    results_folder_path = pth.join(RESULTS_FOLDER_PATH, "api_optim")
    configuration_file_path = pth.join(results_folder_path, "oad_process.toml")

    # Generation of configuration file ----------------------------------------
    api.generate_configuration_file(configuration_file_path, True)

    # Generation of inputs ----------------------------------------------------
    # We get the same inputs as in tutorial notebook
    source_xml = pth.join(root_folder_path, "src", "fastoad", "notebooks",
                          "tutorial", "data", "CeRAS01_baseline.xml")
    api.generate_inputs(configuration_file_path, source_xml, overwrite=True)

    # Run optim ---------------------------------------------------------------
    problem = api.optimize_problem(configuration_file_path, True)
    assert not problem.optim_failed

    # Check that weight-performances loop correctly converged
    assert_allclose(
        problem["data:weight:aircraft:OWE"],
        problem["data:weight:airframe:mass"] +
        problem["data:weight:propulsion:mass"] +
        problem["data:weight:systems:mass"] +
        problem["data:weight:furniture:mass"] +
        problem["data:weight:crew:mass"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MZFW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:max_payload"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MTOW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:payload"] +
        problem["data:mission:sizing:needed_block_fuel"],
        atol=1,
    )

    # Design Variable
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"],
                    17.076,
                    atol=1e-3)

    # Constraint
    assert_allclose(problem["data:handling_qualities:static_margin"],
                    0.05,
                    rtol=1e-5)

    # Objective
    assert_allclose(problem["data:mission:sizing:needed_block_fuel"],
                    20837,
                    atol=1)
Exemple #3
0
def est_api(cleanup):
    # Generation of inputs ----------------------------------------------------
    # We get the same inputs as in tutorial notebook
    DATA_FOLDER_PATH = pth.join(NOTEBOOKS_PATH, "tutorial", "data")
    WORK_FOLDER_PATH = pth.join(NOTEBOOKS_PATH, "tutorial", "workdir")
    configuration_file = pth.join(WORK_FOLDER_PATH, "oad_process.toml")
    SOURCE_FILE = pth.join(DATA_FOLDER_PATH, XML_NAME)
    _api.generate_configuration_file(configuration_file, overwrite=True)

    # Run 800NM model ---------------------------------------------------------
    api.generate_inputs(configuration_file, SOURCE_FILE, overwrite=True)
    api.evaluate_problem(configuration_file, True)

    OUTPUT_FILE = pth.join(WORK_FOLDER_PATH, 'problem_outputs.xml')
    Beechcraft_800nm_OUTPUT_FILE = pth.join(WORK_FOLDER_PATH, 'problem_outputs_Beechcraft_800nm_mda.xml')
    copy(OUTPUT_FILE, Beechcraft_800nm_OUTPUT_FILE)

    # Run 1000NM model --------------------------------------------------------
    viewer = VariableViewer()
    viewer.load(SOURCE_FILE)
    index = np.where(viewer.dataframe['Name'] == 'data:TLAR:range')[0][0]
    viewer.dataframe.at[index, 'Value'] = 1000.0
    viewer.save(SOURCE_FILE)

    api.generate_inputs(configuration_file, SOURCE_FILE, overwrite=True)
    api.evaluate_problem(configuration_file, True)

    OUTPUT_FILE = pth.join(WORK_FOLDER_PATH, 'problem_outputs.xml')
    Beechcraft_1000nm_OUTPUT_FILE = pth.join(WORK_FOLDER_PATH, 'problem_outputs_Beechcraft_1000nm_mda.xml')
    copy(OUTPUT_FILE, Beechcraft_1000nm_OUTPUT_FILE)

    # Try geometry plot -------------------------------------------------------
    fig = wing_geometry_plot(Beechcraft_800nm_OUTPUT_FILE, name='Beechcraft 800 nm MDA')
    fig = wing_geometry_plot(Beechcraft_1000nm_OUTPUT_FILE, name='Beechcraft 1000 nm MDA', fig=fig)
    fig.show()
    fig = aircraft_geometry_plot(Beechcraft_800nm_OUTPUT_FILE, name='Beechcraft 800 nm MDA')
    fig = aircraft_geometry_plot(Beechcraft_1000nm_OUTPUT_FILE, name='Beechcraft 1000 nm MDA', fig=fig)
    fig.show()

    # Try mass breakdown ------------------------------------------------------
    fig = mass_breakdown_sun_plot(Beechcraft_800nm_OUTPUT_FILE)
    fig.show()
    fig = mass_breakdown_bar_plot(Beechcraft_800nm_OUTPUT_FILE, name='Beechcraft 800 nm MDA')
    fig = mass_breakdown_bar_plot(Beechcraft_1000nm_OUTPUT_FILE, name='Beechcraft 1000 nm MDA', fig=fig)
    fig.show()

    # Run optimization --------------------------------------------------------
    viewer = VariableViewer()
    viewer.load(SOURCE_FILE)
    index = np.where(viewer.dataframe['Name'] == 'data:TLAR:range')[0][0]
    viewer.dataframe.at[index, 'Value'] = 800.0
    viewer.save(SOURCE_FILE)

    api.generate_inputs(configuration_file, SOURCE_FILE, overwrite=True)
    problem = api.optimize_problem(configuration_file, True)
    assert not problem.optim_failed

    # Check that weight-performances loop correctly converged
    assert_allclose(
        problem["data:weight:aircraft:OWE"],
        problem["data:weight:airframe:mass"]
        + problem["data:weight:propulsion:mass"]
        + problem["data:weight:systems:mass"]
        + problem["data:weight:furniture:mass"]
        + problem["data:weight:crew:mass"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MZFW"],
        problem["data:weight:aircraft:OWE"] + problem["data:weight:aircraft:max_payload"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MTOW"],
        problem["data:weight:aircraft:OWE"]
        + problem["data:weight:aircraft:payload"]
        + problem["data:mission:sizing:fuel"],
        atol=1,
    )

    # Design Variable
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"], 17.06, atol=1e-1)

    # Constraint
    assert_allclose(problem["data:handling_qualities:static_margin"], 0.05, atol=1e-2)

    # Objective
    assert_allclose(problem["data:mission:sizing:fuel"], 20565, atol=50)
Exemple #4
0
def test_api(cleanup):

    # Generation of inputs ----------------------------------------------------
    # We get the same inputs as in tutorial notebook
    configuration_file = pth.join(NOTEBOOKS_PATH, "tutorial", "workdir",
                                  "oad_process.toml")
    source_file = pth.join(NOTEBOOKS_PATH, "tutorial", "data",
                           "beechcraft_76.xml")
    _api.generate_configuration_file(configuration_file, overwrite=True)

    api.generate_inputs(configuration_file, source_file, overwrite=True)

    # Run model ---------------------------------------------------------------
    problem = api.evaluate_problem(configuration_file, True)

    # Check that weight-performances loop correctly converged
    assert_allclose(
        problem["data:weight:aircraft:OWE"],
        problem["data:weight:airframe:mass"] +
        problem["data:weight:propulsion:mass"] +
        problem["data:weight:systems:mass"] +
        problem["data:weight:furniture:mass"],
        rtol=5e-2,
    )
    assert_allclose(
        problem["data:weight:aircraft:MZFW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:max_payload"],
        rtol=5e-2,
    )
    assert_allclose(
        problem["data:weight:aircraft:MTOW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:payload"] +
        problem["data:mission:sizing:fuel"],
        rtol=5e-2,
    )

    assert_allclose(problem["data:handling_qualities:static_margin"],
                    -0.005519,
                    atol=1e-3)
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"],
                    16.5,
                    atol=1e-2)
    assert_allclose(problem["data:weight:aircraft:MTOW"], 77065, atol=1)
    assert_allclose(problem["data:geometry:wing:area"], 130.29, atol=1e-2)
    assert_allclose(problem["data:geometry:vertical_tail:area"],
                    27.65,
                    atol=1e-2)
    assert_allclose(problem["data:geometry:horizontal_tail:area"],
                    35.25,
                    atol=1e-2)
    assert_allclose(problem["data:mission:sizing:fuel"], 20494, atol=1)

    # Run optim ---------------------------------------------------------------
    problem = api.optimize_problem(configuration_file, True)
    assert not problem.optim_failed

    # Check that weight-performances loop correctly converged
    assert_allclose(
        problem["data:weight:aircraft:OWE"],
        problem["data:weight:airframe:mass"] +
        problem["data:weight:propulsion:mass"] +
        problem["data:weight:systems:mass"] +
        problem["data:weight:furniture:mass"] +
        problem["data:weight:crew:mass"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MZFW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:max_payload"],
        atol=1,
    )
    assert_allclose(
        problem["data:weight:aircraft:MTOW"],
        problem["data:weight:aircraft:OWE"] +
        problem["data:weight:aircraft:payload"] +
        problem["data:mission:sizing:fuel"],
        atol=1,
    )

    # Design Variable
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"],
                    17.06,
                    atol=1e-1)

    # Constraint
    assert_allclose(problem["data:handling_qualities:static_margin"],
                    0.05,
                    atol=1e-2)

    # Objective
    assert_allclose(problem["data:mission:sizing:fuel"], 20565, atol=50)