Cantera  4.0.0a1
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 (int 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 (int i = 0; i < mat.outerSize() + 1; ++i) {
52 outer[i] = outerPtr[i];
53 }
54}
55
56#define KIN_1D(FUNC_NAME) \
57 inline void kin_ ## FUNC_NAME(Cantera::Kinetics* object, std::span<double> data) \
58 { object->FUNC_NAME(data); }
59
60KIN_1D(getFwdRatesOfProgress)
61KIN_1D(getRevRatesOfProgress)
62KIN_1D(getNetRatesOfProgress)
63
64KIN_1D(getFwdRateConstants_ddT)
65KIN_1D(getFwdRateConstants_ddP)
66KIN_1D(getFwdRateConstants_ddC)
67
68KIN_1D(getFwdRatesOfProgress_ddT)
69KIN_1D(getRevRatesOfProgress_ddT)
70KIN_1D(getNetRatesOfProgress_ddT)
71
72KIN_1D(getFwdRatesOfProgress_ddP)
73KIN_1D(getRevRatesOfProgress_ddP)
74KIN_1D(getNetRatesOfProgress_ddP)
75
76KIN_1D(getFwdRatesOfProgress_ddC)
77KIN_1D(getRevRatesOfProgress_ddC)
78KIN_1D(getNetRatesOfProgress_ddC)
79
80KIN_1D(getEquilibriumConstants)
81KIN_1D(getFwdRateConstants)
82KIN_1D(getRevRateConstants)
83
84KIN_1D(getDeltaEnthalpy)
85KIN_1D(getDeltaGibbs)
86KIN_1D(getDeltaEntropy)
87KIN_1D(getDeltaSSEnthalpy)
88KIN_1D(getDeltaSSGibbs)
89KIN_1D(getDeltaSSEntropy)
90
91KIN_1D(getThirdBodyConcentrations)
92
93KIN_1D(getCreationRates)
94KIN_1D(getDestructionRates)
95KIN_1D(getNetProductionRates)
96
97KIN_1D(getCreationRates_ddT)
98KIN_1D(getDestructionRates_ddT)
99KIN_1D(getNetProductionRates_ddT)
100
101KIN_1D(getCreationRates_ddP)
102KIN_1D(getDestructionRates_ddP)
103KIN_1D(getNetProductionRates_ddP)
104
105KIN_1D(getCreationRates_ddC)
106KIN_1D(getDestructionRates_ddC)
107KIN_1D(getNetProductionRates_ddC)
108
109#endif
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for exceptions thrown by Cantera classes.