Пример #1
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)
Пример #2
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)
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)
Пример #4
0
 def _generate_conf_file(args):
     """Generates a sample TOML file."""
     try:
         api.generate_configuration_file(args.conf_file, args.force)
     except FastFileExistsError:
         if _query_yes_no(
                 'Configuration file "%s" already exists. Do you want to overwrite it?'
                 % args.conf_file):
             api.generate_configuration_file(args.conf_file, True)
         else:
             print("No file written.")
Пример #5
0
def run_non_regression_test(
    conf_file,
    legacy_result_file,
    result_dir,
    use_xfoil=False,
    global_tolerance=1e-2,
    vars_to_check=None,
    specific_tolerance=5.0e-3,
    check_weight_perfo_loop=True,
):
    """
    Convenience function for non regression tests
    :param conf_file: FAST-OAD configuration file
    :param legacy_result_file: reference data for inputs and outputs
    :param result_dir: relative name, folder will be in RESULTS_FOLDER_PATH
    :param use_xfoil: if True, XFOIL computation will be activated
    :param vars_to_check: variables that will be concerned by specific_tolerance
    :param specific_tolerance: test will fail if absolute relative error between computed and
                               reference values is beyond this value for variables in vars_to_check
    :param global_tolerance: test will fail if absolute relative error between computed and
                             reference values is beyond this value for ANY variable
    :param check_weight_perfo_loop: if True, consistency of weights will be checked
    """
    results_folder_path = pth.join(RESULTS_FOLDER_PATH, result_dir)
    configuration_file_path = pth.join(results_folder_path, conf_file)

    # Copy of configuration file and generation of problem instance ------------------
    api.generate_configuration_file(configuration_file_path)  # just ensure folders are created...
    shutil.copy(pth.join(DATA_FOLDER_PATH, conf_file), configuration_file_path)
    configurator = FASTOADProblemConfigurator(configuration_file_path)
    configurator._set_configuration_modifier(XFOILConfigurator(use_xfoil))

    # Generation of inputs ----------------------------------------
    ref_inputs = pth.join(DATA_FOLDER_PATH, legacy_result_file)
    configurator.write_needed_inputs(ref_inputs)

    # Get problem with inputs -------------------------------------
    problem = configurator.get_problem(read_inputs=True)
    problem.setup()

    # Run model ---------------------------------------------------------------
    problem.run_model()
    problem.write_outputs()

    om.view_connections(
        problem, outfile=pth.join(results_folder_path, "connections.html"), show_browser=False
    )

    if check_weight_perfo_loop:
        _check_weight_performance_loop(problem)

    ref_data = DataFile(pth.join(DATA_FOLDER_PATH, legacy_result_file))

    row_list = []
    for ref_var in ref_data:
        try:
            value = problem.get_val(ref_var.name, units=ref_var.units)[0]
        except KeyError:
            continue
        row_list.append(
            {
                "name": ref_var.name,
                "units": ref_var.units,
                "ref_value": ref_var.value[0],
                "value": value,
            }
        )

    df = pd.DataFrame(row_list)
    df["rel_delta"] = (df.value - df.ref_value) / df.ref_value
    df["rel_delta"][(df.ref_value == 0) & (abs(df.value) <= 1e-10)] = 0.0
    df["abs_rel_delta"] = np.abs(df.rel_delta)

    pd.set_option("display.max_rows", None)
    pd.set_option("display.max_columns", None)
    pd.set_option("display.width", 1000)
    pd.set_option("display.max_colwidth", 120)
    print(df.sort_values(by=["abs_rel_delta"]))

    if vars_to_check is not None:
        for name in vars_to_check:
            assert_allclose(df.ref_value, df.value, rtol=global_tolerance)
            row = df.loc[df.name == name]
            assert_allclose(row.ref_value, row.value, rtol=specific_tolerance)
    else:
        assert np.all(df.abs_rel_delta < specific_tolerance)