Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions pycycle/elements/flight_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@


class FlightConditions(Element):
"""Determines total and static flow properties given an altitude and Mach number using the input atmosphere model"""
"""
Determines total and static flow properties given an altitude and Mach number using the input atmosphere model.

With `use_external_atmosphere=True` the built-in atmosphere is replaced by the inputs
`ambient_static_temperature`, `ambient_static_pressure` and `ambient_density`, so the ambient
state can come from another model, such as a mission analysis or a non-standard day.
"""

def initialize(self):
self.options.declare('composition', default=None,
Expand All @@ -20,6 +26,10 @@ def initialize(self):
'is mixed into the flow at at the ratio set by the `mix_ratio` input')
self.options.declare('mix_ratio_name', default='mix:ratio',
desc='The name of the input that governs the mix ratio of the reactant to the primary flow')
self.options.declare('use_external_atmosphere', default=False, types=bool,
desc='If True, the built-in atmosphere model is not added and the ambient state is set '
'by the inputs `ambient_static_temperature`, `ambient_static_pressure` and '
'`ambient_density` instead of `alt` and `dTs`')

super().initialize()

Expand Down Expand Up @@ -53,7 +63,19 @@ def setup(self):
# composition = self.Fl_O_data['Fl_O']
composition = self.options['composition']

self.add_subsystem('ambient', Ambient(), promotes=('alt', 'dTs')) # inputs
if self.options['use_external_atmosphere']:
# pass the externally supplied ambient state through to the same outputs as Ambient
ambient = om.ExecComp(['Ts = Ts_in', 'Ps = Ps_in', 'rhos = rhos_in'],
Ts={'units': 'degR'}, Ts_in={'val': 518.67, 'units': 'degR'},
Ps={'units': 'psi'}, Ps_in={'val': 14.696, 'units': 'psi'},
rhos={'units': 'slug/ft**3'}, rhos_in={'val': 0.0023769, 'units': 'slug/ft**3'},
has_diag_partials=True)
self.add_subsystem('ambient', ambient,
promotes_inputs=[('Ts_in', 'ambient_static_temperature'),
('Ps_in', 'ambient_static_pressure'),
('rhos_in', 'ambient_density')])
else:
self.add_subsystem('ambient', Ambient(), promotes=('alt', 'dTs')) # inputs

