← Back to team overview

dolfin team mailing list archive

Swig director typemaps for ODE solvers

 

Hello!

I have been trying to get the python wrappes of the ODE solvers in place again and learn more about Swig. The wrappers have been broken since the change from uBLASVector to real*.

Dolfin needs to call functions implemented on the python side, so directors are needed. This simple typemap seems to do the job:

%typemap(directorin) double* ODE_ARGIN
{
  // Get the length of the arrays
  int n = size();
  $input = PyArray_SimpleNewFromData(1, &n, NPY_DOUBLE, $1_name);
}

Some questions from a Swig newbie: Is this the preferred way of doing this?
Note that the typemap have to call size() (a member function of class ODE) to get the length of the array, so I guess it is not possible to use a more generic typemap.

It seems to me that no "directorargout" typemap is needed when returning arrays, since the numpy arrays are just wrapping the plain c array. Is this safe?

How should "const double*" be handled (I used a const_cast<double *> when I tested it, to avoid compiler errors)? Is data copying needed here?

Benjamin



Follow ups