5#include "cantera/numerics/eigen_sparse.h"
14std::map<std::string, PyObject*> mapped_PyWarnings = {
16 {
"Bytes", PyExc_BytesWarning},
17 {
"Cantera", PyExc_UserWarning},
18 {
"Deprecation", PyExc_DeprecationWarning},
19 {
"Future", PyExc_FutureWarning},
20 {
"Import", PyExc_ImportWarning},
21 {
"PendingDeprecation", PyExc_PendingDeprecationWarning},
22 {
"Resource", PyExc_ResourceWarning},
23 {
"Runtime", PyExc_RuntimeWarning},
24 {
"Syntax", PyExc_SyntaxWarning},
25 {
"Unicode", PyExc_UnicodeWarning},
26 {
"User", PyExc_UserWarning}
30std::string get_cantera_version()
32 return std::string(CANTERA_VERSION);
35int get_sundials_version()
37 return CT_SUNDIALS_VERSION;
43 virtual void write(
const std::string& s) {
45 static const size_t N = 999;
46 for (
size_t i = 0; i < s.size(); i+=N) {
47 PySys_WriteStdout(
"%s", s.substr(i, N).c_str());
53 PySys_WriteStdout(
"%s",
"\n");
57 virtual void warn(
const std::string& warning,
const std::string& msg) {
58 if (mapped_PyWarnings.find(warning) != mapped_PyWarnings.end()) {
59 PyErr_WarnEx(mapped_PyWarnings[warning], msg.c_str(), 1);
62 PyErr_WarnEx(PyExc_Warning, msg.c_str(), 1);
66 virtual void error(
const std::string& msg) {
67 PyErr_SetString(PyExc_RuntimeError, msg.c_str());
73void CxxArray2D_set(
Cantera::Array2D& array,
size_t i,
size_t j,
double value)
79size_t sparseTriplets(
const Eigen::SparseMatrix<double>& mat,
80 int* rows,
int* cols,
double* data,
size_t length)
83 for (
int i = 0; i < mat.outerSize(); i++) {
84 for (Eigen::SparseMatrix<double>::InnerIterator it(mat, i); it; ++it) {
86 rows[count] = it.row();
87 cols[count] = it.col();
88 data[count] = it.value();
95 "Output arrays have insufficient length. Required size is {}, "
96 "while provided length is {}.", count, length);
102void sparseCscData(
const Eigen::SparseMatrix<double>& mat,
103 double* value,
int* inner,
int* outer)
105 if (!mat.isCompressed()) {
107 "Invalid input: Eigen matrix is not compressed.");
110 const double* valuePtr = mat.valuePtr();
111 const int* innerPtr = mat.innerIndexPtr();
112 for (
size_t i = 0; i < mat.nonZeros(); ++i) {
113 value[i] = valuePtr[i];
114 inner[i] = innerPtr[i];
117 const int* outerPtr = mat.outerIndexPtr();
118 for (
size_t i = 0; i < mat.outerSize() + 1; ++i) {
119 outer[i] = outerPtr[i];
124#define SPARSE_MATRIX(PREFIX, CLASS_NAME, FUNC_NAME) \
125 Eigen::SparseMatrix<double> PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object) \
126 { return object->FUNC_NAME(); }
129#define ARRAY_FUNC(PREFIX, CLASS_NAME, FUNC_NAME) \
130 void PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object, double* data) \
131 { object->FUNC_NAME(data); }
134#define ARRAY_FUNC2(PREFIX, CLASS_NAME, FUNC_NAME) \
135 void PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object, size_t dim, double* data) \
136 { object->FUNC_NAME(dim, data); }
139#define ARRAY_POLY(PREFIX, CLASS_NAME, FUNC_NAME) \
140 void PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object, size_t i, double* data) \
141 { object->FUNC_NAME(i, data); }
143#define ARRAY_POLY_BINARY(PREFIX, CLASS_NAME, FUNC_NAME) \
144 void PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object, size_t i, size_t j, double* data) \
145 { object->FUNC_NAME(i, j, data); }
147#define THERMO_1D(FUNC_NAME) ARRAY_FUNC(thermo, ThermoPhase, FUNC_NAME)
148#define KIN_1D(FUNC_NAME) ARRAY_FUNC(kin, Kinetics, FUNC_NAME)
149#define KIN_SPARSE_MATRIX(FUNC_NAME) SPARSE_MATRIX(kin, Kinetics, FUNC_NAME)
150#define TRANSPORT_1D(FUNC_NAME) ARRAY_FUNC(tran, Transport, FUNC_NAME)
151#define TRANSPORT_2D(FUNC_NAME) ARRAY_FUNC2(tran, Transport, FUNC_NAME)
152#define TRANSPORT_POLY(FUNC_NAME) ARRAY_POLY(tran, Transport, FUNC_NAME)
153#define TRANSPORT_POLY_BINARY(FUNC_NAME) ARRAY_POLY_BINARY(tran, Transport, FUNC_NAME)
155THERMO_1D(getMassFractions)
156THERMO_1D(setMassFractions)
157THERMO_1D(getMoleFractions)
158THERMO_1D(setMoleFractions)
159THERMO_1D(getConcentrations)
160THERMO_1D(setConcentrations)
162THERMO_1D(getMolecularWeights)
164THERMO_1D(getChemPotentials)
165THERMO_1D(getElectrochemPotentials)
166THERMO_1D(getPartialMolarEnthalpies)
167THERMO_1D(getPartialMolarEntropies)
168THERMO_1D(getPartialMolarIntEnergies)
169THERMO_1D(getPartialMolarCp)
170THERMO_1D(getPartialMolarVolumes)
171THERMO_1D(getEnthalpy_RT)
172THERMO_1D(getEntropy_R)
173THERMO_1D(getIntEnergy_RT)
174THERMO_1D(getGibbs_RT)
176THERMO_1D(getActivities)
177THERMO_1D(getActivityCoefficients)
179KIN_SPARSE_MATRIX(reactantStoichCoeffs)
180KIN_SPARSE_MATRIX(productStoichCoeffs)
181KIN_SPARSE_MATRIX(revProductStoichCoeffs)
183KIN_1D(getFwdRatesOfProgress)
184KIN_1D(getRevRatesOfProgress)
185KIN_1D(getNetRatesOfProgress)
187KIN_SPARSE_MATRIX(fwdRatesOfProgress_ddX)
188KIN_SPARSE_MATRIX(revRatesOfProgress_ddX)
189KIN_SPARSE_MATRIX(netRatesOfProgress_ddX)
191KIN_1D(getFwdRateConstants_ddT)
192KIN_1D(getFwdRateConstants_ddP)
193KIN_1D(getFwdRateConstants_ddC)
195KIN_1D(getFwdRatesOfProgress_ddT)
196KIN_1D(getRevRatesOfProgress_ddT)
197KIN_1D(getNetRatesOfProgress_ddT)
199KIN_1D(getFwdRatesOfProgress_ddP)
200KIN_1D(getRevRatesOfProgress_ddP)
201KIN_1D(getNetRatesOfProgress_ddP)
203KIN_1D(getFwdRatesOfProgress_ddC)
204KIN_1D(getRevRatesOfProgress_ddC)
205KIN_1D(getNetRatesOfProgress_ddC)
207KIN_1D(getEquilibriumConstants)
208KIN_1D(getFwdRateConstants)
209KIN_1D(getRevRateConstants)
211KIN_1D(getDeltaEnthalpy)
213KIN_1D(getDeltaEntropy)
214KIN_1D(getDeltaSSEnthalpy)
215KIN_1D(getDeltaSSGibbs)
216KIN_1D(getDeltaSSEntropy)
218KIN_1D(getThirdBodyConcentrations)
220KIN_1D(getCreationRates)
221KIN_1D(getDestructionRates)
222KIN_1D(getNetProductionRates)
224KIN_SPARSE_MATRIX(creationRates_ddX)
225KIN_SPARSE_MATRIX(destructionRates_ddX)
226KIN_SPARSE_MATRIX(netProductionRates_ddX)
228KIN_1D(getCreationRates_ddT)
229KIN_1D(getDestructionRates_ddT)
230KIN_1D(getNetProductionRates_ddT)
232KIN_1D(getCreationRates_ddP)
233KIN_1D(getDestructionRates_ddP)
234KIN_1D(getNetProductionRates_ddP)
236KIN_1D(getCreationRates_ddC)
237KIN_1D(getDestructionRates_ddC)
238KIN_1D(getNetProductionRates_ddC)
240TRANSPORT_1D(getMixDiffCoeffs)
241TRANSPORT_1D(getMixDiffCoeffsMass)
242TRANSPORT_1D(getMixDiffCoeffsMole)
243TRANSPORT_1D(getThermalDiffCoeffs)
244TRANSPORT_1D(getSpeciesViscosities)
245TRANSPORT_1D(getMobilities)
247TRANSPORT_2D(getMultiDiffCoeffs)
248TRANSPORT_2D(getBinaryDiffCoeffs)
250TRANSPORT_POLY(getViscosityPolynomial)
251TRANSPORT_POLY(setViscosityPolynomial)
252TRANSPORT_POLY(getConductivityPolynomial)
253TRANSPORT_POLY(setConductivityPolynomial)
254TRANSPORT_POLY_BINARY(getBinDiffusivityPolynomial)
255TRANSPORT_POLY_BINARY(setBinDiffusivityPolynomial)
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Base class for exceptions thrown by Cantera classes.
Base class for 'loggers' that write text messages to log files.
virtual void writeendl()
Write an end of line character and flush output.
virtual void write(const std::string &msg)
Write a log message.
virtual void error(const std::string &msg)
Write an error message and quit.
virtual void warn(const std::string &warning, const std::string &msg)
Write a warning message.
Header for Base class for 'loggers' that write text messages to log files (see Writing messages to th...