Exemplo n.º 1
0
    def setUp(self):

        self.thermo = species_data.Properties(
            species_data.co2_co_o2, init_elements=constants.CO2_CO_O2_ELEMENTS)

        p = self.prob = Problem()
        p.model = Group()
        p.model.suppress_solver_output = True

        p.model.add_subsystem('props',
                              PropsCalcs(thermo=self.thermo),
                              promotes=['*'])

        p.model.set_input_defaults('T', 4000., units='degK')
        p.model.set_input_defaults('P', 1.034210, units='bar')

        n = np.array([0.02040741, 0.0023147, 0.0102037])
        p.model.set_input_defaults('n', n)

        result_T = np.array([-1.74791977, 1.81604241, -0.24571810])
        p.model.set_input_defaults('result_T', result_T)

        result_P = np.array([0.48300853, 0.48301125, -0.01522548])
        p.model.set_input_defaults('result_P', result_P)

        p.setup(check=False)
        p['n_moles'] = 0.03292581
Exemplo n.º 2
0
    def setUp(self):

        self.thermo = species_data.Properties(
            species_data.co2_co_o2, init_elements=constants.CO2_CO_O2_ELEMENTS)

        p = self.prob = Problem()
        p.model = Group()
        p.model.suppress_solver_output = True

        p.model.add_subsystem('props_rhs',
                              PropsRHS(thermo=self.thermo),
                              promotes=[
                                  'T', 'n', 'composition', 'rhs_T', 'rhs_P',
                                  'lhs_TP', 'n_moles'
                              ])
        p.model.set_input_defaults('T', 4000., units='degK')

        n = np.array([0.02040741, 0.0023147, 0.0102037])
        p.model.set_input_defaults('n', n)

        b = np.array([0.02272211, 0.04544422])
        p.model.set_input_defaults('composition', b)
        p.model.set_input_defaults('n_moles', 0.03292581)

        p.setup(check=False)
        p['n_moles'] = 0.03292581
Exemplo n.º 3
0
    def test_element_filter(self):

        elements1_provided = {'C': 1, 'O': 1}
        products1_expected = ['CO', 'CO2', 'O2']
        thermo1 = species_data.Properties(
            thermo_data_module=species_data.co2_co_o2,
            init_elements=elements1_provided)
        elements1_expected = {'C', 'O'}
        products1 = thermo1.products
        elements1 = thermo1.elements

        elements2_provided = {'Ar': 1, 'C': 1, 'N': 1, 'O': 1}
        products2_expected = [
            'Ar', 'CO', 'CO2', 'N', 'NO', 'NO2', 'NO3', 'N2', 'O', 'O2'
        ]
        thermo2 = species_data.Properties(
            thermo_data_module=species_data.janaf,
            init_elements=elements2_provided)
        elements2_expected = {'Ar', 'C', 'N', 'O'}
        products2 = thermo2.products
        elements2 = thermo2.elements

        elements3_provided = {'Ar': 1, 'C': 1, 'H': 1, 'N': 1}
        products3_expected = ['Ar', 'CH4', 'C2H4', 'H', 'H2', 'N', 'NH3', 'N2']
        thermo3 = species_data.Properties(
            thermo_data_module=species_data.janaf,
            init_elements=elements3_provided)
        elements3_expected = {'Ar', 'C', 'H', 'N'}
        products3 = thermo3.products
        elements3 = thermo3.elements

        self.assertEqual(products1, products1_expected)
        self.assertEqual(set(elements1), elements1_expected)

        self.assertEqual(products2, products2_expected)
        self.assertEqual(set(elements2), elements2_expected)

        self.assertEqual(products3, products3_expected)
        self.assertEqual(set(elements3), elements3_expected)
