20 Reactor::Reactor() : ReactorBase(),
33 cout <<
"Error: reactor is empty." << endl;
53 size_t loc =
m_nsp + 3;
55 for (
size_t m = 0; m < m_nwalls; m++) {
56 surf = m_wall[m]->surface(m_lr[m]);
58 m_wall[m]->getCoverages(m_lr[m], y + loc);
67 m_sdot.resize(
m_nsp, 0.0);
70 for (
size_t w = 0; w < m_nwalls; w++)
71 if (m_wall[w]->surface(m_lr[w])) {
72 m_nv += m_wall[w]->surface(m_lr[w])->nSpecies();
79 size_t nt = 0, maxnt = 0;
80 for (
size_t m = 0; m < m_nwalls; m++) {
81 m_wall[m]->initialize();
82 if (m_wall[m]->kinetics(m_lr[m])) {
83 nt = m_wall[m]->kinetics(m_lr[m])->nTotalSpecies();
87 if (m_wall[m]->kinetics(m_lr[m])) {
89 &m_wall[m]->kinetics(m_lr[m])->thermo(0)) {
91 "First phase of all kinetics managers must be"
98 std::sort(m_pnum.begin(), m_pnum.end());
104 if (m_nsens ==
npos) {
107 m_nsens = m_pnum.size();
108 for (m = 0; m < m_nwalls; m++) {
109 ns = m_wall[m]->nSensParams(m_lr[m]);
110 m_nsens_wall.push_back(ns);
119 for (
size_t i = 0; i < m_nv; i++) {
121 "y[" +
int2str(i) +
"] is not finite");
142 while (abs(dT / T) > 10 * DBL_EPSILON) {
146 dT = std::min(dT, 0.5 * T);
150 std::string message =
"no convergence";
152 message +=
"\nT = " +
fp2str(T);
162 size_t loc =
m_nsp + 3;
164 for (
size_t m = 0; m < m_nwalls; m++) {
165 surf = m_wall[m]->surface(m_lr[m]);
167 m_wall[m]->setCoverages(m_lr[m], y+loc);
180 doublereal* ydot, doublereal* params)
186 size_t npar = m_pnum.size();
187 for (
size_t n = 0; n < npar; n++) {
192 for (
size_t m = 0; m < m_nwalls; m++) {
193 if (m_nsens_wall[m] > 0) {
194 m_wall[m]->setSensitivityParameters(m_lr[m], params + ploc);
195 ploc += m_nsens_wall[m];
203 double* dYdt = ydot + 3;
206 size_t loc =
m_nsp+3;
207 fill(m_sdot.begin(), m_sdot.end(), 0.0);
208 for (
size_t i = 0; i < m_nwalls; i++) {
209 int lr = 1 - 2*m_lr[i];
210 double vdot = lr*m_wall[i]->vdot(time);
212 m_Q += lr*m_wall[i]->Q(time);
213 Kinetics* kin = m_wall[i]->kinetics(m_lr[i]);
214 SurfPhase* surf = m_wall[i]->surface(m_lr[i]);
220 m_wall[i]->syncCoverages(m_lr[i]);
224 for (
size_t k = 1; k < nk; k++) {
225 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->
size(k);
226 sum -= ydot[loc + k];
231 double wallarea = m_wall[i]->area();
232 for (
size_t k = 0; k <
m_nsp; k++) {
233 m_sdot[k] += m_work[k]*wallarea;
248 double mdot_surf = 0.0;
249 for (
size_t k = 0; k <
m_nsp; k++) {
251 dYdt[k] = (
m_wdot[k] * m_vol + m_sdot[k]) * mw[k] /
m_mass;
252 mdot_surf += m_sdot[k] * mw[k];
256 for (
size_t k = 0; k <
m_nsp; k++) {
258 dYdt[k] -= Y[k] * mdot_surf /
m_mass;
279 for (
size_t i = 0; i < m_nOutlets; i++) {
280 double mdot_out = m_outlet[i]->massFlowRate(time);
283 ydot[2] -= mdot_out * enthalpy;
288 for (
size_t i = 0; i < m_nInlets; i++) {
289 double mdot_in = m_inlet[i]->massFlowRate(time);
291 for (
size_t n = 0; n <
m_nsp; n++) {
292 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
294 dYdt[n] += (mdot_spec - mdot_in * Y[n]) /
m_mass;
297 ydot[2] += mdot_in * m_inlet[i]->enthalpy_mass();
304 for (
size_t i = 0; i < m_nv; i++) {
306 "ydot[" +
int2str(i) +
"] is not finite");
311 size_t npar = m_pnum.size();
312 for (
size_t n = 0; n < npar; n++) {
317 for (
size_t m = 0; m < m_nwalls; m++) {
318 if (m_nsens_wall[m] > 0) {
319 m_wall[m]->resetSensitivityParameters(m_lr[m]);
320 ploc += m_nsens_wall[m];
330 "Reaction number out of range ("+
int2str(rxn)+
")");
334 m_pnum.push_back(rxn);
335 m_mult_save.push_back(1.0);
340 std::vector<std::pair<void*, int> > order;
341 order.push_back(std::make_pair(const_cast<Reactor*>(
this), 0));
342 for (
size_t n = 0; n < m_nwalls; n++) {
343 if (m_nsens_wall[n]) {
344 order.push_back(std::make_pair(m_wall[n], m_lr[n]));
369 size_t walloffset = 0, kp = 0;
371 for (
size_t m = 0; m < m_nwalls; m++) {
372 if (m_wall[m]->kinetics(m_lr[m])) {
373 kp = m_wall[m]->kinetics(m_lr[m])->reactionPhaseIndex();
374 th = &m_wall[m]->kinetics(m_lr[m])->thermo(kp);
377 return k + 3 +
m_nsp + walloffset;
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).
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 getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
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.
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
#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.
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.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
Public interface for kinetics managers.
Base class for exceptions thrown by Cantera classes.
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.
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.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
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 std::string reactionString(size_t i) const
Return a string representing the reaction.
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
doublereal m_vdot
Tolerance on the temperature.
void setState_TR(doublereal t, doublereal rho)
Set the internally stored temperature (K) and density (kg/m^3)
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...
doublereal siteDensity()
Returns the site density.