15#include "cantera/numerics/eigen_dense.h"
38 if (nm ==
"temperature") {
47 throw CanteraError(
"IdealGasMoleReactor::componentIndex",
48 "Component '{}' not found", nm);
63 if (m_thermo->
type() !=
"ideal-gas" && m_thermo->
type() !=
"plasma") {
65 "Incompatible phase type '{}' provided", m_thermo->
type());
74 return 1.5 * m_thermo->
maxTemp();
83 return 0.5 * m_thermo->
minTemp();
117 double& mcvdTdt = RHS[0];
118 auto dndt = RHS.subspan(
m_sidx);
135 for (
size_t n = 0; n <
m_nsp; n++) {
144 for (
auto outlet : m_outlet) {
145 for (
size_t n = 0; n <
m_nsp; n++) {
154 for (
auto inlet : m_inlet) {
157 for (
size_t n = 0; n <
m_nsp; n++) {
161 mcvdTdt -=
m_uk[n] * imw[n] * mdot_spec;
191 for (
int k = 0; k < dnk_dnj.outerSize(); k++) {
192 for (Eigen::SparseMatrix<double>::InnerIterator it(dnk_dnj, k); it; ++it) {
193 trips.emplace_back(
static_cast<int>(it.row() +
m_offset +
m_sidx),
202 * std::sqrt(std::numeric_limits<double>::epsilon());
204 vector<double> lhsPerturbed(
m_nv, 1.0), lhsCurrent(
m_nv, 1.0);
205 vector<double> rhsPerturbed(
m_nv, 0.0), rhsCurrent(
m_nv, 0.0);
206 vector<double> yCurrent(
m_nv);
208 vector<double> yPerturbed = yCurrent;
210 yPerturbed[0] += deltaTemp;
214 eval(time, lhsPerturbed, rhsPerturbed);
217 eval(time, lhsCurrent, rhsCurrent);
219 for (
size_t j = 0; j <
m_nv; j++) {
220 double ydotPerturbed = rhsPerturbed[j] / lhsPerturbed[j];
221 double ydotCurrent = rhsCurrent[j] / lhsCurrent[j];
223 (ydotPerturbed - ydotCurrent) / deltaTemp);
226 Eigen::VectorXd netProductionRates = Eigen::VectorXd::Zero(
m_nsp);
227 Eigen::VectorXd internal_energy = Eigen::VectorXd::Zero(
m_nsp);
228 Eigen::VectorXd specificHeat = Eigen::VectorXd::Zero(
m_nsp);
234 for (
size_t i = 0; i <
m_nsp; i++) {
236 netProductionRates[i] *=
m_vol;
239 double qdot = internal_energy.dot(netProductionRates);
241 Eigen::VectorXd uk_dnkdnj_sums = dnk_dnj.transpose() * internal_energy;
243 for (
size_t j = 0; j <
m_nsp; j++) {
245 (specificHeat[j] * qdot -
m_TotalCv * uk_dnkdnj_sums[j]) * denom);
251 double& f_species, span<double> f_energy)
253 f_species = 1.0 /
m_vol;
254 for (
size_t k = 0; k <
m_nsp; k++) {
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.
void eval(double t, span< double > LHS, span< double > RHS) override
Evaluate the reactor governing equations.
void evalSteady(double t, span< double > LHS, span< double > RHS) override
Evaluate the governing equations with modifications for the steady-state solver.
size_t componentIndex(const string &nm) const override
Return the index in the solution vector for this reactor of the component named nm.
vector< double > m_uk
Species molar internal energies.
void getJacobianElements(vector< Eigen::Triplet< double > > &trips) override
Calculate an approximate Jacobian to accelerate preconditioned solvers.
vector< size_t > initializeSteady() override
Initialize the reactor before solving a steady-state problem.
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.
double m_initialTemperature
Initial temperature [K]; used for steady-state calculations.
double m_initialVolume
Initial volume [m³]; used for steady-state calculations.
void updateState(span< const double > y) override
Set the state of the reactor to correspond to the state vector y.
void getState(span< double > y) override
Get the current state of the reactor.
double m_TotalCv
Total heat capacity ( ) [J/K].
void getJacobianScalingFactors(double &f_species, span< double > f_energy) override
Get scaling factors for the Jacobian matrix terms proportional to .
virtual void getNetProductionRates(span< 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 getMoles(span< 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
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 setMassFromMoles(span< const double > y)
Set internal mass variable based on moles given.
span< const double > inverseMolecularWeights() const
Return a const reference to the internal vector of molecular weights.
virtual void setMolesNoTruncate(span< const double > N)
Set the state of the object with moles in [kmol].
size_t speciesIndex(const string &name, bool raise=true) const
Returns the index of a species named 'name' within the Phase object.
void setState_TD(double t, double rho)
Set the internally stored temperature (K) and density (kg/m^3)
double temperature() const
Temperature (K).
virtual double density() const
Density (kg/m^3).
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.
size_t m_nv
Number of state variables for 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_offset
Offset into global ReactorNet state vector.
double m_mass
Current mass of the reactor [kg].
size_t m_nsp
Number of homogeneous species in the mixture.
virtual void updateConnected(bool updatePressure)
Update state information needed by connected reactors, flow devices, and walls.
double time()
Current value of the simulation time [s], for reactor networks that are solved in the time domain.
void evalWalls(double t) override
Evaluate terms related to Walls.
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
vector< double > m_wdot
Species net molar production rates.
bool energyEnabled() const override
Returns true if solution of the energy equation is enabled.
double m_Qdot
net heat transfer into the reactor, through walls [W]
void updateSurfaceProductionRates()
Update m_sdot to reflect current production rates of bulk phase species due to reactions on adjacent ...
vector< double > m_sdot
Total production rate of bulk 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 double minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid.
virtual void getPartialMolarCp(span< 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 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 and composition [J/kg/K].
virtual void getPartialMolarIntEnergies(span< double > ubar) const
Return an array of partial molar internal energies for the species in the mixture.
virtual double intrinsicHeating()
Intrinsic volumetric heating rate [W/m³].
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.
span< double > asSpan(Eigen::DenseBase< Derived > &v)
Convenience wrapper for accessing Eigen vector/array/map data as a span.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...