8#ifndef CT_THIRDBODYCALC_H
9#define CT_THIRDBODYCALC_H
22 void install(
size_t rxnNumber,
const std::map<size_t, double>& enhanced,
23 double dflt=1.0,
size_t rxnIndex=
npos) {
29 for (
const auto& eff : enhanced) {
32 m_eff.back().push_back(eff.second - dflt);
34 if (rxnIndex ==
npos) {
41 void update(
const vector_fp& conc,
double ctot,
double* work) {
42 for (
size_t i = 0; i <
m_species.size(); i++) {
44 for (
size_t j = 0; j <
m_species[i].size(); j++) {
58 void multiply(
double* output,
const double* work) {
92 void install(
size_t rxnNumber,
const std::map<size_t, double>& efficiencies,
93 double default_efficiency,
bool mass_action) {
104 m_eff.emplace_back();
105 for (
const auto& eff : efficiencies) {
108 m_eff.back().push_back(eff.second - default_efficiency);
110 static_cast<int>(rxnNumber),
111 static_cast<int>(eff.first), eff.second - default_efficiency);
118 Eigen::SparseMatrix<double> efficiencies;
119 efficiencies.setZero();
120 efficiencies.resize(nRxn, nSpc);
122 efficiencies.setFromTriplets(
126 std::vector<Eigen::Triplet<double>> triplets;
128 for (
size_t i = 0; i <
m_default.size(); i++) {
130 for (
size_t j = 0; j < nSpc; j++) {
131 triplets.emplace_back(
137 Eigen::SparseMatrix<double> defaults(nRxn, nSpc);
138 defaults.reserve(triplets.size());
139 defaults.setFromTriplets(triplets.begin(), triplets.end());
147 for (
size_t j = 0; j <
m_species[i].size(); j++) {
155 void multiply(
double* output,
const double* concm) {
158 output[ix] *= concm[ix];
167 Eigen::Map<const Eigen::VectorXd> mapped(product,
m_multipliers.rows());
172 void scale(
const double* in,
double* out,
double factor)
const {
175 out[ix] = factor * in[ix];
181 void scaleM(
const double* in,
double* out,
182 const double* concm,
double factor)
const
186 out[ix] = factor * concm[ix] * in[ix];
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
void scaleM(const double *in, double *out, const double *concm, double factor) const
Scale entries involving third-body collider in rate expression by third-body concentration and factor...
Eigen::SparseMatrix< double > m_multipliers
Sparse derivative multiplier matrix.
std::vector< size_t > m_reaction_index
Indices of reactions that use third-bodies within vector of concentrations.
std::vector< Eigen::Triplet< double > > m_efficiencyList
Sparse efficiency matrix (compensated for defaults) Each triplet corresponds to (reaction index,...
void update(const vector_fp &conc, double ctot, double *concm) const
Update third-body concentrations in full vector.
std::vector< size_t > m_mass_action_index
Indices within m_reaction_index of reactions that consider third-body effects in the law of mass acti...
bool empty() const
Return boolean indicating whether ThirdBodyCalc3 is empty.
vector_fp m_default
The default efficiency for each reaction.
std::vector< vector_fp > m_eff
m_eff[i][j] is the efficiency of the j-th species in reaction i.
void multiply(double *output, const double *concm)
Multiply output with effective third-body concentration.
Eigen::SparseMatrix< double > derivatives(const double *product)
Calculate derivatives with respect to species concentrations.
void scale(const double *in, double *out, double factor) const
Scale entries involving third-body collider in law of mass action by factor.
void install(size_t rxnNumber, const std::map< size_t, double > &efficiencies, double default_efficiency, bool mass_action)
Install reaction that uses third-body effects in ThirdBodyCalc3 manager.
void resizeCoeffs(size_t nSpc, size_t nRxn)
Resize the sparse coefficient matrix.
std::vector< size_t > m_no_mass_action_index
Indices within m_reaction_index of reactions that consider third-body effects in the rate expression.
std::vector< std::vector< size_t > > m_species
m_species[i][j] is the index of the j-th species in reaction i.
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
std::vector< size_t > m_reaction_index
Indices of reactions that use third-bodies within vector of concentrations.
vector_fp m_default
The default efficiency for each reaction.
std::vector< vector_fp > m_eff
m_eff[i][j] is the efficiency of the j-th species in reaction i.
std::vector< size_t > m_true_index
Actual index of reaction within the full reaction array.
void copy(const vector_fp &work, double *concm)
Update third-body concentrations in full vector.
std::vector< std::vector< size_t > > m_species
m_species[i][j] is the index of the j-th species in reaction i.
This file contains definitions of constants, types and terms that are used in internal routines and a...
#define AssertTrace(expr)
Assertion must be true or an error is thrown.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.