dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #19317
Re: Swig director typemaps for ODE solvers
On Monday August 23 2010 15:59:15 Benjamin Kehlet wrote:
> 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.
This is why we instroduced the dolfin::Array class. So speciallized typemaps
like this could be avoided.
Is there any way you can port the ODE interface to using dolfin::Array
instead? Then most of the typemaps should be inplace already.
> 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?
Yes I think so.
> 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?
Should not be any problem as Python does not know what const is.
Johan
Follow ups
References