예제 #1
0
파일: nozzle.py 프로젝트: lamkina/pyCycle
    def setup(self):
        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']
        nozzType = self.options['nozzType']
        lossCoef = self.options['lossCoef']

        # elements = self.options['elements']
        composition = self.Fl_I_data['Fl_I']

        self.add_subsystem('mach_choked', om.IndepVarComp(
            'MN',
            1.000,
        ))

        # Create inlet flow station
        in_flow = FlowIn(fl_name="Fl_I")
        self.add_subsystem('in_flow', in_flow, promotes_inputs=['Fl_I:*'])

        # PR_bal = self.add_subsystem('PR_bal', BalanceComp())
        # PR_bal.add_balance('PR', units=None, eq_units='lbf/inch**2', lower=1.001)
        # self.connect('PR_bal.PR', 'PR')
        # 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=['*'])

        # Calculate pressure at the throat
        prom_in = [('Pt_in', 'Fl_I:tot:P'), 'PR', 'dPqP']
        self.add_subsystem('press_calcs',
                           PressureCalcs(),
                           promotes_inputs=prom_in,
                           promotes_outputs=['Ps_calc'])

        # Calculate throat total flow properties
        throat_total = Thermo(mode='total_hP',
                              fl_name='Fl_O:tot',
                              method=thermo_method,
                              thermo_kwargs={
                                  'composition': composition,
                                  'spec': thermo_data
                              })
        prom_in = [('h', 'Fl_I:tot:h'),
                   ('composition', 'Fl_I:tot:composition')]
        self.add_subsystem('throat_total',
                           throat_total,
                           promotes_inputs=prom_in,
                           promotes_outputs=['Fl_O:*'])
        self.connect('press_calcs.Pt_th', 'throat_total.P')

        # Calculate static properties for sonic flow
        throat_static_MN = Thermo(mode='static_MN',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': composition,
                                      'spec': thermo_data
                                  })
        prom_in = [('ht', 'Fl_I:tot:h'), ('W', 'Fl_I:stat:W'),
                   ('composition', 'Fl_I:tot:composition')]
        self.add_subsystem('staticMN',
                           throat_static_MN,
                           promotes_inputs=prom_in)
        self.connect('throat_total.S', 'staticMN.S')
        self.connect('mach_choked.MN', 'staticMN.MN')
        self.connect('press_calcs.Pt_th', 'staticMN.guess:Pt')
        self.connect('throat_total.gamma', 'staticMN.guess:gamt')
        # self.connect('Fl_I.flow:flow_products','staticMN.init_prod_amounts')

        # Calculate static properties based on exit static pressure
        throat_static_Ps = Thermo(mode='static_Ps',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': composition,
                                      'spec': thermo_data
                                  })
        prom_in = [('ht', 'Fl_I:tot:h'), ('W', 'Fl_I:stat:W'),
                   ('Ps', 'Ps_calc'), ('composition', 'Fl_I:tot:composition')]
        self.add_subsystem('staticPs',
                           throat_static_Ps,
                           promotes_inputs=prom_in)
        self.connect('throat_total.S', 'staticPs.S')
        # self.connect('press_calcs.Ps_calc', 'staticPs.Ps')
        # self.connect('Fl_I.flow:flow_products','staticPs.init_prod_amounts')

        # Calculate ideal exit flow properties
        ideal_flow = Thermo(mode='static_Ps',
                            method=thermo_method,
                            thermo_kwargs={
                                'composition': composition,
                                'spec': thermo_data
                            })
        prom_in = [('ht', 'Fl_I:tot:h'), ('S', 'Fl_I:tot:S'),
                   ('W', 'Fl_I:stat:W'), ('Ps', 'Ps_calc'),
                   ('composition', 'Fl_I:tot:composition')]
        self.add_subsystem('ideal_flow', ideal_flow, promotes_inputs=prom_in)
        # self.connect('press_calcs.Ps_calc', 'ideal_flow.Ps')
        # self.connect('Fl_I.flow:flow_products','ideal_flow.init_prod_amounts')

        # Determine throat and exit flow properties based on nozzle type and exit static pressure
        mux = Mux(nozzType=nozzType, fl_out_name='Fl_O')
        prom_in = [('Ps:W', 'Fl_I:stat:W'), ('MN:W', 'Fl_I:stat:W'),
                   ('Ps:P', 'Ps_calc'), 'Ps_calc']
        self.add_subsystem('mux',
                           mux,
                           promotes_inputs=prom_in,
                           promotes_outputs=['*:stat:*'])
        self.connect('throat_total.S', 'mux.S')
        self.connect('staticPs.h', 'mux.Ps:h')
        self.connect('staticPs.T', 'mux.Ps:T')
        self.connect('staticPs.rho', 'mux.Ps:rho')
        self.connect('staticPs.gamma', 'mux.Ps:gamma')
        self.connect('staticPs.Cp', 'mux.Ps:Cp')
        self.connect('staticPs.Cv', 'mux.Ps:Cv')
        self.connect('staticPs.V', 'mux.Ps:V')
        self.connect('staticPs.Vsonic', 'mux.Ps:Vsonic')
        self.connect('staticPs.MN', 'mux.Ps:MN')
        self.connect('staticPs.area', 'mux.Ps:area')

        self.connect('staticMN.h', 'mux.MN:h')
        self.connect('staticMN.T', 'mux.MN:T')
        self.connect('staticMN.Ps', 'mux.MN:P')
        self.connect('staticMN.rho', 'mux.MN:rho')
        self.connect('staticMN.gamma', 'mux.MN:gamma')
        self.connect('staticMN.Cp', 'mux.MN:Cp')
        self.connect('staticMN.Cv', 'mux.MN:Cv')
        self.connect('staticMN.V', 'mux.MN:V')
        self.connect('staticMN.Vsonic', 'mux.MN:Vsonic')
        self.connect('mach_choked.MN', 'mux.MN:MN')
        self.connect('staticMN.area', 'mux.MN:area')

        # Calculate nozzle performance paramters based on
        perf_calcs = PerformanceCalcs(lossCoef=lossCoef)
        if lossCoef == "Cv":
            other_inputs = ['Cv', 'Ps_calc']
        else:
            other_inputs = ['Cfg', 'Ps_calc']
        prom_in = [('W_in', 'Fl_I:stat:W')] + other_inputs
        self.add_subsystem('perf_calcs',
                           perf_calcs,
                           promotes_inputs=prom_in,
                           promotes_outputs=['Fg'])
        self.connect('ideal_flow.V', 'perf_calcs.V_ideal')
        # self.connect('ideal_flow.area', 'perf_calcs.A_ideal')

        if lossCoef == 'Cv':
            self.connect('Fl_O:stat:V', 'perf_calcs.V_actual')
            self.connect('Fl_O:stat:area', 'perf_calcs.A_actual')
            self.connect('Fl_O:stat:P', 'perf_calcs.Ps_actual')

        if self.options['internal_solver']:
            newton = self.nonlinear_solver = om.NewtonSolver()
            newton.options['atol'] = 1e-10
            newton.options['rtol'] = 1e-10
            newton.options['maxiter'] = 20
            newton.options['iprint'] = 2
            newton.options['solve_subsystems'] = True
            newton.options['reraise_child_analysiserror'] = False
            newton.linesearch = om.BoundsEnforceLS()
            newton.linesearch.options['bound_enforcement'] = 'scalar'

            newton.linesearch.options['iprint'] = -1
            self.linear_solver = om.DirectSolver(assemble_jac=True)

        super().setup()
