I am trying to evaluate a Function coming from a solve
call in FEniCS 1.5.0 and tried this in the first place:
NUM_ELEM = 10
mesh = UnitSquareMesh(NUM_ELEM, NUM_ELEM)
# [...]
vals = np.empty((NUM_ELEM + 1) * (NUM_ELEM + 1), dtype=float)
u.eval(vals, mesh.coordinates())
but got a TypeError: contiguous numpy array of 'double' expected. Make sure that the numpy array is contiguous, with 1 dimension, and uses dtype=float_
. I have tried also this combination but fails with the same exception:
for v in vertices(mesh):
u.eval(vals[:, None][v.index()], mesh.coordinates()[v.index()])
What is the best way to evaluate a Function
in an array? I would like a solution working in a general case, i.e. points not coming from the mesh, but from np.meshgrid
for example. I am aware I could always write a for loop but I am looking for a straightforward approach.