13 #include <boost/math/tools/roots.hpp> 16 namespace bmt = boost::math::tools;
30 void Reactor::setKineticsMgr(Kinetics& kin)
43 "Use getState instead. To be removed after Cantera 2.3.");
51 "Error: reactor is empty.");
76 for (
auto& S : m_surfaces) {
77 S->getCoverages(y + loc);
78 loc += S->thermo()->nSpecies();
84 if (!m_thermo || (m_chem && !
m_kin)) {
85 throw CanteraError(
"Reactor::initialize",
"Reactor contents not set" 86 " for reactor '" + m_name +
"'.");
96 for (
size_t n = 0; n < m_wall.size(); n++) {
106 for (
auto& S : m_surfaces) {
107 m_nv += S->thermo()->nSpecies();
108 size_t nt = S->kinetics()->nTotalSpecies();
109 maxnt = std::max(maxnt, nt);
110 if (m_chem && &
m_kin->
thermo(0) != &S->kinetics()->thermo(0)) {
112 "First phase of all kinetics managers must be the gas.");
115 m_work.resize(maxnt);
120 size_t ns = m_sensParams.size();
121 for (
auto& S : m_surfaces) {
122 ns += S->nSensParams();
145 auto u_err = [
this, U](
double T) {
151 boost::uintmax_t maxiter = 100;
152 std::pair<double, double> TT;
154 TT = bmt::bracket_and_solve_root(
155 u_err, T, 1.2,
true, bmt::eps_tolerance<double>(48), maxiter);
156 }
catch (std::exception& err) {
161 if (fabs(TT.first - TT.second) > 1e-7*TT.first) {
163 "bracket_and_solve_root failed");
182 for (
auto& S : m_surfaces) {
183 S->setCoverages(y+loc);
184 loc += S->thermo()->nSpecies();
189 doublereal* ydot, doublereal* params)
192 double* dYdt = ydot + 3;
210 for (
size_t k = 0; k <
m_nsp; k++) {
214 dYdt[k] -= Y[k] * mdot_surf /
m_mass;
228 for (
size_t i = 0; i < m_outlet.size(); i++) {
229 double mdot_out = m_outlet[i]->massFlowRate(time);
232 ydot[2] -= mdot_out * m_enthalpy;
237 for (
size_t i = 0; i < m_inlet.size(); i++) {
238 double mdot_in = m_inlet[i]->massFlowRate(time);
240 for (
size_t n = 0; n <
m_nsp; n++) {
241 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
243 dYdt[n] += (mdot_spec - mdot_in * Y[n]) /
m_mass;
246 ydot[2] += mdot_in * m_inlet[i]->enthalpy_mass();
258 for (
size_t i = 0; i < m_wall.size(); i++) {
259 int lr = 1 - 2*m_lr[i];
260 m_vdot += lr*m_wall[i]->vdot(t);
261 m_Q += lr*m_wall[i]->Q(t);
270 double mdot_surf = 0.0;
272 for (
auto S : m_surfaces) {
284 for (
size_t k = 1; k < nk; k++) {
285 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->
size(k);
286 sum -= ydot[loc + k];
291 double wallarea = S->area();
292 for (
size_t k = 0; k <
m_nsp; k++) {
293 m_sdot[k] += m_work[k]*wallarea;
294 mdot_surf +=
m_sdot[k] * mw[k];
304 "Reaction number out of range ({})", rxn);
309 m_sensParams.emplace_back(
310 SensitivityParameter{rxn, p, 1.0, SensParameterType::reaction});
316 throw CanteraError(
"Reactor::addSensitivitySpeciesEnthalpy",
317 "Species index out of range ({})", k);
323 m_sensParams.emplace_back(
324 SensitivityParameter{k, p, m_thermo->
Hf298SS(k),
325 SensParameterType::enthalpy});
337 size_t offset =
m_nsp;
338 for (
auto& S : m_surfaces) {
355 }
else if (nm ==
"m" || nm ==
"mass") {
358 "Using the name 'm' for mass is deprecated, and will be " 359 "disabled after Cantera 2.3. Use 'mass' instead.");
362 }
else if (nm ==
"V" || nm ==
"volume") {
365 "Using the name 'V' for volume is deprecated, and will be " 366 "disabled after Cantera 2.3. Use 'volume' instead.");
369 }
else if (nm ==
"U" || nm ==
"int_energy") {
372 "Using the name 'U' for internal energy is deprecated, and " 373 "will be disabled after Cantera 2.3. Use 'int_energy' instead.");
388 }
else if (k >= 3 && k <
neq()) {
390 if (k < m_thermo->nSpecies()) {
395 for (
auto& S : m_surfaces) {
397 if (k < th->nSpecies()) {
404 throw CanteraError(
"Reactor::componentName",
"Index is out of bounds.");
412 for (
auto& p : m_sensParams) {
413 if (p.type == SensParameterType::reaction) {
416 }
else if (p.type == SensParameterType::enthalpy) {
420 for (
auto& S : m_surfaces) {
421 S->setSensitivityParameters(params);
425 m_kin->invalidateCache();
434 for (
auto& p : m_sensParams) {
435 if (p.type == SensParameterType::reaction) {
437 }
else if (p.type == SensParameterType::enthalpy) {
441 for (
auto& S : m_surfaces) {
442 S->resetSensitivityParameters();
446 m_kin->invalidateCache();
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
doublereal m_mass
total mass
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
Header file for class Wall.
vector_fp m_wdot
Species net molar production rates.
doublereal temperature() const
Temperature (K).
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
void saveState(vector_fp &state) const
Save the current internal state of the phase.
const size_t npos
index returned by functions to indicate "no position"
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn (in the homogeneous phase)...
ReactorNet & network()
The ReactorNet that this reactor belongs to.
virtual void evalWalls(double t)
Evaluate terms related to Walls.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
size_t nSpecies() const
Returns the number of species in the phase.
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
virtual doublereal density() const
Density (kg/m^3).
doublereal enthalpy_mass() const
Specific enthalpy. Units: J/kg.
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...
virtual std::string componentName(size_t k)
Return the name of the solution component with index i.
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
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 void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Base class for a phase with thermodynamic properties.
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
doublereal Hf298SS(const size_t k) const
Report the 298 K Heat of Formation of the standard state of one species (J kmol-1) ...
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected...
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
ReactorSurface * reactorSurface(int leftright)
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
std::string speciesName(size_t k) const
Name of the species with index k.
Represents a wall between between two ReactorBase objects.
doublereal m_Q
net heat transfer through walls [W]
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object...
virtual double evalSurfaces(double t, double *ydot)
Evaluate terms related to surface reactions.
Public interface for kinetics managers.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
virtual void getState(doublereal *y)
Get the the current state of the reactor.
Base class for exceptions thrown by Cantera classes.
size_t nReactions() const
Number of reactions in the reaction mechanism.
std::string reactionString(size_t i) const
Return a string representing the reaction.
virtual void initialize()
Called just before the start of integration.
virtual void resetHf298(const size_t k=npos)
Restore the original heat of formation of one or more species.
Header file for class ReactorSurface.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Kinetics * kinetics(int leftright)
Return a pointer to the surface kinetics object for the left (leftright=0) or right (leftright=1) wal...
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object...
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.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
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) ...
size_t m_nsp
Number of homogeneous species in the mixture.
virtual size_t neq()
Number of equations (state variables) for this reactor.
doublereal size(size_t k) const
This routine returns the size of species k.
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
doublereal m_vdot
net rate of volume change from moving walls [m^3/s]
Namespace for the Cantera kernel.
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.
void setState_TR(doublereal t, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase.
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
doublereal siteDensity()
Returns the site density.
std::string name() const
Return the name of this reactor.