Go to the documentation of this file.
13 #include <boost/math/tools/roots.hpp>
16 namespace bmt = boost::math::tools;
44 "Error: reactor is empty.");
69 for (
auto& S : m_surfaces) {
70 S->getCoverages(y + loc);
71 loc += S->thermo()->nSpecies();
77 if (!m_thermo || (m_chem && !
m_kin)) {
78 throw CanteraError(
"Reactor::initialize",
"Reactor contents not set"
79 " for reactor '" + m_name +
"'.");
86 for (
size_t n = 0; n < m_wall.size(); n++) {
93 for (
auto& S : m_surfaces) {
94 m_nv += S->thermo()->nSpecies();
95 size_t nt = S->kinetics()->nTotalSpecies();
96 maxnt = std::max(maxnt, nt);
97 if (m_chem && &
m_kin->
thermo(0) != &S->kinetics()->thermo(0)) {
99 "First phase of all kinetics managers must be the gas.");
102 m_work.resize(maxnt);
107 size_t ns = m_sensParams.size();
108 for (
auto& S : m_surfaces) {
109 ns += S->nSensParams();
132 auto u_err = [
this, U](
double T) {
138 boost::uintmax_t maxiter = 100;
139 std::pair<double, double> TT;
141 TT = bmt::bracket_and_solve_root(
142 u_err, T, 1.2,
true, bmt::eps_tolerance<double>(48), maxiter);
143 }
catch (std::exception&) {
148 bmt::eps_tolerance<double>(48), maxiter);
149 }
catch (std::exception& err2) {
153 "{}\nat U = {}, rho = {}", err2.what(), U,
m_mass / m_vol);
156 if (fabs(TT.first - TT.second) > 1e-7*TT.first) {
157 throw CanteraError(
"Reactor::updateState",
"root finding failed");
171 for (
auto& S : m_surfaces) {
172 S->setCoverages(y+loc);
173 loc += S->thermo()->nSpecies();
180 if (updatePressure) {
188 for (
size_t i = 0; i < m_outlet.size(); i++) {
189 m_outlet[i]->updateMassFlowRate(time);
191 for (
size_t i = 0; i < m_inlet.size(); i++) {
192 m_inlet[i]->updateMassFlowRate(time);
197 doublereal* ydot, doublereal* params)
200 double* dYdt = ydot + 3;
218 for (
size_t k = 0; k <
m_nsp; k++) {
222 dYdt[k] -= Y[k] * mdot_surf /
m_mass;
236 for (
auto outlet : m_outlet) {
240 ydot[2] -= mdot * m_enthalpy;
245 for (
auto inlet : m_inlet) {
248 for (
size_t n = 0; n <
m_nsp; n++) {
251 dYdt[n] += (mdot_spec - mdot * Y[n]) /
m_mass;
266 for (
size_t i = 0; i < m_wall.size(); i++) {
267 int lr = 1 - 2*m_lr[i];
268 m_vdot += lr*m_wall[i]->vdot(t);
269 m_Q += lr*m_wall[i]->Q(t);
278 double mdot_surf = 0.0;
280 for (
auto S : m_surfaces) {
292 for (
size_t k = 1; k < nk; k++) {
293 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->
size(k);
294 sum -= ydot[loc + k];
300 double wallarea = S->area();
301 for (
size_t k = 0; k <
m_nsp; k++) {
302 m_sdot[k] += m_work[bulkloc + k] * wallarea;
303 mdot_surf +=
m_sdot[k] * mw[k];
313 "Reaction number out of range ({})", rxn);
318 m_sensParams.emplace_back(
319 SensitivityParameter{rxn, p, 1.0, SensParameterType::reaction});
325 throw CanteraError(
"Reactor::addSensitivitySpeciesEnthalpy",
326 "Species index out of range ({})", k);
332 m_sensParams.emplace_back(
333 SensitivityParameter{k, p, m_thermo->
Hf298SS(k),
334 SensParameterType::enthalpy});
346 size_t offset =
m_nsp;
347 for (
auto& S : m_surfaces) {
364 }
else if (nm ==
"mass") {
366 }
else if (nm ==
"volume") {
368 }
else if (nm ==
"int_energy") {
382 }
else if (k >= 3 && k <
neq()) {
384 if (k < m_thermo->nSpecies()) {
389 for (
auto& S : m_surfaces) {
391 if (k < th->nSpecies()) {
398 throw CanteraError(
"Reactor::componentName",
"Index is out of bounds.");
406 for (
auto& p : m_sensParams) {
407 if (p.type == SensParameterType::reaction) {
410 }
else if (p.type == SensParameterType::enthalpy) {
414 for (
auto& S : m_surfaces) {
415 S->setSensitivityParameters(params);
419 m_kin->invalidateCache();
428 for (
auto& p : m_sensParams) {
429 if (p.type == SensParameterType::reaction) {
431 }
else if (p.type == SensParameterType::enthalpy) {
435 for (
auto& S : m_surfaces) {
436 S->resetSensitivityParameters();
440 m_kin->invalidateCache();
448 "Error: reactor is empty.");
454 [](
double val){return val>0;})) {
465 std::fill(limits, limits + m_nv, -1.0);
476 "Error: reactor is empty.");
481 "Cannot set limit on a reactor that is not "
482 "assigned to a ReactorNet object.");
486 }
else if (k > m_nv) {
488 "Index out of bounds.");
495 [](
double val){return val>0;})) {
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
doublereal time()
Current value of the simulation time.
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
virtual double evalSurfaces(double t, double *ydot)
Evaluate terms related to surface reactions.
virtual void modifyOneHf298SS(const size_t k, const doublereal Hf298New)
Modify the value of the 298 K Heat of Formation of one species in the phase (J kmol-1)
bool hasAdvanceLimits()
Check whether Reactor object uses advance limits.
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
virtual void addSensitivitySpeciesEnthalpy(size_t k)
Add a sensitivity parameter associated with the enthalpy formation of species k (in the homogeneous p...
doublereal intEnergy_mass() const
Specific internal energy. Units: J/kg.
const double * massFractions() const
Return a const pointer to the mass fraction array.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
Public interface for kinetics managers.
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object.
virtual void getState(doublereal *y)
Get the the current state of the reactor.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual size_t componentIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the component named nm.
double massFlowRate(double time=-999.0)
Mass flow rate (kg/s).
virtual void updateConnected(bool updatePressure)
Update the state information needed by connected reactors and flow devices.
void setState_TR(doublereal t, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
doublereal m_vdot
net rate of volume change from moving walls [m^3/s]
virtual void initialize()
Called just before the start of integration.
virtual double density() const
Density (kg/m^3).
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
virtual void setMassFractions_NoNorm(const double *const y)
Set the mass fractions to the specified values without normalizing.
vector_fp m_advancelimits
Advance step limit.
size_t m_nsp
Number of homogeneous species in the mixture.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
void initialize()
Initialize the reactor network.
ReactorNet * m_net
The ReactorNet that this reactor is part of.
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
void setAdvanceLimit(const std::string &nm, const double limit)
Set individual step size limit for compoment name nm
bool getAdvanceLimits(double *limits)
Retrieve absolute step size limits during advance.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
virtual void setKineticsMgr(Kinetics &kin)
Specify chemical kinetics governing the reactor.
void saveState(vector_fp &state) const
Save the current internal state of the phase.
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
doublereal m_mass
total mass
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
doublereal Hf298SS(const size_t k) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1)
Base class for a phase with thermodynamic properties.
virtual void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
std::string name() const
Return the name of this reactor.
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
size_t registerSensitivityParameter(const std::string &name, double value, double scale)
Used by Reactor and Wall objects to register the addition of sensitivity parameters so that the React...
virtual size_t neq()
Number of equations (state variables) for this reactor.
doublereal temperature() const
Temperature (K).
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn (in the homogeneous phase).
size_t nSpecies() const
Returns the number of species in the phase.
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
virtual size_t speciesIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the species named nm, in either the homog...
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
doublereal siteDensity()
Returns the site density.
const double GasConstant
Universal Gas Constant [J/kmol/K].
void setAdvanceLimits(const double *limits)
Set absolute step size limits during advance.
ReactorNet & network()
The ReactorNet that this reactor belongs to.
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Base class for exceptions thrown by Cantera classes.
virtual std::string componentName(size_t k)
Return the name of the solution component with index i.
void getMassFractions(double *const y) const
Get the species mass fractions.
size_t nReactions() const
Number of reactions in the reaction mechanism.
const size_t npos
index returned by functions to indicate "no position"
std::string reactionString(size_t i) const
Return a string representing the reaction.
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Namespace for the Cantera kernel.
std::string speciesName(size_t k) const
Name of the species with index k.
double enthalpy_mass()
specific enthalpy
size_t surfacePhaseIndex() const
This returns the integer index of the phase which has ThermoPhase type cSurf.
virtual void evalWalls(double t)
Evaluate terms related to Walls.
virtual void resetHf298(const size_t k=npos)
Restore the original heat of formation of one or more species.
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
doublereal m_Q
net heat transfer through walls [W]
vector_fp m_wdot
Species net molar production rates.
virtual double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.