13#include <boost/math/tools/roots.hpp>
16namespace bmt = boost::math::tools;
24 for (
auto& S : m_surfaces) {
25 double area = S->area();
26 auto currPhase = S->thermo();
27 size_t tempLoc = currPhase->nSpecies();
28 double surfDensity = currPhase->siteDensity();
29 S->getCoverages(y + loc);
31 for (
size_t i = 0; i < tempLoc; i++) {
32 y[i + loc] = y[i + loc] * area * surfDensity / currPhase->size(i);
47 vector<double> coverages(m_nv_surf, 0.0);
48 for (
auto& S : m_surfaces) {
49 auto surf = S->thermo();
50 double invArea = 1/S->area();
51 double invSurfDensity = 1/surf->siteDensity();
52 size_t tempLoc = surf->nSpecies();
53 for (
size_t i = 0; i < tempLoc; i++) {
54 coverages[i + loc] = y[i + loc] * invArea * surf->size(i) * invSurfDensity;
56 S->setCoverages(coverages.data()+loc);
63 fill(sdot, sdot +
m_nsp, 0.0);
65 for (
auto S : m_surfaces) {
68 double wallarea = S->area();
74 for (
size_t k = 0; k < nk; k++) {
75 RHS[loc + k] = m_work[surfloc + k] * wallarea / surf->
size(k);
81 for (
size_t k = 0; k <
m_nsp; k++) {
82 sdot[k] += m_work[bulkloc + k] * wallarea;
90 for (
auto& S : m_surfaces) {
93 auto kin = S->kinetics();
94 size_t nk = S->thermo()->nSpecies();
96 size_t spi = kin->reactionPhaseIndex();
97 size_t gpi = kin->speciesPhaseIndex(kin->kineticsSpeciesIndex(
100 Eigen::SparseMatrix<double> surfJac = kin->netProductionRates_ddCi();
103 for (
int k=0; k<surfJac.outerSize(); ++k) {
104 for (Eigen::SparseMatrix<double>::InnerIterator it(surfJac, k); it; ++it) {
105 size_t row = it.row();
106 size_t col = it.col();
107 auto& rowPhase = kin->speciesPhase(row);
108 auto& colPhase = kin->speciesPhase(col);
109 size_t rpi = kin->phaseIndex(rowPhase.name());
110 size_t cpi = kin->phaseIndex(colPhase.name());
114 if ((rpi == spi || rpi == gpi) && (cpi == spi || cpi == gpi) ) {
116 row -= kin->kineticsSpeciesIndex(0, rpi);
117 col -= kin->kineticsSpeciesIndex(0, cpi);
121 row = (rpi != spi) ? row : row +
offset;
133 triplets.emplace_back(
static_cast<int>(row),
static_cast<int>(col),
134 scalar * it.value());
148 for (
size_t i = 0; i <
m_nsp; i++) {
149 y[i] =
m_mass * imw[i] * Y[i];
158 for (
size_t i = 0; i <
m_nsp; i++) {
167 "Error: reactor is empty.");
193 auto u_err = [
this, U](
double T) {
198 boost::uintmax_t maxiter = 100;
199 pair<double, double> TT;
201 TT = bmt::bracket_and_solve_root(
202 u_err, T, 1.2,
true, bmt::eps_tolerance<double>(48), maxiter);
203 }
catch (std::exception&) {
208 bmt::eps_tolerance<double>(48), maxiter);
209 }
catch (std::exception& err2) {
213 "{}\nat U = {}, rho = {}", err2.what(), U,
m_mass /
m_vol);
216 if (fabs(TT.first - TT.second) > 1e-7*TT.first) {
217 throw CanteraError(
"MoleReactor::updateState",
"root finding failed");
229 double* dndt = RHS +
m_sidx;
254 for (
size_t k = 0; k <
m_nsp; k++) {
260 for (
auto outlet : m_outlet) {
262 for (
size_t n = 0; n <
m_nsp; n++) {
273 for (
auto inlet : m_inlet) {
275 for (
size_t n = 0; n <
m_nsp; n++) {
291 }
else if (nm ==
"int_energy") {
293 }
else if (nm ==
"volume") {
307 if (k < m_thermo->nSpecies()) {
312 for (
auto& S : m_surfaces) {
314 if (k < th->nSpecies()) {
321 throw CanteraError(
"MoleReactor::componentName",
"Index is out of bounds.");
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Header file for class ReactorSurface.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Base class for exceptions thrown by Cantera classes.
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
double enthalpy_mass()
specific enthalpy
double massFlowRate()
Mass flow rate (kg/s).
Public interface for kinetics managers.
size_t reactionPhaseIndex() const
Phase where the reactions occur.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
void evalSurfaces(double *LHS, double *RHS, double *sdot) override
Evaluate terms related to surface reactions.
void getSurfaceInitialConditions(double *y) override
Get initial conditions for SurfPhase objects attached to this reactor.
void getMoles(double *y)
Get moles of the system from mass fractions stored by thermo object.
void eval(double t, double *LHS, double *RHS) override
Evaluate the reactor governing equations.
size_t componentIndex(const string &nm) const override
Return the index in the solution vector for this reactor of the component named nm.
const size_t m_sidx
const value for the species start index
void setMassFromMoles(double *y)
Set internal mass variable based on moles given.
virtual void addSurfaceJacobian(vector< Eigen::Triplet< double > > &triplets)
For each surface in the reactor, update vector of triplets with all relevant surface jacobian derivat...
void getState(double *y) override
Get the the current state of the reactor.
string componentName(size_t k) override
Return the name of the solution component with index i.
void updateState(double *y) override
Set the state of the reactor to correspond to the state vector y.
void initialize(double t0=0.0) override
Initialize the reactor.
void updateSurfaceState(double *y) override
Update the state of SurfPhase objects attached to this reactor.
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
size_t nSpecies() const
Returns the number of species in the phase.
void setState_TD(double t, double rho)
Set the internally stored temperature (K) and density (kg/m^3)
double temperature() const
Temperature (K).
string speciesName(size_t k) const
Name of the species with index k.
virtual void setDensity(const double density_)
Set the internally stored density (kg/m^3) of the phase.
const vector< double > & inverseMolecularWeights() const
Return a const reference to the internal vector of molecular weights.
const double * massFractions() const
Return a const pointer to the mass fraction array.
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
virtual double density() const
Density (kg/m^3).
virtual void setMolesNoTruncate(const double *const N)
Set the state of the object with moles in [kmol].
virtual double pressure() const
Return the thermodynamic pressure (Pa).
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
FlowDevice & inlet(size_t n=0)
Return a reference to the n-th inlet FlowDevice connected to this reactor.
double m_vol
Current volume of the reactor [m^3].
size_t m_nsp
Number of homogeneous species in the mixture.
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
vector< double > m_wdot
Species net molar production rates.
virtual void evalWalls(double t)
Evaluate terms related to Walls.
size_t neq()
Number of equations (state variables) for this reactor.
double m_Qdot
net heat transfer into the reactor, through walls [W]
vector< double > m_sdot
Production rates of gas phase species on surfaces [kmol/s].
double m_vdot
net rate of volume change from moving walls [m^3/s]
void initialize(double t0=0.0) override
Initialize the reactor.
virtual size_t speciesIndex(const string &nm) const
Return the index in the solution vector for this reactor of the species named nm, in either the homog...
virtual void updateConnected(bool updatePressure)
Update the state information needed by connected reactors, flow devices, and reactor walls.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.
Base class for a phase with thermodynamic properties.
virtual double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
double intEnergy_mass() const
Specific internal energy. Units: J/kg.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
offset
Offsets of solution components in the 1D solution array.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...