예제 #2
0
    def test_set_total_equivalence(self):

        p_TP = om.Problem()
        p_TP.model = Thermo(mode='total_TP',
                            method='CEA',
                            thermo_kwargs={
                                'elements': constants.AIR_ELEMENTS,
                                'spec': species_data.janaf
                            })
        p_TP.setup()
        p_TP.set_solver_print(level=-1)

        p_hP = om.Problem()
        p_hP.model = Thermo(mode='total_hP',
                            method='CEA',
                            thermo_kwargs={
                                'elements': constants.AIR_ELEMENTS,
                                'spec': species_data.janaf
                            })
        p_hP.setup()
        p_hP.set_solver_print(level=-1)

        p_SP = om.Problem()
        p_SP.model = Thermo(mode='total_SP',
                            method='CEA',
                            thermo_kwargs={
                                'elements': constants.AIR_ELEMENTS,
                                'spec': species_data.janaf
                            })
        p_SP.setup()
        p_SP.set_solver_print(level=-1)

        def check(T, P):

            p_TP.set_val('T', T, units='degR')
            p_TP.set_val('P', P, units='psi')

            # print('TP check')
            p_TP.run_model()
            h_from_TP = p_TP.get_val('flow:h', units='cal/g')
            S_from_TP = p_TP.get_val('flow:S', units='cal/(g*degK)')

            p_hP.set_val('h', h_from_TP, units='cal/g')
            p_hP.set_val('P', P, units='psi')

            # print('hp check')
            p_hP.run_model()

            assert_near_equal(p_hP['flow:T'], p_TP['flow:T'], 1e-4)

            p_SP.set_val('S', S_from_TP, units='cal/(g*degK)')
            p_SP.set_val('P', P, units='psi')

            # print('SP check')
            p_SP.run_model()

            assert_near_equal(p_SP['flow:T'], p_TP['flow:T'], 1e-4)

        check(518., 14.7)
        check(3000., 30.)
        check(1500., 80.)
예제 #3
0
파일: cooling.py 프로젝트: lamkina/pyCycle
    def setup(self):

        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']

        if thermo_data is None:
            thermo_data = THERMO_DEFAULT_COMPOSITIONS[thermo_method]

        main_flow_composition = self.options['main_flow_composition']
        bld_flow_composition = self.options['bld_flow_composition']
        mix_flow_composition = self.options['mix_flow_composition']

        self.add_subsystem('cooling_calcs',
                           CoolingCalcs(n_stages=self.options['n_stages'],
                                        i_row=self.options['i_row'],
                                        T_safety=self.options['T_safety'],
                                        T_metal=self.options['T_metal']),
                           promotes_inputs=[
                               'Pt_in', 'Pt_out', 'W_primary', 'Tt_primary',
                               'Tt_cool', 'ht_primary', 'ht_cool', 'x_factor',
                               'turb_pwr'
                           ],
                           promotes_outputs=['W_cool'])

        consts = self.add_subsystem(
            'consts',
            om.IndepVarComp())  # values that should not be changed ever
        consts.add_output('bld_frac_P', val=1)

        self.add_subsystem('mix_n',
                           ThermoAdd(method=thermo_method,
                                     mix_mode='flow',
                                     mix_names='cool',
                                     thermo_kwargs={
                                         'spec': thermo_data,
                                         'inflow_composition':
                                         main_flow_composition,
                                         'mix_composition':
                                         bld_flow_composition,
                                     }),
                           promotes_inputs=[('Fl_I:stat:W', 'W_primary'),
                                            ('Fl_I:tot:composition',
                                             'composition_primary'),
                                            'cool:composition'],
                           promotes_outputs=[
                               ('Wout', 'W_out'),
                           ])

        mixed_flow = Thermo(mode='total_hP',
                            fl_name='Fl_O:tot',
                            method=thermo_method,
                            thermo_kwargs={
                                'composition': mix_flow_composition,
                                'spec': thermo_data
                            })
        self.add_subsystem('mixed_flow',
                           mixed_flow,
                           promotes_outputs=['Fl_O:tot:*'])

        # promoted
        # self.connect('', 'mix_n.Pt_in')
        # self.connect('', 'mix_n.Pt_out')
        # self.connect('', 'mix_n.W_primary')
        # self.connect('', 'mix_n.n_in')
        # self.connect('', 'mix_n.cool:n')

        self.connect('W_cool', 'mix_n.cool:W')

        # self.connect('consts.bld_frac_P', 'mix_n.cool:frac_P')

        self.connect('mix_n.composition_out', 'mixed_flow.composition')
        self.connect('cooling_calcs.ht_out', 'mixed_flow.h')
        self.connect('cooling_calcs.Pt_stage', 'mixed_flow.P')
예제 #4
0
파일: inlet.py 프로젝트: caflack/pyCycle
    def setup(self):
        thermo_data = self.options['thermo_data']
        elements = self.options['elements']
        statics = self.options['statics']
        design = self.options['design']

        num_element = len(elements)

        # Create inlet flow station
        flow_in = FlowIn(fl_name='Fl_I')
        self.add_subsystem('flow_in', flow_in, promotes=['Fl_I:tot:*', 'Fl_I:stat:*'])
        
        # Perform inlet engineering calculations
        self.add_subsystem('calcs_inlet', Calcs(),
                           promotes_inputs=['ram_recovery', ('Pt_in', 'Fl_I:tot:P'),
                                            ('V_in', 'Fl_I:stat:V'), ('W_in', 'Fl_I:stat:W')],
                           promotes_outputs=['F_ram'])

        # Calculate real flow station properties
        real_flow = Thermo(mode='total_TP', fl_name='Fl_O:tot', 
                           method='CEA', 
                           thermo_kwargs={'elements':elements, 
                                          'spec':thermo_data})
        self.add_subsystem('real_flow', real_flow,
                           promotes_inputs=[('T', 'Fl_I:tot:T'), ('composition', 'Fl_I:tot:composition')],
                           promotes_outputs=['Fl_O:*'])


        self.connect("calcs_inlet.Pt_out", "real_flow.P")

        if statics:
            if design:
                #   Calculate static properties

                out_stat = Thermo(mode='static_MN', fl_name='Fl_O:stat', 
                                  method='CEA', 
                                  thermo_kwargs={'elements':elements, 
                                                 'spec':thermo_data})
                self.add_subsystem('out_stat', out_stat,
                                   promotes_inputs=[('composition', 'Fl_I:tot:composition'), ('W', 'Fl_I:stat:W'), 'MN'],
                                   promotes_outputs=['Fl_O:stat:*'])

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

            else:
                # Calculate static properties
                out_stat = Thermo(mode='static_A', fl_name='Fl_O:stat', 
                                  method='CEA', 
                                  thermo_kwargs={'elements':elements, 
                                                 'spec':thermo_data})
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('W', 'Fl_I:stat:W'),
                           'area']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat', out_stat, promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

        else:
            self.add_subsystem('W_passthru', PassThrough('Fl_I:stat:W', 'Fl_O:stat:W', 0.0, units= "lbm/s"),
                               promotes=['*'])
예제 #5
0
    def test_set_total_SP(self):

        #

        p = om.Problem()
        p.model = Thermo(mode='total_SP',
                         method='CEA',
                         thermo_kwargs={
                             'elements': constants.CO2_CO_O2_ELEMENTS,
                             'spec': species_data.co2_co_o2
                         })

        r = p.model

        p.setup(check=False)

        # NOTE: This case is very touchy and requires weird solver settings
        p.model.nonlinear_solver.options['solve_subsystems'] = True
        p.model.base_thermo.chem_eq.nonlinear_solver.options['maxiter'] = 1

        p.model.base_thermo.chem_eq.nonlinear_solver.linesearch = om.ArmijoGoldsteinLS(
        )
        p.model.base_thermo.chem_eq.nonlinear_solver.linesearch.options[
            'maxiter'] = 2

        p.set_solver_print(level=2)
        p.final_setup()

        # p.model.nonlinear_solver.options['maxiter'] = 0

        p.set_val('S', 2.35711010759, units="Btu/(lbm*degR)")
        p.set_val('P', 1.034210, units="bar")

        p.run_model()

        expected_concentrations = np.array(
            [0.62003271, 0.06995092, 0.31001638])

        n = p['n']
        n_moles = p['n_moles']
        concentrations = n / n_moles
        assert_near_equal(concentrations, expected_concentrations, 1e-4)

        expected_n_moles = 0.0329313730421

        assert_near_equal(n_moles, expected_n_moles, 1e-4)
        assert_near_equal(p['gamma'], 1.19054696779, 1e-4)

        # 1500K
        p['T'] = 4000.

        p['S'] = 1.5852424435
        p.run_model()

        expected_concentrations = np.array(
            [3.58768646e-04, 9.99461847e-01, 1.79384323e-04])
        n = p['n']
        n_moles = p['n_moles']
        concentrations = n / n_moles

        assert_near_equal(concentrations, expected_concentrations, 1e-4)

        expected_n_moles = 0.022726185333
        assert_near_equal(n_moles, expected_n_moles, 1e-4)
        assert_near_equal(p['gamma'], 1.16396871, 1e-4)
