From 557078229f1ddbb251877c28eab5551ae9fae75b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 7 Mar 2013 18:51:31 +0000 Subject: [PATCH] [1D] Save and restore solver tolerances --- interfaces/cython/cantera/test/test_onedim.py | 9 ++++-- src/oneD/Domain1D.cpp | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 9e68e0841..43088b50f 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -215,11 +215,14 @@ class TestFreeFlame(utilities.CanteraTest): # Create flame object with dummy initial grid self.sim = ct.FreeFlame(self.gas) - self.sim.flame.set_steady_tolerances(default=self.tol_ss) - self.sim.flame.set_transient_tolerances(default=self.tol_ts) - self.sim.restore(filename, 'test', loglevel=0) + # Sim is initially in "steady-state" mode, so this returns the + # steady-state tolerances + rtol, atol = self.sim.flame.tolerances('T') + self.assertNear(rtol, self.tol_ss[0]) + self.assertNear(atol, self.tol_ss[1]) + P2a = self.sim.P self.assertNear(p, P1) diff --git a/src/oneD/Domain1D.cpp b/src/oneD/Domain1D.cpp index b3da6b2ab..585488a0d 100644 --- a/src/oneD/Domain1D.cpp +++ b/src/oneD/Domain1D.cpp @@ -4,10 +4,12 @@ */ #include "cantera/oneD/Domain1D.h" + #include "cantera/base/ctml.h" #include using namespace std; +using namespace ctml; namespace Cantera { @@ -128,11 +130,39 @@ XML_Node& Domain1D::save(XML_Node& o, const doublereal* const sol) d.addAttribute("points", nPoints()); d.addAttribute("components", nComponents()); d.addAttribute("id", id()); + addFloatArray(d, "abstol_transient", nComponents(), &m_atol_ts[0]); + addFloatArray(d, "reltol_transient", nComponents(), &m_rtol_ts[0]); + addFloatArray(d, "abstol_steady", nComponents(), &m_atol_ss[0]); + addFloatArray(d, "reltol_steady", nComponents(), &m_rtol_ss[0]); return d; } void Domain1D::restore(const XML_Node& dom, doublereal* soln, int loglevel) { + vector_fp values; + vector nodes; + dom.getChildren("floatArray", nodes); + for (size_t i = 0; i < nodes.size(); i++) { + string title = nodes[i]->attrib("title"); + getFloatArray(*nodes[i], values, false); + if (values.size() != nComponents()) { + throw CanteraError("Domain1D::restore", "Got an array of length " + + int2str(values.size()) + " when one of length " + + int2str(nComponents()) + "was expected."); + } + if (title == "abstol_transient") { + m_atol_ts = values; + } else if (title == "reltol_transient") { + m_rtol_ts = values; + } else if (title == "abstol_steady") { + m_atol_ss = values; + } else if (title == "reltol_steady") { + m_rtol_ss = values; + } else { + throw CanteraError("Domain1D::restore", + "Got an unexpected array, '" + title + "'"); + } + } } // called to set up initial grid, and after grid refinement