[1D] Deprecate loglevel in save/restore

This commit is contained in:
Ingmar Schoegl 2023-03-20 10:11:28 -05:00
parent 5841dcda84
commit 4406110573
8 changed files with 96 additions and 50 deletions

View File

@ -160,7 +160,7 @@ public:
virtual void eval(size_t jg, double* xg, double* rg,
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel);
virtual void restore(SolutionArray& arr, double* soln);
protected:
int m_ilr;
@ -199,7 +199,7 @@ public:
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel) {}
virtual void restore(SolutionArray& arr, double* soln) {}
};
/**
@ -229,7 +229,7 @@ public:
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel) {}
virtual void restore(SolutionArray& arr, double* soln) {}
};
@ -259,7 +259,7 @@ public:
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel) {}
virtual void restore(SolutionArray& arr, double* soln) {}
};
@ -293,7 +293,7 @@ public:
virtual void eval(size_t jg, double* xg, double* rg,
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel);
virtual void restore(SolutionArray& arr, double* soln);
protected:
size_t m_nsp = 0;
@ -330,7 +330,7 @@ public:
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel);
virtual void restore(SolutionArray& arr, double* soln);
virtual void show(std::ostream& s, const double* x);
@ -373,7 +373,7 @@ public:
integer* diagg, double rdt);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel);
virtual void restore(SolutionArray& arr, double* soln);
virtual void _getInitialSoln(double* x) {
m_sphase->getCoverages(x);

View File

@ -369,12 +369,10 @@ public:
/*!
* @param[in] arr SolutionArray defining the state of this domain
* @param[out] soln Value of the solution vector, local to this domain
* @param[in] loglevel 0 to suppress all output; 1 to show warnings; 2 for
* verbose output
*
* @since New in Cantera 3.0.
*/
virtual void restore(SolutionArray& arr, double* soln, int loglevel) {
virtual void restore(SolutionArray& arr, double* soln) {
throw NotImplementedError("Domain1D::restore", "Needs to be overloaded.");
}
@ -547,7 +545,7 @@ protected:
virtual AnyMap getMeta() const;
//! Retrieve meta data
virtual void setMeta(const AnyMap& meta, int loglevel);
virtual void setMeta(const AnyMap& meta);
double m_rdt = 0.0;
size_t m_nv = 0;

View File

@ -134,12 +134,21 @@ public:
* @param id Identifier of solution within the container file
* @param desc Description of the solution
* @param loglevel Level of diagnostic output
* @param overwrite Force overwrite if name exists; optional (default=`False`)
* @deprecated To be removed after Cantera 3.0; loglevel is deprecated.
*/
void save(const std::string& fname, const std::string& id,
const std::string& desc, int loglevel);
/**
* Save the current solution to a container file.
* @param fname Name of output container file
* @param id Identifier of solution within the container file
* @param desc Description of the solution
* @param overwrite Force overwrite if name exists; optional (default=false)
* @param compression Compression level (optional; HDF only)
*/
void save(const std::string& fname, const std::string& id,
const std::string& desc, int loglevel=1,
bool overwrite=false, int compression=0);
const std::string& desc, bool overwrite=false, int compression=0);
/**
* Save the residual of the current solution to a container file.
@ -147,21 +156,39 @@ public:
* @param id Identifier of solution within the container file
* @param desc Description of the solution
* @param loglevel Level of diagnostic output
* @param overwrite Force overwrite if name exists; optional (default=`False`)
* @deprecated To be removed after Cantera 3.0; loglevel is deprecated.
*/
void saveResidual(const std::string& fname, const std::string& id,
const std::string& desc, int loglevel);
/**
* Save the residual of the current solution to a container file.
* @param fname Name of output container file
* @param id Identifier of solution within the container file
* @param desc Description of the solution
* @param overwrite Force overwrite if name exists; optional (default=false)
* @param compression Compression level (optional; HDF only)
*/
void saveResidual(const std::string& fname, const std::string& id,
const std::string& desc, int loglevel=1,
bool overwrite=false, int compression=0);
const std::string& desc, bool overwrite=false, int compression=0);
/**
* Initialize the solution with a previously-saved solution.
* @param fname Name of container file
* @param id Identifier of solution within the container file
* @param loglevel Level of diagnostic output
* @deprecated To be removed after Cantera 3.0; loglevel is deprecated.
* @return AnyMap containing header information
*/
AnyMap restore(const std::string& fname, const std::string& id, int loglevel=2);
AnyMap restore(const std::string& fname, const std::string& id, int loglevel);
/**
* Initialize the solution with a previously-saved solution.
* @param fname Name of container file
* @param id Identifier of solution within the container file
* @return AnyMap containing header information
*/
AnyMap restore(const std::string& fname, const std::string& id);
//! @}

