6#ifndef CT_REACTORDELEGATOR_H
7#define CT_REACTORDELEGATOR_H
58 template <
class... Args>
60 : R(std::forward<Args>(args)...)
62 install(
"initialize", m_initialize, [
this](
double t0) { R::initialize(t0); });
64 [
this](span<double> y) {
67 install(
"updateState", m_updateState,
68 [
this](span<double> y) {
71 install(
"updateConnected", m_updateConnected,
72 [
this](
bool updatePressure) { R::updateConnected(updatePressure); });
74 [
this](
double t, span<double> LHS, span<double> RHS) {
78 if constexpr (std::is_base_of<Reactor, R>::value) {
79 install(
"evalWalls", m_evalWalls, [
this](
double t) { R::evalWalls(t); });
81 install(
"componentName", m_componentName,
82 [
this](
size_t k) {
return R::componentName(k); });
83 install(
"componentIndex", m_componentIndex,
84 [
this](
const string& nm) {
return R::componentIndex(nm); });
89 string type()
const override {
90 return fmt::format(
"Extensible{}", R::type());
93 void initialize(
double t0)
override {
97 void getState(span<double> y)
override {
102 void updateState(span<const double> y)
override {
103 checkArraySize(
"ReactorDelegator::updateState", y.size(), R::m_nv);
107 void updateConnected(
bool updatePressure)
override {
108 m_updateConnected(updatePressure);
111 void eval(
double t, span<double> LHS, span<double> RHS)
override {
112 checkArraySize(
"ReactorDelegator::eval[LHS]", LHS.size(), R::m_nv);
113 checkArraySize(
"ReactorDelegator::eval[RHS]", RHS.size(), R::m_nv);
117 void evalWalls(
double t)
override {
118 if constexpr (std::is_base_of<Reactor, R>::value) {
125 string componentName(
size_t k)
override {
126 return m_componentName(k);
129 size_t componentIndex(
const string& nm)
const override {
130 return m_componentIndex(nm);
140 if constexpr (std::is_base_of<Reactor, R>::value) {
144 "Expansion rate is undefined for reactors of type '{}'.", type());
149 if constexpr (std::is_base_of<Reactor, R>::value) {
153 "Expansion rate is undefined for reactors of type '{}'.", type());
158 if constexpr (std::is_base_of<Reactor, R>::value) {
162 "Heat rate is undefined for reactors of type '{}'.", type());
167 if constexpr (std::is_base_of<Reactor, R>::value) {
171 "Heat rate is undefined for reactors of type '{}'.", type());
180 function<void(
double)> m_initialize;
181 function<void(span<double>)> m_getState;
182 function<void(span<double>)> m_updateState;
183 function<void(
bool)> m_updateConnected;
184 function<void(
double, span<double>, span<double>)> m_eval;
185 function<void(
double)> m_evalWalls;
186 function<string(
size_t)> m_componentName;
187 function<size_t(
const string&)> m_componentIndex;
Header file for class ReactorSurface.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Delegate member functions of a C++ class to externally-specified functions.
void install(const string &name, function< void()> &target, const function< void()> &func)
Install a function with the signature void() as being delegatable.
span< double > stripConst(const span< const double > &s)
Helper to remove const for cases where the delegated function signature uses span<const double>.
An error indicating that an unimplemented function has been called.
An abstract base class for providing access to protected capabilities Reactor objects from delegate m...
virtual void setNEq(size_t n)=0
Set the number of equations represented by this reactor.
virtual span< double > surfaceProductionRates()=0
Production rates on surfaces.
virtual void setHeatRate(double q)=0
Set the net heat transfer rate (for example, through walls) into the reactor [W].
virtual void setExpansionRate(double v)=0
Set the net rate of volume change (for example, from moving walls) [m^3/s].
virtual double heatRate() const =0
Get the net heat transfer rate (for example, through walls) into the reactor [W].
virtual double expansionRate() const =0
Get the net rate of volume change (for example, from moving walls) [m^3/s].
virtual void evalWalls(double t)
Evaluate contributions from walls connected to this reactor.
Delegate methods of the Reactor class to external functions.
void setNEq(size_t n) override
Set the number of equations represented by this reactor.
double heatRate() const override
Get the net heat transfer rate (for example, through walls) into the reactor [W].
double expansionRate() const override
Get the net rate of volume change (for example, from moving walls) [m^3/s].
span< double > surfaceProductionRates() override
Production rates on surfaces.
void setExpansionRate(double v) override
Set the net rate of volume change (for example, from moving walls) [m^3/s].
void setHeatRate(double q) override
Set the net heat transfer rate (for example, through walls) into the reactor [W].
Namespace for the Cantera kernel.
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.