diff --git a/include/cantera/oneD/Domain1D.h b/include/cantera/oneD/Domain1D.h index ddcc63b06..c5a4ab4c2 100644 --- a/include/cantera/oneD/Domain1D.h +++ b/include/cantera/oneD/Domain1D.h @@ -530,7 +530,7 @@ public: virtual void showSolution_s(std::ostream& s, const doublereal* x) {} virtual void showSolution(const doublereal* x); - virtual void restore(const XML_Node& dom, doublereal* soln) {} + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel) {} doublereal z(size_t jlocal) const { return m_z[jlocal]; diff --git a/include/cantera/oneD/Inlet1D.h b/include/cantera/oneD/Inlet1D.h index e85ad4cce..357f3e771 100644 --- a/include/cantera/oneD/Inlet1D.h +++ b/include/cantera/oneD/Inlet1D.h @@ -183,7 +183,7 @@ public: virtual void eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); protected: @@ -218,7 +218,7 @@ public: integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); virtual void _finalize(const doublereal* x) {} virtual void _getInitialSoln(doublereal* x) { x[0] = 0.0; @@ -250,7 +250,7 @@ public: integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); virtual void _finalize(const doublereal* x) { ; //m_temp = x[0]; } @@ -283,7 +283,7 @@ public: integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); virtual void _finalize(const doublereal* x) { ; //m_temp = x[0]; } @@ -335,7 +335,7 @@ public: virtual void eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); protected: @@ -370,7 +370,7 @@ public: integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); virtual void _getInitialSoln(doublereal* x) { x[0] = m_temp; @@ -433,7 +433,7 @@ public: integer* diagg, doublereal rdt); virtual void save(XML_Node& o, const doublereal* const soln); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); virtual void _getInitialSoln(doublereal* x) { x[0] = m_temp; diff --git a/include/cantera/oneD/OneDim.h b/include/cantera/oneD/OneDim.h index e8471e72c..6ed24f296 100644 --- a/include/cantera/oneD/OneDim.h +++ b/include/cantera/oneD/OneDim.h @@ -193,7 +193,7 @@ public: void writeStats(int printTime = 1); void save(const std::string& fname, std::string id, - const std::string& desc, doublereal* sol); + const std::string& desc, doublereal* sol, int loglevel); // options void setMinTimeStep(doublereal tmin) { diff --git a/include/cantera/oneD/Sim1D.h b/include/cantera/oneD/Sim1D.h index b8281b5c3..31676b2ea 100644 --- a/include/cantera/oneD/Sim1D.h +++ b/include/cantera/oneD/Sim1D.h @@ -73,10 +73,10 @@ public: //@} void save(const std::string& fname, const std::string& id, - const std::string& desc); + const std::string& desc, int loglevel=1); void saveResidual(const std::string& fname, const std::string& id, - const std::string& desc); + const std::string& desc, int loglevel=1); /// Print to stream s the current solution for all domains. void showSolution(std::ostream& s); @@ -115,7 +115,7 @@ public: */ void setGridMin(int dom, double gridmin); - void restore(const std::string& fname, const std::string& id); + void restore(const std::string& fname, const std::string& id, int loglevel=2); void getInitialSoln(); void setSolution(const doublereal* soln) { diff --git a/include/cantera/oneD/StFlow.h b/include/cantera/oneD/StFlow.h index 43de70b86..533bede5e 100644 --- a/include/cantera/oneD/StFlow.h +++ b/include/cantera/oneD/StFlow.h @@ -188,7 +188,8 @@ public: */ virtual void save(XML_Node& o, const doublereal* const sol); - virtual void restore(const XML_Node& dom, doublereal* soln); + virtual void restore(const XML_Node& dom, doublereal* soln, + int loglevel); // overloaded in subclasses virtual std::string flowType() { diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 4e5d82313..2c5797e43 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -408,8 +408,8 @@ cdef extern from "cantera/oneD/Sim1D.h": void solve(int, cbool) except + void refine(int) except + void setRefineCriteria(size_t, double, double, double, double) - void save(string, string, string) except + - void restore(string, string) except + + void save(string, string, string, int) except + + void restore(string, string, int) except + void writeStats(int) except + int domainIndex(string) except + double value(size_t, size_t, size_t) except + diff --git a/interfaces/cython/cantera/onedim.pyx b/interfaces/cython/cantera/onedim.pyx index b37a619da..92a84ea8f 100644 --- a/interfaces/cython/cantera/onedim.pyx +++ b/interfaces/cython/cantera/onedim.pyx @@ -699,7 +699,8 @@ cdef class Sim1D: """ self.sim.setFixedTemperature(T) - def save(self, filename='soln.xml', name='solution', description='none'): + def save(self, filename='soln.xml', name='solution', description='none', + loglevel=1): """ Save the solution in XML format. @@ -708,19 +709,22 @@ cdef class Sim1D: """ self.sim.save(stringify(filename), stringify(name), - stringify(description)) + stringify(description), loglevel) - def restore(self, filename='soln.xml', name='solution'): + def restore(self, filename='soln.xml', name='solution', loglevel=2): """Set the solution vector to a previously-saved solution. :param filename: solution file :param name: solution name within the file + :param loglevel: + Amount of logging information to display while restoring, + from 0 (disabled) to 2 (most verbose). >>> s.restore(filename='save.xml', id='energy_off') """ - self.sim.restore(stringify(filename), stringify(name)) + self.sim.restore(stringify(filename), stringify(name), loglevel) self._initialized = True def showStats(self, printTime=True): diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 04e529483..0a1eb6873 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -186,10 +186,10 @@ class TestFreeFlame(utilities.CanteraTest): u1 = self.sim.u V1 = self.sim.V - self.sim.save(filename, 'test') + self.sim.save(filename, 'test', loglevel=0) self.create_sim(p, Tin, reactants) - self.sim.restore(filename, 'test') + self.sim.restore(filename, 'test', loglevel=0) Y2 = self.sim.Y u2 = self.sim.u V2 = self.sim.V diff --git a/src/oneD/OneDim.cpp b/src/oneD/OneDim.cpp index d4417d385..58b04185a 100644 --- a/src/oneD/OneDim.cpp +++ b/src/oneD/OneDim.cpp @@ -474,7 +474,8 @@ doublereal OneDim::timeStep(int nsteps, doublereal dt, doublereal* x, void OneDim::save(const std::string& fname, std::string id, - const std::string& desc, doublereal* sol) + const std::string& desc, doublereal* sol, + int loglevel) { struct tm* newtime; @@ -519,7 +520,9 @@ void OneDim::save(const std::string& fname, std::string id, } ct->write(s); s.close(); - writelog("Solution saved to file "+fname+" as solution "+id+".\n"); + if (loglevel > 0) { + writelog("Solution saved to file "+fname+" as solution "+id+".\n"); + } } diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index fcb651ca3..cf55a822d 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -143,23 +143,24 @@ void Sim1D::setProfile(size_t dom, size_t comp, void Sim1D::save(const std::string& fname, const std::string& id, - const std::string& desc) + const std::string& desc, int loglevel) { - OneDim::save(fname, id, desc, DATA_PTR(m_x)); + OneDim::save(fname, id, desc, DATA_PTR(m_x), loglevel); } void Sim1D::saveResidual(const std::string& fname, const std::string& id, - const std::string& desc) + const std::string& desc, int loglevel) { vector_fp res(m_x.size(), -999); OneDim::eval(npos, &m_x[0], &res[0], 0.0); - OneDim::save(fname, id, desc, &res[0]); + OneDim::save(fname, id, desc, &res[0], loglevel); } /** * Initialize the solution with a previously-saved solution. */ -void Sim1D::restore(const std::string& fname, const std::string& id) +void Sim1D::restore(const std::string& fname, const std::string& id, + int loglevel) { ifstream s(fname.c_str()); //char buf[100]; @@ -195,7 +196,7 @@ void Sim1D::restore(const std::string& fname, const std::string& id) m_xnew.resize(sz); for (m = 0; m < m_nd; m++) { if (xd[m]) { - domain(m).restore(*xd[m], DATA_PTR(m_x) + domain(m).loc()); + domain(m).restore(*xd[m], DATA_PTR(m_x) + domain(m).loc(), loglevel); } } resize(); diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 304bfb197..5303de74c 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -1044,7 +1044,7 @@ size_t StFlow::componentIndex(const std::string& name) const } -void StFlow::restore(const XML_Node& dom, doublereal* soln) +void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) { vector ignored; @@ -1079,8 +1079,10 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) if (nm == "z") { getFloatArray(fa,x,false); np = x.size(); - writelog("Grid contains "+int2str(np)+ - " points.\n"); + if (loglevel >= 2) { + writelog("Grid contains "+int2str(np)+ + " points.\n"); + } readgrid = true; setupGrid(np, DATA_PTR(x)); } @@ -1090,13 +1092,17 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) "domain contains no grid points."); } - writelog("Importing datasets:\n"); + if (loglevel >= 2) { + writelog("Importing datasets:\n"); + } for (n = 0; n < nd; n++) { const XML_Node& fa = *d[n]; nm = fa["title"]; getFloatArray(fa,x,false); if (nm == "u") { - writelog("axial velocity "); + if (loglevel >= 2) { + writelog("axial velocity "); + } if (x.size() == np) { for (j = 0; j < np; j++) { soln[index(0,j)] = x[j]; @@ -1107,7 +1113,9 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) } else if (nm == "z") { ; // already read grid } else if (nm == "V") { - writelog("radial velocity "); + if (loglevel >= 2) { + writelog("radial velocity "); + } if (x.size() == np) { for (j = 0; j < np; j++) { soln[index(1,j)] = x[j]; @@ -1116,7 +1124,9 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) goto error; } } else if (nm == "T") { - writelog("temperature "); + if (loglevel >= 2) { + writelog("temperature "); + } if (x.size() == np) { for (j = 0; j < np; j++) { soln[index(2,j)] = x[j]; @@ -1136,7 +1146,9 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) goto error; } } else if (nm == "L") { - writelog("lambda "); + if (loglevel >=2) { + writelog("lambda "); + } if (x.size() == np) { for (j = 0; j < np; j++) { soln[index(3,j)] = x[j]; @@ -1145,7 +1157,9 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) goto error; } } else if (m_thermo->speciesIndex(nm) != npos) { - writelog(nm+" "); + if (loglevel >=2) { + writelog(nm+" "); + } if (x.size() == np) { k = m_thermo->speciesIndex(nm); did_species[k] = 1; @@ -1158,7 +1172,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) } } - if (ignored.size() != 0) { + if (loglevel >=2 && !ignored.empty()) { writelog("\n\n"); writelog("Ignoring datasets:\n"); size_t nn = ignored.size(); @@ -1167,13 +1181,15 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln) } } - for (ks = 0; ks < nsp; ks++) { - if (did_species[ks] == 0) { - if (!wrote_header) { - writelog("Missing data for species:\n"); - wrote_header = true; + if (loglevel >= 1) { + for (ks = 0; ks < nsp; ks++) { + if (did_species[ks] == 0) { + if (!wrote_header) { + writelog("Missing data for species:\n"); + wrote_header = true; + } + writelog(m_thermo->speciesName(ks)+" "); } - writelog(m_thermo->speciesName(ks)+" "); } } diff --git a/src/oneD/boundaries1D.cpp b/src/oneD/boundaries1D.cpp index 5109894c8..cf6935e30 100644 --- a/src/oneD/boundaries1D.cpp +++ b/src/oneD/boundaries1D.cpp @@ -253,7 +253,7 @@ save(XML_Node& o, const doublereal* const soln) } void Inlet1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { //map x; //getFloats(dom, x); @@ -322,7 +322,7 @@ save(XML_Node& o, const doublereal* const soln) } void Empty1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { resize(1,1); } @@ -413,7 +413,7 @@ save(XML_Node& o, const doublereal* const soln) } void Symm1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { resize(1,1); } @@ -523,7 +523,7 @@ save(XML_Node& o, const doublereal* const soln) } void Outlet1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { resize(1,1); } @@ -672,7 +672,7 @@ save(XML_Node& o, const doublereal* const soln) } void OutletRes1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { resize(1,1); } @@ -761,7 +761,7 @@ save(XML_Node& o, const doublereal* const soln) } void Surf1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { map x; ctml::getFloats(dom, x); @@ -924,7 +924,7 @@ save(XML_Node& o, const doublereal* const soln) } void ReactingSurf1D:: -restore(const XML_Node& dom, doublereal* soln) +restore(const XML_Node& dom, doublereal* soln, int loglevel) { map x; ctml::getFloats(dom, x);