Example #1
0
def test_api_eval_mission(cleanup):
    results_folder_path = pth.join(RESULTS_FOLDER_PATH, "api_eval_mission")
    configuration_file_path = pth.join(results_folder_path, "oad_process.yml")
    api._PROBLEM_CONFIGURATOR = MissionConfigurator()

    # 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",
        "01_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)
    api._PROBLEM_CONFIGURATOR = None

    # Check that weight-performances loop correctly converged
    _check_weight_performance_loop(problem)

    assert_allclose(problem["data:handling_qualities:static_margin"], 0.05, atol=1e-2)
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"], 17.149, atol=1e-2)
    assert_allclose(problem["data:weight:aircraft:MTOW"], 74846, atol=1)
    assert_allclose(problem["data:geometry:wing:area"], 126.581, atol=1e-2)
    assert_allclose(problem["data:geometry:vertical_tail:area"], 27.535, atol=1e-2)
    assert_allclose(problem["data:geometry:horizontal_tail:area"], 35.848, atol=1e-2)
    assert_allclose(problem["data:mission:sizing:needed_block_fuel"], 19495, atol=1)
Example #2
0
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.yml")

    # 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",
        "01_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
    _check_weight_performance_loop(problem)

    # Design Variable
    assert_allclose(problem["data:geometry:wing:aspect_ratio"], 14.52, atol=1e-2)

    # Constraint
    assert_allclose(problem["data:geometry:wing:span"], 44.88, atol=1e-2)

    # Objective
    assert_allclose(problem["data:mission:sizing:needed_block_fuel"], 18900.0, atol=1)
def test_api_eval_breguet(cleanup):
    results_folder_path = pth.join(RESULTS_FOLDER_PATH, "api_eval_breguet")
    configuration_file_path = pth.join(results_folder_path, "oad_process.yml")

    # 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(DATA_FOLDER_PATH, "CeRAS01_notebooks.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
    _check_weight_performance_loop(problem)

    assert_allclose(problem["data:handling_qualities:static_margin"], 0.05, atol=1e-2)
    assert_allclose(problem["data:geometry:wing:MAC:at25percent:x"], 17.149, atol=1e-2)
    assert_allclose(problem["data:weight:aircraft:MTOW"], 74892, atol=1)
    assert_allclose(problem["data:geometry:wing:area"], 126.732, atol=1e-2)
    assert_allclose(problem["data:geometry:vertical_tail:area"], 27.565, atol=1e-2)
    assert_allclose(problem["data:geometry:horizontal_tail:area"], 35.884, atol=1e-2)
    assert_allclose(problem["data:mission:sizing:needed_block_fuel"], 19527, atol=1)
Example #4
0
def test_optimization_viewer_save(cleanup):
    """
    Basic tests for testing the OptimizationViewer save method.
    """
    filename = pth.join(DATA_FOLDER_PATH, "valid_sellar.toml")
    new_filename = pth.join(RESULTS_FOLDER_PATH, "new_valid_sellar.toml")
    copyfile(filename, new_filename)

    # Loading new file
    problem_configuration = FASTOADProblemConfigurator(filename)

    optim_viewer = OptimizationViewer()

    api.generate_inputs(new_filename,
                        pth.join(DATA_FOLDER_PATH, "inputs.xml"),
                        overwrite=True)

    # Load new file
    optim_viewer.load(problem_configuration)
    optim_viewer.save()
    optim_viewer.load(problem_configuration)

    # We run the problem
    api.optimize_problem(new_filename, overwrite=True)
    optim_viewer.load(problem_configuration)
    optim_viewer.save()
    optim_viewer.load(problem_configuration)
Example #5
0
def test_optimization_viewer_load(cleanup):
    """
    Basic tests for testing the OptimizationViewer load method.
    """
    filename = pth.join(DATA_FOLDER_PATH, "valid_sellar.toml")

    # The problem has not yet been run
    problem_configuration = FASTOADProblemConfigurator(filename)

    optim_viewer = OptimizationViewer()

    # No input file exists
    with pytest.raises(FastMissingFile):
        optim_viewer.load(problem_configuration)

    api.generate_inputs(filename,
                        pth.join(DATA_FOLDER_PATH, "inputs.xml"),
                        overwrite=True)

    # Input file exist
    optim_viewer.load(problem_configuration)

    # We run the problem
    api.optimize_problem(filename, overwrite=True)

    # Load the results
    optim_viewer.load(problem_configuration)
Example #6
0
 def _generate_inputs(args):
     """Generates input file according to command line arguments."""
     schema = "legacy" if args.legacy else "native"
     try:
         api.generate_inputs(args.conf_file, args.source, schema, args.force)
     except FastFileExistsError as exc:
         if _query_yes_no(
             'Input file "%s" already exists. Do you want to overwrite it?' % exc.args[1]
         ):
             api.generate_inputs(args.conf_file, args.source, schema, True)
         else:
             print("No file written.")
Example #7
0
def test_optimization_viewer_display(cleanup):
    """
    Basic tests for testing the OptimizationViewer load method.
    """
    filename = pth.join(DATA_FOLDER_PATH, "valid_sellar.toml")

    # The problem has not yet been ran
    problem_configuration = FASTOADProblemConfigurator(filename)

    optim_viewer = OptimizationViewer()

    api.generate_inputs(filename,
                        pth.join(DATA_FOLDER_PATH, "inputs.xml"),
                        overwrite=True)

    optim_viewer.load(problem_configuration)
    optim_viewer.display()