8#ifndef CT_THIRDBODYCALC_H
9#define CT_THIRDBODYCALC_H
23 void install(
size_t rxnNumber,
const map<size_t, double>& efficiencies,
24 double default_efficiency,
bool mass_action) {
36 for (
const auto& [k, efficiency] : efficiencies) {
39 m_eff.back().push_back(efficiency - default_efficiency);
41 static_cast<int>(rxnNumber),
42 static_cast<int>(k), efficiency - default_efficiency);
49 Eigen::SparseMatrix<double> efficiencies;
50 efficiencies.setZero();
51 efficiencies.resize(nRxn, nSpc);
53 efficiencies.setFromTriplets(
57 vector<Eigen::Triplet<double>> triplets;
59 for (
size_t i = 0; i <
m_default.size(); i++) {
61 for (
size_t j = 0; j < nSpc; j++) {
62 triplets.emplace_back(
68 Eigen::SparseMatrix<double> defaults(nRxn, nSpc);
69 defaults.reserve(triplets.size());
70 defaults.setFromTriplets(triplets.begin(), triplets.end());
75 void update(
const vector<double>& conc,
double ctot,
double* concm)
const {
78 for (
size_t j = 0; j <
m_species[i].size(); j++) {
86 void multiply(
double* output,
const double* concm) {
89 output[ix] *= concm[ix];
97 Eigen::SparseMatrix<double>
derivatives(
const double* product) {
98 Eigen::Map<const Eigen::VectorXd> mapped(product,
m_multipliers.rows());
103 void scale(
const double* in,
double* out,
double factor)
const {
106 out[ix] = factor * in[ix];
112 void scaleM(
const double* in,
double* out,
113 const double* concm,
double factor)
const
117 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.
vector< Eigen::Triplet< double > > m_efficiencyList
Sparse efficiency matrix (compensated for defaults) Each triplet corresponds to (reaction index,...
vector< vector< size_t > > m_species
m_species[i][j] is the index of the j-th species in reaction i.
vector< vector< double > > m_eff
m_eff[i][j] is the efficiency of the j-th species in reaction i.
vector< double > m_default
The default efficiency for each reaction.
bool empty() const
Return boolean indicating whether ThirdBodyCalc is empty.
void install(size_t rxnNumber, const map< size_t, double > &efficiencies, double default_efficiency, bool mass_action)
Install reaction that uses third-body effects in ThirdBodyCalc manager.
vector< size_t > m_no_mass_action_index
Indices within m_reaction_index of reactions that consider third-body effects in the rate expression.
void multiply(double *output, const double *concm)
Multiply output with effective third-body concentration.
void update(const vector< double > &conc, double ctot, double *concm) const
Update third-body concentrations in full vector.
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.
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...
void resizeCoeffs(size_t nSpc, size_t nRxn)
Resize the sparse coefficient matrix.
vector< size_t > m_reaction_index
Indices of reactions that use third-bodies within vector of concentrations.
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"