# Function evaluation on a grid

Asked by Yi Jiang on 2013-05-07

Hi all,

I am trying to calculate a 3D Function f on a large set of points, say a uniform cubic grid. Besides, the cubic grid points do not coincide with the mesh vertices where the Function f is defined. For example:

from dolfin import *
mesh1 = Mesh( meshfile) # A uniform mesh
V1 = FunctionSpace(mesh1, 'CG', 1)
f = Function(V1)
f = ... # Construct f (e.g. by solving a PDE based on mesh1)

mesh2 = UnitCube(100,100,100) # Geometrically, the unit cube domain is a subset of mesh1's domain

Now I want to calculate the values of f at all vertices of mesh2.

I know that I can either use interpolate function:

V2 = FunctionSpace(mesh2, ‘CG', 1)
f2 = interpolate(f, V2)

Then f2.vector().array() gives me those values.

Or I can loop all vertices of mesh2 explicitly, and at each step invoke f(x, y, z) to calculate at that vertex.

The problem is that both these two methods are very very costly, and the interpolate method is even more time consuming than the explicit loop. Does anybody know if there is a more efficient way to do this job?

Thanks a lot,

## Question information

Language:
English Edit question
Status:
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2013-05-07
2013-05-09
 Anders Logg (logg) said on 2013-05-09: #1

consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

 Anders Logg (logg) said on 2013-05-09: #2