Cantera  3.0.0
Loading...
Searching...
No Matches
kinetics_utils.h
1// This file is part of Cantera. See License.txt in the top-level directory or
2// at https://cantera.org/license.txt for license and copyright information.
3
4#ifndef PY_KINETICS_UTILS_H
5#define PY_KINETICS_UTILS_H
6
8#include "cantera/numerics/eigen_sparse.h"
9#include "wrappers.h"
10
11// Service function to pass index/value triplets describing sparse matrix
12inline size_t sparseTriplets(const Eigen::SparseMatrix<double>& mat,
13 int* rows, int* cols, double* data, size_t length)
14{
15 size_t count = 0;
16 for (int i = 0; i < mat.outerSize(); i++) {
17 for (Eigen::SparseMatrix<double>::InnerIterator it(mat, i); it; ++it) {
18 if (count < length) {
19 rows[count] = it.row();
20 cols[count] = it.col();
21 data[count] = it.value();
22 }
23 count++;
24 }
25 }
26 if (count > length) {
27 throw Cantera::CanteraError("sparseComponents",
28 "Output arrays have insufficient length. Required size is {}, "
29 "while provided length is {}.", count, length);
30 }
31 return count;
32}
33
34// Service function to pass CSC data describing sparse matrix
35inline void sparseCscData(const Eigen::SparseMatrix<double>& mat,
36 double* value, int* inner, int* outer)
37{
38 if (!mat.isCompressed()) {
39 throw Cantera::CanteraError("sparseCscData",
40 "Invalid input: Eigen matrix is not compressed.");
41 }
42
43 const double* valuePtr = mat.valuePtr();
44 const int* innerPtr = mat.innerIndexPtr();
45 for (size_t i = 0; i < mat.nonZeros(); ++i) {
46 value[i] = valuePtr[i];
47 inner[i] = innerPtr[i];
48 }
49
50 const int* outerPtr = mat.outerIndexPtr();
51 for (size_t i = 0; i < mat.outerSize() + 1; ++i) {
52 outer[i] = outerPtr[i];
53 }
54}
55
56#define KIN_1D(FUNC_NAME) ARRAY_FUNC(kin, Kinetics, FUNC_NAME)
57
58KIN_1D(getFwdRatesOfProgress)
59KIN_1D(getRevRatesOfProgress)
60KIN_1D(getNetRatesOfProgress)
61
62KIN_1D(getFwdRateConstants_ddT)
63KIN_1D(getFwdRateConstants_ddP)
64KIN_1D(getFwdRateConstants_ddC)
65
66KIN_1D(getFwdRatesOfProgress_ddT)
67KIN_1D(getRevRatesOfProgress_ddT)
68KIN_1D(getNetRatesOfProgress_ddT)
69
70KIN_1D(getFwdRatesOfProgress_ddP)
71KIN_1D(getRevRatesOfProgress_ddP)
72KIN_1D(getNetRatesOfProgress_ddP)
73
74KIN_1D(getFwdRatesOfProgress_ddC)
75KIN_1D(getRevRatesOfProgress_ddC)
76KIN_1D(getNetRatesOfProgress_ddC)
77
78KIN_1D(getEquilibriumConstants)
79KIN_1D(getFwdRateConstants)
80KIN_1D(getRevRateConstants)
81
82KIN_1D(getDeltaEnthalpy)
83KIN_1D(getDeltaGibbs)
84KIN_1D(getDeltaEntropy)
85KIN_1D(getDeltaSSEnthalpy)
86KIN_1D(getDeltaSSGibbs)
87KIN_1D(getDeltaSSEntropy)
88
89KIN_1D(getThirdBodyConcentrations)
90
91KIN_1D(getCreationRates)
92KIN_1D(getDestructionRates)
93KIN_1D(getNetProductionRates)
94
95KIN_1D(getCreationRates_ddT)
96KIN_1D(getDestructionRates_ddT)
97KIN_1D(getNetProductionRates_ddT)
98
99KIN_1D(getCreationRates_ddP)
100KIN_1D(getDestructionRates_ddP)
101KIN_1D(getNetProductionRates_ddP)
102
103KIN_1D(getCreationRates_ddC)
104KIN_1D(getDestructionRates_ddC)
105KIN_1D(getNetProductionRates_ddC)
106
107#endif
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for exceptions thrown by Cantera classes.