2 # distutils: language = c++
3 # distutils: sources = ColoringSolid.C
6 DAFoam : Discrete Adjoint with OpenFOAM
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
15 # declare cpp functions
16 cdef extern from "ColoringSolid.H" namespace "Foam":
17 cppclass ColoringSolid:
18 ColoringSolid(char *, object) except +
21 # create python wrappers that call cpp functions
22 cdef class pyColoringSolid:
24 # define a class pointer for cpp functions
26 ColoringSolid * _thisptr
28 # initialize this class pointer with NULL
32 # deallocate the class pointer, and
33 # make sure we don't have memory leak
34 def __dealloc__(self):
35 if self._thisptr != NULL:
38 # point the class pointer to the cpp class constructor
39 def __init__(self, argsAll, pyOptions):
41 argsAll: string that contains all the arguments
42 for running OpenFOAM solvers, including
43 the name of the solver.
45 For example, in OpenFOAM, if we run the following:
47 mpirun -np 2 simpleFoam -parallel
49 Then, the corresponding call in pySimpleFoam is:
51 SimpleFoam("SimpleFoam -parallel")
53 self._thisptr = new ColoringSolid(argsAll, pyOptions)
55 # wrap all the other member functions in the cpp class