6#ifndef CT_REACTORBASE_H
7#define CT_REACTORBASE_H
11#include "cantera/numerics/eigen_sparse.h"
31enum class SensParameterType {
50class ReactorBase :
public std::enable_shared_from_this<ReactorBase>
68 ReactorBase(shared_ptr<Solution> sol,
bool clone,
const string&
name=
"(none)");
76 virtual string type()
const {
118 "Volume is undefined for reactors of type '{}'.",
type());
125 "Area is undefined for reactors of type '{}'.",
type());
131 "Wall evaluation is undefined for reactors of type '{}'.",
type());
138 "Area is undefined for reactors of type '{}'.",
type());
146 "Not implemented for reactor type '{}'.",
type());
153 "Not implemented for reactor type '{}'.",
type());
160 "Not implemented for reactor type '{}'.",
type());
167 "Not implemented for reactor type '{}'.",
type());
184 return m_inlet.size();
189 return m_outlet.size();
194 return m_wall.size();
219 return m_surfaces.size();
247 "Not implemented for reactor type '{}'.",
type());
266 virtual void eval(
double t,
double* LHS,
double* RHS) {
277 virtual void evalDae(
double t,
double* y,
double* ydot,
double* residual) {
287 virtual void evalSteady(
double t,
double* LHS,
double* RHS) {
289 "Not implemented for reactor type '{}'.",
type());
372 virtual Eigen::SparseMatrix<double>
jacobian();
501 return m_sensParams.size();
515 vector<double> m_state;
516 vector<FlowDevice*> m_inlet, m_outlet;
518 vector<WallBase*> m_wall;
519 vector<ReactorSurface*> m_surfaces;
536 vector<SensitivityParameter> m_sensParams;
A map of string keys to values whose type can vary at runtime.
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
An error indicating that an unimplemented function has been called.
Base class for reactor objects.
FlowDevice & outlet(size_t n=0)
Return a reference to the n-th outlet FlowDevice connected to this reactor.
double massFraction(size_t k) const
Return the mass fraction of the k-th species.
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
virtual void getJacobianScalingFactors(double &f_species, double *f_energy)
Get scaling factors for the Jacobian matrix terms proportional to .
virtual double upperBound(size_t k) const
Get the upper bound on the k-th component of the local state vector.
virtual void addSensitivitySpeciesEnthalpy(size_t k)
Add a sensitivity parameter associated with the enthalpy formation of species k.
virtual void evalWalls(double t)
Evaluate contributions from walls connected to this reactor.
virtual void getStateDae(double *y, double *ydot)
Get the current state and derivative vector of the reactor for a DAE solver.
bool m_defaultNameSet
true if default name has been previously set.
size_t nWalls()
Return the number of Wall objects connected to this reactor.
virtual void setArea(double a)
Set an area associated with a reactor [m²].
WallBase & wall(size_t n)
Return a reference to the n-th Wall connected to this reactor.
double density() const
Returns the current density (kg/m^3) of the reactor's contents.
double pressure() const
Returns the current pressure (Pa) of the reactor.
virtual void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
double m_pressure
Current pressure in the reactor [Pa].
virtual string type() const
String indicating the reactor model implemented.
ReactorNet * m_net
The ReactorNet that this reactor is part of.
virtual void addWall(WallBase &w, int lr)
Insert a Wall between this reactor and another reactor.
void setNetwork(ReactorNet *net)
Set the ReactorNet that this reactor belongs to.
size_t neq()
Number of equations (state variables) for this reactor.
bool setDefaultName(map< string, int > &counts)
Set the default name of a reactor. Returns false if it was previously set.
virtual void resetBadValues(double *y)
Reset physically or mathematically problematic values, such as negative species concentrations.
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn
size_t m_nv
Number of state variables for this reactor.
virtual double area() const
Returns an area associated with a reactor [m²].
virtual size_t componentIndex(const string &nm) const
Return the index in the solution vector for this reactor of the component named nm.
void setName(const string &name)
Set the name of this reactor.
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 temperature() const
Returns the current temperature (K) of the reactor's contents.
virtual void evalSteady(double t, double *LHS, double *RHS)
Evaluate the governing equations with modifications for the steady-state solver.
virtual bool chemistryEnabled() const
Returns true if changes in the reactor composition due to chemical reactions are enabled.
virtual vector< size_t > initializeSteady()
Initialize the reactor before solving a steady-state problem.
vector< int > m_lr
Vector of length nWalls(), indicating whether this reactor is on the left (0) or right (1) of each wa...
double m_vol
Current volume of the reactor [m^3].
virtual void eval(double t, double *LHS, double *RHS)
Evaluate the reactor governing equations.
size_t m_offset
Offset into global ReactorNet state vector.
virtual size_t nSensParams() const
Number of sensitivity parameters associated with this reactor.
void setOffset(size_t offset)
Set the starting offset for this reactor's state variables within the global state vector of the Reac...
virtual void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
virtual string componentName(size_t k)
Return the name of the solution component with index i.
size_t speciesOffset() const
Offset of the first species in the local state vector.
span< const double > surfaceProductionRates() const
Production rates on surfaces.
virtual void syncState()
Set the state of the reactor to the associated ThermoPhase object.
virtual void evalDae(double t, double *y, double *ydot, double *residual)
Evaluate the reactor governing equations.
double m_mass
Current mass of the reactor [kg].
virtual void setEnergyEnabled(bool eflag=true)
Set the energy equation on or off.
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
vector< double > m_sdot
species production rates on surfaces
const double * massFractions() const
Return the vector of species mass fractions.
size_t m_nsp
Number of homogeneous species in the mixture.
string m_name
Reactor name.
double mass() const
Returns the mass (kg) of the reactor's contents.
virtual void setInitialVolume(double vol)
Set the initial reactor volume.
double volume() const
Returns the current volume (m^3) of the reactor.
ReactorNet & network()
The ReactorNet that this reactor belongs to.
double residenceTime()
Return the residence time (s) of the contents of this reactor, based on the outlet mass flow rates an...
size_t offset() const
Get the starting offset for this reactor's state variables within the global state vector of the Reac...
virtual double lowerBound(size_t k) const
Get the lower bound on the k-th component of the local state vector.
size_t nOutlets()
Return the number of outlet FlowDevice objects connected to this reactor.
virtual void setChemistryEnabled(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
virtual void getConstraints(double *constraints)
Given a vector of length neq(), mark which variables should be considered algebraic constraints.
virtual void initialize(double t0=0.0)
Initialize the reactor.
size_t nInlets()
Return the number of inlet FlowDevice objects connected to this reactor.
ReactorSurface * surface(size_t n)
Return a reference to the n-th ReactorSurface connected to this reactor.
virtual bool preconditionerSupported() const
Return a false if preconditioning is not supported or true otherwise.
virtual void updateState(double *y)
Set the state of the reactor to correspond to the state vector y.
double m_enthalpy
Current specific enthalpy of the reactor [J/kg].
virtual bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
shared_ptr< Solution > phase()
Access the Solution object used to represent the contents of this reactor.
virtual void setDerivativeSettings(AnyMap &settings)
Use this to set the kinetics objects derivative settings.
virtual void getState(double *y)
Get the current state of the reactor.
shared_ptr< const Solution > phase() const
Access the Solution object used to represent the contents of this reactor.
virtual void getJacobianElements(vector< Eigen::Triplet< double > > &trips)
Get Jacobian elements for this reactor within the full reactor network.
virtual bool timeIsIndependent() const
Indicates whether the governing equations for this reactor are functions of time or a spatial variabl...
string name() const
Return the name of this reactor.
virtual void updateConnected(bool updatePressure)
Update state information needed by connected reactors, flow devices, and walls.
double enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
virtual void addSurface(ReactorSurface *surf)
Add a ReactorSurface object to a Reactor object.
A class representing a network of connected reactors.
A surface where reactions can occur that is in contact with the bulk fluid of a Reactor.
Base class for a phase with thermodynamic properties.
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
virtual Eigen::SparseMatrix< double > jacobian()
Calculate the Jacobian of a specific reactor specialization.
Namespace for the Cantera kernel.
offset
Offsets of solution components in the 1D solution array.
size_t global
global parameter index
SensParameterType type
type of sensitivity parameter
size_t local
local parameter index
double value
nominal value of the parameter