Submesh and copy function values in MPI

Hi community,

I am struggling to assign values to a function on a submesh from the parent mesh. I have referred to previous posts like first, second, and third.

Problem definition: I have a “mesh_complete” which is a UnitCubeMesh and function “u” defined on the same mesh. I also have a solid mesh which I only use to create a boundary mesh and project the boundary on the “mesh_complete” such as to define a subdomain in the overlapping region on “mesh_complete”.

Next in the overlapping region, I intend to create a submesh (using MeshView because that works in parallel) and create a function “u_cut” on the submesh and assign same values as the original function “u”. Check out the following MWE:

import numpy as np
from dolfin import *

timer_total = Timer(“Total_run_time”)
wall_time = 0
timer_total.start()

mesh_complete = UnitCubeMesh(16,16,16)
V = FunctionSpace(mesh_complete, “Lagrange”, 2)
complete_dofmap = V.dofmap()

u = Function(V)
u = interpolate(Expression(“x[1]”, degree=2), V)

mesh_solid = BoxMesh(Point(0.2, 0.2, 0.2), Point(0.6, 0.6, 0.6), 11, 11, 11)
bmesh = BoundaryMesh(mesh_solid, ‘exterior’)

class MyDomain(SubDomain):
def inside(self, x, on_boundary):
return True

mark_sub_domain = MeshFunction(“size_t”, mesh_complete, mesh_complete.topology().dim(), 0)
mark_sub_domain.set_all(0)
mark_domain = MyDomain() # ? --------------------------
mark_domain.mark(mark_sub_domain, 1)
cut_mesh = MeshView.create(mark_sub_domain, 1)

V_cut = VectorFunctionSpace(cut_mesh, “Lagrange”, 2)
u_cut = Function(V_cut)
cut_dofmap = V_cut.dofmap()

cut = cut_mesh.topology().mapping()[mesh_complete.id()].cell_map()

for c in cells(cut_mesh):
u_cut.vector()[cut_dofmap.cell_dofs(c.index())] = 0.0 # Assign same values from u

File(‘u.pvd’) << u
File(‘u_cut.pvd’) << mark_sub_domain

wall_time = timer_total.stop()
print(wall_time)

My issues are specifically:

  1. I am not able to create the subdomain on mesh_complete in the overlapping region.
  2. I am not able to assign the correct values to u_cut in an efficient manner such that it also works for 2nd order vector elements in MPI.

I am using FEniCS 2019-dev version. I have been struggling on this for a while, any suggestions are highly appreciated! :slight_smile: