Skip to content

Commit

Permalink
addresses issue #615
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed May 10, 2019
1 parent fbe4ce5 commit 751afa3
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions interfaces/cython/cantera/onedim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,12 @@ cdef class Sim1D:
self.sim.solve(loglevel, <cbool>refine_grid)
return

def set_transport(multi):
self.gas.transport_model = multi
for dom in self.domains:
if isinstance(dom, _FlowBase):
dom.set_transport(self.gas)

have_user_tolerances = any(dom.have_user_tolerances for dom in self.domains)
if have_user_tolerances:
# Save the user-specified tolerances
Expand All @@ -894,16 +900,18 @@ cdef class Sim1D:

# Do initial steps without Soret diffusion
soret_doms = [dom for dom in self.domains if getattr(dom, 'soret_enabled', False)]
for dom in soret_doms:
dom.soret_enabled = False

def set_soret(soret):
for dom in soret_doms:
dom.soret_enabled = soret

set_soret(False)

# Do initial solution steps without multicomponent transport
transport = self.gas.transport_model
solve_multi = self.gas.transport_model == 'Multi'
if solve_multi:
self.gas.transport_model = 'Mix'
for dom in self.domains:
if isinstance(dom, _FlowBase):
dom.set_transport(self.gas)
set_transport('Mix')

def log(msg, *args):
if loglevel:
Expand Down Expand Up @@ -934,6 +942,11 @@ cdef class Sim1D:
except CanteraError as e:
log(str(e))
solved = False
except Exception as e:
# restore settings before re-raising exception
set_transport(transport)
set_soret(True)
raise e

# If initial solve using energy equation fails, fall back on the
# traditional fixed temperature solve followed by solving the energy
Expand All @@ -947,6 +960,11 @@ cdef class Sim1D:
except CanteraError as e:
log(str(e))
solved = False
except Exception as e:
# restore settings before re-raising exception
set_transport(transport)
set_soret(True)
raise e

if solved:
log('Solving on {} point grid with energy equation re-enabled', N)
Expand All @@ -957,6 +975,11 @@ cdef class Sim1D:
except CanteraError as e:
log(str(e))
solved = False
except Exception as e:
# restore settings before re-raising exception
set_transport(transport)
set_soret(True)
raise e

if solved and not self.extinct() and refine_grid:
# Found a non-extinct solution on the fixed grid
Expand All @@ -967,6 +990,11 @@ cdef class Sim1D:
except CanteraError as e:
log(str(e))
solved = False
except Exception as e:
# restore settings before re-raising exception
set_transport(transport)
set_soret(True)
raise e

if solved and not self.extinct():
# Found a non-extinct solution on the refined grid
Expand All @@ -983,15 +1011,11 @@ cdef class Sim1D:

if solve_multi:
log('Solving with multicomponent transport')
self.gas.transport_model = 'Multi'
for dom in self.domains:
if isinstance(dom, _FlowBase):
dom.set_transport(self.gas)
set_transport('Multi')

if soret_doms:
log('Solving with Soret diffusion')
for dom in soret_doms:
dom.soret_enabled = True
set_soret(True)

if have_user_tolerances:
log('Solving with user-specifed tolerances')
Expand All @@ -1005,7 +1029,6 @@ cdef class Sim1D:
if have_user_tolerances or solve_multi or soret_doms:
self.sim.solve(loglevel, <cbool>refine_grid)


def refine(self, loglevel=1):
"""
Refine the grid, adding points where solution is not adequately
Expand Down

0 comments on commit 751afa3

Please sign in to comment.