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

Preferred way to evaluate a function at a given point

+1 vote

Observations

I am specifically referring to the Poisson equation example (http://fenicsproject.org/documentation/dolfin/1.0.0/python/demo/pde/poisson/python/documentation.html).
After solving I am left with the solution function u and I would like to evaluate it at points that are different from the vertices of the mesh.
From

>>> dir(u)
[..., '__call__', ..., 'eval', 'eval_cell', 'evaluate', ...]

I see that there seem to be different ways to evaluate a function.
Checking

>>> help(u.__call__)

this seems to be the method I am looking for.
I also tried u.eval however its behaviour is not clear. From

>>> help(u.eval)

I see it expects the following arguments:

* eval\ (values, x)

So for the specific 2D example I thought x should be of length 2, however the method doesn't complain when using larger arrays.

>>> import numpy as np
>>> values = np.zeros(1, dtype=np.float_)
>>> u.eval(vaues, np.zeros(1, dtype=np.float_))  # no error
>>> u.eval(vaues, np.zeros(2, dtype=np.float_))  # no error
>>> u.eval(vaues, np.zeros(3, dtype=np.float_))  # no error

Like __call__ I expected the method to raise an exception if the presented arguments are invalid:

>>> u(np.zeros(1, dtype=np.float_))  # TypeError: expected the geometry argument to be of length 2
>>> u(np.zeros(1, dtype=np.float_))  # works fine
>>> u(np.zeros(3, dtype=np.float_))  # TypeError: expected the geometry argument to be of length 2

Checking

>>> help(u.evaluate)

it is not clear what this function is doing.

Questions

So I summarize my questions as follows:

  1. What method is preferred to evaluate a function at a given point?
  2. How is eval different from __call__ and what are the precise arguments that have to be provided to eval?
  3. How is eval_cell different from eval? Are the coordinates relative to the given cell?
  4. What is evaluate doing? In what situations would you use it?
  5. Is FEniCS performing some kind of interpolation if the point of evaluation is not one of the mesh vertices?
asked May 29, 2016 by Dominik1123 FEniCS Novice (190 points)
...