def setUp(self): thermo = Thermo(janaf, AIR_FUEL_MIX) self.prob = Problem() self.prob.model.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_MIX)) self.prob.model.add_subsystem( 'burner', Combustor(thermo_data=janaf, inflow_elements=AIR_MIX, air_fuel_elements=AIR_FUEL_MIX, fuel_type="JP-7")) self.prob.model.add_subsystem( 'turbine', Turbine(map_data=LPT2269, design=False, elements=AIR_FUEL_MIX)) self.prob.model.set_input_defaults('burner.MN', .01, units=None) self.prob.model.set_input_defaults('burner.Fl_I:FAR', .01, units=None) self.prob.model.set_input_defaults('turbine.Nmech', 1000., units='rpm'), self.prob.model.set_input_defaults('flow_start.P', 17., units='psi'), self.prob.model.set_input_defaults('flow_start.T', 500.0, units='degR'), self.prob.model.set_input_defaults('flow_start.W', 0., units='lbm/s'), self.prob.model.set_input_defaults('turbine.area', 150., units='inch**2') connect_flow(self.prob.model, "flow_start.Fl_O", "burner.Fl_I") connect_flow(self.prob.model, "burner.Fl_O", "turbine.Fl_I") self.prob.set_solver_print(level=-1) self.prob.setup(check=False)
def setUp(self): self.prob = Problem() des_vars = self.prob.model.add_subsystem('des_vars', IndepVarComp(), promotes=['*']) des_vars.add_output('P', 17., units='psi'), des_vars.add_output('T', 500.0, units='degR'), des_vars.add_output('W', 0., units='lbm/s'), des_vars.add_output('Nmech', 1000., units='rpm'), des_vars.add_output('area_targ', 150., units='inch**2') des_vars.add_output('burner_MN', .01, units=None) des_vars.add_output('burner_FAR', .01, units=None) self.prob.model.add_subsystem( 'flow_start', FlowStart(thermo_data=janaf, elements=AIR_MIX)) self.prob.model.add_subsystem( 'burner', Combustor(thermo_data=janaf, inflow_elements=AIR_MIX, air_fuel_elements=AIR_FUEL_MIX, fuel_type="JP-7")) self.prob.model.add_subsystem( 'turbine', Turbine(map_data=LPT2269, design=False, elements=AIR_FUEL_MIX)) connect_flow(self.prob.model, "flow_start.Fl_O", "burner.Fl_I") connect_flow(self.prob.model, "burner.Fl_O", "turbine.Fl_I") self.prob.model.connect("P", "flow_start.P") self.prob.model.connect("T", "flow_start.T") self.prob.model.connect("W", "flow_start.W") self.prob.model.connect("Nmech", "turbine.Nmech") self.prob.model.connect("area_targ", "turbine.area") self.prob.model.connect("burner_MN", "burner.MN") self.prob.model.connect("burner_FAR", "burner.Fl_I:FAR") self.prob.set_solver_print(level=-1) self.prob.setup(check=False)
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): prob = Problem() model = prob.model = Group() n_init = np.array([ 3.23319258e-04, 1.00000000e-10, 1.10131241e-05, 1.00000000e-10, 1.63212420e-10, 6.18813039e-09, 1.00000000e-10, 2.69578835e-02, 1.00000000e-10, 7.23198770e-03 ]) model.add_subsystem('des_var1', IndepVarComp('Fl_I:tot:P', 100.0, units='lbf/inch**2'), promotes=["*"]) model.add_subsystem('des_var2', IndepVarComp('Fl_I:tot:h', 100.0, units='Btu/lbm'), promotes=["*"]) model.add_subsystem('des_var3', IndepVarComp('Fl_I:stat:W', 100.0, units='lbm/s'), promotes=["*"]) model.add_subsystem('des_var4', IndepVarComp('Fl_I:FAR', 0.0), promotes=["*"]) model.add_subsystem('des_var5', IndepVarComp('MN', 0.5), promotes=["*"]) model.add_subsystem('des_var6', IndepVarComp('Fl_I:tot:n', n_init), promotes=["*"]) model.add_subsystem('combustor', Combustor(), promotes=["*"]) prob.set_solver_print(level=2) prob.setup(check=False) # 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['MN'] = data[h_map['Fl_O.MN']] prob.run_model() # check outputs tol = 1.0e-2 npss = data[h_map['Fl_O.Pt']] pyc = prob['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['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['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['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['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['Fl_I:stat:W'] * (prob['Fl_I:FAR']) rel_err = abs(npss - pyc) / npss print('Wfuel:', npss, pyc, rel_err) self.assertLessEqual(rel_err, tol) print('') check_element_partials(self, prob, tol=1e-4)
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)