[1D] Save and restore solver tolerances
This commit is contained in:
parent
d20476df8e
commit
557078229f
2 changed files with 36 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@
|
|||
*/
|
||||
|
||||
#include "cantera/oneD/Domain1D.h"
|
||||
#include "cantera/base/ctml.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
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<XML_Node*> 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue