pyColoringSolid.pyx
Go to the documentation of this file.
1 
2 # distutils: language = c++
3 # distutils: sources = ColoringSolid.C
4 
5 '''
6  DAFoam : Discrete Adjoint with OpenFOAM
7  Version : v3
8 
9  Description:
10  Cython wrapper functions that call OpenFOAM libraries defined
11  in the *.C and *.H files. The python naming convention is to
12  add "py" before the C++ class name
13 '''
14 
15 # declare cpp functions
16 cdef extern from "ColoringSolid.H" namespace "Foam":
17  cppclass ColoringSolid:
18  ColoringSolid(char *, object) except +
19  void run()
20 
21 # create python wrappers that call cpp functions
22 cdef class pyColoringSolid:
23 
24  # define a class pointer for cpp functions
25  cdef:
26  ColoringSolid * _thisptr
27 
28  # initialize this class pointer with NULL
29  def __cinit__(self):
30  self._thisptr = NULL
31 
32  # deallocate the class pointer, and
33  # make sure we don't have memory leak
34  def __dealloc__(self):
35  if self._thisptr != NULL:
36  del self._thisptr
37 
38  # point the class pointer to the cpp class constructor
39  def __init__(self, argsAll, pyOptions):
40  '''
41  argsAll: string that contains all the arguments
42  for running OpenFOAM solvers, including
43  the name of the solver.
44 
45  For example, in OpenFOAM, if we run the following:
46 
47  mpirun -np 2 simpleFoam -parallel
48 
49  Then, the corresponding call in pySimpleFoam is:
50 
51  SimpleFoam("SimpleFoam -parallel")
52  '''
53  self._thisptr = new ColoringSolid(argsAll, pyOptions)
54 
55  # wrap all the other member functions in the cpp class
56  def run(self):
57  self._thisptr.run()