Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reactor API #1515

Merged
merged 14 commits into from
Jul 1, 2023
Merged
6 changes: 6 additions & 0 deletions include/cantera/clib/ctreactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ extern "C" {
CANTERA_CAPI int flowdev_new(const char* type);
CANTERA_CAPI int flowdev_del(int i);
CANTERA_CAPI int flowdev_install(int i, int n, int m);
//! @deprecated To be removed after Cantera 3.0; replaced by flowdev_setPrimary
CANTERA_CAPI int flowdev_setMaster(int i, int n);
CANTERA_CAPI int flowdev_setPrimary(int i, int n);
CANTERA_CAPI double flowdev_massFlowRate(int i);
CANTERA_CAPI int flowdev_setMassFlowCoeff(int i, double v);
CANTERA_CAPI int flowdev_setValveCoeff(int i, double v);
Expand All @@ -62,8 +64,12 @@ extern "C" {
CANTERA_CAPI int wall_new(const char* type);
CANTERA_CAPI int wall_del(int i);
CANTERA_CAPI int wall_install(int i, int n, int m);
//! @deprecated Only used by traditional MATLAB toolbox
CANTERA_CAPI double wall_vdot(int i, double t);
CANTERA_CAPI double wall_expansionRate(int i);
//! @deprecated Only used by traditional MATLAB toolbox
CANTERA_CAPI double wall_Q(int i, double t);
CANTERA_CAPI double wall_heatRate(int i);
CANTERA_CAPI double wall_area(int i);
CANTERA_CAPI int wall_setArea(int i, double v);
CANTERA_CAPI int wall_setThermalResistance(int i, double rth);
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/numerics/Func1.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Func1
return "functor";
}

//! Returns a string describing the type of the function
//! Returns a string with the class name of the functor
//! @since New in Cantera 3.0.
string typeName() const;

Expand Down
30 changes: 30 additions & 0 deletions include/cantera/zeroD/FlowDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,43 @@ class FlowDevice
return *m_out;
}

//! Return current value of the pressure function.
/*!
* The mass flow rate [kg/s] is calculated given the pressure drop [Pa] and a
* coefficient set by a flow device specific function; unless a user-defined
* pressure function is set, this is the pressure difference across the device.
* The calculation of mass flow rate depends to the flow device.
* @since New in Cantera 3.0.
*/
double evalPressureFunction();

//! Set a function of pressure that is used in determining the
//! mass flow rate through the device. The evaluation of mass flow
//! depends on the derived flow device class.
virtual void setPressureFunction(Func1* f);

//! Return current value of the time function.
/*!
* The mass flow rate [kg/s] is calculated for a Flow device, and multiplied by a
* function of time, which returns 1.0 unless a user-defined function is provided.
* The calculation of mass flow rate depends on the flow device.
* @since New in Cantera 3.0.
*/
double evalTimeFunction();

//! Set a function of time that is used in determining
//! the mass flow rate through the device. The evaluation of mass flow
//! depends on the derived flow device class.
virtual void setTimeFunction(Func1* g);

//! Set current reactor network time
/*!
* @since New in Cantera 3.0.
*/
void setSimTime(double time) {
m_time = time;
}

protected:
double m_mdot = Undef;

Expand All @@ -99,6 +126,9 @@ class FlowDevice
//! Coefficient set by derived classes; used by updateMassFlowRate
double m_coeff = 1.0;

//! Current reactor network time
double m_time = 0.;

private:
size_t m_nspin = 0;
size_t m_nspout = 0;
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/zeroD/Reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class Reactor : public ReactorBase
//! Update the state of SurfPhase objects attached to this reactor
virtual void updateSurfaceState(double* y);

//! Update the state information needed by connected reactors and flow
//! devices. Called from updateState().
//! Update the state information needed by connected reactors, flow devices,
//! and reactor walls. Called from updateState().
//! @param updatePressure Indicates whether to update #m_pressure. Should
//! `true` for reactors where the pressure is a dependent property,
//! calculated from the state, and `false` when the pressure is constant
Expand Down
16 changes: 8 additions & 8 deletions include/cantera/zeroD/ReactorDelegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ class ReactorAccessor
virtual void setNEq(size_t n) = 0;

//! Get the net rate of volume change (for example, from moving walls) [m^3/s]
virtual double vdot() const = 0;
virtual double expansionRate() const = 0;

