33 cout <<
"Error: reactor is empty." << endl;
59 for (
size_t m = 0; m < m_wall.size(); m++) {
60 SurfPhase* surf = m_wall[m]->surface(m_lr[m]);
62 m_wall[m]->getCoverages(m_lr[m], y + loc);
70 if (!m_thermo || !
m_kin) {
71 throw CanteraError(
"Reactor::initialize",
"Reactor contents not set"
72 " for reactor '" + m_name +
"'.");
78 for (
size_t w = 0; w < m_wall.size(); w++)
79 if (m_wall[w]->surface(m_lr[w])) {
80 m_nv += m_wall[w]->surface(m_lr[w])->nSpecies();
87 size_t nt = 0, maxnt = 0;
88 for (
size_t m = 0; m < m_wall.size(); m++) {
89 m_wall[m]->initialize();
90 if (m_wall[m]->kinetics(m_lr[m])) {
91 nt = m_wall[m]->kinetics(m_lr[m])->nTotalSpecies();
92 maxnt = std::max(maxnt, nt);
93 if (m_wall[m]->kinetics(m_lr[m])) {
95 &m_wall[m]->kinetics(m_lr[m])->thermo(0)) {
97 "First phase of all kinetics managers must be"
103 m_work.resize(maxnt);
104 std::sort(m_pnum.begin(), m_pnum.end());
109 if (m_nsens ==
npos) {
112 m_nsens = m_pnum.size();
113 for (m = 0; m < m_wall.size(); m++) {
114 ns = m_wall[m]->nSensParams(m_lr[m]);
115 m_nsens_wall.push_back(ns);
130 for (
size_t i = 0; i < m_nv; i++) {
132 "y[" +
int2str(i) +
"] is not finite");
151 double dUprev = 1e10;
156 while (abs(dT / T) > 10 * DBL_EPSILON) {
164 if (std::abs(dU) < std::abs(dUprev)) {
169 dT = std::min(dT, 0.5 * T) * damp;
173 std::string message =
"no convergence";
175 message +=
"\nT = " +
fp2str(T);
197 for (
size_t m = 0; m < m_wall.size(); m++) {
198 SurfPhase* surf = m_wall[m]->surface(m_lr[m]);
200 m_wall[m]->setCoverages(m_lr[m], y+loc);
207 doublereal* ydot, doublereal* params)
210 double* dYdt = ydot + 3;
228 for (
size_t k = 0; k <
m_nsp; k++) {
232 dYdt[k] -= Y[k] * mdot_surf /
m_mass;
249 for (
size_t i = 0; i < m_outlet.size(); i++) {
250 double mdot_out = m_outlet[i]->massFlowRate(time);
253 ydot[2] -= mdot_out * m_enthalpy;
258 for (
size_t i = 0; i < m_inlet.size(); i++) {
259 double mdot_in = m_inlet[i]->massFlowRate(time);
261 for (
size_t n = 0; n <
m_nsp; n++) {
262 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
264 dYdt[n] += (mdot_spec - mdot_in * Y[n]) /
m_mass;
267 ydot[2] += mdot_in * m_inlet[i]->enthalpy_mass();
273 for (
size_t i = 0; i < m_nv; i++) {
275 "ydot[" +
int2str(i) +
"] is not finite");
285 for (
size_t i = 0; i < m_wall.size(); i++) {
286 int lr = 1 - 2*m_lr[i];
287 m_vdot += lr*m_wall[i]->vdot(t);
288 m_Q += lr*m_wall[i]->Q(t);
298 double mdot_surf = 0.0;
300 for (
size_t i = 0; i < m_wall.size(); i++) {
301 Kinetics* kin = m_wall[i]->kinetics(m_lr[i]);
302 SurfPhase* surf = m_wall[i]->surface(m_lr[i]);
308 m_wall[i]->syncCoverages(m_lr[i]);
312 for (
size_t k = 1; k < nk; k++) {
313 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->
size(k);
314 sum -= ydot[loc + k];
319 double wallarea = m_wall[i]->area();
320 for (
size_t k = 0; k <
m_nsp; k++) {
321 m_sdot[k] += m_work[k]*wallarea;
322 mdot_surf +=
m_sdot[k] * mw[k];
333 "Reaction number out of range ("+
int2str(rxn)+
")");
337 m_pnum.push_back(rxn);
338 m_mult_save.push_back(1.0);
343 std::vector<std::pair<void*, int> > order;
344 order.push_back(std::make_pair(const_cast<Reactor*>(
this), 0));
345 for (
size_t n = 0; n < m_wall.size(); n++) {
346 if (m_nsens_wall[n]) {
347 order.push_back(std::make_pair(m_wall[n], m_lr[n]));
362 size_t walloffset = 0, kp = 0;
364 for (
size_t m = 0; m < m_wall.size(); m++) {
365 if (m_wall[m]->kinetics(m_lr[m])) {
366 kp = m_wall[m]->kinetics(m_lr[m])->reactionPhaseIndex();
367 th = &m_wall[m]->kinetics(m_lr[m])->thermo(kp);
370 return k +
m_nsp + walloffset;
384 }
else if (nm ==
"m" || nm ==
"mass") {
386 }
else if (nm ==
"V" || nm ==
"volume") {
388 }
else if (nm ==
"U" || nm ==
"int_energy") {
400 size_t npar = m_pnum.size();
401 for (
size_t n = 0; n < npar; n++) {
406 for (
size_t m = 0; m < m_wall.size(); m++) {
407 if (m_nsens_wall[m] > 0) {
408 m_wall[m]->setSensitivityParameters(m_lr[m], params + ploc);
409 ploc += m_nsens_wall[m];
420 size_t npar = m_pnum.size();
421 for (
size_t n = 0; n < npar; n++) {
426 for (
size_t m = 0; m < m_wall.size(); m++) {
427 if (m_nsens_wall[m] > 0) {
428 m_wall[m]->resetSensitivityParameters(m_lr[m]);
429 ploc += m_nsens_wall[m];
const std::string & reactionString(size_t i) const
Return a string representing the reaction.
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
virtual doublereal density() const
Density (kg/m^3).
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
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)
Header file for class Wall.
vector_fp m_wdot
Species net molar production rates.
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
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.
doublereal size(size_t k) const
This routine returns the size of species k.
virtual void evalWalls(double t)
Evaluate terms related to Walls Calculates m_vdot and m_Q based on wall movement and heat transfer...
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
#define AssertFinite(expr, procedure, message)
Throw an exception if the specified exception is not a finite number.
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
doublereal intEnergy_mass() const
Specific internal energy.
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.
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 speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
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...
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
virtual double evalSurfaces(double t, double *ydot)
Evaluate terms related to surface reactions Calculates m_sdot and rate of change in surface species c...
Public interface for kinetics managers.
Base class for exceptions thrown by Cantera classes.
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...
doublereal cv_mass() const
Specific heat at constant volume.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
std::string name() const
Return the name of this reactor.
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
void registerSensitivityReaction(void *reactor, size_t reactionIndex, const std::string &name, int leftright=0)
Used by Reactor and Wall objects to register the addition of sensitivity reactions so that the Reacto...
size_t nSpecies() const
Returns the number of species in the phase.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
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 void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
doublereal enthalpy_mass() const
Specific enthalpy.
size_t nReactions() const
Number of reactions in the reaction mechanism.
std::vector< std::pair< void *, int > > getSensitivityOrder() const
Return a vector specifying the ordering of objects to use when determining sensitivity parameter indi...
size_t m_nsp
Number of homogeneous species in the mixture.
void saveState(vector_fp &state) const
Save the current internal state of the phase Write to vector 'state' the current internal state...
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 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]
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.
doublereal temperature() const
Returns the current temperature (K) of the reactor's contents.
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
doublereal siteDensity()
Returns the site density.