From 7f6880a0b7f3a382dfb85e508933060ecd90d0b3 Mon Sep 17 00:00:00 2001 From: Carl Recine Date: Mon, 17 Jun 2024 10:31:09 -0700 Subject: [PATCH 1/3] initial commit --- aviary/docs/examples/images/OAS_xdsm.PNG | Bin aviary/docs/user_guide/aviary_commands.ipynb | 8 +-- aviary/interface/download_models.py | 1 - .../interface/test/test_cmd_entry_points.py | 60 +++++++++++++++++- 4 files changed, 63 insertions(+), 6 deletions(-) mode change 100755 => 100644 aviary/docs/examples/images/OAS_xdsm.PNG diff --git a/aviary/docs/examples/images/OAS_xdsm.PNG b/aviary/docs/examples/images/OAS_xdsm.PNG old mode 100755 new mode 100644 diff --git a/aviary/docs/user_guide/aviary_commands.ipynb b/aviary/docs/user_guide/aviary_commands.ipynb index aa34c6053..4a16c3754 100644 --- a/aviary/docs/user_guide/aviary_commands.ipynb +++ b/aviary/docs/user_guide/aviary_commands.ipynb @@ -194,7 +194,7 @@ "`aviary hangar turbofan_22k.txt` Copy the 22k turbofan deck\n", "`aviary hangar N3CC/N3CC_data.py` Copy the N3CC data\n", "`aviary hangar small_single_aisle_GwGm.dat small_single_aisle_GwGm.csv` Copy the Fortran and Aviary input decks for the small single aisle\n", - "`aviary hangar turbofan_22k.txt ~/example_files` Copy the engine model into ~/example_files\n", + "`aviary hangar turbofan_22k.txt -o ~/example_files` Copy the engine model into ~/example_files\n", "```\n" ] }, @@ -282,9 +282,9 @@ "\n", "Example usage:\n", "```\n", - "`aviary convert_engine GASP_turbofan_23k_1.eng turbofan_23k_1_lbm_s.deck GASP` Convert a GASP based turbofan\n", - "`aviary convert_engine turbofan_22k.eng turbofan_22k.txt FLOPS` Convert a FLOPS based turbofan\n", - "`aviary convert_engine turboprop_4465hp.eng turboprop_4465hp.deck GASP_TP` Convert a GASP based turboprop\n", + "`aviary convert_aero_table subsystems/aerodynamics/gasp_based/data/GASP_aero_free.txt turbofan_23k_1_lbm_s.deck GASP` Convert a GASP based turbofan\n", + "`aviary convert_aero_table turbofan_22k.eng turbofan_22k.txt FLOPS` Convert a FLOPS based turbofan\n", + "`aviary convert_aero_table turboprop_4465hp.eng turboprop_4465hp.deck GASP_TP` Convert a GASP based turboprop\n", "```\n" ] }, diff --git a/aviary/interface/download_models.py b/aviary/interface/download_models.py index e58c3dea1..37bf1e85d 100644 --- a/aviary/interface/download_models.py +++ b/aviary/interface/download_models.py @@ -91,7 +91,6 @@ def _setup_hangar_parser(parser: argparse.ArgumentParser): def _exec_hangar(args, user_args): - # check if args.input_deck is a list, if so, use the first element input_decks = [] for input_deck in args.input_decks: input_decks.append(get_model(input_deck, args.verbose)) diff --git a/aviary/interface/test/test_cmd_entry_points.py b/aviary/interface/test/test_cmd_entry_points.py index b8df65de8..afb475bbf 100644 --- a/aviary/interface/test/test_cmd_entry_points.py +++ b/aviary/interface/test/test_cmd_entry_points.py @@ -8,7 +8,6 @@ @use_tempdirs class CommandEntryPointsTestCases(unittest.TestCase): - def run_and_test_cmd(self, cmd): # this only tests that a given command line tool returns a 0 return code. It doesn't # check the expected output at all. The underlying functions that implement the @@ -18,6 +17,8 @@ def run_and_test_cmd(self, cmd): except subprocess.CalledProcessError as err: self.fail(f"Command '{cmd}' failed. Return code: {err.returncode}") + +class run_missionTestCases(CommandEntryPointsTestCases): @require_pyoptsparse(optimizer="SNOPT") def bench_test_SNOPT_cmd(self): cmd = 'aviary run_mission models/test_aircraft/aircraft_for_bench_GwGm.csv --optimizer SNOPT --max_iter 1' @@ -40,6 +41,8 @@ def bench_test_phase_info_cmd(self): ' --phase_info interface/default_phase_info/two_dof.py' self.run_and_test_cmd(cmd) + +class fortran_to_aviaryTestCases(CommandEntryPointsTestCases): def test_diff_configuration_conversion(self): filepath = pkg_resources.resource_filename('aviary', 'models/test_aircraft/converter_configuration_test_data_GwGm.dat') @@ -73,5 +76,60 @@ def test_force_conversion(self): self.run_and_test_cmd(cmd2) +class hangarTestCases(CommandEntryPointsTestCases): + def test_copy_folder(self): + cmd = f'aviary hangar engines' + self.run_and_test_cmd(cmd) + + def test_copy_deck(self): + cmd = f'aviary hangar turbofan_22k.txt' + self.run_and_test_cmd(cmd) + + def test_copy_n3cc_data(self): + cmd = f'aviary hangar N3CC/N3CC_data.py' + self.run_and_test_cmd(cmd) + + def test_copy_multiple(self): + cmd = f'aviary hangar small_single_aisle_GwGm.dat small_single_aisle_GwGm.csv' + self.run_and_test_cmd(cmd) + + def test_copy_to(self): + outfile = Path.cwd() / 'example_files' + cmd = f'aviary hangar small_single_aisle_GwGm.dat -o {outfile}' + self.run_and_test_cmd(cmd) + + +class convert_engineTestCases(CommandEntryPointsTestCases): + def test_GASP_conversion(self): + filepath = pkg_resources.resource_filename( + 'aviary', 'models/engines/GASP_turbofan_23k_1.eng') + outfile = Path.cwd() / 'turbofan_23k_1_lbm_s.deck' + cmd = f'aviary convert_engine {filepath} {outfile} GASP' + self.run_and_test_cmd(cmd) + + def test_FLOPS_conversion(self): + filepath = pkg_resources.resource_filename( + 'aviary', 'models/engines/turbofan_22k.eng') + outfile = Path.cwd() / 'turbofan_22k.txt' + cmd = f'aviary convert_engine {filepath} {outfile} -f FLOPS' + self.run_and_test_cmd(cmd) + + def test_GASP_TP_conversion(self): + filepath = pkg_resources.resource_filename( + 'aviary', 'models/engines/turboprop_4465hp.eng') + outfile = Path.cwd() / 'turboprop_4465hp.eng' + cmd = f'aviary convert_engine {filepath} {outfile} --data_format GASP_TP' + self.run_and_test_cmd(cmd) + + +class convert_aero_tableTestCases(CommandEntryPointsTestCases): + def test_FLOPS_conversion(self): + filepath = pkg_resources.resource_filename('aviary', + 'models/N3CC/N3CC_generic_low_speed_polars_FLOPSinp.txt') + outfile = Path.cwd() / 'N3CC' / 'output.dat' + cmd = f'aviary fortran_to_aviary {filepath} -o {outfile} -l FLOPS' + self.run_and_test_cmd(cmd) + + if __name__ == "__main__": unittest.main() From d3f7defc1488b7575cda639100c8b971bcbe3592 Mon Sep 17 00:00:00 2001 From: Carl Recine Date: Thu, 20 Jun 2024 16:53:35 -0700 Subject: [PATCH 2/3] Added test to check file is converted as expected, testing more cli --- .../interface/test/test_cmd_entry_points.py | 36 ++++++++++++++----- .../utils/test/test_aero_table_conversion.py | 30 +++++++++++++++- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/aviary/interface/test/test_cmd_entry_points.py b/aviary/interface/test/test_cmd_entry_points.py index afb475bbf..6817b7579 100644 --- a/aviary/interface/test/test_cmd_entry_points.py +++ b/aviary/interface/test/test_cmd_entry_points.py @@ -100,32 +100,50 @@ def test_copy_to(self): class convert_engineTestCases(CommandEntryPointsTestCases): + def get_file(self, filename): + filepath = pkg_resources.resource_filename('aviary', filename) + if not Path(filepath).exists(): + self.skipTest(f"couldn't find {filepath}") + return filepath + def test_GASP_conversion(self): - filepath = pkg_resources.resource_filename( - 'aviary', 'models/engines/GASP_turbofan_23k_1.eng') + # skipped because the original files don't exist any longer + filepath = self.get_file('models/engines/GASP_turbofan_23k_1.eng') outfile = Path.cwd() / 'turbofan_23k_1_lbm_s.deck' - cmd = f'aviary convert_engine {filepath} {outfile} GASP' + cmd = f'aviary convert_engine {filepath} {outfile} -f GASP' self.run_and_test_cmd(cmd) def test_FLOPS_conversion(self): - filepath = pkg_resources.resource_filename( - 'aviary', 'models/engines/turbofan_22k.eng') + # skipped because the original files don't exist any longer + filepath = self.get_file('models/engines/turbofan_22k.eng') outfile = Path.cwd() / 'turbofan_22k.txt' cmd = f'aviary convert_engine {filepath} {outfile} -f FLOPS' self.run_and_test_cmd(cmd) def test_GASP_TP_conversion(self): - filepath = pkg_resources.resource_filename( - 'aviary', 'models/engines/turboprop_4465hp.eng') + filepath = self.get_file('models/engines/turboprop_4465hp.eng') outfile = Path.cwd() / 'turboprop_4465hp.eng' cmd = f'aviary convert_engine {filepath} {outfile} --data_format GASP_TP' self.run_and_test_cmd(cmd) class convert_aero_tableTestCases(CommandEntryPointsTestCases): + def get_file(self, filename): + filepath = pkg_resources.resource_filename('aviary', filename) + if not Path(filepath).exists(): + self.skipTest(f"couldn't find {filepath}") + return filepath + + def test_GASP_conversion(self): + filepath = self.get_file( + 'subsystems/aerodynamics/gasp_based/data/GASP_aero_flaps.txt') + outfile = Path.cwd() / 'output.dat' + cmd = f'aviary fortran_to_aviary {filepath} -o {outfile} -l GASP' + self.run_and_test_cmd(cmd) + def test_FLOPS_conversion(self): - filepath = pkg_resources.resource_filename('aviary', - 'models/N3CC/N3CC_generic_low_speed_polars_FLOPSinp.txt') + filepath = self.get_file( + 'models/N3CC/N3CC_generic_low_speed_polars_FLOPSinp.txt') outfile = Path.cwd() / 'N3CC' / 'output.dat' cmd = f'aviary fortran_to_aviary {filepath} -o {outfile} -l FLOPS' self.run_and_test_cmd(cmd) diff --git a/aviary/utils/test/test_aero_table_conversion.py b/aviary/utils/test/test_aero_table_conversion.py index 13f36a153..6cef6f368 100644 --- a/aviary/utils/test/test_aero_table_conversion.py +++ b/aviary/utils/test/test_aero_table_conversion.py @@ -1,12 +1,13 @@ import unittest import numpy as np +from pathlib import Path from openmdao.utils.assert_utils import assert_near_equal from openmdao.utils.testing_utils import use_tempdirs from aviary.utils.functions import get_path -from aviary.utils.aero_table_conversion import _load_flops_aero_table, _load_gasp_aero_table +from aviary.utils.aero_table_conversion import _load_flops_aero_table, _load_gasp_aero_table, _exec_ATC @use_tempdirs @@ -131,6 +132,33 @@ def test_FLOPS_table(self): assert_near_equal(cd0_data.get_val('Altitude', 'ft'), expected_cd0_alt) assert_near_equal(cd0_data.get_val('Zero-Lift Drag Coefficient'), expected_cd0) + def test_GASP_file(self): + def args(): return None + args.input_file = 'subsystems/aerodynamics/gasp_based/data/GASP_aero_flaps.txt' + args.output_file = str(Path.cwd() / Path('TEST_'+Path(args.input_file).name)) + args.data_format = 'GASP' + _exec_ATC(args, None) + + validation_data = get_path( + 'subsystems/aerodynamics/gasp_based/data/large_single_aisle_1_aero_flaps.txt') + + # Open the converted and validation files + with open(args.output_file, 'r') as f_in, open(validation_data, 'r') as expected: + for line in f_in: + if any(s in line for s in ['created']): + break + # Remove whitespace and compare + expected_line = ''.join(expected.readline().split()) + line_no_whitespace = ''.join(line.split()) + + # Assert that the lines are equal + try: + self.assertEqual(line_no_whitespace.count(expected_line), 1) + + except Exception as error: + exc_string = f'Error: {args.output_file}\nFound: {line_no_whitespace}\nExpected: {expected_line}' + raise Exception(exc_string) + if __name__ == '__main__': unittest.main() From 9ef611e14fb0c18d14ea44c8820af58b9f8c023f Mon Sep 17 00:00:00 2001 From: Carl Recine Date: Thu, 20 Jun 2024 16:58:32 -0700 Subject: [PATCH 3/3] updated docs --- aviary/docs/user_guide/aviary_commands.ipynb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aviary/docs/user_guide/aviary_commands.ipynb b/aviary/docs/user_guide/aviary_commands.ipynb index 4a16c3754..595e1391f 100644 --- a/aviary/docs/user_guide/aviary_commands.ipynb +++ b/aviary/docs/user_guide/aviary_commands.ipynb @@ -282,9 +282,8 @@ "\n", "Example usage:\n", "```\n", - "`aviary convert_aero_table subsystems/aerodynamics/gasp_based/data/GASP_aero_free.txt turbofan_23k_1_lbm_s.deck GASP` Convert a GASP based turbofan\n", - "`aviary convert_aero_table turbofan_22k.eng turbofan_22k.txt FLOPS` Convert a FLOPS based turbofan\n", - "`aviary convert_aero_table turboprop_4465hp.eng turboprop_4465hp.deck GASP_TP` Convert a GASP based turboprop\n", + "`aviary convert_aero_table subsystems/aerodynamics/gasp_based/data/GASP_aero_free.txt large_single_aisle_1_aero_flaps.txt GASP` Convert a GASP based aero table\n", + "`aviary convert_aero_table utils/test/flops_test_polar.txt aviary_flops_polar.txt FLOPS` Convert a FLOPS based aero table\n", "```\n" ] },