From 946ccdb48cade25bb118596dda2b3c0af1076430 Mon Sep 17 00:00:00 2001 From: anushka-tahiliani Date: Mon, 16 Nov 2026 14:03:32 -0500 Subject: [PATCH] Add external atmosphere option to FlightConditions and PR_guess to Nozzle FlightConditions(use_external_atmosphere=True) replaces the built-in atmosphere with ambient_static_temperature, ambient_static_pressure and ambient_density inputs, so the ambient state can come from another model such as a mission analysis or a non-standard day. Nozzle(PR_guess=...) sets the starting value of the PR_bal pressure ratio, previously fixed at 2.0. Both defaults leave results unchanged. --- pycycle/elements/flight_conditions.py | 26 +++++++- pycycle/elements/nozzle.py | 9 ++- .../elements/test/test_flightconditions.py | 59 +++++++++++++++++++ pycycle/elements/test/test_nozzle.py | 20 +++++++ 4 files changed, 110 insertions(+), 4 deletions(-) diff --git a/pycycle/elements/flight_conditions.py b/pycycle/elements/flight_conditions.py index 8875cdcc..2dd3e16a 100644 --- a/pycycle/elements/flight_conditions.py +++ b/pycycle/elements/flight_conditions.py @@ -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, @@ -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() @@ -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: diff --git a/pycycle/elements/nozzle.py b/pycycle/elements/nozzle.py index 165ebba6..4d1db7b4 100644 --- a/pycycle/elements/nozzle.py +++ b/pycycle/elements/nozzle.py @@ -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) @@ -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() @@ -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'), diff --git a/pycycle/elements/test/test_flightconditions.py b/pycycle/elements/test/test_flightconditions.py index fa0f8285..f1257743 100644 --- a/pycycle/elements/test/test_flightconditions.py +++ b/pycycle/elements/test/test_flightconditions.py @@ -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() diff --git a/pycycle/elements/test/test_nozzle.py b/pycycle/elements/test/test_nozzle.py index 6da7f6ee..551129e1 100644 --- a/pycycle/elements/test/test_nozzle.py +++ b/pycycle/elements/test/test_nozzle.py @@ -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()