Skip to content

Commit

Permalink
Revise structure of yaml output
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingmar Schoegl committed Aug 18, 2019
1 parent f848b5d commit 3391b47
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
16 changes: 8 additions & 8 deletions interfaces/cython/cantera/test/test_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/zeroD/ReactorBase.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//! @file ReactorBase.cpp

// This file is part of Cantera. See License.txt in the top-level directory or
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
50 changes: 25 additions & 25 deletions src/zeroD/ReactorNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::string ReactorNet::toYAML() const
std::map<std::string, ReactorBase* > reactors;
std::map<std::string, WallBase* > walls;
std::map<std::string, FlowDevice*> devices;
std::map<std::string, ReactorSurface*> surfaces;
// std::map<std::string, ReactorSurface*> surfaces;

// construct complete maps
for (auto r=m_reactors.begin(); r!=m_reactors.end(); r++) {
Expand Down Expand Up @@ -93,21 +93,21 @@ std::string ReactorNet::toYAML() const
reactors.emplace(uniqueName((void const *)(&out)), &out);
}

// surfaces
for (size_t i=0; i<rb->nSurfaces(); i++) {
// // surfaces
// for (size_t i=0; i<rb->nSurfaces(); 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 3391b47

Please sign in to comment.