View File

@ -169,7 +169,7 @@ public:
virtual void show(const double* x);
virtual shared_ptr<SolutionArray> asArray(const double* soln) const;
virtual void restore(SolutionArray& arr, double* soln, int loglevel);
virtual void restore(SolutionArray& arr, double* soln);
//! Set flow configuration for freely-propagating flames, using an internal
//! point with a fixed temperature as the condition to determine the inlet
@ -288,7 +288,7 @@ public:
protected:
virtual AnyMap getMeta() const;
virtual void setMeta(const AnyMap& state, int loglevel);
virtual void setMeta(const AnyMap& state);
doublereal wdot(size_t k, size_t j) const {
return m_wdot(k,j);

View File

@ -240,9 +240,9 @@ shared_ptr<SolutionArray> Inlet1D::asArray(const double* soln) const
return arr;
}
void Inlet1D::restore(SolutionArray& arr, double* soln, int loglevel)
void Inlet1D::restore(SolutionArray& arr, double* soln)
{
Boundary1D::setMeta(arr.meta(), loglevel);
Boundary1D::setMeta(arr.meta());
arr.setLoc(0);
auto phase = arr.thermo();
auto meta = arr.meta();
@ -523,9 +523,9 @@ shared_ptr<SolutionArray> OutletRes1D::asArray(const double* soln) const
return arr;
}
void OutletRes1D::restore(SolutionArray& arr, double* soln, int loglevel)
void OutletRes1D::restore(SolutionArray& arr, double* soln)
{
Boundary1D::setMeta(arr.meta(), loglevel);
Boundary1D::setMeta(arr.meta());
arr.setLoc(0);
auto phase = arr.thermo();
m_temp = phase->temperature();
@ -572,9 +572,9 @@ shared_ptr<SolutionArray> Surf1D::asArray(const double* soln) const
return SolutionArray::create(m_solution, 0, meta);
}
void Surf1D::restore(SolutionArray& arr, double* soln, int loglevel)
void Surf1D::restore(SolutionArray& arr, double* soln)
{
Boundary1D::setMeta(arr.meta(), loglevel);
Boundary1D::setMeta(arr.meta());
arr.setLoc(0);
m_temp = arr.thermo()->temperature();
}
@ -778,9 +778,9 @@ shared_ptr<SolutionArray> ReactingSurf1D::asArray(const double* soln) const
return arr;
}
void ReactingSurf1D::restore(SolutionArray& arr, double* soln, int loglevel)
void ReactingSurf1D::restore(SolutionArray& arr, double* soln)
{
Boundary1D::setMeta(arr.meta(), loglevel);
Boundary1D::setMeta(arr.meta());
arr.setLoc(0);
auto surf = std::dynamic_pointer_cast<SurfPhase>(arr.thermo());
if (!surf) {

View File

@ -145,7 +145,7 @@ AnyMap Domain1D::serialize(const double* soln) const
return out;
}
void Domain1D::setMeta(const AnyMap& meta, int loglevel)
void Domain1D::setMeta(const AnyMap& meta)
{
auto set_tols = [&](const AnyValue& tols, const string& which, vector_fp& out)
{
@ -160,7 +160,7 @@ void Domain1D::setMeta(const AnyMap& meta, int loglevel)
std::string name = componentName(i);
if (tol.hasKey(name)) {
out[i] = tol[name].asDouble();
} else if (loglevel) {
} else {
warn_user("Domain1D::setMeta", "No {} found for component '{}'",
which, name);
}
@ -183,7 +183,7 @@ void Domain1D::restore(const AnyMap& state, double* soln, int loglevel)
"To be removed after Cantera 3.0; restore from SolutionArray instead.");
auto arr = SolutionArray::create(solution());
arr->readEntry(state, "", "");
restore(*arr, soln, loglevel);
restore(*arr, soln);
}
void Domain1D::locate()

View File

@ -115,7 +115,18 @@ void Sim1D::setProfile(size_t dom, size_t comp,
}
void Sim1D::save(const std::string& fname, const std::string& id,
const std::string& desc, int loglevel, bool overwrite, int compression)
const std::string& desc, int loglevel)
{
warn_deprecated("Sim1D::save",
"To be removed after Cantera 3.0; use version without loglevel instead.");
save(fname, id, desc, true); // legacy version overwrites data
if (loglevel > 0) {
writelog("Solution saved to file '{}' as entry '{}'.\n", fname, id);
}
}
void Sim1D::save(const std::string& fname, const std::string& id,
const std::string& desc, bool overwrite, int compression)
{
size_t dot = fname.find_last_of(".");
string extension = (dot != npos) ? toLowerCopy(fname.substr(dot+1)) : "";
@ -125,9 +136,6 @@ void Sim1D::save(const std::string& fname, const std::string& id,
auto arr = dom->asArray(m_x.data() + dom->loc());
arr->writeEntry(fname, id, dom->id(), overwrite, compression);
}
if (loglevel > 0) {
writelog("Solution saved to file '{}' as group '{}'.\n", fname, id);
}
return;
}
if (extension == "yaml" || extension == "yml") {
@ -147,24 +155,31 @@ void Sim1D::save(const std::string& fname, const std::string& id,
std::ofstream out(fname);
out << data.toYamlString();
AnyMap::clearCachedFile(fname);
if (loglevel > 0) {
writelog("Solution saved to file '{}' as entry '{}'.\n", fname, id);
}
return;
}
throw CanteraError("Sim1D::save", "Unsupported file format '{}'.", extension);
}
void Sim1D::saveResidual(const std::string& fname, const std::string& id,
const std::string& desc,
int loglevel, bool overwrite, int compression)
const std::string& desc, int loglevel)
{
warn_deprecated("Sim1D::saveResidual",
"To be removed after Cantera 3.0; use version without loglevel instead.");
saveResidual(fname, id, desc, true); // legacy version overwrites data
if (loglevel > 0) {
writelog("Solution saved to file '{}' as entry '{}'.\n", fname, id);
}
}
void Sim1D::saveResidual(const std::string& fname, const std::string& id,
const std::string& desc, bool overwrite, int compression)
{
vector_fp res(m_x.size(), -999);
OneDim::eval(npos, &m_x[0], &res[0], 0.0);
// Temporarily put the residual into m_x, since this is the vector that the save()
// function reads.
std::swap(res, m_x);
save(fname, id, desc, loglevel, overwrite, compression);
save(fname, id, desc, overwrite, compression);
std::swap(res, m_x);
}
@ -255,8 +270,14 @@ AnyMap legacyH5(shared_ptr<SolutionArray> arr, const AnyMap& header={})
} // end unnamed namespace
AnyMap Sim1D::restore(const std::string& fname, const std::string& id,
int loglevel)
AnyMap Sim1D::restore(const std::string& fname, const std::string& id, int loglevel)
{
warn_deprecated("Sim1D::saveResidual",
"To be removed after Cantera 3.0; use version without loglevel instead.");
return restore(fname, id);
}
AnyMap Sim1D::restore(const std::string& fname, const std::string& id)
{
size_t dot = fname.find_last_of(".");
string extension = (dot != npos) ? toLowerCopy(fname.substr(dot+1)) : "";
@ -281,7 +302,7 @@ AnyMap Sim1D::restore(const std::string& fname, const std::string& id,
resize();
m_xlast_ts.clear();
for (auto dom : m_dom) {
dom->restore(*arrs[dom->id()], m_x.data() + dom->loc(), loglevel);
dom->restore(*arrs[dom->id()], m_x.data() + dom->loc());
}
finalize();
} else if (extension == "yaml" || extension == "yml") {
@ -298,7 +319,7 @@ AnyMap Sim1D::restore(const std::string& fname, const std::string& id,
resize();
m_xlast_ts.clear();
for (auto dom : m_dom) {
dom->restore(*arrs[dom->id()], m_x.data() + dom->loc(), loglevel);
dom->restore(*arrs[dom->id()], m_x.data() + dom->loc());
}
finalize();
} else {

View File

@ -821,9 +821,9 @@ shared_ptr<SolutionArray> StFlow::asArray(const double* soln) const
return arr;
}
void StFlow::restore(SolutionArray& arr, double* soln, int loglevel)
void StFlow::restore(SolutionArray& arr, double* soln)
{
Domain1D::setMeta(arr.meta(), loglevel);
Domain1D::setMeta(arr.meta());
arr.setLoc(0);
auto phase = arr.thermo();
m_press = phase->pressure();
@ -841,14 +841,14 @@ void StFlow::restore(SolutionArray& arr, double* soln, int loglevel)
for (size_t j = 0; j < nPoints(); j++) {
soln[index(i,j)] = data[j];
}
} else if (loglevel) {
} else {
warn_user("StFlow::restore", "Saved state does not contain values for "
"component '{}' in domain '{}'.", name, id());
}
}
updateProperties(npos, soln + loc(), 0, m_points - 1);
setMeta(arr.meta(), loglevel);
setMeta(arr.meta());
}
string StFlow::flowType() const {
@ -863,7 +863,7 @@ string StFlow::flowType() const {
}
}
void StFlow::setMeta(const AnyMap& state, int loglevel)
void StFlow::setMeta(const AnyMap& state)
{
if (state.hasKey("energy-enabled")) {
const AnyValue& ee = state["energy-enabled"];