Skip to content

Commit

Permalink
[Python/1D] Detect invalid boundary conditions for flame configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jun 7, 2024
1 parent 1e70ba3 commit f937af3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions interfaces/cython/cantera/onedim.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,10 @@ def set_initial_guess(self, data=None, group=None):
u0o = mdoto / rho0o
T0o = self.oxidizer_inlet.T

if mdoto == mdotf == 0.0:
raise CanteraError("Mass flow for fuel and/or oxidizer "
"must be positive")

zst = 1 / (1 + self.gas.stoich_air_fuel_ratio(Yin_f, Yin_o, 'mass'))
Yst = zst * Yin_f + (1.0 - zst) * Yin_o

Expand Down Expand Up @@ -1348,6 +1352,10 @@ def set_initial_guess(self, equilibrate=True, data=None, group=None):
rhob = self.gas.density
ub = self.products.mdot / rhob

if uu == ub == 0.0:
raise CanteraError("Mass flow for reactants and/or products "
"must be positive")

locs = np.array([0.0, 0.4, 0.6, 1.0])
self.set_profile('T', locs, [Tu, Tu, Teq, Tb])
for k in range(self.gas.n_species):
Expand Down Expand Up @@ -1422,6 +1430,9 @@ def set_initial_guess(self, data=None, group=None):
if data:
return

if self.reactants.mdot == 0:
raise CanteraError("Reactants velocity must be positive")

Yu = self.reactants.Y
Tu = self.reactants.T
self.gas.TPY = Tu, self.flame.P, Yu
Expand Down
35 changes: 35 additions & 0 deletions test/python/test_onedim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,27 @@ def test_equivalence_ratio(self):
assert phi[0] == np.inf
assert np.isclose(phi[-1], 0.0)

def test_bad_boundary_conditions(self):
gas = ct.Solution("h2o2.yaml")
gas.TP = 300, ct.one_atm
sim = ct.CounterflowDiffusionFlame(gas, width=0.2)
sim.fuel_inlet.X = "H2: 1.0"

sim.oxidizer_inlet.X = "H2: 1.0, O2: 1.0"
sim.fuel_inlet.X = "O2: 1.0, N2: 3.76"
with pytest.raises(ct.CanteraError, match="Mass flow for fuel"):
sim.set_initial_guess()

sim.fuel_inlet.mdot = 1.0
sim.oxidizer_inlet.mdot = 1.0
with pytest.raises(ct.CanteraError, match="too much oxygen"):
sim.set_initial_guess()

sim.oxidizer_inlet.X = "O2: 1.0, N2: 3.76"
sim.fuel_inlet.X = "H2: 1.0"
sim.set_initial_guess()


class TestCounterflowPremixedFlame(utilities.CanteraTest):
# Note: to re-create the reference file:
# (1) set PYTHONPATH to build/python.
Expand Down Expand Up @@ -1262,6 +1283,14 @@ def test_restart(self):
self.assertNear(mdot[0], sim.reactants.mdot, 1e-4)
self.assertNear(mdot[-1], -sim.products.mdot, 1e-4)

def test_bad_boundary_conditions(self):
gas = ct.Solution("h2o2.yaml")
gas.TPX = 300, 0.05 * ct.one_atm, "H2:1.6, O2:1, AR:7"
sim = ct.CounterflowPremixedFlame(gas=gas, width=0.2)
with pytest.raises(ct.CanteraError, match="must be positive"):
sim.solve(loglevel=0)


class TestCounterflowPremixedFlameNonIdeal(utilities.CanteraTest):
# Note: to re-create the reference file:
# (1) set PYTHONPATH to build/python.
Expand Down Expand Up @@ -1700,6 +1729,12 @@ def run_save_restore(self, mode):

sim2.solve(loglevel=0)

def test_bad_boundary_conditions(self):
gas = ct.Solution("h2o2.yaml")
gas.TPX = 300, 0.05 * ct.one_atm, "H2:1.6, O2:1, AR:7"
sim = ct.CounterflowTwinPremixedFlame(gas=gas, width=0.2)
with pytest.raises(ct.CanteraError, match="must be positive"):
sim.solve(loglevel=0)

class TestIonFreeFlame(utilities.CanteraTest):
@utilities.slow_test
Expand Down

0 comments on commit f937af3

Please sign in to comment.