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

mixed function space interpolation

0 votes

How can I do the interpolation of a constant function
on a mixed function space? I try it on the above script
with the mixed space W without success.

from dolfin import *

k = 8
mesh = UnitSquareMesh(k, k)

V0 = VectorFunctionSpace(mesh, "CG", 1)
V1 = VectorFunctionSpace(mesh, "CG", 2)
P0 = FunctionSpace(mesh, "CG", 1)

W = MixedFunctionSpace([V0, V1, P0])

v0_const = Constant((2.0, 2.0))
v0_inter = interpolate(v0_const, V0)

W_const = Constant((2.0, 2.0), (2.0, 2.0), (2.0))
W_inter = interpolate(W_const, W)

I can't understand the error message of ipython

File "", line 1, in
runfile('/home/parallels/mixed_function_interpolation.py', wdir='/home/parallels')

File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)

File "/home/parallels/mixed_function_interpolation.py", line 17, in
W_const = Constant((2.0, 2.0), (2.0, 2.0), (2.0))

File "/home/parallels/Work/FEniCS/lib/python2.7/site-packages/dolfin/functions/constant.py", line 72, in init
domain = ufl.as_domain(cell)

File "/home/parallels/Work/FEniCS/lib/python2.7/site-packages/ufl/domain.py", line 326, in as_domain
return Domain(as_cell(domain))

File "/home/parallels/Work/FEniCS/lib/python2.7/site-packages/ufl/cell.py", line 359, in as_cell
error("Invalid cell %s." % cell)

TypeError: not all arguments converted during string formatting

asked Nov 8, 2014 by Andre Machado FEniCS User (1,040 points)

1 Answer

+1 vote

Hi, the call should be

W_const = Constant((2.0, 2.0, 2.0, 2.0, 2.0))
W_inter = interpolate(W_const, W)
assert all(near(v, 2) for v in W_inter.vector().array())
answered Nov 8, 2014 by MiroK FEniCS Expert (80,920 points)

Thank you MiroK!

...