Cantera  2.3.0
wrappers.h
1 // This file is part of Cantera. See License.txt in the top-level directory or
2 // at http://www.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 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(getChemPotentials)
77 THERMO_1D(getElectrochemPotentials)
78 THERMO_1D(getPartialMolarEnthalpies)
79 THERMO_1D(getPartialMolarEntropies)
80 THERMO_1D(getPartialMolarIntEnergies)
81 THERMO_1D(getPartialMolarCp)
82 THERMO_1D(getPartialMolarVolumes)
83 THERMO_1D(getEnthalpy_RT)
84 THERMO_1D(getEntropy_R)
85 THERMO_1D(getIntEnergy_RT)
86 THERMO_1D(getGibbs_RT)
87 THERMO_1D(getCp_R)
88 
89 KIN_1D(getFwdRatesOfProgress)
90 KIN_1D(getRevRatesOfProgress)
91 KIN_1D(getNetRatesOfProgress)
92 
93 KIN_1D(getEquilibriumConstants)
94 KIN_1D(getFwdRateConstants)
95 KIN_1D(getRevRateConstants)
96 
97 KIN_1D(getDeltaEnthalpy)
98 KIN_1D(getDeltaGibbs)
99 KIN_1D(getDeltaEntropy)
100 KIN_1D(getDeltaSSEnthalpy)
101 KIN_1D(getDeltaSSGibbs)
102 KIN_1D(getDeltaSSEntropy)
103 
104 KIN_1D(getCreationRates)
105 KIN_1D(getDestructionRates)
106 KIN_1D(getNetProductionRates)
107 
108 TRANSPORT_1D(getMixDiffCoeffs)
109 TRANSPORT_1D(getMixDiffCoeffsMass)
110 TRANSPORT_1D(getMixDiffCoeffsMole)
111 TRANSPORT_1D(getThermalDiffCoeffs)
112 
113 TRANSPORT_2D(getMultiDiffCoeffs)
114 TRANSPORT_2D(getBinaryDiffCoeffs)
Base class for &#39;loggers&#39; that write text messages to log files.
Definition: logger.h:40
virtual void write(const std::string &msg)
Write a log message.
Definition: logger.h:57
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
virtual void error(const std::string &msg)
Write an error message and quit.
Definition: logger.h:81
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:31
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Header for Base class for &#39;loggers&#39; that write text messages to log files (see Writing messages to th...
virtual void writeendl()
Write an end of line character and flush output.
Definition: logger.h:66
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).