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

Can GenericFunctions not be interpolated?

+3 votes

Is there a deeper reason why GenericFunctions cannot be interpolated?

from dolfin import *

f = Expression('sin(x[0])')

mesh = UnitSquareMesh(20, 20)
V = FunctionSpace(mesh, 'CG', 1)

u = Function(V)
u.interpolate(f) # no problemo

u.interpolate(2 * f) # mööp

I'd like to avoid the projection step here.

asked Jul 22, 2013 by nschloe FEniCS User (7,120 points)
edited Aug 12, 2013 by Garth N. Wells

Actually GenericFunction can be interpolated but 2 * f is not GenericFunction but it is UFL something.

1 Answer

+3 votes
 
Best answer

In the development version of FEniCS (DOLFIN) you can create an Expression from any scalar GenericFunction. So your last line could be exchanged with:

u.interpolate(Expression("2 * f", f=f))
answered Aug 12, 2013 by johanhake FEniCS Expert (22,480 points)
selected Aug 12, 2013 by nschloe
...