dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #15494
Re: More troubles with C++ function in Python
On Mon, Sep 21, 2009 at 09:07:50AM +0200, Johan Hake wrote:
> On Monday 21 September 2009 09:02:18 Garth N. Wells wrote:
> > Anders Logg wrote:
> > > On Mon, Sep 21, 2009 at 07:46:44AM +0200, Johan Hake wrote:
> > >> On Sunday 20 September 2009 23:32:19 Anders Logg wrote:
> > >>> Should the following code work? It fails for me with
> > >>>
> > >>> TypeError: in method 'new_MyFunction', argument 1 of type
> > >>> 'dolfin::FunctionSpace const &'
> > >>>
> > >>> code ="""
> > >>> class MyFunction : public Function
> > >>> {
> > >>> public:
> > >>>
> > >>> MyFunction(const FunctionSpace& V) : Function(V) {}
> > >>>
> > >>> void eval(double* values, const Data& data) const
> > >>> {
> > >>> values[0] = sin(data.x[0]);
> > >>> }
> > >>> };
> > >>> """
> > >>
> > >> code ="""
> > >> class MyFunction : public Function
> > >> {
> > >> public:
> > >>
> > >> MyFunction(boost::shared_ptr<FunctionSpace> V) : Function(V) {}
> > >>
> > >> void eval(double* values, const Data& data) const
> > >> {
> > >> values[0] = sin(data.x[0]);
> > >> }
> > >> };
> > >> """
> > >>
> > >> Should work.
> > >
> > > Yes! Thanks.
> > >
> > >> Will update docstring.
> > >
> > > Great.
> >
> > It would be nice to add this example to the manual or somewhere so how
> > to do it is not lost for others.
>
> Yes we need an extended entry in the manual on creating user defined functions
> (or expressions) in Python. For now there is a working example in the
> docstring of Function.
>
> I think the docstring could serve as a starting point for a manual entry. I
> also think that the manual should at least cover the examples showed in the
> docstring.
It would also be nice with a demo.
--
Anders
Attachment:
signature.asc
Description: Digital signature
References