Function evaluation on a grid

Asked by Yi Jiang

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:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Revision history for this message
Anders Logg (logg) said :
#2

FEniCS no longer uses Launchapd for Questions & Answers. Please
consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

Can you help with this problem?

Provide an answer of your own, or ask Yi Jiang for more information if necessary.

To post a message you must log in.