def _build_problem(self, designed_stream=1, complex=False): p = Problem() cycle = p.model = Cycle() cycle.set_input_defaults('start1.P', 9.218, units='psi') cycle.set_input_defaults('start1.T', 1524.32, units='degR') cycle.set_input_defaults('start1.MN', 0.4463) cycle.set_input_defaults('start1.W', 161.49, units='lbm/s') cycle.set_input_defaults('start2.P', 8.68, units='psi') cycle.set_input_defaults('start2.T', 524., units='degR') cycle.set_input_defaults('start2.MN', 0.4463) cycle.set_input_defaults('start2.W', 158., units='lbm/s') cycle.add_subsystem('start1', FlowStart(elements=AIR_FUEL_ELEMENTS)) cycle.add_subsystem('start2', FlowStart(elements=AIR_ELEMENTS)) cycle.add_subsystem( 'mixer', Mixer(design=True, designed_stream=designed_stream, Fl_I1_elements=AIR_FUEL_ELEMENTS, Fl_I2_elements=AIR_ELEMENTS)) cycle.pyc_connect_flow('start1.Fl_O', 'mixer.Fl_I1') cycle.pyc_connect_flow('start2.Fl_O', 'mixer.Fl_I2') p.setup(force_alloc_complex=complex) p.set_solver_print(level=-1) return p
def test_mix_diff(self): # mix two identical streams and make sure you get twice the area and the same total pressure p = Problem() cycle = p.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = janaf cycle.set_input_defaults('start1.P', 17., units='psi') cycle.set_input_defaults('start2.P', 15., units='psi') cycle.set_input_defaults('T', 500., units='degR') cycle.set_input_defaults('MN', 0.5) cycle.set_input_defaults('W', 100., units='lbm/s') cycle.add_subsystem('start1', FlowStart(), promotes=['MN', 'T', 'W']) cycle.add_subsystem('start2', FlowStart(), promotes=['MN', 'T', 'W']) cycle.add_subsystem('mixer', Mixer(design=True)) cycle.pyc_connect_flow('start1.Fl_O', 'mixer.Fl_I1') cycle.pyc_connect_flow('start2.Fl_O', 'mixer.Fl_I2') p.set_solver_print(level=-1) p.setup() p.run_model() tol = 1e-6 assert_near_equal(p['mixer.Fl_O:stat:area'], 653.26524074, tolerance=tol) assert_near_equal(p['mixer.Fl_O:tot:P'], 15.89206597, tolerance=tol) assert_near_equal(p['mixer.ER'], 1.1333333333, tolerance=tol)
def setUp(self): self.prob = Problem() self.prob.model = Cycle() self.prob.model.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS)) self.prob.model.add_subsystem( 'turbine', Turbine(map_data=LPT2269, design=True, elements=AIR_ELEMENTS)) self.prob.model.set_input_defaults('turbine.Nmech', 1000.0, units='rpm') self.prob.model.set_input_defaults('flow_start.MN', 0.0) self.prob.model.set_input_defaults('turbine.PR', 4.0) self.prob.model.set_input_defaults('turbine.MN', 0.0) self.prob.model.set_input_defaults('flow_start.P', 17.0, units='psi') self.prob.model.set_input_defaults('flow_start.T', 500.0, units='degR') self.prob.model.set_input_defaults('flow_start.W', 100.0, units='lbm/s') self.prob.model.set_input_defaults('turbine.eff', 0.9) self.prob.model.pyc_connect_flow('flow_start.Fl_O', 'turbine.Fl_I') self.prob.setup(check=False, force_alloc_complex=True) self.prob.set_solver_print(level=-1)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = janaf # cycle.options['thermo_method'] = 'TABULAR' # cycle.options['thermo_data'] = AIR_JETA_TAB_SPEC cycle.set_input_defaults('flow_start.P', 17, units='psi') cycle.set_input_defaults('flow_start.T', 500.0, units='degR') cycle.set_input_defaults('inlet.MN', 0.5) cycle.set_input_defaults('inlet.Fl_I:stat:V', 1., units='ft/s') cycle.set_input_defaults('flow_start.W', 1., units='lbm/s') cycle.add_subsystem('flow_start', FlowStart()) cycle.add_subsystem('inlet', Inlet()) # total and static fl_src = "flow_start.Fl_O" fl_target = "inlet.Fl_I" cycle.pyc_connect_flow("flow_start.Fl_O", "inlet.Fl_I") self.prob.set_solver_print(level=-1) self.prob.setup(check=False, force_alloc_complex=True)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS)) cycle.add_subsystem( 'burner', Combustor(thermo_data=janaf, inflow_elements=AIR_ELEMENTS, air_fuel_elements=AIR_FUEL_ELEMENTS, fuel_type="JP-7")) cycle.add_subsystem( 'turbine', Turbine(map_data=LPT2269, design=False, elements=AIR_FUEL_ELEMENTS)) cycle.set_input_defaults('burner.MN', .01, units=None) cycle.set_input_defaults('burner.Fl_I:FAR', .01, units=None) cycle.set_input_defaults('turbine.Nmech', 1000., units='rpm'), cycle.set_input_defaults('flow_start.P', 17., units='psi'), cycle.set_input_defaults('flow_start.T', 500.0, units='degR'), cycle.set_input_defaults('flow_start.W', 0., units='lbm/s'), cycle.set_input_defaults('turbine.area', 150., units='inch**2') cycle.pyc_connect_flow("flow_start.Fl_O", "burner.Fl_I") cycle.pyc_connect_flow("burner.Fl_O", "turbine.Fl_I") self.prob.set_solver_print(level=-1) self.prob.setup(check=False)
def setUp(self): self.prob = om.Problem() self.prob.model = Cycle() self.prob.model.options['thermo_method'] = 'CEA' self.prob.model.options['thermo_data'] = janaf self.prob.model.set_input_defaults('fc.MN', 0.0) self.prob.model.set_input_defaults('fc.alt', 0.0, units="ft") self.prob.model.set_input_defaults('fc.dTs', 0.0, units='degR') fc = self.prob.model.add_subsystem('fc', FlightConditions()) self.prob.setup(check=False, force_alloc_complex=True) self.prob.set_solver_print(level=-1)
def test_mix_air_with_airfuel(self): p = Problem() cycle = p.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = janaf cycle.set_input_defaults('start1.P', 9.218, units='psi') cycle.set_input_defaults('start1.T', 1524.32, units='degR') cycle.set_input_defaults('start1.MN', 0.4463) cycle.set_input_defaults('start1.W', 161.49, units='lbm/s') cycle.set_input_defaults('start2.P', 8.68, units='psi') cycle.set_input_defaults('start2.T', 524., units='degR') cycle.set_input_defaults('start2.MN', 0.4463) cycle.set_input_defaults('start2.W', 158., units='lbm/s') cycle.add_subsystem('start1', FlowStart(composition=CEA_AIR_FUEL_COMPOSITION)) cycle.add_subsystem('start2', FlowStart(composition=CEA_AIR_COMPOSITION)) cycle.add_subsystem('mixer', Mixer(design=True, designed_stream=1)) cycle.pyc_connect_flow('start1.Fl_O', 'mixer.Fl_I1') cycle.pyc_connect_flow('start2.Fl_O', 'mixer.Fl_I2') p.setup(force_alloc_complex=True) p.set_solver_print(level=-1) p.run_model() tol = 1e-6 assert_near_equal(p['mixer.Fl_O:stat:area'], 2786.86877031, tolerance=tol) assert_near_equal(p['mixer.Fl_O:tot:P'], 8.87520497, tolerance=tol) assert_near_equal(p['mixer.ER'], 1.06198157, tolerance=tol) partials = p.check_partials( includes=['mixer.area_calc*', 'mixer.mix_flow*', 'mixer.imp_out*'], out_stream=None, method='cs') assert_check_partials(partials, atol=1e-8, rtol=1e-8)
def test_case1(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = species_data.janaf cycle.add_subsystem('flow_start', FlowStart(), promotes=['MN', 'P', 'T']) cycle.add_subsystem('bleed', BleedOut(bleed_names=['bld1', 'bld2']), promotes=['MN']) cycle.pyc_connect_flow('flow_start.Fl_O', 'bleed.Fl_I') cycle.set_input_defaults('MN', 0.5) cycle.set_input_defaults('bleed.bld1:frac_W', 0.1) cycle.set_input_defaults('bleed.bld2:frac_W', 0.1) cycle.set_input_defaults('P', 17., units='psi') cycle.set_input_defaults('T', 500., units='degR') cycle.set_input_defaults('flow_start.W', 500., units='lbm/s') self.prob.setup(check=False, force_alloc_complex=True) self.prob.set_solver_print(level=-1) self.prob.run_model() tol = 2.0e-5 Tt_in = self.prob.get_val('bleed.Fl_I:tot:T', units='degR') Pt_in = self.prob.get_val('bleed.Fl_I:tot:P', units='psi') W_in = self.prob['bleed.Fl_I:stat:W'] assert_near_equal(self.prob['bleed.Fl_O:tot:T'], Tt_in, tol) assert_near_equal(self.prob['bleed.bld1:tot:T'], Tt_in, tol) assert_near_equal(self.prob['bleed.bld2:tot:T'], Tt_in, tol) assert_near_equal(self.prob['bleed.Fl_O:tot:P'], Pt_in, tol) assert_near_equal(self.prob['bleed.bld1:tot:P'], Pt_in, tol) assert_near_equal(self.prob['bleed.bld2:tot:P'], Pt_in, tol) assert_near_equal(self.prob['bleed.Fl_O:stat:W'], W_in*0.8, tol) assert_near_equal(self.prob['bleed.bld1:stat:W'], W_in*0.1, tol) assert_near_equal(self.prob['bleed.bld2:stat:W'], W_in*0.1, tol) partial_data = self.prob.check_partials(out_stream=None, method='cs', includes=['bleed.*'], excludes=['*.base_thermo.*',]) assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS)) cycle.add_subsystem('splitter', Splitter(elements=AIR_ELEMENTS)) cycle.set_input_defaults('flow_start.P', 17., units='psi') cycle.set_input_defaults('flow_start.T', 500., units='degR') cycle.set_input_defaults('splitter.MN1', 0.5) cycle.set_input_defaults('splitter.MN2', 0.5) cycle.set_input_defaults('flow_start.W', 10., units='lbm/s') cycle.pyc_connect_flow('flow_start.Fl_O', 'splitter.Fl_I') self.prob.set_solver_print(level=-1) self.prob.setup(check=False, force_alloc_complex=True)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS)) cycle.add_subsystem( 'compressor', Compressor(map_data=AXI5, design=False, elements=AIR_ELEMENTS, map_extrap=False)) cycle.set_input_defaults('compressor.s_PR', val=1.) cycle.set_input_defaults('compressor.s_eff', val=1.) cycle.set_input_defaults('compressor.s_Wc', val=1.) cycle.set_input_defaults('compressor.s_Nc', val=1.) cycle.set_input_defaults('compressor.map.alphaMap', val=0.) cycle.set_input_defaults('compressor.Nmech', 0., units='rpm') cycle.set_input_defaults('flow_start.P', 17., units='psi') cycle.set_input_defaults('flow_start.T', 500., units='degR') cycle.set_input_defaults('flow_start.W', 0., units='lbm/s') cycle.set_input_defaults('compressor.area', 50., units='inch**2') cycle.pyc_connect_flow("flow_start.Fl_O", "compressor.Fl_I") newton = self.prob.model.nonlinear_solver = NewtonSolver() newton.options['atol'] = 1e-8 newton.options['rtol'] = 1e-8 newton.options['iprint'] = 2 newton.options['maxiter'] = 10 newton.options['solve_subsystems'] = True newton.options['max_sub_solves'] = 10 newton.linesearch = BoundsEnforceLS() newton.linesearch.options['bound_enforcement'] = 'scalar' newton.linesearch.options['iprint'] = -1 self.prob.model.linear_solver = DirectSolver(assemble_jac=True) self.prob.set_solver_print(level=-1) self.prob.setup(check=False, force_alloc_complex=True)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = janaf cycle.add_subsystem('flow_start', FlowStart(thermo_data=janaf)) cycle.add_subsystem('compressor', Compressor(design=True)) cycle.set_input_defaults('flow_start.P', 17., units='psi') cycle.set_input_defaults('flow_start.T', 500., units='degR') cycle.set_input_defaults('compressor.MN', 0.5) cycle.set_input_defaults('flow_start.W', 10., units='lbm/s') cycle.set_input_defaults('compressor.PR', 6.) cycle.set_input_defaults('compressor.eff', 0.9) cycle.pyc_connect_flow("flow_start.Fl_O", "compressor.Fl_I") self.prob.set_solver_print(level=-1) self.prob.setup(check=False, force_alloc_complex=True)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.set_input_defaults('flow_start.P', 17, units='psi') cycle.set_input_defaults('flow_start.T', 500.0, units='degR') cycle.set_input_defaults('inlet.MN', 0.5) cycle.set_input_defaults('inlet.Fl_I:stat:V', 1., units='ft/s') cycle.set_input_defaults('flow_start.W', 1., units='lbm/s') cycle.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS)) cycle.add_subsystem('inlet', Inlet(elements=AIR_ELEMENTS)) # total and static fl_src = "flow_start.Fl_O" fl_target = "inlet.Fl_I" cycle.pyc_connect_flow("flow_start.Fl_O", "inlet.Fl_I") self.prob.set_solver_print(level=-1) self.prob.setup(check=False, force_alloc_complex=True)
def setup_helper(self, NozzType, LossType): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = janaf cycle.add_subsystem('flow_start', FlowStart()) cycle.add_subsystem( 'nozzle', Nozzle(nozzType=NozzType, lossCoef=LossType, internal_solver=True)) cycle.set_input_defaults('flow_start.P', 17.0, units='psi') cycle.set_input_defaults('flow_start.T', 500.0, units='degR') cycle.set_input_defaults('flow_start.MN', 0.2) cycle.set_input_defaults('nozzle.Ps_exhaust', 17.0, units='psi') cycle.set_input_defaults('flow_start.W', 0.0, units='lbm/s') cycle.pyc_connect_flow("flow_start.Fl_O", "nozzle.Fl_I") if LossType == 'Cv': self.prob.model.set_input_defaults('nozzle.Cv', 0.99) elif LossType == 'Cfg': self.prob.model.set_input_defaults('nozzle.Cfg', 0.99) self.prob.set_solver_print(level=-1) self.prob.setup(check=False, force_alloc_complex=True) header = [ 'Cfg', 'Cv', 'PsExh', 'Fl_I.W', 'Fl_I.MN', 'Fl_I.s', 'Fl_I.Pt', 'Fl_I.Tt', 'Fl_I.ht', 'Fl_I.rhot', 'Fl_I.gamt', 'Fl_O.MN', 'Fl_O.s', 'Fl_O.Pt', 'Fl_O.Tt', 'Fl_O.ht', 'Fl_O.rhot', 'Fl_O.gamt', 'Fl_O.Ps', 'Fl_Th.MN', 'Fl_Th.s', 'Fl_Th.Pt', 'Fl_Th.Tt', 'Fl_Th.ht', 'Fl_Th.rhot', 'Fl_Th.gamt', 'Fl_Th.Ps', 'Fl_Th.Aphy', 'Fg', 'FgIdeal', 'Vactual', 'AthCold', 'AR', 'PR' ] self.h_map = dict(((v_name, i) for i, v_name in enumerate(header))) self.fpath = os.path.dirname(os.path.realpath(__file__))
def test_mix_same(self): # mix two identical streams and make sure you get twice the area and the same total pressure p = Problem() cycle = p.model = Cycle() cycle.set_input_defaults('P', 17., units='psi') cycle.set_input_defaults('T', 500., units='degR') cycle.set_input_defaults('MN', 0.5) cycle.set_input_defaults('W', 100., units='lbm/s') cycle.add_subsystem('start1', FlowStart(), promotes=['P', 'T', 'MN', 'W']) cycle.add_subsystem('start2', FlowStart(), promotes=['P', 'T', 'MN', 'W']) cycle.add_subsystem( 'mixer', Mixer(design=True, Fl_I1_elements=AIR_ELEMENTS, Fl_I2_elements=AIR_ELEMENTS)) cycle.pyc_connect_flow('start1.Fl_O', 'mixer.Fl_I1') cycle.pyc_connect_flow('start2.Fl_O', 'mixer.Fl_I2') p.set_solver_print(level=-1) p.setup() p['mixer.balance.P_tot'] = 17 p.run_model() tol = 2e-7 assert_near_equal(p['mixer.Fl_O:stat:area'], 2 * p['start1.Fl_O:stat:area'], tolerance=tol) assert_near_equal(p['mixer.Fl_O:tot:P'], p['P'], tolerance=tol) assert_near_equal(p['mixer.ER'], 1, tolerance=tol)
def test_case1(self): p = om.Problem() p.model = Cycle() p.model.options['thermo_method'] = 'CEA' p.model.options['thermo_data'] = janaf cfd_start = p.model.add_subsystem('cfd_start', CFDStart(), promotes=['*']) p.model.set_input_defaults('Ps', units='kPa', val=100) p.model.set_input_defaults('V', units='m/s', val=100.) p.model.set_input_defaults('area', units='m**2', val=1) p.model.set_input_defaults('W', units='kg/s', val=100.) p.setup() p.run_model() tol = 1e-4 assert_near_equal(p['Fl_O:tot:P'], 15.24202341, tol) # psi assert_near_equal(p.get_val('Fl_O:stat:P', units='kPa'), 100, tol) assert_near_equal(p.get_val('Fl_O:stat:MN'), 0.26744049, tol)
def setUp(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = janaf cycle.options['design'] = False cycle.add_subsystem('flow_start', FlowStart()) cycle.add_subsystem('burner', Combustor(fuel_type="JP-7")) cycle.add_subsystem('turbine', Turbine(map_data=LPT2269)) cycle.set_input_defaults('burner.Fl_I:FAR', .01, units=None) cycle.set_input_defaults('turbine.Nmech', 1000., units='rpm'), cycle.set_input_defaults('flow_start.P', 17., units='psi'), cycle.set_input_defaults('flow_start.T', 500.0, units='degR'), cycle.set_input_defaults('flow_start.W', 0., units='lbm/s'), cycle.set_input_defaults('turbine.area', 150., units='inch**2') cycle.pyc_connect_flow("flow_start.Fl_O", "burner.Fl_I") cycle.pyc_connect_flow("burner.Fl_O", "turbine.Fl_I") self.prob.set_solver_print(level=-1) self.prob.setup(check=False)
def test_case1(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS)) cycle.add_subsystem( 'nozzle', Nozzle(elements=AIR_ELEMENTS, lossCoef='Cfg', internal_solver=True)) cycle.set_input_defaults('nozzle.Ps_exhaust', 10.0, units='lbf/inch**2') cycle.set_input_defaults('flow_start.MN', 0.0) cycle.set_input_defaults('flow_start.T', 500.0, units='degR') cycle.set_input_defaults('flow_start.P', 17.0, units='psi') cycle.set_input_defaults('flow_start.W', 100.0, units='lbm/s') cycle.pyc_connect_flow("flow_start.Fl_O", "nozzle.Fl_I") self.prob.setup(check=False, force_alloc_complex=True) # 4 cases to check against for i, data in enumerate(ref_data): self.prob['nozzle.Cfg'] = data[h_map['Cfg']] self.prob['nozzle.Ps_exhaust'] = data[h_map['PsExh']] # input flowstation self.prob['flow_start.P'] = data[h_map['Fl_I.Pt']] self.prob['flow_start.T'] = data[h_map['Fl_I.Tt']] self.prob['flow_start.W'] = data[h_map['Fl_I.W']] self.prob['flow_start.MN'] = data[h_map['Fl_I.MN']] self.prob.run_model() # check outputs Fg, V, PR = data[h_map['Fg']], data[h_map['Vactual']], data[ h_map['PR']] MN = data[h_map['Fl_O.MN']] Ath = data[h_map['Ath']] Pt = data[h_map['Fl_O.Pt']] MN_computed = self.prob['nozzle.Fl_O:stat:MN'] Fg_computed = self.prob['nozzle.Fg'] V_computed = self.prob['nozzle.Fl_O:stat:V'] PR_computed = self.prob['nozzle.PR'] Ath_computed = self.prob['nozzle.Fl_O:stat:area'] Pt_computed = self.prob['nozzle.Fl_O:tot:P'] # Used for all tol = 5.e-3 assert_near_equal(MN_computed, MN, tol) assert_near_equal(Fg_computed, Fg, tol) assert_near_equal(V_computed, V, tol) assert_near_equal(Pt_computed, Pt, tol) assert_near_equal(PR_computed, PR, tol) assert_near_equal(Ath_computed, Ath, tol) partial_data = self.prob.check_partials(out_stream=None, method='cs', includes=['nozzle.*'], excludes=[ '*.base_thermo.*', ]) assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)
def test_case1(self): prob = Problem() model = prob.model = Cycle() model.options['thermo_method'] = 'CEA' model.options['thermo_data'] = species_data.janaf model.add_subsystem( 'ivc', IndepVarComp('in_composition', [ 3.23319235e-04, 1.10132233e-05, 5.39157698e-02, 1.44860137e-02 ])) model.add_subsystem('flow_start', FlowStart()) model.add_subsystem('combustor', Combustor()) model.pyc_connect_flow('flow_start.Fl_O', 'combustor.Fl_I') # model.set_input_defaults('Fl_I:tot:P', 100.0, units='lbf/inch**2') # model.set_input_defaults('Fl_I:tot:h', 100.0, units='Btu/lbm') # model.set_input_defaults('Fl_I:stat:W', 100.0, units='lbm/s') model.set_input_defaults('combustor.Fl_I:FAR', 0.0) model.set_input_defaults('combustor.MN', 0.5) # needed because composition is sized by connection # model.connect('ivc.in_composition', ['Fl_I:tot:composition', 'Fl_I:stat:composition', ]) prob.set_solver_print(level=2) prob.setup(check=False, force_alloc_complex=True) # 6 cases to check against for i, data in enumerate(ref_data): # input flowstation # prob['Fl_I:tot:P'] = data[h_map['Fl_I.Pt']] # prob['Fl_I:tot:h'] = data[h_map['Fl_I.ht']] # prob['Fl_I:stat:W'] = data[h_map['Fl_I.W']] # prob['Fl_I:FAR'] = data[h_map['FAR']] prob.set_val('flow_start.P', data[h_map['Fl_I.Pt']], units='psi') prob.set_val('flow_start.T', data[h_map['Fl_I.Tt']], units='degR') prob.set_val('flow_start.W', data[h_map['Fl_I.W']], units='lbm/s') prob['combustor.Fl_I:FAR'] = data[h_map['FAR']] prob['combustor.MN'] = data[h_map['Fl_O.MN']] prob.run_model() # prob.model.combustor.mix_fuel.list_inputs(print_arrays=True) # prob.model.combustor.mix_fuel.list_outputs(print_arrays=True) # print(prob['combustor.Fl_I:tot:composition']) # print(prob['combustor.Fl_I:tot:n']) print(prob['combustor.Fl_I:tot:h']) print(prob['combustor.Fl_I:tot:P']) # exit() # check outputs tol = 1.0e-2 npss = data[h_map['Fl_O.Pt']] pyc = prob['combustor.Fl_O:tot:P'] rel_err = abs(npss - pyc) / npss print('Pt out:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) npss = data[h_map['Fl_O.Tt']] pyc = prob['combustor.Fl_O:tot:T'] rel_err = abs(npss - pyc) / npss print('Tt out:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) npss = data[h_map['Fl_O.ht']] pyc = prob['combustor.Fl_O:tot:h'] rel_err = abs(npss - pyc) / npss print('ht out:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) npss = data[h_map['Fl_O.Ps']] pyc = prob['combustor.Fl_O:stat:P'] rel_err = abs(npss - pyc) / npss print('Ps out:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) npss = data[h_map['Fl_O.Ts']] pyc = prob['combustor.Fl_O:stat:T'] rel_err = abs(npss - pyc) / npss print('Ts out:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) npss = data[h_map['Wfuel']] pyc = prob['combustor.Fl_I:stat:W'] * (prob['combustor.Fl_I:FAR']) rel_err = abs(npss - pyc) / npss print('Wfuel:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) print('') partial_data = prob.check_partials( out_stream=None, method='cs', includes=[ 'combustor.*', ], excludes=['*.base_thermo.*', '*.mix_fuel.*']) assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)
def test_case_with_dPqP_MN(self): self.prob = Problem() # need two cycles, because we can't mix design and off-design cycle_DES = self.prob.model.add_subsystem('DESIGN', Cycle()) cycle_DES.options['thermo_method'] = 'CEA' cycle_DES.options['thermo_data'] = species_data.janaf cycle_OD = self.prob.model.add_subsystem('OFF_DESIGN', Cycle()) cycle_OD.options['design'] = False cycle_OD.options['thermo_method'] = 'CEA' cycle_OD.options['thermo_data'] = species_data.janaf cycle_DES.add_subsystem('flow_start', FlowStart(), promotes=['P', 'T', 'MN', 'W']) cycle_OD.add_subsystem('flow_start_OD', FlowStart(), promotes=['P', 'T', 'W', 'MN']) expMN = 1.0 cycle_DES.add_subsystem('duct', Duct(expMN=expMN), promotes=['MN']) cycle_OD.add_subsystem('duct', Duct(expMN=expMN, design=False)) cycle_DES.pyc_connect_flow('flow_start.Fl_O', 'duct.Fl_I') cycle_OD.pyc_connect_flow('flow_start_OD.Fl_O', 'duct.Fl_I') cycle_DES.set_input_defaults('P', 17., units='psi') cycle_DES.set_input_defaults('T', 500., units='degR') cycle_DES.set_input_defaults('MN', 0.5) cycle_DES.set_input_defaults('duct.dPqP', 0.0) cycle_DES.set_input_defaults('W', 500., units='lbm/s') cycle_OD.set_input_defaults('P', 17., units='psi') cycle_OD.set_input_defaults('T', 500., units='degR') cycle_OD.set_input_defaults('MN', 0.25) cycle_OD.set_input_defaults('duct.dPqP', 0.0) cycle_OD.set_input_defaults('W', 500., units='lbm/s') self.prob.model.connect("DESIGN.duct.s_dPqP", "OFF_DESIGN.duct.s_dPqP") self.prob.model.connect("DESIGN.duct.Fl_O:stat:area", "OFF_DESIGN.duct.area") self.prob.setup(check=False, force_alloc_complex=True) self.prob.set_solver_print(level=-1) data = ref_data[0] self.prob['DESIGN.duct.dPqP'] = data[h_map['dPqP']] # input flowstation self.prob['DESIGN.P'] = data[h_map['Fl_I.Pt']] self.prob['DESIGN.T'] = data[h_map['Fl_I.Tt']] self.prob['DESIGN.MN'] = data[h_map['Fl_O.MN']] self.prob['DESIGN.W'] = data[h_map['Fl_I.W']] # self.prob['DESIGN.duct.Fl_I:stat:V'] = data[h_map['Fl_I.V']] # input flowstation self.prob['OFF_DESIGN.P'] = data[h_map['Fl_I.Pt']] self.prob['OFF_DESIGN.T'] = data[h_map['Fl_I.Tt']] self.prob['OFF_DESIGN.W'] = data[h_map['Fl_I.W']] # self.prob['OFF_DESIGN.duct.Fl_I:stat:V'] = data[h_map['Fl_I.V']] # give a decent initial guess for Ps print(self.prob['DESIGN.P'], self.prob['DESIGN.T'], self.prob['DESIGN.MN']) self.prob.run_model() # check outputs pt, ht, ps, ts = data[h_map['Fl_O.Pt']], data[h_map['Fl_O.ht']], data[ h_map['Fl_O.Ps']], data[h_map['Fl_O.Ts']] pt_computed = self.prob['OFF_DESIGN.duct.Fl_O:tot:P'] ht_computed = self.prob['OFF_DESIGN.duct.Fl_O:tot:h'] ps_computed = self.prob['OFF_DESIGN.duct.Fl_O:stat:P'] ts_computed = self.prob['OFF_DESIGN.duct.Fl_O:stat:T'] tol = 1.0e-4 assert_near_equal(pt_computed, 8.84073152, tol) assert_near_equal(ht_computed, ht, tol) assert_near_equal(ps_computed, 8.26348914, tol) assert_near_equal(ts_computed, ts, tol) partial_data = self.prob.check_partials(out_stream=None, method='cs', includes=['duct.*'], excludes=[ '*.base_thermo.*', ]) assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)
def test_case1(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.options['thermo_method'] = 'CEA' cycle.options['thermo_data'] = species_data.janaf cycle.add_subsystem('flow_start', FlowStart(), promotes=['MN', 'P', 'T']) cycle.add_subsystem('duct', Duct(), promotes=['MN']) cycle.pyc_connect_flow('flow_start.Fl_O', 'duct.Fl_I') cycle.set_input_defaults('MN', 0.5) cycle.set_input_defaults('duct.dPqP', 0.0) cycle.set_input_defaults('P', 17., units='psi') cycle.set_input_defaults('T', 500., units='degR') cycle.set_input_defaults('flow_start.W', 500., units='lbm/s') self.prob.setup(check=False, force_alloc_complex=True) self.prob.set_solver_print(level=-1) # 6 cases to check against for i, data in enumerate(ref_data): self.prob['duct.dPqP'] = data[h_map['dPqP']] # input flowstation self.prob['P'] = data[h_map['Fl_I.Pt']] self.prob['T'] = data[h_map['Fl_I.Tt']] self.prob['MN'] = data[h_map['Fl_O.MN']] self.prob['flow_start.W'] = data[h_map['Fl_I.W']] self.prob['duct.Fl_I:stat:V'] = data[h_map['Fl_I.V']] # give a decent initial guess for Ps print(i, self.prob['P'], self.prob['T'], self.prob['MN']) self.prob.run_model() # check outputs pt, ht, ps, ts = data[h_map['Fl_O.Pt']], data[h_map[ 'Fl_O.ht']], data[h_map['Fl_O.Ps']], data[h_map['Fl_O.Ts']] pt_computed = self.prob['duct.Fl_O:tot:P'] ht_computed = self.prob['duct.Fl_O:tot:h'] ps_computed = self.prob['duct.Fl_O:stat:P'] ts_computed = self.prob['duct.Fl_O:stat:T'] tol = 2.0e-2 assert_near_equal(pt_computed, pt, tol) assert_near_equal(ht_computed, ht, tol) assert_near_equal(ps_computed, ps, tol) assert_near_equal(ts_computed, ts, tol) partial_data = self.prob.check_partials(out_stream=None, method='cs', includes=['duct.*'], excludes=[ '*.base_thermo.*', ]) assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)
def test_case_with_dPqP_MN(self): self.prob = Problem() cycle = self.prob.model = Cycle() cycle.add_subsystem('flow_start', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS), promotes=['P', 'T', 'MN', 'W']) cycle.add_subsystem('flow_start_OD', FlowStart(thermo_data=janaf, elements=AIR_ELEMENTS), promotes=['P', 'T', 'W']) expMN = 1.0 cycle.add_subsystem('duct_des', Duct(elements=AIR_ELEMENTS, expMN=expMN), promotes=['MN']) cycle.add_subsystem( 'duct_OD', Duct(elements=AIR_ELEMENTS, expMN=expMN, design=False)) cycle.pyc_connect_flow('flow_start.Fl_O', 'duct_des.Fl_I') cycle.pyc_connect_flow('flow_start_OD.Fl_O', 'duct_OD.Fl_I') cycle.set_input_defaults('P', 17., units='psi') cycle.set_input_defaults('T', 500., units='degR') cycle.set_input_defaults('MN', 0.5) cycle.set_input_defaults('flow_start_OD.MN', 0.25) cycle.set_input_defaults('duct_des.dPqP', 0.0) cycle.set_input_defaults('W', 500., units='lbm/s') cycle.connect("duct_des.s_dPqP", "duct_OD.s_dPqP") cycle.connect("duct_des.Fl_O:stat:area", "duct_OD.area") self.prob.setup(check=False, force_alloc_complex=True) self.prob.set_solver_print(level=-1) data = ref_data[0] self.prob['duct_des.dPqP'] = data[h_map['dPqP']] # input flowstation self.prob['P'] = data[h_map['Fl_I.Pt']] self.prob['T'] = data[h_map['Fl_I.Tt']] self.prob['MN'] = data[h_map['Fl_O.MN']] self.prob['W'] = data[h_map['Fl_I.W']] self.prob['duct_des.Fl_I:stat:V'] = data[h_map['Fl_I.V']] # give a decent initial guess for Ps print(self.prob['P'], self.prob['T'], self.prob['MN']) self.prob.run_model() # check outputs pt, ht, ps, ts = data[h_map['Fl_O.Pt']], data[h_map['Fl_O.ht']], data[ h_map['Fl_O.Ps']], data[h_map['Fl_O.Ts']] pt_computed = self.prob['duct_OD.Fl_O:tot:P'] ht_computed = self.prob['duct_OD.Fl_O:tot:h'] ps_computed = self.prob['duct_OD.Fl_O:stat:P'] ts_computed = self.prob['duct_OD.Fl_O:stat:T'] tol = 1.0e-4 assert_near_equal(pt_computed, 8.84073152, tol) assert_near_equal(ht_computed, ht, tol) assert_near_equal(ps_computed, 8.26348914, tol) assert_near_equal(ts_computed, ts, tol) partial_data = self.prob.check_partials(out_stream=None, method='cs', includes=['duct_OD.*'], excludes=[ '*.base_thermo.*', ]) assert_check_partials(partial_data, atol=1e-8, rtol=1e-8)