Exemple #1
0
def run(num_procs):
    from spitfire.chemistry.mechanism import ChemicalMechanismSpec
    from spitfire.chemistry.tabulation import build_nonadiabatic_defect_steady_slfm_library
    import spitfire.chemistry.analysis as sca
    import numpy as np

    test_xml = abspath(join('tests', 'test_mechanisms', 'h2-burke.xml'))
    m = ChemicalMechanismSpec(cantera_xml=test_xml, group_name='h2-burke')
    pressure = 101325.
    air = m.stream(stp_air=True)
    air.TP = 1200., pressure
    fuel = m.stream('TPY', (300., pressure, 'H2:1'))

    flamelet_specs = {
        'mech_spec': m,
        'oxy_stream': air,
        'fuel_stream': fuel,
        'grid_points': 34
    }

    l = build_nonadiabatic_defect_steady_slfm_library(
        flamelet_specs,
        verbose=False,
        diss_rate_values=np.logspace(0, 1, 4),
        integration_args={'transient_tolerance': 1e-10},
        num_procs=num_procs)
    l = sca.compute_specific_enthalpy(m, l)
    l = sca.compute_isochoric_specific_heat(m, l)
    l = sca.compute_isobaric_specific_heat(m, l)
    l = sca.compute_density(m, l)
    l = sca.compute_pressure(m, l)
    l = sca.compute_viscosity(m, l)

    return l
Exemple #2
0
def run():
    from spitfire.chemistry.mechanism import ChemicalMechanismSpec
    from spitfire.chemistry.tabulation import build_adiabatic_eq_library, apply_mixing_model, PDFSpec
    import spitfire.chemistry.analysis as sca

    test_xml = abspath(join('tests', 'test_mechanisms', 'h2-burke.xml'))
    m = ChemicalMechanismSpec(cantera_xml=test_xml, group_name='h2-burke')
    pressure = 101325.
    air = m.stream(stp_air=True)
    air.TP = 1200., pressure
    fuel = m.stream('TPY', (300., pressure, 'H2:1'))

    flamelet_specs = {
        'mech_spec': m,
        'oxy_stream': air,
        'fuel_stream': fuel,
        'grid_points': 34
    }

    l = build_adiabatic_eq_library(flamelet_specs, verbose=False)
    l = sca.compute_specific_enthalpy(m, l)
    l = sca.compute_isochoric_specific_heat(m, l)
    l = sca.compute_isobaric_specific_heat(m, l)
    l = sca.compute_density(m, l)
    l = sca.compute_pressure(m, l)
    l = sca.compute_viscosity(m, l)
    scaled_variance_values = np.linspace(0., 1., 5)
    l_t = apply_mixing_model(l, {
        'mixture_fraction':
        PDFSpec(pdf='ClipGauss', scaled_variance_values=scaled_variance_values)
    },
                             num_procs=1)
    return l_t
Exemple #3
0
def run():
    from spitfire.chemistry.mechanism import ChemicalMechanismSpec
    from spitfire.chemistry.reactors import HomogeneousReactor
    import numpy as np

    xml = abspath(join('tests', 'test_mechanisms', 'h2-burke.xml'))
    mechanism = ChemicalMechanismSpec(cantera_xml=xml, group_name='h2-burke')

    air = mechanism.stream(stp_air=True)
    fuel = mechanism.stream('X', 'H2:1')

    mix = mechanism.mix_for_equivalence_ratio(1.0, fuel, air)
    mix.TP = 1200., 101325.

    reactor_dict = {
        'cp, adiabatic':
        HomogeneousReactor(mechanism, mix, 'isobaric', 'adiabatic', 'closed'),
        'cp, isothermal':
        HomogeneousReactor(mechanism, mix, 'isobaric', 'isothermal', 'closed'),
        'cv, adiabatic':
        HomogeneousReactor(mechanism, mix, 'isochoric', 'adiabatic', 'closed'),
        'cv, isothermal':
        HomogeneousReactor(mechanism, mix, 'isochoric', 'isothermal', 'closed')
    }

    sol_dict = dict()
    for r in reactor_dict:
        output = reactor_dict[r].integrate_to_steady()
        Y = np.array([
            output['mass fraction ' + s].copy()
            for s in mechanism.species_names
        ])
        sol_dict[r] = (output.time_values.copy(), output['temperature'], Y)

    return sol_dict
