[Cython/1D] Modify the auto solver so the minimal code is in the try block.

This ensures we only catch an error from a single solve call so it is handled properly.
This commit is contained in:
Bryan W. Weber 2016-11-10 19:32:28 -05:00 committed by Bryan W. Weber
parent c91bdee2e2
commit 3fd46f7a1f

View file

@ -847,30 +847,38 @@ cdef class Sim1D:
self.set_initial_guess(*self._initial_guess_args,
**self._initial_guess_kwargs)
# Try solving with energy enabled, which usually works
log('Solving on {} point grid with energy equation enabled', N)
self.energy_enabled = True
try:
# Try solving with energy enabled, which usually works
log('Solving on {} point grid with energy equation enabled', N)
self.energy_enabled = True
self.sim.solve(loglevel, <cbool>False)
solved = True
except CanteraError as e:
log(str(e))
solved = False
# If initial solve using energy equation fails, fall back on the
# traditional fixed temperature solve followed by solving the energy
# equation
if not solved:
# If initial solve using energy equation fails, fall back on the
# traditional fixed temperature solve followed by solving the energy
# equation
log('Initial solve failed; Retrying with energy equation disabled')
self.energy_enabled = False
try:
self.energy_enabled = False
self.sim.solve(loglevel, <cbool>False)
log('Solving on {} point grid with energy equation re-enabled', N)
self.energy_enabled = True
self.sim.solve(loglevel, <cbool>False)
solved = True
except CanteraError as e:
log(str(e))
solved = False
if solved:
log('Solving on {} point grid with energy equation re-enabled', N)
self.energy_enabled = True
try:
self.sim.solve(loglevel, <cbool>False)
solved = True
except CanteraError as e:
log(str(e))
solved = False
if solved and not self.extinct():
# Found a non-extinct solution on the fixed grid