예제 #6
0
    def setup(self):
        thermo_data = self.options['thermo_data']
        elements = self.options['elements']
        statics = self.options['statics']
        design = self.options['design']
        bleeds = self.options['bleed_names']

        num_element = len(elements)

        # Create inlet flowstation
        flow_in = FlowIn(fl_name='Fl_I')
        self.add_subsystem('flow_in',
                           flow_in,
                           promotes=['Fl_I:tot:*', 'Fl_I:stat:*'])

        # Bleed flow calculations
        blds = BleedCalcs(bleed_names=bleeds)
        bld_port_globs = ['{}:*'.format(bn) for bn in bleeds]
        self.add_subsystem('bld_calcs',
                           blds,
                           promotes_inputs=[('W_in', 'Fl_I:stat:W'),
                                            '*:frac_W'],
                           promotes_outputs=['W_out'] + bld_port_globs)

        bleed_names = []
        for BN in bleeds:

            bleed_names.append(BN + '_flow')
            bleed_flow = Thermo(mode='total_TP',
                                fl_name=BN + ":tot",
                                method='CEA',
                                thermo_kwargs={
                                    'elements': elements,
                                    'spec': thermo_data
                                })
            self.add_subsystem(BN + '_flow',
                               bleed_flow,
                               promotes_inputs=[('composition',
                                                 'Fl_I:tot:composition'),
                                                ('T', 'Fl_I:tot:T'),
                                                ('P', 'Fl_I:tot:P')],
                               promotes_outputs=['{}:tot:*'.format(BN)])

        # Total Calc
        real_flow = Thermo(mode='total_TP',
                           fl_name="Fl_O:tot",
                           method='CEA',
                           thermo_kwargs={
                               'elements': elements,
                               'spec': thermo_data
                           })
        prom_in = [('composition', 'Fl_I:tot:composition'),
                   ('T', 'Fl_I:tot:T'), ('P', 'Fl_I:tot:P')]
        self.add_subsystem('real_flow',
                           real_flow,
                           promotes_inputs=prom_in,
                           promotes_outputs=['Fl_O:*'])

        if statics:
            if design:
                #   Calculate static properties
                out_stat = Thermo(mode='static_MN',
                                  fl_name="Fl_O:stat",
                                  method='CEA',
                                  thermo_kwargs={
                                      'elements': elements,
                                      'spec': thermo_data
                                  })
                prom_in = [('composition', 'Fl_I:tot:composition'), 'MN']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
                self.connect('W_out', 'out_stat.W')

            else:
                # Calculate static properties
                out_stat = Thermo(mode='static_A',
                                  fl_name="Fl_O:stat",
                                  method='CEA',
                                  thermo_kwargs={
                                      'elements': elements,
                                      'spec': thermo_data
                                  })
                prom_in = [('composition', 'Fl_I:tot:composition'), 'area']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
                self.connect('W_out', 'out_stat.W')
        else:
            self.add_subsystem('W_passthru',
                               PassThrough('W_out',
                                           'Fl_O:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])
예제 #7
0
    def setup(self):
        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']

        inflow_composition = self.Fl_I_data['Fl_I']
        air_fuel_composition = self.Fl_O_data['Fl_O']
        design = self.options['design']
        statics = self.options['statics']

        # Create combustor flow station
        in_flow = FlowIn(fl_name='Fl_I')
        self.add_subsystem('in_flow',
                           in_flow,
                           promotes=['Fl_I:tot:*', 'Fl_I:stat:*'])

        self.add_subsystem('mix_fuel',
                           self.thermo_add_comp,
                           promotes=[
                               'Fl_I:stat:W', ('mix:ratio', 'Fl_I:FAR'),
                               'Fl_I:tot:composition', 'Fl_I:tot:h',
                               ('mix:W', 'Wfuel'), 'Wout'
                           ])

        # Pressure loss
        prom_in = [('Pt_in', 'Fl_I:tot:P'), 'dPqP']
        self.add_subsystem('p_loss', PressureLoss(), promotes_inputs=prom_in)

        # Calculate vitiated flow station properties
        vit_flow = Thermo(mode='total_hP',
                          fl_name='Fl_O:tot',
                          method=thermo_method,
                          thermo_kwargs={
                              'composition': air_fuel_composition,
                              'spec': thermo_data
                          })
        self.add_subsystem('vitiated_flow',
                           vit_flow,
                           promotes_outputs=['Fl_O:*'])
        self.connect("mix_fuel.mass_avg_h", "vitiated_flow.h")
        self.connect("mix_fuel.composition_out", "vitiated_flow.composition")
        self.connect("p_loss.Pt_out", "vitiated_flow.P")

        if statics:
            if design:
                # Calculate static properties.

                out_stat = Thermo(mode='static_MN',
                                  fl_name='Fl_O:stat',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': air_fuel_composition,
                                      'spec': thermo_data
                                  })
                prom_in = ['MN']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect("mix_fuel.composition_out",
                             "out_stat.composition")
                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
                self.connect('Wout', 'out_stat.W')

            else:
                # Calculate static properties.
                out_stat = Thermo(mode='static_A',
                                  fl_name='Fl_O:stat',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': air_fuel_composition,
                                      'spec': thermo_data
                                  })
                prom_in = ['area']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)
                self.connect("mix_fuel.composition_out",
                             "out_stat.composition")

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
                self.connect('Wout', 'out_stat.W')

        else:
            self.add_subsystem('W_passthru',
                               PassThrough('Wout',
                                           'Fl_O:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])

        super().setup()
예제 #8
0
    def setup(self):
        #(self, mapclass=NCP01map(), design=True, thermo_data=species_data.janaf, elements=AIR_ELEMENTS, bleeds=[],statics=True):

        map_data = self.options['map_data']
        interp_method = self.options['map_interp_method']
        map_extrap = self.options['map_extrap']
        # self.linear_solver = ScipyGMRES()
        # self.linear_solver.options['atol'] = 2e-8
        # self.linear_solver.options['maxiter'] = 100
        # self.linear_solver.options['restart'] = 100

        # self.nonlinear_solver = Newton()
        # self.nonlinear_solver.options['utol'] = 1e-9

        thermo_method = self.options['thermo_method']
        design = self.options['design']
        bleeds = self.options['bleed_names']
        thermo_data = self.options['thermo_data']
        elements = self.options['elements']
        statics = self.options['statics']

        num_element = len(elements)

        # Create inlet flow station
        flow_in = FlowIn(fl_name='Fl_I')
        self.add_subsystem('flow_in', flow_in, promotes_inputs=['Fl_I:*'])

        self.add_subsystem('corrinputs', CorrectedInputsCalc(),
                           promotes_inputs=(
                               'Nmech', ('W_in', 'Fl_I:stat:W'),
                               ('Pt', 'Fl_I:tot:P'), ('Tt', 'Fl_I:tot:T')),
                           promotes_outputs=('Nc', 'Wc'))

        map_calcs = CompressorMap(map_data=self.options['map_data'], design=design,
                            interp_method=interp_method, extrap=map_extrap)
        self.add_subsystem('map', map_calcs,
                            promotes=['s_Nc','s_eff','s_Wc','s_PR','Nc','Wc',
                                    'PR','eff','SMN','SMW'])

        # Calculate pressure rise across compressor
        self.add_subsystem('press_rise', PressureRise(), promotes_inputs=[
                           'PR', ('Pt_in', 'Fl_I:tot:P')])

        # Calculate ideal flow station properties
        ideal_flow = Thermo(mode='total_SP', 
                            method=thermo_method, 
                            thermo_kwargs={'elements':elements, 
                                           'spec':thermo_data})
        self.add_subsystem('ideal_flow', ideal_flow,
                           promotes_inputs=[('S', 'Fl_I:tot:S'),
                                            ('composition', 'Fl_I:tot:composition')])
        self.connect("press_rise.Pt_out", "ideal_flow.P")

        # Calculate enthalpy rise across compressor
        self.add_subsystem("enth_rise", EnthalpyRise(),
                           promotes_inputs=['eff', ('inlet_ht', 'Fl_I:tot:h')])
        self.connect("ideal_flow.h", "enth_rise.ideal_ht")

        # Calculate real flow station properties
        real_flow = Thermo(mode='total_hP', fl_name='Fl_O:tot', 
                                  method=thermo_method, 
                                  thermo_kwargs={'elements':elements, 
                                                 'spec':thermo_data})
        self.add_subsystem('real_flow', real_flow,
                           promotes_inputs=[
                               ('composition', 'Fl_I:tot:composition')],
                           promotes_outputs=['Fl_O:tot:*'])
        self.connect("enth_rise.ht_out", "real_flow.h")
        self.connect("press_rise.Pt_out", "real_flow.P")
        #clculate Polytropic Efficiency
        self.add_subsystem('eff_poly_calc', eff_poly_calc(),
                            promotes_inputs=[('PR','PR'),
                                             ('S_in','Fl_I:tot:S'),
                                             ('S_out','Fl_O:tot:S'),
                                             # ('Cp','Fl_I:tot:Cp'),
                                             # ('Cv','Fl_I:tot:Cv'),
                                             ('Rt', 'Fl_I:tot:R')],
                            promotes_outputs=['eff_poly'] )

        # Calculate shaft power consumption
        blds_pwr = BleedsAndPower(bleed_names=bleeds)
        bld_inputs = ['frac_W', 'frac_P', 'frac_work']
        bld_in_vars = ['{0}:{1}'.format(
            bn, in_name) for bn, in_name in itertools.product(bleeds, bld_inputs)]
        bld_out_globs = ['{}:*'.format(bn) for bn in bleeds]

        self.add_subsystem('blds_pwr', blds_pwr,
                           promotes_inputs=['Nmech', ('W_in', 'Fl_I:stat:W'),
                                            ('ht_in', 'Fl_I:tot:h'),
                                            ('Pt_in', 'Fl_I:tot:P'),
                                            ('Pt_out', 'Fl_O:tot:P'), ] + bld_in_vars,
                           promotes_outputs=['power', 'trq', 'W_out'] + bld_out_globs)
        self.connect('enth_rise.ht_out', 'blds_pwr.ht_out')

        bleed_names = []
        for BN in bleeds:

            bleed_names.append(BN + '_flow')
            bleed_flow = Thermo(mode='total_hP', fl_name=BN + ":tot", 
                                  method=thermo_method, 
                                  thermo_kwargs={'elements':elements, 
                                                 'spec':thermo_data})
            self.add_subsystem(BN + '_flow', bleed_flow,
                               promotes_inputs=[
                                   ('composition', 'Fl_I:tot:composition')],
                               promotes_outputs=['{}:tot:*'.format(BN)])
            self.connect(BN + ':ht', BN + "_flow.h")
            self.connect(BN + ':Pt', BN + "_flow.P")


        if statics:
            if design:
                #   Calculate static properties
                out_stat = Thermo(mode='static_MN', fl_name='Fl_O:stat', 
                                  method=thermo_method, 
                                  thermo_kwargs={'elements':elements, 
                                                 'spec':thermo_data})
                self.add_subsystem('out_stat', out_stat,
                                   promotes_inputs=[
                                       'MN', ('composition', 'Fl_I:tot:composition')],
                                   promotes_outputs=['Fl_O:stat:*'])
                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('W_out', 'out_stat.W')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

            else:  # Calculate static properties
                out_stat = Thermo(mode='static_A', fl_name='Fl_O:stat', 
                                  method=thermo_method, 
                                  thermo_kwargs={'elements':elements, 
                                                 'spec':thermo_data})
                self.add_subsystem('out_stat', out_stat,
                                   promotes_inputs=[
                                       'area', ('composition', 'Fl_I:tot:composition')],
                                   promotes_outputs=['Fl_O:stat:*'])

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('W_out', 'out_stat.W')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

            self.set_order(['flow_in', 'corrinputs', 'map',
                            'press_rise','ideal_flow', 'enth_rise',
                            'real_flow','eff_poly_calc' ,'blds_pwr',] 
                            + bleed_names + ['out_stat'])

        else:
            self.add_subsystem('W_passthru', PassThrough('W_out',
                                                         'Fl_O:stat:W',
                                                         1.0,
                                                         units="lbm/s"),
                               promotes=['*'])
            self.set_order(['flow_in', 'corrinputs', 'map',
                            'press_rise','ideal_flow', 'enth_rise',
                            'real_flow','eff_poly_calc' , 'blds_pwr'] 
                            + bleed_names + ['W_passthru'])


        # define the group level defaults
        self.set_input_defaults('Fl_I:FAR', val=0., units=None)
        self.set_input_defaults('PR', val=2., units=None)
        self.set_input_defaults('eff', val=0.99, units=None)
예제 #9
0
    def setup(self):

        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']
        elements = self.options['elements']
        bleed_elements = self.options['bleed_elements']
        map_data = self.options['map_data']
        designFlag = self.options['design']
        bleeds = self.options['bleed_names']
        statics = self.options['statics']
        interp_method = self.options['map_interp_method']
        map_extrap = self.options['map_extrap']

        num_element = len(elements)
        num_bld_element = len(bleed_elements)

        # Create inlet flow station
        in_flow = FlowIn(fl_name='Fl_I')
        self.add_subsystem('in_flow', in_flow, promotes_inputs=['Fl_I:*'])

        self.add_subsystem('corrinputs',
                           CorrectedInputsCalc(),
                           promotes_inputs=[
                               'Nmech', ('W_in', 'Fl_I:stat:W'),
                               ('Pt', 'Fl_I:tot:P'), ('Tt', 'Fl_I:tot:T')
                           ],
                           promotes_outputs=['Np', 'Wp'])

        turb_map = TurbineMap(map_data=map_data,
                              design=designFlag,
                              interp_method=interp_method,
                              extrap=map_extrap)
        if designFlag:
            self.add_subsystem(
                'map',
                turb_map,
                promotes_inputs=['Np', 'Wp', 'PR', 'eff'],
                promotes_outputs=['s_PR', 's_Wp', 's_eff', 's_Np'])
        else:
            self.add_subsystem(
                'map',
                turb_map,
                promotes_inputs=['Np', 'Wp', 's_PR', 's_Wp', 's_eff', 's_Np'],
                promotes_outputs=['PR', 'eff'])

        # Calculate pressure drop across turbine
        self.add_subsystem('press_drop',
                           PressureDrop(),
                           promotes_inputs=['PR', ('Pt_in', 'Fl_I:tot:P')])

        # Calculate ideal flow station properties
        ideal_flow = Thermo(mode='total_SP',
                            method=thermo_method,
                            thermo_kwargs={
                                'elements': elements,
                                'spec': thermo_data
                            })
        self.add_subsystem('ideal_flow',
                           ideal_flow,
                           promotes_inputs=[('S', 'Fl_I:tot:S'),
                                            ('composition',
                                             'Fl_I:tot:composition')])
        self.connect("press_drop.Pt_out", "ideal_flow.P")

        # # Calculate enthalpy drop across turbine
        # self.add_subsystem("enth_drop", EnthalpyDrop(), promotes=['eff'])
        # self.connect("Fl_I:tot:h", "enth_drop.ht_in")
        # self.connect("ideal_flow.h", "enth_drop.ht_out_ideal")

        for BN in bleeds:
            bld_flow = FlowIn(fl_name=BN)
            self.add_subsystem(BN, bld_flow, promotes_inputs=[f'{BN}:*'])

        # # Calculate bleed parameters
        blds = BleedPressure(bleed_names=bleeds)
        self.add_subsystem('blds',
                           blds,
                           promotes_inputs=[
                               ('Pt_in', 'Fl_I:tot:P'),
                           ] + [f'{BN}:frac_P' for BN in bleeds])
        self.connect('press_drop.Pt_out', 'blds.Pt_out')

        bleed_element_list = [bleed_elements for name in bleeds]
        bld_mix = ThermoAdd(mix_thermo_data=thermo_data,
                            inflow_elements=elements,
                            mix_elements=bleed_element_list,
                            mix_names=bleeds,
                            mix_mode='flow')
        self.add_subsystem(
            'bld_mix',
            bld_mix,
            promotes_inputs=['Fl_I:stat:W', 'Fl_I:tot:composition'] +
            [(f'{BN}:W', f'{BN}:stat:W') for BN in bleeds] +
            [(f'{BN}:composition', f'{BN}:tot:composition') for BN in bleeds],
            promotes_outputs=[('Wout', 'W_out')])

        bleed_names2 = []
        for BN in bleeds:
            # Determine bleed inflow properties
            bleed_names2.append(BN + '_inflow')
            inflow = Thermo(mode='total_hP',
                            method=thermo_method,
                            thermo_kwargs={
                                'elements': bleed_elements,
                                'spec': thermo_data
                            })
            self.add_subsystem(BN + '_inflow',
                               inflow,
                               promotes_inputs=[('composition',
                                                 BN + ":tot:composition"),
                                                ('h', BN + ':tot:h')])
            self.connect(f'blds.{BN}:Pt', f'{BN}_inflow.P')

            # Ideally expand bleeds to exit pressure
            bleed_names2.append(f'{BN}_ideal')
            ideal = Thermo(mode='total_SP',
                           method=thermo_method,
                           thermo_kwargs={
                               'elements': bleed_elements,
                               'spec': thermo_data
                           })
            self.add_subsystem(f'{BN}_ideal',
                               ideal,
                               promotes_inputs=[('composition',
                                                 BN + ":tot:composition")])
            self.connect(f"{BN}_inflow.flow:S", f"{BN}_ideal.S")
            self.connect("press_drop.Pt_out", f"{BN}_ideal.P")

        # Calculate shaft power and exit enthalpy with cooling flows production
        self.add_subsystem('pwr_turb',
                           EnthalpyAndPower(bleed_names=bleeds),
                           promotes_inputs=[
                               'Nmech', 'eff', 'W_out',
                               ('W_in', 'Fl_I:stat:W'), ('ht_in', 'Fl_I:tot:h')
                           ] + [(BN + ':W', BN + ':stat:W') for BN in bleeds] +
                           [(BN + ':ht', BN + ':tot:h') for BN in bleeds] +
                           [(BN + ':ht_ideal', BN + '_ideal.h')
                            for BN in bleeds],
                           promotes_outputs=['power', 'trq', 'ht_out_b4bld'])
        self.connect('ideal_flow.h', 'pwr_turb.ht_out_ideal')

        # Calculate real flow station properties before bleed air is added
        real_flow_b4bld = Thermo(mode='total_hP',
                                 fl_name="Fl_O_b4bld:tot",
                                 method=thermo_method,
                                 thermo_kwargs={
                                     'elements': elements,
                                     'spec': thermo_data
                                 })
        self.add_subsystem('real_flow_b4bld',
                           real_flow_b4bld,
                           promotes_inputs=[('composition',
                                             'Fl_I:tot:composition')])
        self.connect('ht_out_b4bld', 'real_flow_b4bld.h')
        self.connect('press_drop.Pt_out', 'real_flow_b4bld.P')

        # Calculate Polytropic efficiency
        self.add_subsystem('eff_poly_calc',
                           eff_poly_calc(),
                           promotes_inputs=[
                               'PR', ('S_in', 'Fl_I:tot:S'),
                               ('Rt', 'Fl_I:tot:R')
                           ],
                           promotes_outputs=['eff_poly'])
        self.connect('real_flow_b4bld.Fl_O_b4bld:tot:S', 'eff_poly_calc.S_out')

        # Calculate real flow station properties
        real_flow = Thermo(mode='total_hP',
                           fl_name="Fl_O:tot",
                           method=thermo_method,
                           thermo_kwargs={
                               'elements': elements,
                               'spec': thermo_data
                           })
        self.add_subsystem('real_flow',
                           real_flow,
                           promotes_outputs=['Fl_O:tot:*'])
        self.connect("pwr_turb.ht_out", "real_flow.h")
        self.connect("press_drop.Pt_out", "real_flow.P")
        self.connect("bld_mix.composition_out", "real_flow.composition")

        # Calculate static properties
        if statics:
            if designFlag:
                #   SetStaticMN
                out_stat = Thermo(mode='static_MN',
                                  fl_name="Fl_O:stat",
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'elements': elements,
                                      'spec': thermo_data
                                  })
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=['MN'],
                                   promotes_outputs=['Fl_O:stat:*'])
                self.connect('bld_mix.composition_out', 'out_stat.composition')
                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('W_out', 'out_stat.W')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

            else:
                #   SetStaticArea
                out_stat = Thermo(mode='static_A',
                                  fl_name="Fl_O:stat",
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'elements': elements,
                                      'spec': thermo_data
                                  })
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=['area'],
                                   promotes_outputs=['Fl_O:stat:*'])
                self.connect('bld_mix.composition_out', 'out_stat.composition')
                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('W_out', 'out_stat.W')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

            self.set_order(
                ['in_flow', 'corrinputs', 'map', 'press_drop', 'ideal_flow'] +
                bleeds + ['bld_mix', 'blds'] + bleed_names2 + [
                    'pwr_turb', 'real_flow_b4bld', 'eff_poly_calc',
                    'real_flow', 'out_stat'
                ])

        else:
            self.add_subsystem('W_passthru',
                               PassThrough('W_out',
                                           'Fl_O:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])
            self.set_order(
                ['in_flow', 'corrinputs', 'map', 'press_drop', 'ideal_flow'] +
                bleeds + ['bld_mix', 'blds'] + bleed_names2 + [
                    'pwr_turb', 'real_flow_b4bld', 'eff_poly_calc',
                    'real_flow', 'W_passthru'
                ])

        self.set_input_defaults('eff', val=0.99, units=None)
예제 #10
0
    def setup(self):
        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']
        if self.options['inflow_thermo_data'] is not None:
            # Set the inflow thermodynamic data package if it is different from the outflow one
            inflow_thermo_data = self.options['inflow_thermo_data']

        else:
            # Set the inflow thermodynamic data package if it is the same as the outflow one
            inflow_thermo_data = thermo_data

        inflow_elements = self.options['inflow_elements']
        air_fuel_elements = self.options['air_fuel_elements']
        design = self.options['design']
        statics = self.options['statics']
        fuel_type = self.options['fuel_type']

        num_air_element = len(inflow_elements)

        # Create combustor flow station
        in_flow = FlowIn(fl_name='Fl_I')
        self.add_subsystem('in_flow',
                           in_flow,
                           promotes=['Fl_I:tot:*', 'Fl_I:stat:*'])

        # Perform combustor engineering calculations
        self.add_subsystem('mix_fuel',
                           ThermoAdd(inflow_thermo_data=inflow_thermo_data,
                                     mix_thermo_data=thermo_data,
                                     inflow_elements=inflow_elements,
                                     mix_elements=fuel_type),
                           promotes=[
                               'Fl_I:stat:W', ('mix:ratio', 'Fl_I:FAR'),
                               'Fl_I:tot:composition', 'Fl_I:tot:h',
                               ('mix:W', 'Wfuel'), 'Wout'
                           ])

        # Pressure loss
        prom_in = [('Pt_in', 'Fl_I:tot:P'), 'dPqP']
        self.add_subsystem('p_loss', PressureLoss(), promotes_inputs=prom_in)

        # Calculate vitiated flow station properties
        vit_flow = Thermo(mode='total_hP',
                          fl_name='Fl_O:tot',
                          method=thermo_method,
                          thermo_kwargs={
                              'elements': air_fuel_elements,
                              'spec': thermo_data
                          })
        self.add_subsystem('vitiated_flow',
                           vit_flow,
                           promotes_outputs=['Fl_O:*'])
        self.connect("mix_fuel.mass_avg_h", "vitiated_flow.h")
        self.connect("mix_fuel.composition_out", "vitiated_flow.composition")
        self.connect("p_loss.Pt_out", "vitiated_flow.P")

        if statics:
            if design:
                # Calculate static properties.

                out_stat = Thermo(mode='static_MN',
                                  fl_name='Fl_O:stat',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'elements': air_fuel_elements,
                                      'spec': thermo_data
                                  })
                prom_in = ['MN']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect("mix_fuel.composition_out",
                             "out_stat.composition")
                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
                self.connect('Wout', 'out_stat.W')

            else:
                # Calculate static properties.
                out_stat = Thermo(mode='static_A',
                                  fl_name='Fl_O:stat',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'elements': air_fuel_elements,
                                      'spec': thermo_data
                                  })
                prom_in = ['area']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)
                self.connect("mix_fuel.composition_out",
                             "out_stat.composition")

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
                self.connect('Wout', 'out_stat.W')

        else:
            self.add_subsystem('W_passthru',
                               PassThrough('Wout',
                                           'Fl_O:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])
예제 #11
0
파일: splitter.py 프로젝트: lamkina/pyCycle
    def setup(self):

        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']
        statics = self.options['statics']
        design = self.options['design']

        composition = self.Fl_I_data['Fl_I']

        # Create inlet flowstation
        flow_in = FlowIn(fl_name='Fl_I')
        self.add_subsystem('flow_in', flow_in, promotes_inputs=('Fl_I:*', ))

        # Split the flows
        self.add_subsystem('split_calc',
                           BPRcalc(),
                           promotes_inputs=('BPR', ('W_in', 'Fl_I:stat:W')))

        # Set Fl_out1 totals based on T, P
        real_flow1 = Thermo(mode='total_TP',
                            fl_name='Fl_O1:tot',
                            method=thermo_method,
                            thermo_kwargs={
                                'composition': composition,
                                'spec': thermo_data
                            })
        self.add_subsystem('real_flow1',
                           real_flow1,
                           promotes_inputs=(('composition',
                                             'Fl_I:tot:composition'),
                                            ('P', 'Fl_I:tot:P'),
                                            ('T', 'Fl_I:tot:T')),
                           promotes_outputs=('Fl_O1:tot:*', ))

        # Set Fl_out2 totals based on T, P
        real_flow2 = Thermo(mode='total_TP',
                            fl_name='Fl_O2:tot',
                            method=thermo_method,
                            thermo_kwargs={
                                'composition': composition,
                                'spec': thermo_data
                            })
        self.add_subsystem('real_flow2',
                           real_flow2,
                           promotes_inputs=(('composition',
                                             'Fl_I:tot:composition'),
                                            ('P', 'Fl_I:tot:P'),
                                            ('T', 'Fl_I:tot:T')),
                           promotes_outputs=('Fl_O2:tot:*', ))

        if statics:
            if design:
                #   Calculate static properties
                out1_stat = Thermo(mode='static_MN',
                                   fl_name='Fl_O1:stat',
                                   method=thermo_method,
                                   thermo_kwargs={
                                       'composition': composition,
                                       'spec': thermo_data
                                   })
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('MN', 'MN1')]
                prom_out = ['Fl_O1:stat:*']
                self.add_subsystem('out1_stat',
                                   out1_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)
                self.connect('Fl_O1:tot:S', 'out1_stat.S')
                self.connect('Fl_O1:tot:h', 'out1_stat.ht')
                self.connect('Fl_O1:tot:P', 'out1_stat.guess:Pt')
                self.connect('Fl_O1:tot:gamma', 'out1_stat.guess:gamt')
                self.connect('split_calc.W1', 'out1_stat.W')

                out2_stat = Thermo(mode='static_MN',
                                   fl_name='Fl_O2:stat',
                                   method=thermo_method,
                                   thermo_kwargs={
                                       'composition': composition,
                                       'spec': thermo_data
                                   })
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('MN', 'MN2')]
                prom_out = ['Fl_O2:stat:*']
                self.add_subsystem('out2_stat',
                                   out2_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)
                self.connect('Fl_O2:tot:S', 'out2_stat.S')
                self.connect('Fl_O2:tot:h', 'out2_stat.ht')
                self.connect('Fl_O2:tot:P', 'out2_stat.guess:Pt')
                self.connect('Fl_O2:tot:gamma', 'out2_stat.guess:gamt')
                self.connect('split_calc.W2', 'out2_stat.W')

            else:
                # Calculate static properties
                out1_stat = Thermo(mode='static_A',
                                   fl_name='Fl_O1:stat',
                                   method=thermo_method,
                                   thermo_kwargs={
                                       'composition': composition,
                                       'spec': thermo_data
                                   })
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('area', 'area1')]
                prom_out = ['Fl_O1:stat:*']
                self.add_subsystem('out1_stat',
                                   out1_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)
                self.connect('Fl_O1:tot:S', 'out1_stat.S')
                self.connect('Fl_O1:tot:h', 'out1_stat.ht')
                self.connect('Fl_O1:tot:P', 'out1_stat.guess:Pt')
                self.connect('Fl_O1:tot:gamma', 'out1_stat.guess:gamt')
                self.connect('split_calc.W1', 'out1_stat.W')

                out2_stat = Thermo(mode='static_A',
                                   fl_name='Fl_O2:stat',
                                   method=thermo_method,
                                   thermo_kwargs={
                                       'composition': composition,
                                       'spec': thermo_data
                                   })
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('area', 'area2')]
                prom_out = ['Fl_O2:stat:*']
                self.add_subsystem('out2_stat',
                                   out2_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)
                self.connect('Fl_O2:tot:S', 'out2_stat.S')
                self.connect('Fl_O2:tot:h', 'out2_stat.ht')
                self.connect('Fl_O2:tot:P', 'out2_stat.guess:Pt')
                self.connect('Fl_O2:tot:gamma', 'out2_stat.guess:gamt')
                self.connect('split_calc.W2', 'out2_stat.W')

        else:
            self.add_subsystem('W1_passthru',
                               PassThrough('split_calc_W1',
                                           'Fl_O1:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])
            self.add_subsystem('W2_passthru',
                               PassThrough('split_calc_W2',
                                           'Fl_O2:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])
            self.connect('split_calc.W1', 'split_calc_W1')
            self.connect('split_calc.W2', 'split_calc_W2')

        super().setup()
예제 #12
0
파일: mixer.py 프로젝트: lamkina/pyCycle
    def setup(self):

        design = self.options['design']
        thermo_data = self.options['thermo_data']
        thermo_method = self.options['thermo_method']

        flow1_composition = self.Fl_I_data['Fl_I1']
        in_flow = FlowIn(fl_name='Fl_I1')
        self.add_subsystem('in_flow1', in_flow, promotes=['Fl_I1:*'])

        flow2_composition = self.Fl_I_data['Fl_I1']
        in_flow = FlowIn(fl_name='Fl_I2')
        self.add_subsystem('in_flow2', in_flow, promotes=['Fl_I2:*'])

        if self.options['designed_stream'] == 1:
            self.default_des_od_conns = [('Fl_O:stat:area', 'area'),
                                         ('Fl_I1_calc:stat:area',
                                          'Fl_I1_stat_calc.area')]
        else:
            self.default_des_od_conns = [('Fl_O:stat:area', 'area'),
                                         ('Fl_I2_calc:stat:area',
                                          'Fl_I2_stat_calc.area')]

        if design:
            # internal flow station to compute the area that is needed to match the static pressures
            if self.options['designed_stream'] == 1:
                Fl1_stat = Thermo(mode='static_Ps',
                                  fl_name="Fl_I1_calc:stat",
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': flow1_composition,
                                      'spec': thermo_data
                                  })
                self.add_subsystem('Fl_I1_stat_calc',
                                   Fl1_stat,
                                   promotes_inputs=[('composition',
                                                     'Fl_I1:tot:composition'),
                                                    ('S', 'Fl_I1:tot:S'),
                                                    ('ht', 'Fl_I1:tot:h'),
                                                    ('W', 'Fl_I1:stat:W'),
                                                    ('Ps', 'Fl_I2:stat:P')],
                                   promotes_outputs=['Fl_I1_calc:stat*'])

                self.add_subsystem('area_calc',
                                   AreaSum(),
                                   promotes_inputs=['Fl_I2:stat:area'],
                                   promotes_outputs=[('area_sum', 'area')])
                self.connect('Fl_I1_calc:stat:area',
                             'area_calc.Fl_I1:stat:area')

            else:
                Fl2_stat = Thermo(mode='static_Ps',
                                  fl_name="Fl_I2_calc:stat",
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': flow2_composition,
                                      'spec': thermo_data
                                  })
                self.add_subsystem('Fl_I2_stat_calc',
                                   Fl2_stat,
                                   promotes_inputs=[('composition',
                                                     'Fl_I2:tot:composition'),
                                                    ('S', 'Fl_I2:tot:S'),
                                                    ('ht', 'Fl_I2:tot:h'),
                                                    ('W', 'Fl_I2:stat:W'),
                                                    ('Ps', 'Fl_I1:stat:P')],
                                   promotes_outputs=['Fl_I2_calc:stat:*'])

                self.add_subsystem('area_calc',
                                   AreaSum(),
                                   promotes_inputs=['Fl_I1:stat:area'],
                                   promotes_outputs=[('area_sum', 'area')])
                self.connect('Fl_I2_calc:stat:area',
                             'area_calc.Fl_I2:stat:area')

        else:
            if self.options['designed_stream'] == 1:
                Fl1_stat = Thermo(mode='static_A',
                                  fl_name="Fl_I1_calc:stat",
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': flow1_composition,
                                      'spec': thermo_data
                                  })
                self.add_subsystem('Fl_I1_stat_calc',
                                   Fl1_stat,
                                   promotes_inputs=[
                                       ('composition',
                                        'Fl_I1:tot:composition'),
                                       ('S', 'Fl_I1:tot:S'),
                                       ('ht', 'Fl_I1:tot:h'),
                                       ('W', 'Fl_I1:stat:W'),
                                       ('guess:Pt', 'Fl_I1:tot:P'),
                                       ('guess:gamt', 'Fl_I1:tot:gamma')
                                   ],
                                   promotes_outputs=['Fl_I1_calc:stat*'])

            else:
                Fl2_stat = Thermo(mode='static_A',
                                  fl_name="Fl_I2_calc:stat",
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'composition': flow2_composition,
                                      'spec': thermo_data
                                  })
                self.add_subsystem('Fl_I2_stat_calc',
                                   Fl2_stat,
                                   promotes_inputs=[
                                       ('composition',
                                        'Fl_I2:tot:composition'),
                                       ('S', 'Fl_I2:tot:S'),
                                       ('ht', 'Fl_I2:tot:h'),
                                       ('W', 'Fl_I2:stat:W'),
                                       ('guess:Pt', 'Fl_I2:tot:P'),
                                       ('guess:gamt', 'Fl_I2:tot:gamma')
                                   ],
                                   promotes_outputs=['Fl_I2_calc:stat*'])

        self.add_subsystem('extraction_ratio',
                           om.ExecComp('ER=Pt1/Pt2',
                                       Pt1={'units': 'Pa'},
                                       Pt2={'units': 'Pa'}),
                           promotes_inputs=[('Pt1', 'Fl_I1:tot:P'),
                                            ('Pt2', 'Fl_I2:tot:P')],
                           promotes_outputs=['ER'])

        self.add_subsystem('flow_add',
                           self.flow_add,
                           promotes_inputs=[('Fl_I:stat:W', 'Fl_I1:stat:W'),
                                            ('Fl_I:tot:composition',
                                             'Fl_I1:tot:composition'),
                                            ('Fl_I:tot:h', 'Fl_I1:tot:h'),
                                            ('mix:W', 'Fl_I2:stat:W'),
                                            ('mix:composition',
                                             'Fl_I2:tot:composition'),
                                            ('mix:h', 'Fl_I2:tot:h')])

        if self.options['designed_stream'] == 1:
            self.add_subsystem('impulse_mix',
                               MixImpulse(),
                               promotes_inputs=[
                                   ('Fl_I1:stat:W', 'Fl_I1_calc:stat:W'),
                                   ('Fl_I1:stat:P', 'Fl_I1_calc:stat:P'),
                                   ('Fl_I1:stat:V', 'Fl_I1_calc:stat:V'),
                                   ('Fl_I1:stat:area', 'Fl_I1_calc:stat:area'),
                                   'Fl_I2:stat:W', 'Fl_I2:stat:P',
                                   'Fl_I2:stat:V', 'Fl_I2:stat:area'
                               ])
        else:
            self.add_subsystem('impulse_mix',
                               MixImpulse(),
                               promotes_inputs=[
                                   'Fl_I1:stat:W', 'Fl_I1:stat:P',
                                   'Fl_I1:stat:V', 'Fl_I1:stat:area',
                                   ('Fl_I2:stat:W', 'Fl_I2_calc:stat:W'),
                                   ('Fl_I2:stat:P', 'Fl_I2_calc:stat:P'),
                                   ('Fl_I2:stat:V', 'Fl_I2_calc:stat:V'),
                                   ('Fl_I2:stat:area', 'Fl_I2_calc:stat:area')
                               ])

        # group to converge for the impulse balance
        conv = self.add_subsystem('impulse_converge',
                                  om.Group(),
                                  promotes=['*'])

        if self.options['internal_solver']:
            newton = conv.nonlinear_solver = om.NewtonSolver()
            newton.options['maxiter'] = 30
            newton.options['atol'] = 1e-5
            newton.options['rtol'] = 1e-99
            newton.options['solve_subsystems'] = True
            newton.options['max_sub_solves'] = 20
            newton.options['reraise_child_analysiserror'] = False
            newton.linesearch = om.BoundsEnforceLS()
            newton.linesearch.options['iprint'] = -1
            conv.linear_solver = om.DirectSolver()

        out_tot = Thermo(mode='total_hP',
                         fl_name='Fl_O:tot',
                         method=thermo_method,
                         thermo_kwargs={
                             'composition': flow1_composition,
                             'spec': thermo_data
                         })
        conv.add_subsystem('out_tot', out_tot, promotes_outputs=['Fl_O:tot:*'])
        self.connect('flow_add.composition_out', 'out_tot.composition')
        self.connect('flow_add.mass_avg_h', 'out_tot.h')
        # note: gets Pt from the balance comp

        out_stat = Thermo(mode='static_A',
                          fl_name='Fl_O:stat',
                          method=thermo_method,
                          thermo_kwargs={
                              'composition': flow1_composition,
                              'spec': thermo_data
                          })
        conv.add_subsystem('out_stat',
                           out_stat,
                           promotes_outputs=['Fl_O:stat:*'],
                           promotes_inputs=[
                               'area',
                           ])
        self.connect('flow_add.composition_out', 'out_stat.composition')
        self.connect('flow_add.Wout', 'out_stat.W')
        conv.connect('Fl_O:tot:S', 'out_stat.S')
        self.connect('flow_add.mass_avg_h', 'out_stat.ht')
        conv.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
        conv.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

        conv.add_subsystem('imp_out', Impulse())
        conv.connect('Fl_O:stat:P', 'imp_out.P')
        conv.connect('Fl_O:stat:area', 'imp_out.area')
        conv.connect('Fl_O:stat:V', 'imp_out.V')
        conv.connect('Fl_O:stat:W', 'imp_out.W')

        balance = conv.add_subsystem('balance', om.BalanceComp())
        balance.add_balance('P_tot',
                            val=100,
                            units='psi',
                            eq_units='N',
                            lower=1e-3,
                            upper=10000)
        conv.connect('balance.P_tot', 'out_tot.P')
        conv.connect('imp_out.impulse', 'balance.lhs:P_tot')
        self.connect(
            'impulse_mix.impulse_mix', 'balance.rhs:P_tot'
        )  #note that this connection comes from outside the convergence group

        super().setup()
