Skip to content

Commit

Permalink
[zeroD] Tie reactor names to network
Browse files Browse the repository at this point in the history
Names of reactors and walls/connectors should be reproducible for a
given reactor network.
  • Loading branch information
ischoegl committed Aug 8, 2024
1 parent 2e61d9f commit f4d93f4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/cantera/zeroD/ReactorNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ class ReactorNet : public FuncEval

void updatePreconditioner(double gamma) override;

//! Create reproducible names for reactors and walls/connectors.
void updateNames(Reactor& r);

//! Estimate a future state based on current derivatives.
//! The function is intended for internal use by ReactorNet::advance
//! and deliberately not exposed in external interfaces.
Expand All @@ -316,6 +319,7 @@ class ReactorNet : public FuncEval
virtual int lastOrder() const;

vector<Reactor*> m_reactors;
map<string, int> m_count;
unique_ptr<Integrator> m_integ;

//! The independent variable in the system. May be either time or space depending
Expand Down
41 changes: 41 additions & 0 deletions src/zeroD/ReactorNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,47 @@ void ReactorNet::addReactor(Reactor& r)
m_integ->setMethod(BDF_Method);
m_integ->setLinearSolverType("DENSE");
}
updateNames(r);
}

void ReactorNet::updateNames(Reactor& r)
{
// ensure that reactors and components have reproducible names
auto rType = r.type();
if (!m_count.count(rType)) {
m_count[rType] = 0;
}
if (r.name() == "(none)" || r.name() == "") {
r.setName(fmt::format("{}_{}", rType, m_count[rType]));
}
m_count[rType]++;

for (size_t i=0; i<r.nWalls(); i++) {
auto& w = r.wall(i);
auto wType = w.type();
if (w.name() == "(none)" || w.name() == "") {
w.setName(fmt::format("{}_{}", wType, m_count[wType]));
}
m_count[wType]++;
}

for (size_t i=0; i<r.nInlets(); i++) {
auto& in = r.inlet(i);
auto inType = in.type();
if (in.name() == "(none)" || in.name() == "") {
in.setName(fmt::format("{}_{}", inType, m_count[inType]));
}
m_count[inType]++;
}

for (size_t i=0; i<r.nOutlets(); i++) {
auto& out = r.outlet(i);
auto outType = out.type();
if (out.name() == "(none)" || out.name() == "") {
out.setName(fmt::format("{}_{}", outType, m_count[outType]));
}
m_count[outType]++;
}
}

Integrator& ReactorNet::integrator() {
Expand Down

0 comments on commit f4d93f4

Please sign in to comment.