conv = self.add_subsystem('conv', om.Group(), promotes=['*'])
if reactant is not False:
Expand Down
9 changes: 7 additions & 2 deletions pycycle/elements/nozzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ class PR_bal(om.ImplicitComponent):
pressure ratio (Pt/Ps) drops below 1.
"""

def initialize(self):
self.options.declare('PR_guess', default=2.0, desc='Initial guess for the total-to-static pressure ratio')

def setup(self):
self.add_input('Ps_exhaust', val=5.0, units='lbf/inch**2', desc='Exhaust static pressure')
self.add_input('Ps_calc', val=5.0, units='lbf/inch**2', desc='Calculated exhaust static pressure')

self.add_output('PR', val=2.0, lower=1.000001, units=None, desc='Total-to-staic pressure ratio')
self.add_output('PR', val=self.options['PR_guess'], lower=1.000001, units=None, desc='Total-to-staic pressure ratio')

self.declare_partials('PR', 'Ps_exhaust', val=1.0)
self.declare_partials('PR', 'Ps_calc', val=-1.0)
Expand Down Expand Up @@ -307,6 +310,8 @@ def initialize(self):
self.options.declare('lossCoef', default='Cv',
desc='If set to "Cfg", then Gross Thrust Coefficient is an input.')
self.options.declare('internal_solver', default=False)
self.options.declare('PR_guess', default=2.0,
desc='Initial guess for the total-to-static pressure ratio solved by PR_bal')

super().initialize()

Expand Down Expand Up @@ -335,7 +340,7 @@ def setup(self):
# self.connect('Ps_exhaust', 'PR_bal.lhs:PR')
# self.connect('Ps_calc', 'PR_bal.rhs:PR')

self.add_subsystem('PR_bal', PR_bal(), promotes_inputs=['*'], promotes_outputs=['*'] )
self.add_subsystem('PR_bal', PR_bal(PR_guess=self.options['PR_guess']), promotes_inputs=['*'], promotes_outputs=['*'] )

# Calculate pressure at the throat
prom_in = [('Pt_in', 'Fl_I:tot:P'),
Expand Down
59 changes: 59 additions & 0 deletions pycycle/elements/test/test_flightconditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,64 @@ def test_case1(self):
# includes=['fc.*'], excludes=['*.base_thermo.*', 'fc.ambient.readAtmTable', '*.exit_static*'])
# assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)


class ExternalAtmosphereTestCase(unittest.TestCase):

def test_matches_builtin_atmosphere(self):
"""An external ambient state reproduces the built-in atmosphere, including a hot day"""
prob = om.Problem()
prob.model = Cycle()
prob.model.options['thermo_method'] = 'CEA'
prob.model.options['thermo_data'] = janaf

prob.model.add_subsystem('fc', FlightConditions())
prob.model.add_subsystem('fc_ext', FlightConditions(use_external_atmosphere=True))

prob.model.connect('fc.ambient.Ts', 'fc_ext.ambient_static_temperature')
prob.model.connect('fc.ambient.Ps', 'fc_ext.ambient_static_pressure')
prob.model.connect('fc.ambient.rhos', 'fc_ext.ambient_density')

prob.setup(check=False, force_alloc_complex=True)
prob.set_solver_print(level=-1)

prob.set_val('fc.W', 100., units='lbm/s')
prob.set_val('fc_ext.W', 100., units='lbm/s')

# standard day at cruise, and a +27 degR hot day takeoff
for alt, MN, dTs in [(35000., 0.8, 0.), (0., 0.25, 27.)]:
prob.set_val('fc.alt', alt, units='ft')
prob.set_val('fc.dTs', dTs, units='degR')
prob.set_val('fc.MN', MN)
prob.set_val('fc_ext.MN', MN)

prob.run_model()

for var in ['tot:P', 'tot:T', 'stat:P', 'stat:T', 'stat:W', 'stat:V']:
assert_near_equal(prob[f'fc_ext.Fl_O:{var}'], prob[f'fc.Fl_O:{var}'], 1e-8)

assert_near_equal(prob.get_val('fc_ext.Fl_O:stat:T', units='degR'), 518.67 + 27., 1e-6)

partial_data = prob.check_partials(out_stream=None, method='cs', includes=['fc_ext.ambient'])
assert_check_partials(partial_data, atol=1e-10, rtol=1e-10)

def test_no_altitude_inputs(self):
"""The external atmosphere replaces the alt and dTs inputs"""
prob = om.Problem()
prob.model = Cycle()
prob.model.options['thermo_method'] = 'CEA'
prob.model.options['thermo_data'] = janaf
prob.model.add_subsystem('fc', FlightConditions(use_external_atmosphere=True))
prob.setup(check=False)
prob.final_setup()

inputs = [meta['prom_name'] for _, meta in
prob.model.list_inputs(out_stream=None, prom_name=True)]
self.assertIn('fc.ambient_static_temperature', inputs)
self.assertIn('fc.ambient_static_pressure', inputs)
self.assertIn('fc.ambient_density', inputs)
self.assertNotIn('fc.alt', inputs)
self.assertNotIn('fc.dTs', inputs)


if __name__ == "__main__":
unittest.main()
20 changes: 20 additions & 0 deletions pycycle/elements/test/test_nozzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,25 @@ def test_case1(self):
includes=['nozzle.*'], excludes=['*.base_thermo.*',])
assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)

def test_PR_guess(self):
"""PR_guess sets the starting value of the nozzle pressure ratio balance"""
prob = Problem()
cycle = prob.model = Cycle()
cycle.options['thermo_method'] = 'CEA'
cycle.options['thermo_data'] = janaf

cycle.add_subsystem('flow_start', FlowStart())
cycle.add_subsystem('nozzle', Nozzle(lossCoef='Cfg', internal_solver=True, PR_guess=1.3))
cycle.add_subsystem('nozzle_default', Nozzle(lossCoef='Cfg', internal_solver=True))
cycle.pyc_connect_flow("flow_start.Fl_O", "nozzle.Fl_I")
cycle.pyc_connect_flow("flow_start.Fl_O", "nozzle_default.Fl_I")

prob.setup(check=False)
prob.final_setup()

assert_near_equal(prob['nozzle.PR'], 1.3, 1e-12)
assert_near_equal(prob['nozzle_default.PR'], 2.0, 1e-12)


if __name__ == "__main__":
unittest.main()