From 48fbac913240ea412cabb74a662852450ab6bd83 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sun, 4 Sep 2022 14:52:11 -0500 Subject: [PATCH] [wip] integrate SolutionArray into Sim1D::restore --- src/oneD/Sim1D.cpp | 50 +++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index 756b2a3591f..362d45cd2c1 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -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 #include @@ -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> 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 @@ -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> 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();