22 if (thermo.
type() !=
"ideal-gas") {
24 "Incompatible phase type provided");
33 "Error: reactor is empty.");
58 }
else if (nm ==
"temperature") {
60 }
else if (nm ==
"volume") {
85 return 1.5 * m_thermo->
maxTemp();
94 return 0.5 * m_thermo->
minTemp();
103 throw CanteraError(
"IdealGasMoleReactor::steadyConstraints",
104 "Steady state solver cannot currently be used with IdealGasMoleReactor"
105 " when reactor surfaces are present.\n"
106 "See https://github.com/Cantera/enhancements/issues/234");
131 double& mcvdTdt = RHS[0];
132 double* dndt = RHS +
m_sidx;
151 for (
size_t n = 0; n <
m_nsp; n++) {
160 for (
auto outlet : m_outlet) {
161 for (
size_t n = 0; n <
m_nsp; n++) {
170 for (
auto inlet : m_inlet) {
173 for (
size_t n = 0; n <
m_nsp; n++) {
177 mcvdTdt -=
m_uk[n] * imw[n] * mdot_spec;
193 "Reactor must be initialized first.");
201 size_t ssize = m_nv -
m_sidx;
204 if (!m_surfaces.empty()) {
205 vector<Eigen::Triplet<double>> species_trips;
206 for (
int k = 0; k < dnk_dnj.outerSize(); k++) {
207 for (Eigen::SparseMatrix<double>::InnerIterator it(dnk_dnj, k); it; ++it) {
208 species_trips.emplace_back(
static_cast<int>(it.row()),
209 static_cast<int>(it.col()), it.value());
213 dnk_dnj.resize(ssize, ssize);
214 dnk_dnj.setFromTriplets(species_trips.begin(), species_trips.end());
219 for (
int k = 0; k < dnk_dnj.outerSize(); k++) {
220 for (Eigen::SparseMatrix<double>::InnerIterator it(dnk_dnj, k); it; ++it) {
222 static_cast<int>(it.col() +
m_sidx), it.value());
229 * std::sqrt(std::numeric_limits<double>::epsilon());
231 vector<double> lhsPerturbed(m_nv, 1.0), lhsCurrent(m_nv, 1.0);
232 vector<double> rhsPerturbed(m_nv, 0.0), rhsCurrent(m_nv, 0.0);
233 vector<double> yCurrent(m_nv);
235 vector<double> yPerturbed = yCurrent;
237 yPerturbed[0] += deltaTemp;
241 eval(time, lhsPerturbed.data(), rhsPerturbed.data());
244 eval(time, lhsCurrent.data(), rhsCurrent.data());
246 for (
size_t j = 0; j < m_nv; j++) {
247 double ydotPerturbed = rhsPerturbed[j] / lhsPerturbed[j];
248 double ydotCurrent = rhsCurrent[j] / lhsCurrent[j];
250 (ydotPerturbed - ydotCurrent) / deltaTemp);
253 Eigen::VectorXd netProductionRates = Eigen::VectorXd::Zero(ssize);
254 Eigen::VectorXd internal_energy = Eigen::VectorXd::Zero(ssize);
255 Eigen::VectorXd specificHeat = Eigen::VectorXd::Zero(ssize);
261 for (
size_t i = 0; i <
m_nsp; i++) {
263 netProductionRates[i] *=
m_vol;
266 double qdot = internal_energy.dot(netProductionRates);
269 double* moles = yCurrent.data() +
m_sidx;
270 for (
size_t i = 0; i < ssize; i++) {
271 NCv += moles[i] * specificHeat[i];
274 double denom = 1 / (NCv * NCv);
275 Eigen::VectorXd uk_dnkdnj_sums = dnk_dnj.transpose() * internal_energy;
277 for (
size_t j = 0; j < ssize; j++) {
279 (specificHeat[j] * qdot - NCv * uk_dnkdnj_sums[j]) * denom);
283 Eigen::SparseMatrix<double> jac(m_nv, m_nv);
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,...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
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).
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
vector< size_t > steadyConstraints() const override
Get the indices of equations that are algebraic constraints when solving the steady-state problem.
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.
Eigen::SparseMatrix< double > jacobian() override
Calculate an approximate Jacobian to accelerate preconditioned solvers.
vector< double > m_uk
Species molar internal energies.
void getState(double *y) override
Get the the current state of the reactor.
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
string componentName(size_t k) override
Return the name of the solution component with index i.
void setThermo(ThermoPhase &thermo) override
Specify the mixture contained in the reactor.
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.
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
double upperBound(size_t k) const override
Get the upper bound on the k-th component of the local state vector.
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.
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...
double lowerBound(size_t k) const override
Get the lower bound on the k-th component of the local state vector.
string componentName(size_t k) override
Return the name of the solution component with index i.
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.
void setState_TD(double t, double rho)
Set the internally stored temperature (K) and density (kg/m^3)
double temperature() const
Temperature (K).
const vector< double > & inverseMolecularWeights() 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 void setThermo(ThermoPhase &thermo)
Specify the mixture contained in the reactor.
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
double m_pressure
Current pressure in the reactor [Pa].
ReactorNet * m_net
The ReactorNet that this reactor is part of.
virtual size_t nSurfs() const
Return the number of surfaces in a 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].
double m_mass
Current mass of the reactor [kg].
size_t m_nsp
Number of homogeneous species in the mixture.
double time()
Current value of the simulation time [s], for reactor networks that are solved in the time domain.
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.
bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
double m_Qdot
net heat transfer into the reactor, through walls [W]
vector< Eigen::Triplet< double > > m_jac_trips
Vector of triplets representing the jacobian.
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]
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.
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 void getPartialMolarCp(double *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
string type() const override
String indicating the thermodynamic model implemented.
virtual void getPartialMolarIntEnergies(double *ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
double cv_mass() const
Specific heat at constant volume. Units: J/kg/K.
Eigen::SparseMatrix< double > netProductionRates_ddCi()
Calculate derivatives for species net production rates with respect to species concentration at const...
const double GasConstant
Universal Gas Constant [J/kmol/K].
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...