Exemplo n.º 4
0
    def test_mix_2fuel(self):

        thermo_spec = species_data.janaf

        air_thermo = species_data.Properties(thermo_spec,
                                             init_elements=CEA_AIR_COMPOSITION)

        p = om.Problem()

        fuel = 'JP-7'
        p.model = ThermoAdd(spec=thermo_spec,
                            inflow_composition=CEA_AIR_COMPOSITION,
                            mix_mode='reactant',
                            mix_composition=[fuel, fuel],
                            mix_names=['fuel1', 'fuel2'])

        p.setup(force_alloc_complex=True)

        # p['Fl_I:stat:P'] = 158.428
        p['Fl_I:stat:W'] = 38.8
        p['Fl_I:tot:h'] = 181.381769
        p['Fl_I:tot:composition'] = air_thermo.b0

        # half the ratio from the 1 fuel test
        ratio = 0.02673 / 2.
        p['fuel1:ratio'] = ratio
        p['fuel2:ratio'] = ratio

        p.run_model()

        tol = 5e-7
        assert_near_equal(p['mass_avg_h'], 176.65965638, tolerance=tol)
        assert_near_equal(p['Wout'], 39.837124, tolerance=tol)
        assert_near_equal(p['fuel1:W'],
                          p['Fl_I:stat:W'] * ratio,
                          tolerance=tol)
        assert_near_equal(p['fuel2:W'],
                          p['Fl_I:stat:W'] * ratio,
                          tolerance=tol)
        assert_near_equal(p['composition_out'],
                          np.array([
                              0.0003149, 0.00186566, 0.00371394, 0.05251212,
                              0.01410888
                          ]),
                          tolerance=tol)

        data = p.check_partials(out_stream=None, method='fd')
        # data = p.check_partials(method='cs')
        assert_check_partials(
            data, atol=2.e-4,
            rtol=2.e-4)  # can't get very accurate checks with FD
Exemplo n.º 5
0
    def test_errors(self):

        product_elements = {'O2': 1}

        with self.assertRaises(ValueError) as cm:

            thermo = species_data.Properties(
                thermo_data_module=species_data.co2_co_o2,
                init_elements=product_elements)

        self.assertEqual(
            str(cm.exception),
            "The provided element `O2` is a product in your provided thermo data, but is not an element."
        )

        bad_elements = {'H': 1}

        with self.assertRaises(ValueError) as cm:

            thermo = species_data.Properties(
                thermo_data_module=species_data.co2_co_o2,
                init_elements=bad_elements)

            self.assertEqual(
                str(cm.exception),
                "The provided element `H` is not used in any products in your thermo data."
            )

        with self.assertRaises(ValueError) as cm:

            thermo = species_data.Properties(
                thermo_data_module=species_data.co2_co_o2)

        self.assertEqual(
            str(cm.exception),
            'You have not provided `init_elements`. In order to set thermodynamic data it must be provided.'
        )
Exemplo n.º 6
0
    def setup(self):

        self.thermo = species_data.Properties(
            self.options['spec'], init_elements=self.options['elements'])

        # these have to be part of the API for the unit_comps to use
        self.composition = self.thermo.b0

        self.add_subsystem('chem_eq',
                           ChemEq(thermo=self.thermo, mode='T'),
                           promotes=['*'])

        self.add_subsystem('props',
                           ThermoCalcs(thermo=self.thermo),
                           promotes=['*'])
Exemplo n.º 7
0
    def test_mix_1fuel(self):

        thermo_spec = species_data.janaf

        air_thermo = species_data.Properties(thermo_spec,
                                             init_elements=AIR_ELEMENTS)

        p = om.Problem()

        fuel = 'JP-7'
        p.model = ThermoAdd(inflow_thermo_data=thermo_spec,
                            mix_thermo_data=thermo_spec,
                            inflow_elements=AIR_ELEMENTS,
                            mix_mode='reactant',
                            mix_elements=fuel,
                            mix_names='fuel')

        p.setup(force_alloc_complex=True)

        # p['Fl_I:stat:P'] = 158.428
        p['Fl_I:stat:W'] = 38.8
        p['Fl_I:tot:h'] = 181.381769
        p['Fl_I:tot:composition'] = air_thermo.b0

        p['fuel:ratio'] = 0.02673

        p.run_model()

        tol = 5e-7
        assert_near_equal(p['mass_avg_h'], 176.65965638, tolerance=tol)
        assert_near_equal(p['Wout'], 39.837124, tolerance=tol)
        assert_near_equal(p['fuel:W'],
                          p['Fl_I:stat:W'] * p['fuel:ratio'],
                          tolerance=tol)
        assert_near_equal(p['composition_out'],
                          np.array([
                              0.0003149, 0.00186566, 0.00371394, 0.05251212,
                              0.01410888
                          ]),
                          tolerance=tol)

        # data = p.check_partials(out_stream=None, method='cs')
        data = p.check_partials(method='cs')
        assert_check_partials(data, atol=1.e-6, rtol=1.e-6)
