This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Repetitive function evaluation at specific points

+1 vote

Hi everyone,

I now from Fenics documentation (and other threads) that point-wise evaluation is expansive (outside dof or vertex).

Suppose we want to evaluate different functions (i mean a lot) from the same FunctionSpace at the same locations (say 50 points in the domain that are given), can we accelarate the process ?

I read that the evaluation process locates the points in the mesh and then find the proper linear combination of basis functions. Can we store these information in some way ?

Thanks a lot for your valuable help,

JayC

asked Dec 6, 2016 by JayC FEniCS Novice (210 points)

A concrete example: Compute the point-wise variance estimator of PDE solutions subject to random source/boundary conditions.

1 Answer

+1 vote

Hi,

for a fast(er) evaluation in a set of fixed points (where the functions you want to evaluate are from the same FunctionSpace), the Probes class from fenicstools might be useful.
Once installed you can proceed as in the following example for some scalar functions:

import numpy as np
from dolfin import *
import fenicstools as ft

# Initialize mesh and function space
mesh = UnitSquareMesh(4,4)
V = FunctionSpace(mesh,'CG', 1)
# Initialize some functions in V
u = interpolate(Expression('x[0]',degree = 1), V)
v = interpolate(Expression('1-x[0]',degree = 1), V)
w = interpolate(Expression('x[0]+1',degree =1 ), V)
flist = [u, v, w]
# Define some points
xp = np.array([[0.1, 0.1],[0.2, 0.2],[0.3, 0.3]])
# Initialize Probes class from fenicstools and evaluate
p = ft.Probes(xp.flatten(), V)
for f in flist:
    p(f)
# Print the result as np.array
print p.array()
answered Dec 6, 2016 by jmmal FEniCS User (5,890 points)

Thank you Jimmal for your quick answer. I'll test it right away !

...