From 16f8145545695c20ccb11a9f1fa20a9f564ba30d Mon Sep 17 00:00:00 2001 From: Richard West Date: Thu, 12 Nov 2009 17:57:10 -0600 Subject: [PATCH] Tweaking cantera simulation advance code (shouldn't advance beyond end time) --- source/rmg/model.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/rmg/model.py b/source/rmg/model.py index 3d20791615..4e637063f1 100755 --- a/source/rmg/model.py +++ b/source/rmg/model.py @@ -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 @@ -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: @@ -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()