Exemplo n.º 8
0
    def setup(self):

        init_elements = self.options['composition']
        if init_elements is None:
            init_elements = CEA_AIR_COMPOSITION

        self.thermo = species_data.Properties(self.options['spec'],
                                              init_elements=init_elements)

        # these have to be part of the API for the unit_comps to use
        self.composition = self.thermo.b0

        self.add_subsystem('chem_eq',
                           ChemEq(thermo=self.thermo),
                           promotes=['*'])

        self.add_subsystem('props',
                           ThermoCalcs(thermo=self.thermo),
                           promotes=['*'])
Exemplo n.º 9
0
    def test_war_vals(self):
        """
        verifies that the ThermoAdd component gives the right answers when adding water to dry air
        """

        prob = om.Problem()

        thermo_spec = species_data.wet_air

        air_thermo = species_data.Properties(thermo_spec,
                                             init_elements=CEA_AIR_COMPOSITION)

        prob.model.add_subsystem('war',
                                 ThermoAdd(
                                     spec=thermo_spec,
                                     inflow_composition=CEA_AIR_COMPOSITION,
                                     mix_composition='Water'),
                                 promotes=['*'])

        prob.setup(force_alloc_complex=True)

        # p['Fl_I:stat:P'] = 158.428
        prob['Fl_I:stat:W'] = 38.8
        prob['mix:ratio'] = .0001  # WAR
        prob['Fl_I:tot:h'] = 181.381769
        prob['Fl_I:tot:composition'] = air_thermo.b0

        prob.run_model()

        tol = 1e-5

        assert_near_equal(prob['composition_out'][0], 3.23286926e-04, tol)
        assert_near_equal(prob['composition_out'][1], 1.10121227e-05, tol)
        assert_near_equal(prob['composition_out'][2], 1.11005769e-05, tol)
        assert_near_equal(prob['composition_out'][3], 5.39103820e-02, tol)
        assert_near_equal(prob['composition_out'][4], 1.44901169e-02, tol)
Exemplo n.º 10
0
        self.drhsT_dn[:num_element] = aij * H0_T
        self.drhsT_dn[num_element] = H0_T

        J['rhs_T', 'T'] = self.drhsT_dT.reshape((-1, 1))
        J['rhs_T', 'n'] = self.drhsT_dn

        # derivs of rhsP are constants, specified in setup

        # derivs of lhs_TP are constants, specified in setup


