Skip to content

Commit

Permalink
Tweaking cantera simulation advance code (shouldn't advance beyond en…
Browse files Browse the repository at this point in the history
…d time)
  • Loading branch information
rwest committed Nov 12, 2009
1 parent 540ded4 commit 16f8145
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions source/rmg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,8 @@ def simulate(self, model):
P = gas.pressure()
V = sim.reactors()[0].volume()
T = gas.temperature()
# recall that Cantera returns molarDensity() in units of kmol/m3
# and this program thinks in mol/m3
# Note that, for molar density, Cantera thinks in kmol/m^3, while
# RMG thinks in mol/m^3
Ni = gas.molarDensity()*1000.0 * gas.moleFractions() * V
y = [P, V, T]; y.extend(Ni)
Ni0 = Ni
Expand All @@ -920,11 +920,13 @@ def simulate(self, model):
first_step = False # don't integrate on first time through, just do the validity checking and result reporting
else:
# Uses a fixed (on a log scale) time step
nexttime = time*1.2589254117941673
nexttime = min(endtime,time*1.2589254117941673)
try:
# advance cantera one step, or two if the first didn't get there
if sim.step(endtime) < endtime:
# advance cantera one step
if sim.step(endtime) < endtime:
# didn't get to endtime, so take another step
if sim.step(endtime) < nexttime:
# still didn't get to endtime, so advance to nextime
sim.advance(nexttime)
# # Uses the same time steps that the Cantera solver used
# try:
Expand All @@ -933,7 +935,7 @@ def simulate(self, model):
logging.exception("Ignoring Cantera error")
logging.debug(e.message)
pass

# Get state at current time
time = sim.time()
P = gas.pressure()
Expand Down

0 comments on commit 16f8145

Please sign in to comment.