8 #ifndef CT_STOICH_MGR_H 9 #define CT_STOICH_MGR_H 132 C1(
size_t rxn = 0,
size_t ic0 = 0) :
137 size_t data(std::vector<size_t>& ic) {
143 void incrementSpecies(
const doublereal* R, doublereal* S)
const {
147 void decrementSpecies(
const doublereal* R, doublereal* S)
const {
151 void multiply(
const doublereal* S, doublereal* R)
const {
155 void incrementReaction(
const doublereal* S, doublereal* R)
const {
159 void decrementReaction(
const doublereal* S, doublereal* R)
const {
163 size_t rxnNumber()
const {
166 size_t speciesIndex(
size_t n)
const {
188 C2(
size_t rxn = 0,
size_t ic0 = 0,
size_t ic1 = 0)
191 size_t data(std::vector<size_t>& ic) {
198 void incrementSpecies(
const doublereal* R, doublereal* S)
const {
200 S[m_ic1] += R[
m_rxn];
203 void decrementSpecies(
const doublereal* R, doublereal* S)
const {
205 S[m_ic1] -= R[
m_rxn];
208 void multiply(
const doublereal* S, doublereal* R)
const {
209 if (S[
m_ic0] < 0 && S[m_ic1] < 0) {
216 void incrementReaction(
const doublereal* S, doublereal* R)
const {
220 void decrementReaction(
const doublereal* S, doublereal* R)
const {
224 size_t rxnNumber()
const {
227 size_t speciesIndex(
size_t n)
const {
228 return (n == 0 ?
m_ic0 : m_ic1);
250 C3(
size_t rxn = 0,
size_t ic0 = 0,
size_t ic1 = 0,
size_t ic2 = 0)
251 : m_rxn(rxn), m_ic0(ic0), m_ic1(ic1), m_ic2(ic2) {}
253 size_t data(std::vector<size_t>& ic) {
261 void incrementSpecies(
const doublereal* R, doublereal* S)
const {
262 S[m_ic0] += R[m_rxn];
263 S[m_ic1] += R[m_rxn];
264 S[m_ic2] += R[m_rxn];
267 void decrementSpecies(
const doublereal* R, doublereal* S)
const {
268 S[m_ic0] -= R[m_rxn];
269 S[m_ic1] -= R[m_rxn];
270 S[m_ic2] -= R[m_rxn];
273 void multiply(
const doublereal* S, doublereal* R)
const {
274 if ((S[m_ic0] < 0 && (S[m_ic1] < 0 || S[m_ic2] < 0)) ||
275 (S[m_ic1] < 0 && S[m_ic2] < 0)) {
278 R[m_rxn] *= S[m_ic0] * S[m_ic1] * S[m_ic2];
282 void incrementReaction(
const doublereal* S, doublereal* R)
const {
283 R[m_rxn] += S[m_ic0] + S[m_ic1] + S[m_ic2];
286 void decrementReaction(
const doublereal* S, doublereal* R)
const {
287 R[m_rxn] -= (S[m_ic0] + S[m_ic1] + S[m_ic2]);
290 size_t rxnNumber()
const {
293 size_t speciesIndex(
size_t n)
const {
294 return (n == 0 ? m_ic0 : (n == 1 ? m_ic1 : m_ic2));
328 for (
size_t n = 0; n <
m_n; n++) {
335 size_t data(std::vector<size_t>& ic) {
337 for (
size_t n = 0; n <
m_n; n++) {
343 doublereal order(
size_t n)
const {
346 doublereal stoich(
size_t n)
const {
349 size_t speciesIndex(
size_t n)
const {
353 void multiply(
const doublereal* input, doublereal* output)
const {
354 for (
size_t n = 0; n <
m_n; n++) {
357 double c = input[
m_ic[n]];
359 output[
m_rxn] *= std::pow(c, order);
367 void incrementSpecies(
const doublereal* input,
368 doublereal* output)
const {
369 doublereal x = input[
m_rxn];
370 for (
size_t n = 0; n <
m_n; n++) {
375 void decrementSpecies(
const doublereal* input,
376 doublereal* output)
const {
377 doublereal x = input[
m_rxn];
378 for (
size_t n = 0; n <
m_n; n++) {
383 void incrementReaction(
const doublereal* input,
384 doublereal* output)
const {
385 for (
size_t n = 0; n <
m_n; n++) {
390 void decrementReaction(
const doublereal* input,
391 doublereal* output)
const {
392 for (
size_t n = 0; n <
m_n; n++) {
438 template<
class InputIter,
class Vec1,
class Vec2>
439 inline static void _multiply(InputIter begin, InputIter end,
440 const Vec1& input, Vec2& output)
442 for (; begin != end; ++begin) {
443 begin->multiply(input, output);
447 template<
class InputIter,
class Vec1,
class Vec2>
448 inline static void _incrementSpecies(InputIter begin,
449 InputIter end,
const Vec1& input, Vec2& output)
451 for (; begin != end; ++begin) {
452 begin->incrementSpecies(input, output);
456 template<
class InputIter,
class Vec1,
class Vec2>
457 inline static void _decrementSpecies(InputIter begin,
458 InputIter end,
const Vec1& input, Vec2& output)
460 for (; begin != end; ++begin) {
461 begin->decrementSpecies(input, output);
465 template<
class InputIter,
class Vec1,
class Vec2>
466 inline static void _incrementReactions(InputIter begin,
467 InputIter end,
const Vec1& input, Vec2& output)
469 for (; begin != end; ++begin) {
470 begin->incrementReaction(input, output);
474 template<
class InputIter,
class Vec1,
class Vec2>
475 inline static void _decrementReactions(InputIter begin,
476 InputIter end,
const Vec1& input, Vec2& output)
478 for (; begin != end; ++begin) {
479 begin->decrementReaction(input, output);
547 void add(
size_t rxn,
const std::vector<size_t>& k) {
550 add(rxn, k, order, stoich);
553 void add(
size_t rxn,
const std::vector<size_t>& k,
const vector_fp& order) {
555 add(rxn, k, order, stoich);
574 void add(
size_t rxn,
const std::vector<size_t>& k,
const vector_fp& order,
576 if (order.size() != k.size()) {
577 throw CanteraError(
"StoichManagerN::add()",
"size of order and species arrays differ");
579 if (stoich.size() != k.size()) {
580 throw CanteraError(
"StoichManagerN::add()",
"size of stoich and species arrays differ");
583 for (
size_t n = 0; n < stoich.size(); n++) {
584 if (fmod(stoich[n], 1.0) || stoich[n] != order[n]) {
589 if (frac || k.size() > 3) {
590 m_cn_list.emplace_back(rxn, k, order, stoich);
596 std::vector<size_t> kRep;
597 for (
size_t n = 0; n < k.size(); n++) {
598 for (
size_t i = 0; i < stoich[n]; i++) {
599 kRep.push_back(k[n]);
603 switch (kRep.size()) {
605 m_c1_list.emplace_back(rxn, kRep[0]);
608 m_c2_list.emplace_back(rxn, kRep[0], kRep[1]);
611 m_c3_list.emplace_back(rxn, kRep[0], kRep[1], kRep[2]);
614 m_cn_list.emplace_back(rxn, k, order, stoich);
619 void multiply(
const doublereal* input, doublereal* output)
const {
620 _multiply(m_c1_list.begin(), m_c1_list.end(), input, output);
621 _multiply(m_c2_list.begin(), m_c2_list.end(), input, output);
622 _multiply(m_c3_list.begin(), m_c3_list.end(), input, output);
623 _multiply(m_cn_list.begin(), m_cn_list.end(), input, output);
626 void incrementSpecies(
const doublereal* input, doublereal* output)
const {
627 _incrementSpecies(m_c1_list.begin(), m_c1_list.end(), input, output);
628 _incrementSpecies(m_c2_list.begin(), m_c2_list.end(), input, output);
629 _incrementSpecies(m_c3_list.begin(), m_c3_list.end(), input, output);
630 _incrementSpecies(m_cn_list.begin(), m_cn_list.end(), input, output);
633 void decrementSpecies(
const doublereal* input, doublereal* output)
const {
634 _decrementSpecies(m_c1_list.begin(), m_c1_list.end(), input, output);
635 _decrementSpecies(m_c2_list.begin(), m_c2_list.end(), input, output);
636 _decrementSpecies(m_c3_list.begin(), m_c3_list.end(), input, output);
637 _decrementSpecies(m_cn_list.begin(), m_cn_list.end(), input, output);
640 void incrementReactions(
const doublereal* input, doublereal* output)
const {
641 _incrementReactions(m_c1_list.begin(), m_c1_list.end(), input, output);
642 _incrementReactions(m_c2_list.begin(), m_c2_list.end(), input, output);
643 _incrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output);
644 _incrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output);
647 void decrementReactions(
const doublereal* input, doublereal* output)
const {
648 _decrementReactions(m_c1_list.begin(), m_c1_list.end(), input, output);
649 _decrementReactions(m_c2_list.begin(), m_c2_list.end(), input, output);
650 _decrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output);
651 _decrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output);
655 std::vector<C1> m_c1_list;
656 std::vector<C2> m_c2_list;
657 std::vector<C3> m_c3_list;
658 std::vector<C_AnyN> m_cn_list;
size_t m_n
Length of the m_ic vector.
size_t m_rxn
Reaction index -> index into the ROP vector.
const size_t npos
index returned by functions to indicate "no position"
size_t m_ic0
Species number.
size_t m_rxn
Reaction number.
size_t m_ic0
Species index -> index into the species vector for the two species.
Handles two species in a single reaction.
std::vector< size_t > m_ic
Vector of species which are involved with this stoichiometric manager calculations.
Handles any number of species in a reaction, including fractional stoichiometric coefficients, and arbitrary reaction orders.
void multiply(const DenseMatrix &A, const double *const b, double *const prod)
Multiply A*b and return the result in prod. Uses BLAS routine DGEMV.
Handles one species in a reaction.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Contains declarations for string manipulation functions within Cantera.
Handles three species in a reaction.
Namespace for the Cantera kernel.
size_t m_rxn
ID of the reaction corresponding to this stoichiometric manager.
vector_fp m_stoich
Stoichiometric coefficients for the reaction, reactant or product side.
vector_fp m_order
Reaction orders for the reaction.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...