25 "Incompatible phase type provided");
27 Reactor::setThermoMgr(thermo);
30 void IdealGasReactor::getInitialConditions(
double t0,
size_t leny,
double* y)
34 cout <<
"Error: reactor is empty." << endl;
37 m_thermo->restoreState(m_state);
40 m_mass = m_thermo->density() * m_vol;
47 y[2] = m_thermo->temperature();
50 m_thermo->getMassFractions(y+3);
54 size_t loc = m_nsp + 3;
56 for (
size_t m = 0; m < m_nwalls; m++) {
57 surf = m_wall[m]->surface(m_lr[m]);
65 void IdealGasReactor::initialize(doublereal t0)
67 m_thermo->restoreState(m_state);
68 m_sdot.resize(m_nsp, 0.0);
69 m_wdot.resize(m_nsp, 0.0);
70 m_uk.resize(m_nsp, 0.0);
72 for (
size_t w = 0; w < m_nwalls; w++)
73 if (m_wall[w]->surface(m_lr[w])) {
74 m_nv += m_wall[w]->surface(m_lr[w])->nSpecies();
77 m_enthalpy = m_thermo->enthalpy_mass();
78 m_pressure = m_thermo->pressure();
79 m_intEnergy = m_thermo->intEnergy_mass();
81 size_t nt = 0, maxnt = 0;
82 for (
size_t m = 0; m < m_nwalls; m++) {
83 m_wall[m]->initialize();
84 if (m_wall[m]->kinetics(m_lr[m])) {
85 nt = m_wall[m]->kinetics(m_lr[m])->nTotalSpecies();
89 if (m_wall[m]->kinetics(m_lr[m])) {
90 if (&m_kin->thermo(0) !=
91 &m_wall[m]->kinetics(m_lr[m])->thermo(0)) {
93 "First phase of all kinetics managers must be"
100 std::sort(m_pnum.begin(), m_pnum.end());
104 void IdealGasReactor::updateState(doublereal* y)
106 for (
size_t i = 0; i < m_nv; i++) {
108 "y[" +
int2str(i) +
"] is not finite");
117 m_thermo->setMassFractions_NoNorm(y+3);
118 m_thermo->setState_TR(y[2], m_mass / m_vol);
120 size_t loc = m_nsp + 3;
122 for (
size_t m = 0; m < m_nwalls; m++) {
123 surf = m_wall[m]->surface(m_lr[m]);
131 m_enthalpy = m_thermo->enthalpy_mass();
132 m_pressure = m_thermo->pressure();
133 m_intEnergy = m_thermo->intEnergy_mass();
134 m_thermo->saveState(m_state);
137 void IdealGasReactor::evalEqs(doublereal time, doublereal* y,
138 doublereal* ydot, doublereal* params)
140 m_thermo->restoreState(m_state);
144 size_t npar = m_pnum.size();
145 for (
size_t n = 0; n < npar; n++) {
146 double mult = m_kin->multiplier(m_pnum[n]);
147 m_kin->setMultiplier(m_pnum[n], mult*params[n]);
150 for (
size_t m = 0; m < m_nwalls; m++) {
151 if (m_nsens_wall[m] > 0) {
152 m_wall[m]->setSensitivityParameters(m_lr[m], params + ploc);
153 ploc += m_nsens_wall[m];
160 double mcvdTdt = 0.0;
162 double* dYdt = ydot + 3;
164 m_thermo->getPartialMolarIntEnergies(&m_uk[0]);
167 size_t loc = m_nsp+3;
168 fill(m_sdot.begin(), m_sdot.end(), 0.0);
169 for (
size_t i = 0; i < m_nwalls; i++) {
170 int lr = 1 - 2*m_lr[i];
171 double vdot = lr*m_wall[i]->vdot(time);
173 m_Q += lr*m_wall[i]->Q(time);
174 Kinetics* kin = m_wall[i]->kinetics(m_lr[i]);
175 SurfPhase* surf = m_wall[i]->surface(m_lr[i]);
181 m_wall[i]->syncCoverages(m_lr[i]);
185 for (
size_t k = 1; k < nk; k++) {
186 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->
size(k);
187 sum -= ydot[loc + k];
192 double wallarea = m_wall[i]->area();
193 for (
size_t k = 0; k < m_nsp; k++) {
194 m_sdot[k] += m_work[k]*wallarea;
199 const vector_fp& mw = m_thermo->molecularWeights();
200 const doublereal* Y = m_thermo->massFractions();
203 m_kin->getNetProductionRates(&m_wdot[0]);
206 double mdot_surf = 0.0;
207 for (
size_t k = 0; k < m_nsp; k++) {
209 dYdt[k] = (m_wdot[k] * m_vol + m_sdot[k]) * mw[k] / m_mass;
210 mdot_surf += m_sdot[k] * mw[k];
215 mcvdTdt += - m_pressure * m_vdot - m_Q;
217 for (
size_t n = 0; n < m_nsp; n++) {
219 mcvdTdt -= m_wdot[n] * m_uk[n] * m_vol;
220 mcvdTdt -= m_sdot[n] * m_uk[n];
222 dYdt[n] -= Y[n] * mdot_surf / m_mass;
228 for (
size_t i = 0; i < m_nOutlets; i++) {
229 double mdot_out = m_outlet[i]->massFlowRate(time);
231 mcvdTdt -= mdot_out * m_pressure * m_vol / m_mass;
235 for (
size_t i = 0; i < m_nInlets; i++) {
236 double mdot_in = m_inlet[i]->massFlowRate(time);
238 mcvdTdt += m_inlet[i]->enthalpy_mass() * mdot_in;
239 for (
size_t n = 0; n < m_nsp; n++) {
240 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
242 dYdt[n] += (mdot_spec - mdot_in * Y[n]) / m_mass;
246 mcvdTdt -= m_uk[n] / mw[n] * mdot_spec;
254 ydot[2] = mcvdTdt / (m_mass * m_thermo->cv_mass());
259 for (
size_t i = 0; i < m_nv; i++) {
261 "ydot[" +
int2str(i) +
"] is not finite");
266 size_t npar = m_pnum.size();
267 for (
size_t n = 0; n < npar; n++) {
268 double mult = m_kin->multiplier(m_pnum[n]);
269 m_kin->setMultiplier(m_pnum[n], mult/params[n]);
272 for (
size_t m = 0; m < m_nwalls; m++) {
273 if (m_nsens_wall[m] > 0) {
274 m_wall[m]->resetSensitivityParameters(m_lr[m]);
275 ploc += m_nsens_wall[m];
281 size_t IdealGasReactor::componentIndex(
const string& nm)
const
286 return Reactor::componentIndex(nm);
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
Header file for class Wall.
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
doublereal size(size_t k) const
This routine returns the size of species k.
#define AssertFinite(expr, procedure, message)
Throw an exception if the specified exception is not a finite number.
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Base class for a phase with thermodynamic properties.
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.
Public interface for kinetics managers.
Base class for exceptions thrown by Cantera classes.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
size_t nSpecies() const
Returns the number of species in the phase.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual int eosType() const
Equation of state type flag.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
const int cIdealGas
Equation of state types:
doublereal siteDensity()
Returns the site density.