← Back to team overview

dolfin team mailing list archive

Re: Swig director typemaps for ODE solvers

 

Anders Logg wrote:
On Tue, Aug 24, 2010 at 01:25:56AM +0200, Benjamin Kehlet wrote:
Johan Hake wrote:
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.
That shouldn't be too complicated. Or was there a reason for
changing to plain c arrays (and not dolfin::Array) in the first
place? Anders?

The reason was that we couldn't get uBLAS to use GMP types so we
needed a more basic container like foo*, but the Array class would
work fine for this. It would also provide a nicer interface for the
user (since u etc will have a size).


Should the functionality in common/real.h (add, sub, axpy, inner etc.) be moved into dolfin::Array then or do you want to keep dolfin::Array as minimal as possible?


--
Anders


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

_______________________________________________
Mailing list: https://launchpad.net/~dolfin
Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~dolfin
More help   : https://help.launchpad.net/ListHelp

--
Anders




Follow ups

References