Skip to content

Commit 8706830

Browse files
author
Ingmar Schoegl
committed
Revise structure of yaml output
1 parent 22dffc0 commit 8706830

File tree

5 files changed

+45
-46
lines changed

5 files changed

+45
-46
lines changed

interfaces/cython/cantera/test/test_reactor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,21 +423,21 @@ def test_yaml(self, **kwargs):
423423

424424
yaml = YAML()
425425
yml = yaml.load(self.net.to_yaml())
426-
self.assertTrue('ReactorNet' in yml)
427-
net = yml['ReactorNet']
426+
self.assertTrue('reactor-network' in yml)
427+
net = yml['reactor-network']
428428

429-
self.assertTrue('ReactorBase' in net)
430-
reactors = [tuple(n)[0] for n in net['ReactorBase']]
429+
self.assertTrue('reactors' in net)
430+
reactors = [tuple(n)[0] for n in net['reactors']]
431431
self.assertTrue(self.r1.name in reactors)
432432
self.assertTrue(self.r2.name in reactors)
433433
self.assertTrue(reservoir.name in reactors)
434434

435-
self.assertTrue('WallBase' in net)
436-
walls = [tuple(n)[0] for n in net['WallBase']]
435+
self.assertTrue('walls' in net)
436+
walls = [tuple(n)[0] for n in net['walls']]
437437
self.assertTrue(self.w.name in walls)
438438

439-
self.assertTrue('FlowDevice' in net)
440-
devices = [tuple(n)[0] for n in net['FlowDevice']]
439+
self.assertTrue('flow-devices' in net)
440+
devices = [tuple(n)[0] for n in net['flow-devices']]
441441
self.assertTrue(mfc.name in devices)
442442

443443
self.r2.name = self.r1.name

src/zeroD/FlowDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ std::string FlowDevice::toYAML() const
6161
yml << YAML::Key << name();
6262
yml << YAML::BeginMap;
6363
yml << YAML::Key << "type" << YAML::Value << typeStr();
64-
yml << YAML::Key << "in" << YAML::Value << m_in->name();
65-
yml << YAML::Key << "out" << YAML::Value << m_out->name();
64+
yml << YAML::Key << "reactors" << YAML::Flow;
65+
yml << YAML::BeginSeq << m_in->name() << m_out->name() << YAML::EndSeq;
6666
yml << YAML::EndMap;
6767
yml << YAML::EndMap;
6868

src/zeroD/ReactorBase.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//! @file ReactorBase.cpp
23

34
// This file is part of Cantera. See License.txt in the top-level directory or
@@ -7,6 +8,7 @@
78
#include "cantera/zeroD/FlowDevice.h"
89
#include "cantera/zeroD/ReactorNet.h"
910
#include "cantera/zeroD/ReactorSurface.h"
11+
#include "cantera/thermo/SurfPhase.h"
1012
#include "cantera/base/yaml.h"
1113

1214
using namespace std;
@@ -57,16 +59,13 @@ std::string ReactorBase::toYAML() const
5759
yml << YAML::BeginMap;
5860
yml << YAML::Key << "type";
5961
yml << YAML::Value << typeStr();
60-
if (m_thermo) {
61-
yml << YAML::Key << "phase";
62-
yml << YAML::Value << m_thermo->name();
63-
yml << YAML::Key << "thermo.type";
64-
yml << YAML::Value << m_thermo->type();
65-
}
66-
if (m_kin) {
67-
yml << YAML::Key << "kinetics.type";
68-
yml << YAML::Value << m_kin->kineticsType();
62+
yml << YAML::Key << "phases" << YAML::Flow;
63+
yml << YAML::BeginSeq;
64+
yml << m_thermo->name();
65+
for (const auto& s : m_surfaces) {
66+
yml << s->thermo()->name();
6967
}
68+
yml << YAML::EndSeq;
7069
yml << YAML::EndMap;
7170
yml << YAML::EndMap;
7271

src/zeroD/ReactorNet.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ std::string ReactorNet::toYAML() const
4848
std::map<std::string, ReactorBase* > reactors;
4949
std::map<std::string, WallBase* > walls;
5050
std::map<std::string, FlowDevice*> devices;
51-
std::map<std::string, ReactorSurface*> surfaces;
51+
// std::map<std::string, ReactorSurface*> surfaces;
5252

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

96-
// surfaces
97-
for (size_t i=0; i<rb->nSurfaces(); i++) {
96+
// // surfaces
97+
// for (size_t i=0; i<rb->nSurfaces(); i++) {
9898

99-
ReactorSurface* surface = rb->surface(i);
100-
surfaces.emplace(uniqueName((void const *)surface), surface);
101-
}
99+
// ReactorSurface* surface = rb->surface(i);
100+
// surfaces.emplace(uniqueName((void const *)surface), surface);
101+
// }
102102
}
103103

