Skip to content

Commit f7534b8

Browse files
committed
[Reactor] Set m_nv in constructor
1 parent 2b25da5 commit f7534b8

File tree

15 files changed

+68
-80
lines changed

15 files changed

+68
-80
lines changed

include/cantera/zeroD/ConstPressureMoleReactor.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ namespace Cantera
2020
class ConstPressureMoleReactor : public MoleReactor
2121
{
2222
public:
23-
using MoleReactor::MoleReactor; // inherit constructors
23+
ConstPressureMoleReactor(shared_ptr<Solution> sol, const string& name="(none)");
24+
ConstPressureMoleReactor(shared_ptr<Solution> sol, bool clone,
25+
const string& name="(none)");
2426

2527
string type() const override {
2628
return "ConstPressureMoleReactor";
2729
};
2830

2931
void getState(double* y) override;
30-
31-
void initialize(double t0=0.0) override;
32-
3332
void eval(double t, double* LHS, double* RHS) override;
3433

3534
vector<size_t> steadyConstraints() const override {

include/cantera/zeroD/ConstPressureReactor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ namespace Cantera
2323
class ConstPressureReactor : public Reactor
2424
{
2525
public:
26-
using Reactor::Reactor; // inherit constructors
26+
ConstPressureReactor(shared_ptr<Solution> sol, const string& name="(none)");
27+
ConstPressureReactor(shared_ptr<Solution> sol, bool clone,
28+
const string& name="(none)");
2729

2830
string type() const override {
2931
return "ConstPressureReactor";
3032
}
3133

3234
void getState(double* y) override;
33-
34-
void initialize(double t0=0.0) override;
3535
void eval(double t, double* LHS, double* RHS) override;
3636
vector<size_t> steadyConstraints() const override;
3737

include/cantera/zeroD/FlowReactor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace Cantera
1616
class FlowReactor : public IdealGasReactor
1717
{
1818
public:
19-
using IdealGasReactor::IdealGasReactor; // inherit constructors
19+
FlowReactor(shared_ptr<Solution> sol, const string& name="(none)");
20+
FlowReactor(shared_ptr<Solution> sol, bool clone, const string& name="(none)");
2021

2122
string type() const override {
2223
return "FlowReactor";
@@ -36,7 +37,6 @@ class FlowReactor : public IdealGasReactor
3637
}
3738

3839
void getStateDae(double* y, double* ydot) override;
39-
void initialize(double t0=0.0) override;
4040
void updateState(double* y) override;
4141

4242
//! Not implemented; FlowReactor implements evalDae() instead.

include/cantera/zeroD/MoleReactor.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ namespace Cantera
2020
class MoleReactor : public Reactor
2121
{
2222
public:
23-
using Reactor::Reactor; // inherit constructors
23+
MoleReactor(shared_ptr<Solution> sol, const string& name="(none)");
24+
MoleReactor(shared_ptr<Solution> sol, bool clone, const string& name="(none)");
2425

2526
string type() const override {
2627
return "MoleReactor";
2728
}
2829

29-
void initialize(double t0=0.0) override;
30-
3130
void getState(double* y) override;
32-
3331
void updateState(double* y) override;
34-
3532
void eval(double t, double* LHS, double* RHS) override;
36-
3733
size_t componentIndex(const string& nm) const override;
3834
string componentName(size_t k) override;
3935
double upperBound(size_t k) const override;

interfaces/cython/cantera/reactor.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ cdef class ExtensibleReactor(Reactor):
501501
A base class for a reactor with delegated methods where the base
502502
functionality corresponds to the `Reactor` class.
503503
504+
The ``__init__`` method of the derived class should allocate and size any
505+
internal variables and set the total number of state variables associated with this
506+
reactor, `n_vars` (if it is different from the base class).
507+
504508
The following methods of the C++ :ct:`Reactor` class can be modified by a
505509
Python class which inherits from this class. For each method, the name below
506510
should be prefixed with ``before_``, ``after_``, or ``replace_``, indicating
@@ -515,9 +519,8 @@ cdef class ExtensibleReactor(Reactor):
515519
from the supplied method and the base class method.
516520
517521
``initialize(self, t0: double) -> None``
518-
Responsible for allocating and setting the sizes of any internal
519-
variables, initializing attached walls, and setting the total number of
520-
state variables associated with this reactor, `n_vars`.
522+
Responsible for initialization that can only be performed after connecting the
523+
elements of the reactor network, such as initializing attached walls.
521524
522525
Called once before the start of time integration.
523526

samples/python/reactors/custom2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def __init__(self, *args, neighbor, **kwargs):
3131
self.k_wall = 1e-2 # proportionality constant, a_wall = k_wall * delta P
3232
self.neighbor = neighbor
3333

34-
def after_initialize(self, t0):
35-
# The initialize function for the base Reactor class will have set
34+
# The constructor for the base Reactor class will have set
3635
# n_vars to already include the volume, internal energy, mass, and mass
3736
# fractions of all the species. Increase this by one to account for
3837
# the added variable of the wall velocity.

samples/python/reactors/porous_media_burner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def __init__(self, *args, props, **kwargs):
195195
self.V = self.A * props.length # reactor volume (m^3)
196196
self.molecular_weights = None
197197
self.species_offset = None
198-
199-
def after_initialize(self, t0):
200198
self.n_vars += 1 # additional equation for the solid temperature
201199
self.index_Ts = self.n_vars - 1
202200
self.species_offset = self.component_index(self.phase.species_name(0))

src/zeroD/ConstPressureMoleReactor.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
namespace Cantera
1616
{
1717

18+
ConstPressureMoleReactor::ConstPressureMoleReactor(shared_ptr<Solution> sol,
19+
const string& name)
20+
: ConstPressureMoleReactor(sol, true, name)
21+
{
22+
}
23+
24+
ConstPressureMoleReactor::ConstPressureMoleReactor(shared_ptr<Solution> sol, bool clone,
25+
const string& name)
26+
: MoleReactor(sol, clone, name)
27+
{
28+
m_nv = 1 + m_nsp; // enthalpy and moles of each species
29+
}
30+
1831
void ConstPressureMoleReactor::getState(double* y)
1932
{
2033
// set mass to be used in getMoles function
@@ -25,12 +38,6 @@ void ConstPressureMoleReactor::getState(double* y)
2538
getMoles(y + m_sidx);
2639
}
2740

28-
void ConstPressureMoleReactor::initialize(double t0)
29-
{
30-
MoleReactor::initialize(t0);
31-
m_nv -= 1; // const pressure system loses 1 more variable from MoleReactor
32-
}
33-
3441
void ConstPressureMoleReactor::updateState(double* y)
3542
{
3643
// the components of y are: [0] the enthalpy, [1...K+1) are the

src/zeroD/ConstPressureReactor.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
namespace Cantera
1515
{
1616

17+
ConstPressureReactor::ConstPressureReactor(shared_ptr<Solution> sol,
18+
const string& name)
19+
: ConstPressureReactor(sol, true, name)
20+
{
21+
}
22+
23+
ConstPressureReactor::ConstPressureReactor(shared_ptr<Solution> sol, bool clone,
24+
const string& name)
25+
: Reactor(sol, clone, name)
26+
{
27+
m_nv = 2 + m_nsp; // mass, enthalpy, and mass fractions of each species
28+
}
29+
1730
void ConstPressureReactor::getState(double* y)
1831
{
1932
// set the first component to the total mass
@@ -27,12 +40,6 @@ void ConstPressureReactor::getState(double* y)
2740

2841
}
2942

30-
void ConstPressureReactor::initialize(double t0)
31-
{
32-
Reactor::initialize(t0);
33-
m_nv -= 1; // Constant pressure reactor has one fewer state variable
34-
}
35-
3643
void ConstPressureReactor::updateState(double* y)
3744
{
3845
// The components of y are [0] the total mass, [1] the total enthalpy,

src/zeroD/FlowReactor.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
namespace Cantera
1818
{
1919

20+
FlowReactor::FlowReactor(shared_ptr<Solution> sol, const string& name)
21+
: FlowReactor(sol, true, name)
22+
{
23+
}
24+
25+
FlowReactor::FlowReactor(shared_ptr<Solution> sol, bool clone, const string& name)
26+
: IdealGasReactor(sol, clone, name)
27+
{
28+
m_nv = 4 + m_nsp; // rho, u, P, T, and species mass fractions
29+
m_rho = m_thermo->density();
30+
// resize temporary arrays
31+
m_wdot.resize(m_nsp);
32+
m_hk.resize(m_nsp);
33+
}
34+
2035
void FlowReactor::getStateDae(double* y, double* ydot)
2136
{
2237
m_thermo->getMassFractions(y+m_offset_Y);
@@ -132,20 +147,6 @@ void FlowReactor::getStateDae(double* y, double* ydot)
132147
solve(a, ydot, 1, 0);
133148
}
134149

135-
void FlowReactor::initialize(double t0)
136-
{
137-
Reactor::initialize(t0);
138-
// initialize state
139-
m_rho = m_thermo->density();
140-
// resize temporary arrays
141-
m_wdot.resize(m_nsp);
142-
m_hk.resize(m_nsp);
143-
// set number of variables to the number of non-species equations
144-
// i.e., density, velocity, pressure and temperature
145-
// plus the number of species in the gas phase
146-
m_nv = m_offset_Y + m_nsp;
147-
}
148-
149150
void FlowReactor::updateState(double* y)
150151
{
151152
// Set the mass fractions and density of the mixture.

0 commit comments

Comments
 (0)