//! Set the net rate of volume change (for example, from moving walls) [m^3/s]
virtual void setVdot(double v) = 0;
virtual void setExpansionRate(double v) = 0;

//! Get the net heat transfer rate (for example, through walls) into the
//! reactor [W]. This value is initialized and calculated as part of
//! Reactor::evalWalls().
virtual double qdot() const = 0;
virtual double heatRate() const = 0;

//! Set the net heat transfer rate (for example, through walls) into the
//! reactor [W]. For a value set using this method to affect the calculations done
//! by Reactor::eval, this method should be called in either a "replace" or "after"
//! delegate for Reactor::evalWalls().
virtual void setQdot(double q) = 0;
virtual void setHeatRate(double q) = 0;

//! Set the state of the thermo object to correspond to the state of the reactor
virtual void restoreThermoState() = 0;
Expand Down Expand Up @@ -160,19 +160,19 @@ class ReactorDelegator : public Delegator, public R, public ReactorAccessor
R::m_nv = n;
}

virtual double vdot() const override {
virtual double expansionRate() const override {
return R::m_vdot;
}

virtual void setVdot(double v) override {
virtual void setExpansionRate(double v) override {
R::m_vdot = v;
}

virtual double qdot() const override {
virtual double heatRate() const override {
return R::m_Qdot;
}

virtual void setQdot(double q) override {
virtual void setHeatRate(double q) override {
R::m_Qdot = q;
}

Expand Down
11 changes: 11 additions & 0 deletions include/cantera/zeroD/ReactorNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class ReactorNet : public FuncEval
//! state as the initial condition.
void setInitialTime(double time);

//! Get the initial value of the independent variable (typically time).
/*!
* @since New in Cantera 3.0.
*/
double getInitialTime() const {
return m_initial_time;
}

//! Get the maximum integrator step.
double maxTimeStep() {
return m_maxstep;
Expand Down Expand Up @@ -316,6 +324,9 @@ class ReactorNet : public FuncEval
//! on the type of reactors in the network.
double m_time = 0.0;

//! The initial value of the independent variable in the system.
double m_initial_time = 0.0;

bool m_init = false;
bool m_integrator_init = false; //!< True if integrator initialization is current
size_t m_nv = 0;
Expand Down
76 changes: 76 additions & 0 deletions include/cantera/zeroD/Wall.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,44 @@ class WallBase
/*!
* This method is called by Reactor::evalWalls(). Base class method
* does nothing (that is, constant volume), but may be overloaded.
* @deprecated To be removed after Cantera 3.0; replaceable by expansionRate.
*/
virtual double vdot(double t) {
warn_deprecated("WallBase::vdot",
"To be removed after Cantera 3.0; replaceable by 'expansionRate'.");
return 0.0;
}

//! Rate of volume change (m^3/s) for the adjacent reactors at current reactor
//! network time.
/*!
* This method is called by Reactor::evalWalls(). Base class method
* does nothing (that is, constant volume), but may be overloaded.
* @since New in Cantera 3.0.
*/
virtual double expansionRate() {
return 0.0;
}

//! Heat flow rate through the wall (W).
/*!
* This method is called by Reactor::evalWalls(). Base class method
* does nothing (that is, an adiabatic wall), but may be overloaded.
* @deprecated To be removed after Cantera 3.0; replaceable by heatRate.
*/
virtual double Q(double t) {
warn_deprecated("WallBase::Q",
"To be removed after Cantera 3.0; replaceable by 'heatRate'.");
return 0.0;
}

//! Heat flow rate through the wall (W) at current reactor network time.
/*!
* This method is called by Reactor::evalWalls(). Base class method
* does nothing (that is, an adiabatic wall), but may be overloaded.
* @since New in Cantera 3.0.
*/
virtual double heatRate() {
return 0.0;
}

Expand Down Expand Up @@ -83,12 +110,23 @@ class WallBase
return *m_right;
}

//! Set current reactor network time
/*!
* @since New in Cantera 3.0.
*/
void setSimTime(double time) {
m_time = time;
}

protected:
ReactorBase* m_left = nullptr;
ReactorBase* m_right = nullptr;

std::vector<ReactorSurface> m_surf;

//! current reactor network time
double m_time = 0.0;

double m_area = 1.0;
};

Expand All @@ -108,6 +146,10 @@ class Wall : public WallBase
return "Wall";
}

//! Wall velocity \f$ v(t) \f$ at current reactor network time.
//! @since New in Cantera 3.0.
double velocity() const;

//! Set the wall velocity to a specified function of time, \f$ v(t) \f$.
void setVelocity(Func1* f=0) {
if (f) {
Expand All @@ -125,9 +167,29 @@ class Wall : public WallBase
* area, and *F(t)* is a specified function of time. Positive values for
* `vdot` correspond to increases in the volume of reactor on left, and
* decreases in the volume of the reactor on the right.
* @deprecated Still used by traditional MATLAB toolbox; replaceable by
* expansionRate.
*/
virtual double vdot(double t);

//! Rate of volume change (m^3/s) for the adjacent reactors.
/*!
* The volume rate of change is given by
* \f[
* \dot V = K A (P_{left} - P_{right}) + F(t)
* \f]
* where *K* is the specified expansion rate coefficient, *A* is the wall area,
* and and *F(t)* is a specified function evaluated at the current network time.
* Positive values for `expansionRate` correspond to increases in the volume of
* reactor on left, and decreases in the volume of the reactor on the right.
* @since New in Cantera 3.0.
*/
virtual double expansionRate();

//! Heat flux function \f$ q_0(t) \f$ evaluated at current reactor network time.
//! @since New in Cantera 3.0.
double heatFlux() const;

//! Specify the heat flux function \f$ q_0(t) \f$.
void setHeatFlux(Func1* q) {
m_qf = q;
Expand All @@ -142,9 +204,23 @@ class Wall : public WallBase
* where *h* is the heat transfer coefficient, *A* is the wall area, and
* *G(t)* is a specified function of time. Positive values denote a flux
* from left to right.
* @deprecated Still used by traditional MATLAB toolbox; replaceable by heatRate.
*/
virtual double Q(double t);

//! Heat flow rate through the wall (W).
/*!
* The heat flux is given by
* \f[
* Q = h A (T_{left} - T_{right}) + A G(t)
* \f]
* where *h* is the heat transfer coefficient, *A* is the wall area, and
* *G(t)* is a specified function of time evaluated at the current network
* time. Positive values denote a flux from left to right.
* @since New in Cantera 3.0.
*/
virtual double heatRate();

void setThermalResistance(double Rth) {
m_rrth = 1.0/Rth;
}
Expand Down
22 changes: 14 additions & 8 deletions include/cantera/zeroD/flowControllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MassFlowController : public FlowDevice

/**
* A class for flow controllers where the flow rate is equal to the flow rate
* of a "master" mass flow controller plus a correction proportional to the
* of a primary mass flow controller plus a correction proportional to the
* pressure difference between the inlet and outlet.
*/
class PressureController : public FlowDevice
Expand All @@ -69,15 +69,21 @@ class PressureController : public FlowDevice
return "PressureController";
}


virtual bool ready() {
return FlowDevice::ready() && m_master != 0;
return FlowDevice::ready() && m_primary != 0;
}

void setMaster(FlowDevice* master) {
m_master = master;
//! Set the primary mass flow controller.
/*!
* @since New in Cantera 3.0.
*/
void setPrimary(FlowDevice* primary) {
m_primary = primary;
}

//! @deprecated To be removed after Cantera 3.0; replaced by setPrimary.
void setMaster(FlowDevice* master);

virtual void setTimeFunction(Func1* g) {
throw NotImplementedError("PressureController::setTimeFunction");
}
Expand All @@ -86,11 +92,11 @@ class PressureController : public FlowDevice
//! rate
/*!
* *c* has units of kg/s/Pa. The mass flow rate is computed as:
* \f[\dot{m} = \dot{m}_{master} + c f(\Delta P) \f]
* \f[\dot{m} = \dot{m}_{primary} + c f(\Delta P) \f]
* where *f* is a functions of pressure drop that is set by
* `setPressureFunction`. If no functions is specified, the mass flow
* rate defaults to:
* \f[\dot{m} = \dot{m}_{master} + c \Delta P \f]
* \f[\dot{m} = \dot{m}_{primary} + c \Delta P \f]
*/
void setPressureCoeff(double c) {
m_coeff = c;
Expand All @@ -104,7 +110,7 @@ class PressureController : public FlowDevice
virtual void updateMassFlowRate(double time);

protected:
FlowDevice* m_master = nullptr;
FlowDevice* m_primary = nullptr;
};

//! Supply a mass flow rate that is a function of the pressure drop across the
Expand Down
Loading