diff --git a/interfaces/cython/cantera/examples/onedim/diffusion_flame.py b/interfaces/cython/cantera/examples/onedim/diffusion_flame.py index 47d5e14c5..303ec013a 100644 --- a/interfaces/cython/cantera/examples/onedim/diffusion_flame.py +++ b/interfaces/cython/cantera/examples/onedim/diffusion_flame.py @@ -49,12 +49,6 @@ f.oxidizer_inlet.T = tin_o f.flame.set_steady_tolerances(default=tol_ss) f.flame.set_transient_tolerances(default=tol_ts) -# construct the initial solution estimate. To do so, it is necessary -# to specify the fuel species. If a fuel mixture is being used, -# specify a representative species here for the purpose of -# constructing an initial guess. -f.set_initial_guess(fuel='C2H6') - # Set the boundary emissivities f.set_boundary_emissivities(0.0, 0.0) # Turn radiation off diff --git a/interfaces/cython/cantera/examples/onedim/diffusion_flame_batch.py b/interfaces/cython/cantera/examples/onedim/diffusion_flame_batch.py index b443ffe6b..f4c364ba2 100644 --- a/interfaces/cython/cantera/examples/onedim/diffusion_flame_batch.py +++ b/interfaces/cython/cantera/examples/onedim/diffusion_flame_batch.py @@ -70,7 +70,6 @@ def interrupt_extinction(t): f.set_interrupt(interrupt_extinction) # Initialize and solve -f.set_initial_guess(fuel='H2') print('Creating the initial solution') f.solve(loglevel=0, refine_grid=refine) diff --git a/interfaces/cython/cantera/examples/onedim/diffusion_flame_extinction.py b/interfaces/cython/cantera/examples/onedim/diffusion_flame_extinction.py index f27b96037..4707eaabe 100644 --- a/interfaces/cython/cantera/examples/onedim/diffusion_flame_extinction.py +++ b/interfaces/cython/cantera/examples/onedim/diffusion_flame_extinction.py @@ -59,7 +59,6 @@ f.set_grid_min(1e-20) temperature_limit_extinction = 500 # K # Initialize and solve -f.set_initial_guess(fuel='H2') print('Creating the initial solution') f.solve(loglevel=0, refine_grid=refine) diff --git a/interfaces/cython/cantera/onedim.py b/interfaces/cython/cantera/onedim.py index 31ddcdf5c..9674edb63 100644 --- a/interfaces/cython/cantera/onedim.py +++ b/interfaces/cython/cantera/onedim.py @@ -494,59 +494,49 @@ class CounterflowDiffusionFlame(FlameBase): super(CounterflowDiffusionFlame, self).__init__( (self.fuel_inlet, self.flame, self.oxidizer_inlet), gas, grid) - def set_initial_guess(self, fuel, oxidizer=None, stoich=None): + def set_initial_guess(self, fuel=None, oxidizer=None, stoich=None): """ - Set the initial guess for the solution. The fuel species must be - specified: - - >>> f.set_initial_guess(fuel='CH4') - - The oxidizer and corresponding stoichiometry must be specified if it - is not 'O2'. The initial guess is generated by assuming infinitely- - fast chemistry. + Set the initial guess for the solution. The initial guess is generated + by assuming infinitely-fast chemistry. """ + if fuel is not None or oxidizer is not None or stoich is not None: + warnings.warn( + 'Arguments to CounterflowDiffusionFlame.set_initial_guess are ' + 'unused and deprecated and will be removed after Cantera 2.3.') super(CounterflowDiffusionFlame, self).set_initial_guess() - if stoich is None: - if oxidizer is None: - if 'O2' in self.gas.species_names: - oxidizer = 'O2' - elif 'o2' in self.gas.species_names: - oxidizer = 'o2' - else: - raise Exception("Can't identify default oxidizer species.") - if oxidizer.upper() == 'O2': - stoich = 0.0 - if 'H' in self.gas.element_names: - stoich += 0.25 * self.gas.n_atoms(fuel, 'H') - if 'C' in self.gas.element_names: - stoich += self.gas.n_atoms(fuel, 'C') - else: - raise Exception('oxidizer/fuel stoichiometric ratio must be ' - 'specified since the oxidizer is not O2') - - kFuel = self.gas.species_index(fuel) - kOx = self.gas.species_index(oxidizer) - - s = stoich * self.gas.molecular_weights[kOx] / self.gas.molecular_weights[kFuel] - phi = s * self.fuel_inlet.Y[kFuel] / self.oxidizer_inlet.Y[kOx] - zst = 1.0 / (1.0 + phi) + moles = lambda el: (self.gas.elemental_mass_fraction(el) / + self.gas.atomic_weight(el)) + # Compute stoichiometric mixture composition Yin_f = self.fuel_inlet.Y - Yin_o = self.oxidizer_inlet.Y - Yst = zst * Yin_f + (1.0 - zst) * Yin_o - self.gas.TPY = self.fuel_inlet.T, self.P, Yin_f mdotf = self.fuel_inlet.mdot u0f = mdotf / self.gas.density T0f = self.fuel_inlet.T + sFuel = moles('O') + if 'C' in self.gas.element_names: + sFuel -= 2 * moles('C') + if 'H' in self.gas.element_names: + sFuel -= 0.5 * moles('H') + + Yin_o = self.oxidizer_inlet.Y self.gas.TPY = self.oxidizer_inlet.T, self.P, Yin_o mdoto = self.oxidizer_inlet.mdot - u0o = mdoto/self.gas.density + u0o = mdoto / self.gas.density T0o = self.oxidizer_inlet.T + sOx = moles('O') + if 'C' in self.gas.element_names: + sOx -= 2 * moles('C') + if 'H' in self.gas.element_names: + sOx -= 0.5 * moles('H') + + zst = 1.0 / (1 - sFuel / sOx) + Yst = zst * Yin_f + (1.0 - zst) * Yin_o + # get adiabatic flame temperature and composition Tbar = 0.5 * (T0f + T0o) self.gas.TPY = Tbar, self.P, Yst @@ -558,6 +548,8 @@ class CounterflowDiffusionFlame(FlameBase): zz = self.flame.grid dz = zz[-1] - zz[0] a = (u0o + u0f)/dz + kOx = (self.gas.species_index('O2') if 'O2' in self.gas.species_names else + self.gas.species_index('o2')) f = np.sqrt(a / (2.0 * self.gas.mix_diff_coeffs[kOx])) x0 = mdotf * dz / (mdotf + mdoto) diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 6480cdfc9..a86103a15 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -412,7 +412,7 @@ class TestDiffusionFlame(utilities.CanteraTest): self.sim.oxidizer_inlet.X = oxidizer self.sim.oxidizer_inlet.T = T_ox - self.sim.set_initial_guess(fuel='H2') + self.sim.set_initial_guess() def solve_fixed_T(self): # Solve with the energy equation disabled