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