예제 #13
0
파일: duct.py 프로젝트: eshendricks/pyCycle
    def setup(self):
        thermo_method = self.options['thermo_method']
        thermo_data = self.options['thermo_data']
        elements = self.options['elements']
        statics = self.options['statics']
        design = self.options['design']
        expMN = self.options['expMN']

        num_element = len(elements)

        # Create inlet flowstation
        flow_in = FlowIn(fl_name='Fl_I')
        self.add_subsystem('flow_in',
                           flow_in,
                           promotes=['Fl_I:tot:*', 'Fl_I:stat:*'])

        if expMN > 1e-10:  # Calcluate pressure losses as function of Mach number
            if design:
                self.add_subsystem(
                    'dPqP_MN',
                    MachPressureLossMap(design=design, expMN=expMN),
                    promotes_inputs=['dPqP', ('MN_in', 'Fl_I:stat:MN')],
                    promotes_outputs=['s_dPqP'])
            else:
                self.add_subsystem(
                    'dPqP_MN',
                    MachPressureLossMap(design=design, expMN=expMN),
                    promotes_inputs=['s_dPqP', ('MN_in', 'Fl_I:stat:MN')],
                    promotes_outputs=['dPqP'])

        #Pressure Loss Component
        prom_in = [('Pt_in', 'Fl_I:tot:P'), 'dPqP']
        self.add_subsystem('p_loss', PressureLoss(), promotes_inputs=prom_in)

        # Energy Calc Component
        prom_in = [('W_in', 'Fl_I:stat:W'), ('ht_in', 'Fl_I:tot:h'), 'Q_dot']
        self.add_subsystem('q_calc', qCalc(), promotes_inputs=prom_in)

        # Total Calc
        real_flow = Thermo(mode='total_hP',
                           fl_name='Fl_O:tot',
                           method=thermo_method,
                           thermo_kwargs={
                               'elements': elements,
                               'spec': thermo_data
                           })
        prom_in = [('composition', 'Fl_I:tot:composition')]
        self.add_subsystem('real_flow',
                           real_flow,
                           promotes_inputs=prom_in,
                           promotes_outputs=['Fl_O:*'])
        self.connect("q_calc.ht_out", "real_flow.h")
        self.connect("p_loss.Pt_out", "real_flow.P")

        if statics:
            if design:
                #   Calculate static properties
                out_stat = Thermo(mode='static_MN',
                                  fl_name='Fl_O:stat',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'elements': elements,
                                      'spec': thermo_data
                                  })
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('W', 'Fl_I:stat:W'), 'MN']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')

            else:
                # Calculate static properties
                out_stat = Thermo(mode='static_A',
                                  fl_name='Fl_O:stat',
                                  method=thermo_method,
                                  thermo_kwargs={
                                      'elements': elements,
                                      'spec': thermo_data
                                  })
                prom_in = [('composition', 'Fl_I:tot:composition'),
                           ('W', 'Fl_I:stat:W'), 'area']
                prom_out = ['Fl_O:stat:*']
                self.add_subsystem('out_stat',
                                   out_stat,
                                   promotes_inputs=prom_in,
                                   promotes_outputs=prom_out)

                self.connect('Fl_O:tot:S', 'out_stat.S')
                self.connect('Fl_O:tot:h', 'out_stat.ht')
                self.connect('Fl_O:tot:P', 'out_stat.guess:Pt')
                self.connect('Fl_O:tot:gamma', 'out_stat.guess:gamt')
        else:
            self.add_subsystem('W_passthru',
                               PassThrough('Fl_I:stat:W',
                                           'Fl_O:stat:W',
                                           1.0,
                                           units="lbm/s"),
                               promotes=['*'])
