From 3391b47ac340adbd37e1b03ff0c96a0f16ee4e80 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sun, 18 Aug 2019 06:35:18 -0500 Subject: [PATCH] Revise structure of yaml output --- .../cython/cantera/test/test_reactor.py | 16 +++--- src/zeroD/ReactorBase.cpp | 17 +++---- src/zeroD/ReactorNet.cpp | 50 +++++++++---------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/interfaces/cython/cantera/test/test_reactor.py b/interfaces/cython/cantera/test/test_reactor.py index 6c53cff83ca..98bcb4612ac 100644 --- a/interfaces/cython/cantera/test/test_reactor.py +++ b/interfaces/cython/cantera/test/test_reactor.py @@ -410,21 +410,21 @@ def test_yaml(self, **kwargs): yaml = YAML() yml = yaml.load(self.net.to_yaml()) - self.assertTrue('ReactorNet' in yml) - net = yml['ReactorNet'] + self.assertTrue('reactor-network' in yml) + net = yml['reactor-network'] - self.assertTrue('ReactorBase' in net) - reactors = [tuple(n)[0] for n in net['ReactorBase']] + self.assertTrue('reactors' in net) + reactors = [tuple(n)[0] for n in net['reactors']] self.assertTrue(self.r1.name in reactors) self.assertTrue(self.r2.name in reactors) self.assertTrue(reservoir.name in reactors) - self.assertTrue('WallBase' in net) - walls = [tuple(n)[0] for n in net['WallBase']] + self.assertTrue('walls' in net) + walls = [tuple(n)[0] for n in net['walls']] self.assertTrue(self.w.name in walls) - self.assertTrue('FlowDevice' in net) - devices = [tuple(n)[0] for n in net['FlowDevice']] + self.assertTrue('flow-devices' in net) + devices = [tuple(n)[0] for n in net['flow-devices']] self.assertTrue(mfc.name in devices) self.r2.name = self.r1.name diff --git a/src/zeroD/ReactorBase.cpp b/src/zeroD/ReactorBase.cpp index 4492a8ae06b..72dc21ad231 100644 --- a/src/zeroD/ReactorBase.cpp +++ b/src/zeroD/ReactorBase.cpp @@ -1,3 +1,4 @@ + //! @file ReactorBase.cpp // This file is part of Cantera. See License.txt in the top-level directory or @@ -7,6 +8,7 @@ #include "cantera/zeroD/FlowDevice.h" #include "cantera/zeroD/ReactorNet.h" #include "cantera/zeroD/ReactorSurface.h" +#include "cantera/thermo/SurfPhase.h" #include "cantera/base/yaml.h" using namespace std; @@ -57,16 +59,13 @@ std::string ReactorBase::toYAML() const yml << YAML::BeginMap; yml << YAML::Key << "type"; yml << YAML::Value << typeStr(); - if (m_thermo) { - yml << YAML::Key << "phase"; - yml << YAML::Value << m_thermo->name(); - yml << YAML::Key << "thermo.type"; - yml << YAML::Value << m_thermo->type(); - } - if (m_kin) { - yml << YAML::Key << "kinetics.type"; - yml << YAML::Value << m_kin->kineticsType(); + yml << YAML::Key << "phases" << YAML::Flow; + yml << YAML::BeginSeq; + yml << m_thermo->name(); + for (const auto& s : m_surfaces) { + yml << s->thermo()->name(); } + yml << YAML::EndSeq; yml << YAML::EndMap; yml << YAML::EndMap; diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index a0f84893541..5536533cfae 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -48,7 +48,7 @@ std::string ReactorNet::toYAML() const std::map reactors; std::map walls; std::map devices; - std::map surfaces; + // std::map surfaces; // construct complete maps for (auto r=m_reactors.begin(); r!=m_reactors.end(); r++) { @@ -93,21 +93,21 @@ std::string ReactorNet::toYAML() const reactors.emplace(uniqueName((void const *)(&out)), &out); } - // surfaces - for (size_t i=0; inSurfaces(); i++) { + // // surfaces + // for (size_t i=0; inSurfaces(); i++) { - ReactorSurface* surface = rb->surface(i); - surfaces.emplace(uniqueName((void const *)surface), surface); - } + // ReactorSurface* surface = rb->surface(i); + // surfaces.emplace(uniqueName((void const *)surface), surface); + // } } // header yml << YAML::BeginMap; - yml << YAML::Key << "ReactorNet"; + yml << YAML::Key << "reactor-network"; yml << YAML::BeginMap; // emit list of reactors - yml << YAML::Key << "ReactorBase"; + yml << YAML::Key << "reactors"; yml << YAML::Value << YAML::BeginSeq; for (const auto& r : reactors) { names.emplace(r.second->name(), r.first); @@ -122,7 +122,7 @@ std::string ReactorNet::toYAML() const // emit list of walls names.clear(); if (walls.size()) { - yml << YAML::Key << "WallBase"; + yml << YAML::Key << "walls"; yml << YAML::Value << YAML::BeginSeq; for (const auto& w : walls) { names.emplace(w.second->name(), w.first); @@ -138,7 +138,7 @@ std::string ReactorNet::toYAML() const // emit list of flow devices names.clear(); if (devices.size()) { - yml << YAML::Key << "FlowDevice"; + yml << YAML::Key << "flow-devices"; yml << YAML::Value << YAML::BeginSeq; for (const auto& d : devices) { names.emplace(d.second->name(), d.first); @@ -151,21 +151,21 @@ std::string ReactorNet::toYAML() const throw CanteraError("ReactorNet::toYAML", "FlowDevice names are not unique."); } - // emit list of reactor surfaces - names.clear(); - if (surfaces.size()) { - yml << YAML::Key << "ReactorSurface"; - yml << YAML::Value << YAML::BeginSeq; - for (const auto& s : surfaces) { - names.emplace(s.second->name(), s.first); - yml << YAML::Load(s.second->toYAML()); - } - yml << YAML::EndSeq; - } - if (names.size()!=surfaces.size()) { - // this should raise a warning, but an applicable warning system is not in place - throw CanteraError("ReactorNet::toYAML", "ReactorSurface names are not unique."); - } + // // emit list of reactor surfaces + // names.clear(); + // if (surfaces.size()) { + // yml << YAML::Key << "ReactorSurface"; + // yml << YAML::Value << YAML::BeginSeq; + // for (const auto& s : surfaces) { + // names.emplace(s.second->name(), s.first); + // yml << YAML::Load(s.second->toYAML()); + // } + // yml << YAML::EndSeq; + // } + // if (names.size()!=surfaces.size()) { + // // this should raise a warning, but an applicable warning system is not in place + // throw CanteraError("ReactorNet::toYAML", "ReactorSurface names are not unique."); + // } // close out yml << YAML::EndMap;