Hi all, I have a mesh and a submesh, and a function defined on the submesh. I would like to create a function defined on the bigger mesh that extends the one I have with a constant value.
Consider the following example where a function $x^2$ is interpolated on half a unit square into function u
.
I would like function U
, defined on the whole square, to be the same as u
where u
is defined and extended to 0.25
elsewhere. Interpolating as in the code below does not work because the function is, well, interpolated.
from dolfin import *
mesh = UnitSquareMesh(20,20)
class Left(SubDomain):
def inside(self, x, on_boundary):
return x[0] < 0.5 + DOLFIN_EPS
sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim())
sub_domains.set_all(0)
Left().mark(sub_domains,1)
leftMesh = SubMesh(mesh,sub_domains,1)
V = FunctionSpace(mesh, "Lagrange", 1)
V2 = FunctionSpace(leftMesh, "Lagrange", 1)
u = Function(V2)
u.interpolate(Expression("x[0]*x[0]",degree=2))
u.set_allow_extrapolation(True)
U = Function(V)
U.interpolate(u)
plot(u)
plot(U, interactive=True)
I searched and found some manual solutions , but I was hoping to be able to find a quick way to map degrees of freedom on one function space to the other, assign the corrisponding ones from u
to U
and set the other ones to the value I want.