← Back to team overview

dolfin team mailing list archive

Re: A minimal c++ Function test and some bugs

 

On Wed, Feb 18, 2009 at 07:56:59PM +0000, A Navaei wrote:
> 2009/2/18 Anders Logg <logg@xxxxxxxxx>:
> > On Wed, Feb 18, 2009 at 02:04:35PM +0000, A Navaei wrote:
> >> 2009/2/17 Anders Logg <logg@xxxxxxxxx>:
> >> > On Tue, Feb 17, 2009 at 03:28:08PM +0000, Garth N. Wells wrote:
> >> >>
> >> >>
> >> >> A Navaei wrote:
> >> >> > The following minimal test for Function in c++ reveals some bugs. I
> >> >> > guess this example can help me with dealing with the current issues of
> >> >> > ImageFunction.
> >> >> >
> >> >> > (1) interpolate.py does not work when a Function is created in c++ and
> >> >> > wrapped (see comment [2]). It seems that the bug is originated from
> >> >> > the copy constructor (see comment [3])
> >> >> >
> >> >> > (2) In order to perform the interpolation, why is it necessary to
> >> >> > create another Function and then copy it?
> >> >> >
> >> >> > (3) Signature checkes seem not working properly (see comment [1]). The
> >> >> > signature-based assignments are error-prone anyway, why the
> >> >> > object-oriented approach is not used?
> >> >> >
> >> >>
> >> >> Signatures are used to permit reading/writing Functions to a file. They
> >> >> are indeed error prone, so I believe that we reached a consensus a short
> >> >> while ago that we would remove pre-compiled elements.
> >> >>
> >> >> Garth
> >> >
> >> > Instead of signatures, I'd recommend that you define a simple form
> >> > file for each of the different types of FunctionSpace you need, for
> >> > example:
> >> >
> >> >  element = FiniteElement("CG", "triangle", 1)
> >> >
> >> >  v = TestFunction(element)
> >> >  u = TrialFunction(element)
> >> >  a = v*u*dx
> >> >
> >> > If you put this in a file named My.form and compile it with FFC using
> >> > -l dolfin, you will get a class named MyFunctionSpace that you can
> >> > then instantiate using just a mesh:
> >> >
> >> >  MyFunctionSpace V(mesh);
> >> >
> >> > Create one form file for each of the different types of FunctionSpace
> >> > that you need, name the files to something suitable and use the
> >> > generated code. That way you won't need to worry about signatures,
> >> > dofmaps and finite elements.
> >>
> >> Effectively, I've been using the very same method all this time, it
> >> does not work.
> >
> > Yes, it does. It's used in about 20 of the demos.
> >
> >> The copy constructor fix never worked. I've been trying to explain
> >> this in many different ways, but the right attention was never paid to
> >> this. Let's see if the sandbox example can convince you this time.
> >>
> >> A Function instance still cannot be returned by reference (or value).
> >> Returning as shared_ptr seems to work initially, but eventually it
> >> generates segmentation fault -- see attached.
> >
> > Yes, it can. There's absolutely no problem to return a Function by
> > reference. See the updated sandbox demo.
> >
> > The only problem is when you want to copy a Function which is only
> > defined in terms of an eval() operator. In those cases the Function
> > cannot be copied.
> >
> > If you do the following:
> >
> > class MyFunction : public Function
> > {
> > public:
> >
> >  MyFunction(const FunctionSpace& V) : Function(V) {};
> >
> >  void eval(double* values, const double* x) const
> >  {
> >    values[0] = sin(x[0]);
> >  }
> > };
> >
> > MyFunction f(V);
> > Function g = f;
> >
> > Do you then expect g to return sin(x)? It would be possible to
> > implement this but it would require g to keep a pointer to f so that
> > the eval() in g may call the eval() in f.
> 
> Yes, we eventually want to get the image data in eval() and obviously
> the work around:
> 
>  Function g(V);
>  g.vector();
>  _f = g;
> 
> does not call eval(). I don't think if it is possible to do this
> without amending the Function class? The denial of changing the
> visibility of the member variables to protected is making this
> unnecessarily more and more complicated. I am attaching the updated
> sandbox test.
> 
> 
> -Ali

I've already said that we can make the _function_space protected in
the Function class. I've done so now and also added a new
interpolation function. See if that helps.

-- 
Anders

Attachment: signature.asc
Description: Digital signature


Follow ups

References