예제 #14
0
파일: cooling.py 프로젝트: askprash/pyCycle
    def setup(self):

        self.add_subsystem('cooling_calcs',
                           CoolingCalcs(n_stages=self.options['n_stages'],
                                        i_row=self.options['i_row'],
                                        T_safety=self.options['T_safety'],
                                        T_metal=self.options['T_metal']),
                           promotes_inputs=[
                               'Pt_in', 'Pt_out', 'W_primary', 'Tt_primary',
                               'Tt_cool', 'ht_primary', 'ht_cool', 'x_factor',
                               'turb_pwr'
                           ],
                           promotes_outputs=['W_cool'])

        consts = self.add_subsystem(
            'consts',
            om.IndepVarComp())  # values that should not be changed ever
        consts.add_output('bld_frac_P', val=1)

        # self.add_subsystem('mix_n', Bleeds(thermo_data=self.options['thermo_data'],
        #                                    main_flow_elements=AIR_FUEL_ELEMENTS,
        #                                    bld_flow_elements=AIR_ELEMENTS,
        #                                    bleed_names=['cool']
        #                                   ),
        #                   promotes_inputs=['Pt_in', 'Pt_out', ('W_in','W_primary'), ('n_in', 'n_primary'), ('cool:n', 'n_cool')],
        #                   promotes_outputs=['W_out'])

        self.add_subsystem(
            'mix_n',
            ThermoAdd(mix_thermo_data=self.options['thermo_data'],
                      inflow_elements=AIR_FUEL_ELEMENTS,
                      mix_mode='flow',
                      mix_elements=AIR_ELEMENTS,
                      mix_names='cool'),
            promotes_inputs=[('Fl_I:stat:W', 'W_primary'),
                             ('Fl_I:tot:composition', 'composition_primary'),
                             'cool:composition'],
            promotes_outputs=[
                ('Wout', 'W_out'),
            ])

        mixed_flow = Thermo(mode='total_hP',
                            fl_name='Fl_O:tot',
                            method='CEA',
                            thermo_kwargs={
                                'elements': AIR_FUEL_ELEMENTS,
                                'spec': self.options['thermo_data']
                            })
        self.add_subsystem('mixed_flow',
                           mixed_flow,
                           promotes_outputs=['Fl_O:tot:*'])

        # promoted
        # self.connect('', 'mix_n.Pt_in')
        # self.connect('', 'mix_n.Pt_out')
        # self.connect('', 'mix_n.W_primary')
        # self.connect('', 'mix_n.n_in')
        # self.connect('', 'mix_n.cool:n')

        self.connect('W_cool', 'mix_n.cool:W')

        # self.connect('consts.bld_frac_P', 'mix_n.cool:frac_P')

        self.connect('mix_n.composition_out', 'mixed_flow.composition')
        self.connect('cooling_calcs.ht_out', 'mixed_flow.h')
        self.connect('cooling_calcs.Pt_stage', 'mixed_flow.P')