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

Why does interpolate not work with multiples of functions?

0 votes
from dolfin import *
mesh = UnitSquareMesh(2,2)
V = FunctionSpace(mesh, "CG", 1)
f = Function(V)
e = Function(V)

f.interpolate(e)
f.interpolate(2*e)

The first interpolate works but the second one doesn't. Shouldn't this be possible in dolfin? All interpolate has to do is to evaluate 2*e for the dofs of f.

asked Feb 11, 2016 by Gabriel Balaban FEniCS User (1,210 points)

1 Answer

0 votes

The problem is that 2*e is an ufl.algebra.Product object (use type(2*e)) and the interpolate function only receive as argument a GenericFunction.

Consider:

f.interpolate(e)
e.vector()[:] *= 2
f.interpolate(e)

or

f.interpolate(e)
f.vector()[:] *= 2
answered Feb 11, 2016 by hernan_mella FEniCS Expert (19,460 points)
edited Feb 12, 2016 by hernan_mella
...