Exemple #4
0
def run():
    from spitfire.chemistry.mechanism import ChemicalMechanismSpec
    from spitfire.chemistry.tabulation import build_unreacted_library
    import spitfire.chemistry.analysis as sca

    test_xml = abspath(join('tests', 'test_mechanisms', 'h2-burke.xml'))
    m = ChemicalMechanismSpec(cantera_xml=test_xml, group_name='h2-burke')
    pressure = 101325.
    air = m.stream(stp_air=True)
    air.TP = 1200., pressure
    fuel = m.stream('TPY', (300., pressure, 'H2:1'))

    flamelet_specs = {
        'mech_spec': m,
        'oxy_stream': air,
        'fuel_stream': fuel,
        'grid_points': 34
    }

    l = build_unreacted_library(flamelet_specs, verbose=False)
    l = sca.compute_specific_enthalpy(m, l)
    l = sca.compute_isochoric_specific_heat(m, l)
    l = sca.compute_isobaric_specific_heat(m, l)
    l = sca.compute_density(m, l)
    l = sca.compute_pressure(m, l)
    l = sca.compute_viscosity(m, l)

    return l
Exemple #5
0
            def test(self):
                gas = ct.Solution('h2o2.yaml', transport_model='Multi')
                mech = ChemicalMechanismSpec.from_solution(gas)

                fs = FlameletSpec(mech_spec=mech,
                                  initial_condition='equilibrium',
                                  oxy_stream=mech.stream('TPX', (300, 1.e5, 'O2:1, N2:3.76')),
                                  fuel_stream=mech.stream('TPY', (300, 1.e5, 'H2:1')),
                                  grid_points=16)
                eq_lib1 = build_adiabatic_eq_library(fs, verbose=False)

                z_dim = Dimension(eq_lib1.mixture_fraction_name, eq_lib1.mixture_fraction_values)
                fuel_T_dim = Dimension('fuel_temperature', np.linspace(0.0, 1.0, 4))
                air_T_dim = Dimension('air_temperature', np.linspace(0.0, 1.0, 3))

                eq_lib2 = Library(z_dim, fuel_T_dim)
                eq_lib2T = Library(fuel_T_dim, z_dim)
                eq_lib3 = Library(z_dim, fuel_T_dim, air_T_dim)
                eq_lib3T1 = Library(fuel_T_dim, z_dim, air_T_dim)
                eq_lib3T2 = Library(fuel_T_dim, air_T_dim, z_dim)

                for p in eq_lib1.props:
                    eq_lib2[p] = eq_lib2.get_empty_dataset()
                    eq_lib2T[p] = eq_lib2T.get_empty_dataset()
                    eq_lib3[p] = eq_lib3.get_empty_dataset()
                    eq_lib3T1[p] = eq_lib3T1.get_empty_dataset()
                    eq_lib3T2[p] = eq_lib3T2.get_empty_dataset()

                for i, fuel_T_offset in enumerate(fuel_T_dim.values):
                    fuel_T = 300 + fuel_T_offset * 500.
                    fs2 = copy(fs)
                    fs2.fuel_stream.TP = fuel_T, 1.e5

                    eq_tmp = build_adiabatic_eq_library(fs2, verbose=False)
                    for p in eq_lib1.props:
                        eq_lib2[p][:, i] = eq_tmp[p]
                        eq_lib2T[p][i, :] = eq_tmp[p]

                    for j, air_T_offset in enumerate(air_T_dim.values):
                        air_T = 300 + air_T_offset * 500.
                        fs3 = copy(fs2)
                        fs3.oxy_stream.TP = air_T, 1.e5

                        eq_tmp = build_adiabatic_eq_library(fs3, verbose=False)
                        for p in eq_lib1.props:
                            eq_lib3[p][:, i, j] = eq_tmp[p]
                            eq_lib3T1[p][i, :, j] = eq_tmp[p]
                            eq_lib3T2[p][i, j, :] = eq_tmp[p]

                nonT_props = list(eq_lib1.props)
                nonT_props.remove('temperature')
                eq_lib1.remove(*nonT_props)
                eq_lib2.remove(*nonT_props)
                eq_lib2T.remove(*nonT_props)
                eq_lib3.remove(*nonT_props)
                eq_lib3T1.remove(*nonT_props)
                eq_lib3T2.remove(*nonT_props)

                z_svv = np.linspace(0., 1., 6)
                Tf_svv = np.linspace(0., 1., 5)

                eq_lib1_t = apply_presumed_PDF_model(eq_lib1, 'ClipGauss', z_svv, verbose=False)
                eq_lib2_t = apply_presumed_PDF_model(eq_lib2, 'ClipGauss', z_svv, verbose=False)
                eq_lib3_t = apply_presumed_PDF_model(eq_lib3, 'ClipGauss', z_svv, num_procs=1, verbose=False)
                eq_lib2T_t = apply_presumed_PDF_model(eq_lib2T, 'ClipGauss', z_svv, verbose=False)
                eq_lib3T1_t = apply_presumed_PDF_model(eq_lib3T1, 'ClipGauss', z_svv, num_procs=1, verbose=False)
                eq_lib3T2_t = apply_presumed_PDF_model(eq_lib3T2, 'ClipGauss', z_svv, num_procs=1, verbose=False)
                eq_lib2_tt = apply_presumed_PDF_model(eq_lib2_t, 'Beta', Tf_svv,
                                                      'fuel_temperature_mean', '', 'Tfvar', num_procs=1, verbose=False)
                eq_lib3_tt = apply_presumed_PDF_model(eq_lib3_t, 'Beta', Tf_svv,
                                                      'fuel_temperature_mean', '', 'Tfvar', num_procs=1, verbose=False)

                def get_dim_names(lib):
                    return [d.name for d in lib.dims]

                self.assertEqual(['mixture_fraction'], get_dim_names(eq_lib1))
                self.assertEqual(['mixture_fraction_mean', 'scaled_scalar_variance_mean'], get_dim_names(eq_lib1_t))
                self.assertEqual(['mixture_fraction', 'fuel_temperature'], get_dim_names(eq_lib2))
                self.assertEqual(['mixture_fraction_mean', 'fuel_temperature_mean', 'scaled_scalar_variance_mean'],
                                 get_dim_names(eq_lib2_t))
                self.assertEqual(
                    ['mixture_fraction_mean', 'fuel_temperature_mean', 'scaled_scalar_variance_mean', 'Tfvar'],
                    get_dim_names(eq_lib2_tt))
                self.assertEqual(['mixture_fraction', 'fuel_temperature', 'air_temperature'],
                                 get_dim_names(eq_lib3))
                self.assertEqual(['mixture_fraction_mean', 'fuel_temperature_mean', 'air_temperature_mean',
                                  'scaled_scalar_variance_mean'],
                                 get_dim_names(eq_lib3_t))
                self.assertEqual(['mixture_fraction_mean', 'fuel_temperature_mean', 'air_temperature_mean',
                                  'scaled_scalar_variance_mean', 'Tfvar'],
                                 get_dim_names(eq_lib3_tt))

                self.assertEqual(['fuel_temperature', 'mixture_fraction'], get_dim_names(eq_lib2T))
                self.assertEqual(['fuel_temperature_mean', 'mixture_fraction_mean', 'scaled_scalar_variance_mean'],
                                 get_dim_names(eq_lib2T_t), eq_lib2T_t)

                self.assertEqual(['fuel_temperature', 'mixture_fraction', 'air_temperature'],
                                 get_dim_names(eq_lib3T1))
                self.assertEqual(['fuel_temperature', 'air_temperature', 'mixture_fraction'],
                                 get_dim_names(eq_lib3T2))
                self.assertEqual(['fuel_temperature_mean', 'mixture_fraction_mean', 'air_temperature_mean',
                                  'scaled_scalar_variance_mean'],
                                 get_dim_names(eq_lib3T1_t))
                self.assertEqual(['fuel_temperature_mean', 'air_temperature_mean', 'mixture_fraction_mean',
                                  'scaled_scalar_variance_mean'],
                                 get_dim_names(eq_lib3T2_t))

                self.assertFalse(np.any(np.isnan(eq_lib1['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib1_t['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib2['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib2T['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib2_t['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib2T_t['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3T1['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3T2['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3_t['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3_tt['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3T1_t['temperature'])))
                self.assertFalse(np.any(np.isnan(eq_lib3T2_t['temperature'])))

                self.assertIsNone(assert_allclose(eq_lib2T['temperature'].T, eq_lib2['temperature']))
                self.assertIsNone(assert_allclose(np.swapaxes(eq_lib3T1['temperature'], 0, 1),
                                                  eq_lib3['temperature']))
                self.assertIsNone(assert_allclose(np.swapaxes(np.swapaxes(eq_lib3T2['temperature'], 1, 2), 0, 1),
                                                  eq_lib3['temperature']))

                self.assertIsNone(assert_allclose(np.squeeze(eq_lib1_t['temperature'][:, 0]),
                                                  eq_lib1['temperature']))
                self.assertIsNone(assert_allclose(np.squeeze(eq_lib2_t['temperature'][:, :, 0]),
                                                  eq_lib2['temperature']))
                self.assertIsNone(assert_allclose(np.squeeze(eq_lib3_t['temperature'][:, :, :, 0]),
                                                  eq_lib3['temperature']))
                self.assertIsNone(assert_allclose(np.squeeze(eq_lib3_tt['temperature'][:, :, :, 0, 0]),
                                                  eq_lib3['temperature']))
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import numpy as np
from spitfire.chemistry.flamelet import Flamelet
from spitfire.chemistry.mechanism import ChemicalMechanismSpec

m = ChemicalMechanismSpec(
    cantera_xml='heptane-liu-hewson-chen-pitsch-highT.xml', group_name='gas')
pressure = 101325.
air = m.stream(stp_air=True)
air.TP = 298., pressure
fuel = m.stream('TPY', (488., pressure, 'NXC7H16:1'))

flamelet_specs = {
    'mech_spec': m,
    'pressure': pressure,
    'oxy_stream': air,
    'fuel_stream': fuel
}


def get_data(cpoint, ccoeff, npts):
    z, dz = Flamelet._clustered_grid(npts, cpoint, ccoeff)
    dz = np.hstack([dz, 1. - z[-2]])
    return z, 1. / dz


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
Exemple #7
0
t_list = np.load('ip_times.npy')
solution_list = np.load('ip_solutions.npy')
# t_list = np.load('t_sg_eg_54.npy')
# solution_list = np.load('q_sg_eg_54.npy')

Tmin = 200.
Tmax = int(np.max(solution_list) // 100 + 1) * 100

nt = t_list.size

ndof = solution_list.size // nt
nq = ndof // nx // ny

# m = ChemicalMechanismSpec(cantera_xml='ethylene-luo.xml', group_name='ethylene-luo')
# m = ChemicalMechanismSpec(cantera_xml='coh2-hawkes.xml', group_name='coh2-hawkes')
m = ChemicalMechanismSpec(cantera_xml='heptane-liu-hewson-chen-pitsch-highT.xml', group_name='gas')

variable = 'T'

pressure = 101325.
air = m.stream(stp_air=True)
air.TP = 300., pressure
# sg = m.stream('X', 'H2:1, CO:2')
sg = m.stream('X', 'H2:1, CO:1, CH4:1, CO2:1')
fuel2 = m.copy_stream(sg)
# fuel2.TP = 300., pressure
fuel2.TP = 400., pressure
# c2h4 = m.stream('X', 'C2H4:1')
eg = m.stream('X', 'CO2:1, H2O:1, CO:0.5, H2:0.001')
c7 = m.stream('X', 'NXC7H16:1')
# fuel1 = m.copy_stream(eg)
Exemple #8
0
from spitfire.chemistry.flamelet import Flamelet
from spitfire.chemistry.mechanism import ChemicalMechanismSpec
from spitfire.time.integrator import Governor, NumberOfTimeSteps, FinalTime, Steady, SaveAllDataToList
from spitfire.time.methods import AdaptiveERK54CashKarp, ESDIRK64, BackwardEulerWithError
from spitfire.time.nonlinear import SimpleNewtonSolver
from spitfire.time.stepcontrol import PIController
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d as a3
from scipy.interpolate import RectBivariateSpline

# m = ChemicalMechanismSpec(cantera_xml='methane-lu30.xml', group_name='methane-lu30')
# m = ChemicalMechanismSpec(cantera_xml='h2-burke.xml', group_name='h2-burke')
# m = ChemicalMechanismSpec(cantera_xml='coh2-hawkes.xml', group_name='coh2-hawkes')
m = ChemicalMechanismSpec(
    cantera_xml='heptane-liu-hewson-chen-pitsch-highT.xml', group_name='gas')
# m = ChemicalMechanismSpec(cantera_xml='dme-bhagatwala.xml', group_name='dme-bhagatwala')
# m = ChemicalMechanismSpec(cantera_xml='ethylene-luo.xml', group_name='ethylene-luo')
pressure = 101325.

print(m.n_species, m.n_reactions)

air = m.stream(stp_air=True)
air.TP = 300., pressure
n2 = m.stream('X', 'N2:1')
c7 = m.stream('X', 'NXC7H16:1')
# dme = m.stream('X', 'CH3OCH3:1')
# ch4 = m.stream('X', 'CH4:1')
# sg = m.stream('X', 'H2:1, CO:2')
sg = m.stream('X', 'H2:1, CO:1, CH4:1, CO2:1')
# eg = m.stream('X', 'CO2:1, H2O:1, CO:0.5, H2:0.001')
Exemple #9
0
from spitfire.chemistry.flamelet2d import _Flamelet2D
from spitfire.chemistry.flamelet import Flamelet
from spitfire.chemistry.mechanism import ChemicalMechanismSpec
from spitfire.time.integrator import Governor, NumberOfTimeSteps, FinalTime, Steady, SaveAllDataToList
from spitfire.time.methods import AdaptiveERK54CashKarp, ESDIRK64, BackwardEulerWithError
from spitfire.time.nonlinear import SimpleNewtonSolver
from spitfire.time.stepcontrol import PIController
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize

m = ChemicalMechanismSpec(cantera_xml='coh2-hawkes.xml',
                          group_name='coh2-hawkes')
print(m.n_species, m.n_reactions)

pressure = 101325.

air = m.stream(stp_air=True)
air.TP = 300., pressure
synthesis_gas = m.stream('X', 'H2:1, CO:1')
exhaust_gas = m.stream('X', 'CO2:1, H2O:1, CO:0.5, H2:0.001')

fuel1 = m.copy_stream(synthesis_gas)
fuel1.TP = 1000., pressure
fuel2 = m.copy_stream(exhaust_gas)
fuel2.TP = 400., pressure

fuel1_name = 'SG'
fuel2_name = 'EG'

x_cp = m.stoich_mixture_fraction(fuel2, air)
Exemple #10
0
            def test(self):
                test_xml = abspath(join('tests', 'test_mechanisms', 'h2-burke.xml'))
                m = ChemicalMechanismSpec(cantera_xml=test_xml, group_name='h2-burke')
                pressure = 101325.
                air = m.stream(stp_air=True)
                air.TP = 300., pressure
                fuel = m.stream('TPY', (300., pressure, 'H2:1'))

                flamelet_specs = {'mech_spec': m, 'oxy_stream': air, 'fuel_stream': fuel, 'grid_points': 34}

                slfm = build_adiabatic_slfm_library(flamelet_specs,
                                                    diss_rate_values=np.logspace(-1, 4, 40),
                                                    diss_rate_ref='stoichiometric',
                                                    include_extinguished=True,
                                                    verbose=False)

                class LogMean1ParamPDF:
                    def __init__(self, sigma):
                        self._sigma = sigma
                        self._mu = 0.
                        self._s2pi = np.sqrt(2. * np.pi)
                        self._xt = np.logspace(-6, 6, 1000)
                        self._pdft = np.zeros_like(self._xt)

                    def get_pdf(self, x):
                        s = self._sigma
                        m = self._mu
                        return 1. / (x * s * self._s2pi) * np.exp(-(np.log(x) - m) * (np.log(x) - m) / (2. * s * s))

                    def set_mean(self, mean):
                        self._mu = np.log(mean) - 0.5 * self._sigma * self._sigma
                        self._pdft = self.get_pdf(self._xt)

                    def set_variance(self, variance):
                        pass

                    def set_scaled_variance(self, variance):
                        raise ValueError(
                            'cannot use set_scaled_variance on LogMean1ParamPDF, use direct variance values')

                    def integrate(self, interpolant):
                        ig = interpolant(self._xt) * self._pdft
                        return simpson(ig, x=self._xt)

                lm_pdf = LogMean1ParamPDF(1.0)

                mass_fracs = slfm.props
                mass_fracs.remove('temperature')
                slfm.remove(*mass_fracs)

                slfm_l = apply_mixing_model(
                    slfm,
                    mixing_spec={}
                )

                slfm_t = apply_mixing_model(
                    slfm,
                    mixing_spec={'dissipation_rate_stoich': PDFSpec(pdf=lm_pdf, variance_values=np.array([1.]))}
                )

                slfm_t2 = apply_mixing_model(
                    slfm,
                    mixing_spec={'dissipation_rate_stoich': PDFSpec(pdf=lm_pdf, variance_values=np.array([1.])),
                                 'mixture_fraction': 'delta'}
                )

                slfm_t3 = apply_mixing_model(
                    slfm,
                    mixing_spec={'dissipation_rate_stoich': PDFSpec(pdf=lm_pdf, variance_values=np.array([1.])),
                                 'mixture_fraction': PDFSpec(pdf='delta')}
                )

                slfm_t4 = apply_mixing_model(
                    slfm,
                    mixing_spec={'dissipation_rate_stoich': 'delta',
                                 'mixture_fraction': PDFSpec(pdf='delta')},
                    added_suffix='_avg'
                )

                slfm_tt1 = apply_mixing_model(
                    slfm_t,
                    mixing_spec={
                        'mixture_fraction_mean': PDFSpec(pdf='ClipGauss', scaled_variance_values=np.linspace(0, 1, 8))},
                    added_suffix=''
                )

                slfm_tt2 = apply_mixing_model(
                    slfm,
                    mixing_spec={'dissipation_rate_stoich': PDFSpec(pdf=lm_pdf, variance_values=np.array([1.])),
                                 'mixture_fraction': PDFSpec(pdf='ClipGauss',
                                                             scaled_variance_values=np.linspace(0, 1, 8))}
                )