pyUnitTests.pyx
Go to the documentation of this file.
1 
2 # distutils: language = c++
3 # distutils: sources = UnitTests.C
4 
5 """
6  DAFoam : Discrete Adjoint with OpenFOAM
7  Version : v4
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 # for using Petsc
16 
17 
18 # declare cpp functions
19 cdef extern from "UnitTests.H" namespace "Foam":
20  cppclass UnitTests:
21  UnitTests() except +
22  void runDAUtilityTest1(char *, object)
23 
24 # create python wrappers that call cpp functions
25 cdef class pyUnitTests:
26 
27  # define a class pointer for cpp functions
28  cdef:
29  UnitTests * _thisptr
30 
31  # initialize this class pointer with NULL
32  def __cinit__(self):
33  self._thisptr = NULL
34 
35  # deallocate the class pointer, and
36  # make sure we don't have memory leak
37  def __dealloc__(self):
38  if self._thisptr != NULL:
39  del self._thisptr
40 
41  # point the class pointer to the cpp class constructor
42  def __init__(self):
43  self._thisptr = new UnitTests()
44 
45  # wrap all the other member functions in the cpp class
46  def runDAUtilityTest1(self, argsAll, pyOptions):
47  self._thisptr.runDAUtilityTest1(argsAll, pyOptions)