Hi all,

recently, a discussion [1] came up about a long-standing weirdness
with Dolfin `Expression`s:
```
from dolfin import *
mesh = UnitIntervalMesh(1)
e1 = Expression("x[0] * x[0]")
print assemble(e1 * dx(mesh))
```
This looks like it's integrating the function x^2 over the interval
[0, 1], but the result – surprisingly to some –, is 0.5 instead of
0.33333. The reason for this behavior is that `e1` gets interpreted as
a linear function by the quadrature. (The optional argument `degree`
of `Expression` defaults to 1.)

While most would agree that this is surprising and that probably
numerous FEniCS codes suffer from bugs related to this, it is unclear
what we should best do about this.

The options include:

 * improve the documentation
 * add a log message/warning when `Expression` interpolation happens
 * add an extra mandatory argument to `Expression`, specifying
    - the element or
    - the function space;
 * introduce functions that evaluate pointwise ("Expressions") to
UFL/UFC/FCC and let dolfin Expression inherit from those;
 * ...

Arguments in favor of adding a mandatory argument include
  * The Python Zen: "Explicit is better than implicit." -- It's just
too easy to make a mistake here.

Arguments for leaving the API as it is include:
  * The user cannot expect to have arbitrary Expressions integrate
exactly. Why should he/she expect it for any function?

What do you think about this? Does the above `assemble()` result
surprise you at all? Do you think we should force user code to be
explicit here or would you think that adding documentation is
sufficient?

Cheers,
Nico


[1] 
https://bitbucket.org/fenics-project/dolfin/issue/355/expression-s-interpolate-to-linear
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics

Reply via email to