← Back to team overview

dolfin team mailing list archive

Re: UserFunction::interpolate(real* values)

 

There seems to be more than one problem here...

1. You need to allocate the array as

    real* xx = new real[3*mesh.numVertices()];

2. Yes indeed, the size is never computed and it needs to be computed correctly or otherwise you'll most likely get a segmentation fault.

For this to work, a user-defined function must know the dimensions of the value type and it currently has no idea... I suggest we make the two functions dim() and rank() in Function virtual so that it is possible to compute this. Any further thoughts?

/Anders


Jake Ostien wrote:
Hi,

I may have found a bug in the interpolation method for the UserFunction. In the private data there is a uint size that gets initialized to 1 in the constructor, but, as near as I can tell, does not get set anywhere else. When I try and do something like <f is a member of a BodyForce class that returns a 3D force vector and is derived from Function, thus its a UserFunction> real* xx = new real[mesh.numVertices];
    f.interpolate(xx);


I get a memory error from glibc. To make a long (painful) story short(er), I realized that in the interpolation function, local_values was of size 1 and needed to be of size 3. So I hard coded in a 3 in place of size, and things magically got better. Unfortunately, it is not clear to me how to fix this in the general case. If anyone has a suggestion, I'd be happy to try it out.

-Jake
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev


Follow ups

References