dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #17759
Re: Passing arrays from Python
-
To:
dolfin@xxxxxxxxxxxxxxxxxxx
-
From:
Johan Hake <johan.hake@xxxxxxxxx>
-
Date:
Sun, 28 Feb 2010 17:05:45 -0800
-
In-reply-to:
<1267303763.3877.19.camel@garth-laptop>
-
User-agent:
KMail/1.12.4 (Linux/2.6.31-20-generic; KDE/4.3.5; i686; ; )
On Saturday 27 February 2010 12:49:23 Garth N. Wells wrote:
> On Sat, 2010-02-27 at 19:58 +0100, Anders Logg wrote:
> > On Sat, Feb 27, 2010 at 06:32:12PM +0000, Garth N. Wells wrote:
> > > How do I pass the pointer to the first element of an array from the
> > > Python interface to a wrapped C++ function? I would like to tabulate
> > > the dofs of a cell, so I tried
> > >
> > > local_facet = cell.index(facet)
> > > dofs = numpy.array(9, dtype=numpy.uint32)
> > > dof_map.tabulate_facet_dofs(dofs, local_facet)
> > >
> > > but I get a bunch of memory errors. I don't know to correctly allocate
> > > 'dofs' such that I can pass it to tabulate_facet_dofs.
> >
> > Try this:
> >
> > cell_dofs = numpy.zeros(n, dtype='I')
>
> Thanks. Did the trick.
An exception should have been raised here asking you to pass an array with
dtype='I'.
Btw, I have never figured out the difference between the different uintXX in
NumPy, versus the string descriptors.
Johan
> Garth
>
> > It has worked for me before. Also note that there are dolfin::Cell
> > functions for some (but not all) of the functions in DofMap which
> > allows access from Python without needing to create a ufc::cell.
> >
> > --
> > Anders
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>
References