Skip to content

Commit

Permalink
[1D] Avoid serializing components that are not used in a given model
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Oct 26, 2021
1 parent 82f00a4 commit 36227f5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/cantera/oneD/IonFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class IonFlow : public StFlow
virtual void setSolvingStage(const size_t phase);

virtual void resize(size_t components, size_t points);
virtual bool componentActive(size_t n) const;

virtual void _finalize(const double* x);
//! set to solve electric field on a point
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/oneD/StFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class StFlow : public Domain1D

virtual size_t componentIndex(const std::string& name) const;

//! Returns true if the specified component is an active part of the solver state
virtual bool componentActive(size_t n) const;

//! Print the solution.
virtual void showSolution(const doublereal* x);

Expand Down
9 changes: 9 additions & 0 deletions src/oneD/IonFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ void IonFlow::resize(size_t components, size_t points){
m_do_electric_field.resize(m_points,false);
}

bool IonFlow::componentActive(size_t n) const
{
if (n == c_offset_E) {
return true;
} else {
return StFlow::componentActive(n);
}
}

void IonFlow::updateTransport(double* x, size_t j0, size_t j1)
{
StFlow::updateTransport(x,j0,j1);
Expand Down
25 changes: 22 additions & 3 deletions src/oneD/StFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,20 @@ size_t StFlow::componentIndex(const std::string& name) const
}
}

bool StFlow::componentActive(size_t n) const
{
switch (n) {
case c_offset_V: // spread_rate
return m_type != cFreeFlow;
case c_offset_L: // lambda
return m_type != cFreeFlow;
case c_offset_E: // eField
return false;
default:
return true;
}
}

void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
{
Domain1D::restore(dom, soln, loglevel);
Expand Down Expand Up @@ -896,10 +910,12 @@ AnyMap StFlow::serialize(const double* soln) const
state["grid"] = m_z;
vector_fp data(nPoints());
for (size_t i = 0; i < nComponents(); i++) {
for (size_t j = 0; j < nPoints(); j++) {
data[j] = soln[index(i,j)];
if (componentActive(i)) {
for (size_t j = 0; j < nPoints(); j++) {
data[j] = soln[index(i,j)];
}
state[componentName(i)] = data;
}
state[componentName(i)] = data;
}

return state;
Expand All @@ -912,6 +928,9 @@ void StFlow::restore(const AnyMap& state, double* soln, int loglevel)
setupGrid(nPoints(), state["grid"].asVector<double>(nPoints()).data());

for (size_t i = 0; i < nComponents(); i++) {
if (!componentActive(i)) {
continue;
}
std::string name = componentName(i);
if (state.hasKey(name)) {
const vector_fp& data = state[name].asVector<double>(nPoints());
Expand Down

0 comments on commit 36227f5

Please sign in to comment.