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

Extend function defined on submesh

0 votes

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.

asked Mar 17, 2017 by Massimiliano Leoni FEniCS User (1,760 points)
edited May 15, 2017 by Massimiliano Leoni

https://fenicsproject.org/qa/12282/change-values-function-mesh-function-defined-boundarymesh

One of the 2 methods suggested should be also working for "mesh and a submesh" instead of "mesh and boundary-mesh"

Hi, thanks for your reply! I will have a look at it next week and let you know if that solves my issue :)

Hi, I finally had the time to look into the two solutions you linked. The selected answer only works for CG1 element, because in that case all degrees of freedom lie on vertexes.
The other solution seems to be too expensive computationally, especially in 3D.

I thought I could sort something out with mixed function spaces, then collapsing to get a map from old to new degrees of freedom, but it looks like I cannot take the product of function spaces defined on different meshes...

but it looks like I cannot take the product of function spaces defined
on different meshes...

No you can't.

Hi, I finally had the time to look into the two solutions you linked.
The selected answer only works for CG1 element, because in that case
all degrees of freedom lie on vertexes. The other solution seems to be
too expensive computationally, especially in 3D.

You got the point. In serial, it's quite time-consuming, but if you are able to get my solution running in parallel, the lack of searching equal dof-coordinates in both meshes will not be the bottleneck, even in 3D. If I figure something out, I will post it within the next month.

...