if __name__ == "__main__":

    from openmdao.api import Problem, Group, IndepVarComp, LinearSystemComp

    thermo = species_data.Properties(species_data.co2_co_o2)

    p = Problem()
    p.model = Group()

    indeps = p.model.add_subsystem('indeps', IndepVarComp(), promotes=['*'])
    indeps.add_output('T', val=2761.56784655, units='degK')
    indeps.add_output('n', val=np.array([2.272e-02, 1.000e-10, 1.136e-02]))
    indeps.add_output('composition', val=np.array([0.023, 0.045]))
    indeps.add_output('n_moles', val=0.0340831628675)

    props_rhs = p.model.add_subsystem('props_rhs',
                                      PropsRHS(thermo=thermo),
                                      promotes=["*"])

    p.model.add_subsystem('ln_T',
Exemplo n.º 11
0
 def setUp(self):
     self.thermo = species_data.Properties(
         species_data.janaf, init_elements=constants.AIR_ELEMENTS)
     p = self.p = Problem(model=Group())
     p.model.suppress_solver_output = True
     p.model.set_input_defaults('P', 1.034210, units="bar")
Exemplo n.º 12
0
        else:
            self.add_subsystem('W_passthru',
                               PassThrough('Fl_I:stat:W',
                                           'Fl_O:stat:W',
                                           0.0,
                                           units="lbm/s"),
                               promotes=['*'])


if __name__ == "__main__":
    from pycycle import constants

    p = om.Problem()
    p.model = Inlet()

    thermo = species_data.Properties(species_data.janaf,
                                     constants.AIR_ELEMENTS)
    p.model.set_input_defaults('Fl_I:tot:T', 284, units='degK')
    p.model.set_input_defaults('Fl_I:tot:P', 5.0, units='lbf/inch**2')
    p.model.set_input_defaults('Fl_I:stat:V', 0.0, units='ft/s')  #keep
    p.model.set_input_defaults('Fl_I:stat:W', 1, units='kg/s')

    p.setup()

    #view_model(p)
    p.run_model()
    # print(p.get_val('Fl_I:tot:T', units='degK'))
    p.model.list_outputs(units=True)

    # generates regression testing setup
    #regression_generator(p)
Exemplo n.º 13
0
    def test_values(self):
        thermo2 = species_data.Properties(
            thermo_data_module=species_data.janaf, init_elements=AIR_ELEMENTS)
        thermo3 = species_data.Properties(
            thermo_data_module=species_data.co2_co_o2,
            init_elements=CO2_CO_O2_ELEMENTS)

        T2 = np.ones(thermo2.num_prod) * 800
        T3 = np.ones(thermo3.num_prod) * 800
        H02 = thermo2.H0(T2)
        H03 = thermo3.H0(T3)
        H0_expected = np.array([
            1.56828125, -14.33638055, -55.73109232, 72.63079725, 16.05970705,
            8.50490177, 15.48013356, 2.2620009, 39.06512544, 2.38109781
        ])
        H0_expected3 = np.array([-14.33638055, -55.73109232, 2.38109781])

        S02 = thermo2.S0(T2)
        S03 = thermo3.S0(T3)
        S0_expected = np.array([
            21.09120423, 27.33539665, 30.96900291, 20.90543864, 28.99563162,
            34.04699324, 37.65697408, 26.58210226, 21.90362596, 28.37546079
        ])
        S0_expected3 = np.array([27.33539665, 30.96900291, 28.37546079])

        Cp02 = thermo2.Cp0(T2)
        Cp03 = thermo3.Cp0(T3)
        Cp0_expected = np.array([
            2.5, 3.83668584, 6.18585395, 2.5, 3.94173049, 6.06074564,
            8.81078156, 3.78063693, 2.52375035, 4.05857378
        ])
        Cp0_expected3 = np.array([3.83668584, 6.18585395, 4.05857378])

        HJ2 = thermo2.H0_applyJ(T2, 1.)
        HJ3 = thermo3.H0_applyJ(T3, 1.)
        HJ_expected = np.array([
            0.00116465, 0.02271633, 0.07739618, -0.0876635, -0.01514747,
            -0.0030552, -0.00833669, 0.0018983, -0.04567672, 0.00209684
        ])
        HJ_expected3 = np.array([0.02271633, 0.07739618, 0.00209684])

        SJ2 = thermo2.S0_applyJ(T2, 1)
        SJ3 = thermo3.S0_applyJ(T3, 1)
        SJ_expected = np.array([
            0.003125, 0.00479586, 0.00773232, 0.003125, 0.00492716, 0.00757593,
            0.01101348, 0.0047258, 0.00315469, 0.00507322
        ])
        SJ_expected3 = np.array([0.00479586, 0.00773232, 0.00507322])

        CpJ2 = thermo2.Cp0_applyJ(T2, 1)
        CpJ3 = thermo3.Cp0_applyJ(T3, 1)
        CpJ_expected = np.array([
            0.0, 8.49157682e-04, 2.05623736e-03, 0.0, 8.39005783e-04,
            1.91861539e-03, 2.54742879e-03, 8.12550383e-04, -5.62484525e-05,
            8.19626699e-04
        ])
        CpJ_expected3 = np.array(
            [8.49157682e-04, 2.05623736e-03, 8.19626699e-04])

        b02 = thermo2.b0
        b03 = thermo3.b0
        b0_expected = np.array(
            [3.23319258e-04, 1.10132241e-05, 5.39157736e-02, 1.44860147e-02])
        b0_expected3 = np.array([0.02272211, 0.04544422])

        tol = 1e-4

        assert_near_equal(H02, H0_expected, tol)
        assert_near_equal(S02, S0_expected, tol)
        assert_near_equal(Cp02, Cp0_expected, tol)

        assert_near_equal(HJ2, HJ_expected, tol)
        assert_near_equal(SJ2, SJ_expected, tol)
        assert_near_equal(CpJ2, CpJ_expected, tol)
        assert_near_equal(b02, b0_expected, tol)

        assert_near_equal(H03, H0_expected3, tol)
        assert_near_equal(S03, S0_expected3, tol)
        assert_near_equal(Cp03, Cp0_expected3, tol)

        assert_near_equal(HJ3, HJ_expected3, tol)
        assert_near_equal(SJ3, SJ_expected3, tol)
        assert_near_equal(CpJ3, CpJ_expected3, tol)
        assert_near_equal(b03, b0_expected3, tol)