Cantera  2.5.1
wrappers.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 #include "cantera/base/logger.h"
8 
9 #include "Python.h"
10 
11 // Wrappers for preprocessor defines
12 std::string get_cantera_version()
13 {
14  return std::string(CANTERA_VERSION);
15 }
16 
17 int get_sundials_version()
18 {
19  return CT_SUNDIALS_VERSION;
20 }
21 
22 class PythonLogger : public Cantera::Logger
23 {
24 public:
25  virtual void write(const std::string& s) {
26  // 1000 bytes is the maximum size permitted by PySys_WriteStdout
27  static const size_t N = 999;
28  for (size_t i = 0; i < s.size(); i+=N) {
29  PySys_WriteStdout("%s", s.substr(i, N).c_str());
30  }
31  std::cout.flush();
32  }
33 
34  virtual void writeendl() {
35  PySys_WriteStdout("%s", "\n");
36  std::cout.flush();
37  }
38 
39  virtual void error(const std::string& msg) {
40  std::string err = "raise Exception('''"+msg+"''')";
41  PyRun_SimpleString(err.c_str());
42  }
43 };
44 
45 // Function for assigning elements of Array2D, since Cython has trouble
46 // with assigning to the reference returned by operator()
47 void CxxArray2D_set(Cantera::Array2D& array, size_t i, size_t j, double value)
48 {
49  array(i,j) = value;
50 }
51 
52 // Function which populates a 1D array
53 #define ARRAY_FUNC(PREFIX, CLASS_NAME, FUNC_NAME) \
54  void PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object, double* data) \
55  { object->FUNC_NAME(data); }
56 
57 // function which takes a stride as the first argument and populates a 2D array
58 #define ARRAY_FUNC2(PREFIX, CLASS_NAME, FUNC_NAME) \
59  void PREFIX ## _ ## FUNC_NAME(Cantera::CLASS_NAME* object, size_t dim, double* data) \
60  { object->FUNC_NAME(dim, data); }
61 
62 
63 #define THERMO_1D(FUNC_NAME) ARRAY_FUNC(thermo, ThermoPhase, FUNC_NAME)
64 #define KIN_1D(FUNC_NAME) ARRAY_FUNC(kin, Kinetics, FUNC_NAME)
65 #define TRANSPORT_1D(FUNC_NAME) ARRAY_FUNC(tran, Transport, FUNC_NAME)
66 #define TRANSPORT_2D(FUNC_NAME) ARRAY_FUNC2(tran, Transport, FUNC_NAME)
67 
68 THERMO_1D(getMassFractions)
69 THERMO_1D(setMassFractions)
70 THERMO_1D(getMoleFractions)
71 THERMO_1D(setMoleFractions)
72 THERMO_1D(getConcentrations)
73 THERMO_1D(setConcentrations)
74 
75 THERMO_1D(getMolecularWeights)
76 THERMO_1D(getCharges)
77 THERMO_1D(getChemPotentials)
78 THERMO_1D(getElectrochemPotentials)
79 THERMO_1D(getPartialMolarEnthalpies)
80 THERMO_1D(getPartialMolarEntropies)
81 THERMO_1D(getPartialMolarIntEnergies)
82 THERMO_1D(getPartialMolarCp)
83 THERMO_1D(getPartialMolarVolumes)
84 THERMO_1D(getEnthalpy_RT)
85 THERMO_1D(getEntropy_R)
86 THERMO_1D(getIntEnergy_RT)
87 THERMO_1D(getGibbs_RT)
88 THERMO_1D(getCp_R)
89 THERMO_1D(getActivities)
90 THERMO_1D(getActivityCoefficients)
91 
92 KIN_1D(getFwdRatesOfProgress)
93 KIN_1D(getRevRatesOfProgress)
94 KIN_1D(getNetRatesOfProgress)
95 
96 KIN_1D(getEquilibriumConstants)
97 KIN_1D(getFwdRateConstants)
98 KIN_1D(getRevRateConstants)
99 
100 KIN_1D(getDeltaEnthalpy)
101 KIN_1D(getDeltaGibbs)
102 KIN_1D(getDeltaEntropy)
103 KIN_1D(getDeltaSSEnthalpy)
104 KIN_1D(getDeltaSSGibbs)
105 KIN_1D(getDeltaSSEntropy)
106 
107 KIN_1D(getCreationRates)
108 KIN_1D(getDestructionRates)
109 KIN_1D(getNetProductionRates)
110 
111 TRANSPORT_1D(getMixDiffCoeffs)
112 TRANSPORT_1D(getMixDiffCoeffsMass)
113 TRANSPORT_1D(getMixDiffCoeffsMole)
114 TRANSPORT_1D(getThermalDiffCoeffs)
115 TRANSPORT_1D(getSpeciesViscosities)
116 TRANSPORT_1D(getMobilities)
117 
118 TRANSPORT_2D(getMultiDiffCoeffs)
119 TRANSPORT_2D(getBinaryDiffCoeffs)
Cantera::Array2D
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:31
logger.h
Cantera::Logger::write
virtual void write(const std::string &msg)
Write a log message.
Definition: logger.h:57
Cantera::Logger
Base class for 'loggers' that write text messages to log files.
Definition: logger.h:40
Kinetics.h
Cantera::Logger::error
virtual void error(const std::string &msg)
Write an error message and quit.
Definition: logger.h:81
Cantera::Logger::writeendl
virtual void writeendl()
Write an end of line character and flush output.
Definition: logger.h:66
TransportBase.h
ThermoPhase.h