104104
// header
105105
yml << YAML::BeginMap;
106-
yml << YAML::Key << "ReactorNet";
106+
yml << YAML::Key << "reactor-network";
107107
yml << YAML::BeginMap;
108108

109109
// emit list of reactors
110-
yml << YAML::Key << "ReactorBase";
110+
yml << YAML::Key << "reactors";
111111
yml << YAML::Value << YAML::BeginSeq;
112112
for (const auto& r : reactors) {
113113
names.emplace(r.second->name(), r.first);
@@ -122,7 +122,7 @@ std::string ReactorNet::toYAML() const
122122
// emit list of walls
123123
names.clear();
124124
if (walls.size()) {
125-
yml << YAML::Key << "WallBase";
125+
yml << YAML::Key << "walls";
126126
yml << YAML::Value << YAML::BeginSeq;
127127
for (const auto& w : walls) {
128128
names.emplace(w.second->name(), w.first);
@@ -138,7 +138,7 @@ std::string ReactorNet::toYAML() const
138138
// emit list of flow devices
139139
names.clear();
140140
if (devices.size()) {
141-
yml << YAML::Key << "FlowDevice";
141+
yml << YAML::Key << "flow-devices";
142142
yml << YAML::Value << YAML::BeginSeq;
143143
for (const auto& d : devices) {
144144
names.emplace(d.second->name(), d.first);
@@ -151,21 +151,21 @@ std::string ReactorNet::toYAML() const
151151
throw CanteraError("ReactorNet::toYAML", "FlowDevice names are not unique.");
152152
}
153153

154-
// emit list of reactor surfaces
155-
names.clear();
156-
if (surfaces.size()) {
157-
yml << YAML::Key << "ReactorSurface";
158-
yml << YAML::Value << YAML::BeginSeq;
159-
for (const auto& s : surfaces) {
160-
names.emplace(s.second->name(), s.first);
161-
yml << YAML::Load(s.second->toYAML());
162-
}
163-
yml << YAML::EndSeq;
164-
}
165-
if (names.size()!=surfaces.size()) {
166-
// this should raise a warning, but an applicable warning system is not in place
167-
throw CanteraError("ReactorNet::toYAML", "ReactorSurface names are not unique.");
168-
}
154+
// // emit list of reactor surfaces
155+
// names.clear();
156+
// if (surfaces.size()) {
157+
// yml << YAML::Key << "ReactorSurface";
158+
// yml << YAML::Value << YAML::BeginSeq;
159+
// for (const auto& s : surfaces) {
160+
// names.emplace(s.second->name(), s.first);
161+
// yml << YAML::Load(s.second->toYAML());
162+
// }
163+
// yml << YAML::EndSeq;
164+
// }
165+
// if (names.size()!=surfaces.size()) {
166+
// // this should raise a warning, but an applicable warning system is not in place
167+
// throw CanteraError("ReactorNet::toYAML", "ReactorSurface names are not unique.");
168+
// }
169169

170170
// close out
171171
yml << YAML::EndMap;

src/zeroD/Wall.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ std::string WallBase::toYAML() const
4242
yml << YAML::Key << name();
4343
yml << YAML::BeginMap;
4444
yml << YAML::Key << "type" << YAML::Value << type();
45-
yml << YAML::Key << "left" << YAML::Value << m_left->name();
46-
yml << YAML::Key << "right" << YAML::Value << m_right->name();
45+
yml << YAML::Key << "reactors" << YAML::Flow;
46+
yml << YAML::BeginSeq << m_left->name() << m_right->name() << YAML::EndSeq;
4747
yml << YAML::EndMap;
4848
yml << YAML::EndMap;
4949

0 commit comments

Comments
 (0)