Skip to content

Commit

Permalink
Merge pull request OpenMDAO#338 from crecine/update_docs_and_tests
Browse files Browse the repository at this point in the history
Updating Docs and Tests for CLI
  • Loading branch information
jkirk5 authored Jun 21, 2024
2 parents 9702291 + 9ef611e commit 925b34b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
Empty file modified aviary/docs/examples/images/OAS_xdsm.PNG
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions aviary/docs/user_guide/aviary_commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -282,9 +282,8 @@
"\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 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"
]
},
Expand Down
1 change: 0 additions & 1 deletion aviary/interface/download_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
78 changes: 77 additions & 1 deletion aviary/interface/test/test_cmd_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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')
Expand Down Expand Up @@ -73,5 +76,78 @@ 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 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):
# 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} -f GASP'
self.run_and_test_cmd(cmd)

def test_FLOPS_conversion(self):
# 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 = 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 = 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)


if __name__ == "__main__":
unittest.main()
30 changes: 29 additions & 1 deletion aviary/utils/test/test_aero_table_conversion.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 925b34b

Please sign in to comment.