Skip to content

Commit

Permalink
Merge pull request OpenMDAO#281 from xjjiang/read_csv_Extended
Browse files Browse the repository at this point in the history
Read csv extended
  • Loading branch information
johnjasa authored May 16, 2024
2 parents 4d6ab72 + a66eee1 commit 31146b6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
9 changes: 6 additions & 3 deletions aviary/docs/getting_started/onboarding_ext_subsystem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"source": [
"from aviary.examples.external_subsystems.battery.battery_builder import BatteryBuilder\n",
"from aviary.examples.external_subsystems.battery.battery_variables import Aircraft\n",
"from aviary.examples.external_subsystems.battery.battery_variable_meta_data import ExtendedMetaData\n",
"\n",
"battery_builder = BatteryBuilder(include_constraints=False)\n",
"\n",
Expand All @@ -231,16 +232,18 @@
"source": [
"prob = av.AviaryProblem()\n",
"\n",
"prob.load_inputs('models/test_aircraft/aircraft_for_bench_FwFm.csv', phase_info)"
"prob.load_inputs('models/test_aircraft/aircraft_for_bench_FwFm.csv',\n",
" phase_info, meta_data=ExtendedMetaData)"
]
},
{
"cell_type": "markdown",
"id": "96ebdf23",
"metadata": {},
"source": [
"Since this example contains new variables in the aircraft hierarchy, the metadata for those variables was added to an extended metadata dictionary. We need to pass that into load_inputs so that it can load susbsystem-specific inputs from the csv file.\n",
"\n",
"In the battery subsystem, the type of battery cell we use is `18650`. The option is not set in `input_file`, instead is is controlled by importing the correct battery map [here](https://github.com/OpenMDAO/Aviary/blob/1fca1c03cb2e1d6387442162e8d7dabf83eee197/aviary/examples/external_subsystems/battery/model/reg_thevenin_interp_group.py#L5)."
"In the battery subsystem, the type of battery cell we use is `18650`. The option is not set in `input_file`, instead it is controlled by importing the correct battery map [here](https://github.com/OpenMDAO/Aviary/blob/1fca1c03cb2e1d6387442162e8d7dabf83eee197/aviary/examples/external_subsystems/battery/model/reg_thevenin_interp_group.py#L5)."
]
},
{
Expand Down Expand Up @@ -755,7 +758,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get_design_vars(self):
Aircraft.Battery.Cell.DISCHARGE_RATE: {
'units': 'A',
'lower': 0.0,
'upper': 1.0,
'upper': 2.0,
},
}

Expand Down Expand Up @@ -250,7 +250,7 @@ def preprocess_inputs(self, aviary_inputs):
In this case, it sets the values battery performance based on the battery cell type.
'''
battery_cell_info_18650 = {
Aircraft.Battery.Cell.DISCHARGE_RATE: [10.5, 'A'],
Aircraft.Battery.Cell.DISCHARGE_RATE: [2.0, 'A'],
Aircraft.Battery.Cell.ENERGY_CAPACITY_MAX: [3.5, 'A*h'],
Aircraft.Battery.Cell.HEAT_CAPACITY: [1020.0, 'J/(kg*K)'],
Aircraft.Battery.Cell.MASS: [0.045, 'kg'],
Expand Down
4 changes: 3 additions & 1 deletion aviary/examples/external_subsystems/battery/run_cruise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from aviary.examples.external_subsystems.battery.battery_builder import BatteryBuilder
from aviary.examples.external_subsystems.battery.battery_variables import Aircraft, Mission
from aviary.examples.external_subsystems.battery.battery_variable_meta_data import ExtendedMetaData


battery_builder = BatteryBuilder()
Expand All @@ -16,7 +17,8 @@

# Load aircraft and options data from user
# Allow for user overrides here
prob.load_inputs('models/test_aircraft/aircraft_for_bench_FwFm.csv', phase_info)
prob.load_inputs('models/test_aircraft/aircraft_for_bench_FwFm.csv',
phase_info, meta_data=ExtendedMetaData)

# Preprocess inputs
prob.check_and_preprocess_inputs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from aviary.examples.external_subsystems.battery.battery_builder import BatteryBuilder
from aviary.examples.external_subsystems.battery.battery_variables import Aircraft
from aviary.examples.external_subsystems.battery.battery_variable_meta_data import ExtendedMetaData
from aviary.api import default_height_energy_phase_info as phase_info


Expand All @@ -22,7 +23,7 @@

# Load aircraft and options data from user
# Allow for user overrides here
prob.load_inputs(input_file, phase_info)
prob.load_inputs(input_file, phase_info, meta_data=ExtendedMetaData)


# Preprocess inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import aviary.api as av

from aviary.examples.external_subsystems.engine_NPSS.table_engine_builder import TableEngineBuilder as EngineBuilder
from aviary.examples.external_subsystems.engine_NPSS.engine_variable_meta_data import ExtendedMetaData


def define_aviary_NPSS_problem():
Expand All @@ -20,7 +21,7 @@ def define_aviary_NPSS_problem():
# Allow for user overrides here
# add engine builder
prob.load_inputs('models/test_aircraft/aircraft_for_bench_FwFm.csv',
phase_info, engine_builder=EngineBuilder())
phase_info, engine_builder=EngineBuilder(), meta_data=ExtendedMetaData)

prob.check_and_preprocess_inputs()

Expand Down
4 changes: 2 additions & 2 deletions aviary/interface/methods_for_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def __init__(self, analysis_scheme=AnalysisScheme.COLLOCATION, **kwargs):
self.regular_phases = []
self.reserve_phases = []

def load_inputs(self, aviary_inputs, phase_info=None, engine_builder=None, verbosity=Verbosity.BRIEF):
def load_inputs(self, aviary_inputs, phase_info=None, engine_builder=None, verbosity=Verbosity.BRIEF, meta_data=BaseMetaData):
"""
This method loads the aviary_values inputs and options that the
user specifies. They could specify files to load and values to
Expand All @@ -251,7 +251,7 @@ def load_inputs(self, aviary_inputs, phase_info=None, engine_builder=None, verbo
# Create AviaryValues object from file (or process existing AviaryValues object
# with default values from metadata) and generate initial guesses
aviary_inputs, initial_guesses = create_vehicle(
aviary_inputs, verbosity=verbosity)
aviary_inputs, verbosity=verbosity, meta_data=meta_data)

# pull which methods will be used for subsystems and mission
self.mission_method = mission_method = aviary_inputs.get_val(
Expand Down
5 changes: 3 additions & 2 deletions aviary/utils/process_input_decks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'alternate': ProblemType.ALTERNATE, 'fallout': ProblemType.FALLOUT}


def create_vehicle(vehicle_deck='', verbosity=Verbosity.BRIEF):
def create_vehicle(vehicle_deck='', verbosity=Verbosity.BRIEF, meta_data=_MetaData):
"""
Creates and initializes a vehicle with default or specified parameters. It sets up the aircraft values
and initial guesses based on the input from the vehicle deck.
Expand Down Expand Up @@ -65,7 +65,8 @@ def create_vehicle(vehicle_deck='', verbosity=Verbosity.BRIEF):
initial_guesses = {}
else:
vehicle_deck = get_path(vehicle_deck)
aircraft_values, initial_guesses = parse_inputs(vehicle_deck, aircraft_values)
aircraft_values, initial_guesses = parse_inputs(
vehicle_deck, aircraft_values, meta_data=meta_data)

return aircraft_values, initial_guesses

Expand Down

0 comments on commit 31146b6

Please sign in to comment.