Skip to content

Commit

Permalink
[wip] integrate SolutionArray into Sim1D::restore
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Sep 29, 2022
1 parent 65f43aa commit 48fbac9
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions src/oneD/Sim1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "cantera/oneD/refine.h"
#include "cantera/numerics/funcs.h"
#include "cantera/base/stringUtils.h"
#include "cantera/base/SolutionArray.h"
#include "cantera/numerics/Func1.h"
#include <limits>
#include <fstream>
Expand Down Expand Up @@ -170,29 +171,25 @@ void Sim1D::restore(const std::string& fname, const std::string& id,
} else if (extension == "h5" || extension == "hdf") {
#if CT_USE_HIGHFIVE_HDF
h5::File file(fname, h5::File::ReadOnly);
if (!file.exist(id) || file.getObjectType(id) != h5::ObjectType::Group) {
throw CanteraError("Sim1D::restore",
"No solution with id '{}'", id);
}
h5::Group grp = file.getGroup(id);
std::map<std::string, std::shared_ptr<SolutionArray>> sols;
for (auto dom : m_dom) {
std::string dn = dom->id();
if (!grp.exist(dn)|| grp.getObjectType(dn) != h5::ObjectType::Group) {
throw CanteraError("Sim1D::restore",
"Saved state '{}' does not contain a domain named '{}'.", id, dn);
}
size_t points;
try {
// determine size based on stored temperature
points = grp.getGroup(dn).getDataSet("T").getElementCount();
} catch (exception& err) {
throw CanteraError("Sim1D::restore",
"Unable to determine domain size:\n{}", err.what());
}
dom->resize(dom->nComponents(), points);
auto arr = SolutionArray::create(dom->solution());
arr->restore(fname, id + "/" + dom->id());
dom->resize(dom->nComponents(), arr->size());
sols[dom->id()] = arr;
}
resize();
m_xlast_ts.clear();
for (auto dom : m_dom) {
auto sol = sols[dom->id()];
std::cout << dom->id() << ": size=" << sol->size() << std::endl;
sol->setIndex(sol->size() - 1);
auto state = sol->getState();
std::cout << state[0] << " / " << state[1] << std::endl;
for (const auto& item : sol->getAuxiliary()) {
std::cout << "- " << item.first << "=" << item.second << std::endl;
}
}

throw CanteraError("Sim1D::restore", "Work in progress.");
#else
Expand All @@ -201,18 +198,13 @@ void Sim1D::restore(const std::string& fname, const std::string& id,
#endif
} else if (extension == "yaml" || extension == "yml") {
AnyMap root = AnyMap::fromYamlFile(fname);
if (!root.hasKey(id)) {
throw InputFileError("Sim1D::restore", root,
"No solution with id '{}'", id);
}
std::map<std::string, std::shared_ptr<SolutionArray>> sols;
const auto& state = root[id];
for (auto dom : m_dom) {
if (!state.hasKey(dom->id())) {
throw InputFileError("Sim1D::restore", state,
"Saved state '{}' does not contain a domain named '{}'.",
id, dom->id());
}
dom->resize(dom->nComponents(), state[dom->id()]["points"].asInt());
auto arr = SolutionArray::create(dom->solution());
arr->restore(fname, id + "/" + dom->id());
dom->resize(dom->nComponents(), arr->size());
sols[dom->id()] = arr;
}
resize();
m_xlast_ts.clear();
Expand Down

0 comments on commit 48fbac9

Please sign in to comment.