### Assign Function to subdomain of another Function

116

views

0

After solving on a SubMesh, how do I assign the resulting solution Function to a Function defined on the full mesh?

As an example, see the MWE below. We split the the full mesh into two SubMeshes, solve our functions on them, but how can we apply the solutions to the full mesh, then solve on that?

As an example, see the MWE below. We split the the full mesh into two SubMeshes, solve our functions on them, but how can we apply the solutions to the full mesh, then solve on that?

```
full_mesh = UnitSquareMesh(20,20)
# Setup submeshes
subdomain = CompiledSubDomain('(x[0] > 0.3 && x[0] < 0.6) && (x[1] > 0.3 && x[0] < 0.6)')
subdomain_data = MeshFunction('size_t', mesh, mesh.topology().dim())
subdomain_data.set_all(2)
subdomain.mark(subdomain_data, 1)
sub_mesh = SubMesh(mesh, subdomain_data, 1)
border_mesh = SubMesh(mesh, subdomain_data, 2)
# Solve for "sub_solution" on inner square submesh marked by "1"
sub_V = FunctionSpace(sub_mesh, 'CG', 1)
sub_v = TestFunction(sub_V)
sub_u = TrialFunction(sub_V)
sub_f = interpolate(Expression('x[0]+x[1]', degree=1), sub_V)
sub_a = inner(grad(sub_u), grad(sub_v))*dx
sub_L = sub_f*sub_v*dx
sub_bc = DirichletBC(sub_V, 0.0, 'on_boundary')
sub_solution = Function(sub_V)
solve(sub_a == sub_L, sub_solution, sub_bc)
# Solve for "border_solution" on the surrounding border submesh marked by "2"
# This uses the "sub_solution"
border_V = FunctionSpace(sub_mesh, 'CG', 1)
border_coeff = assemble(sub_solution*dx)
border_solution = interpolate(Constant(border_coeff), border_V)
# Solve on the full mesh using both sub_solution and border_solution
full_V = FunctionSpace(full_mesh, 'CG', 1)
full_v = TestFunction(full_V)
full_u = TrialFunction(full_V)
full_f = interpolate(Expression('10.0*(x[0]+x[1])', degree=1), full_V)
full_q = Function(full_V)
################################
################################
# How do I do this assignment? #
################################
################################
full_q.assign(sub_solution)
full_q.assign(border_solution)
#################################
#################################
#################################
full_a = full_q*inner(grad(full_u), grad(full_v))*dx
full_L = full_f*full_v*dx
full_bc = DirichletBC(full_V, -1.0, 'on_boundary')
full_solution = Function(full_V)
solve(full_a == full_L, full_solution, full_bc)
```

Community: FEniCS Project

### 1 Answer

0

I am not sure if this is what you are looking for .. but you may try

https://github.com/mikaem/fenicstools/wiki/Interpolation-nonmatching-mesh-in-parallel

I have used this with latest FEniCS version.
Thanks for the suggestion. That seems like a nice tool, but I'm using dolfin-adjoint, so I'm limited to using only FEniCS methods. Hopefully others who stumble on this thread find it useful.

https://github.com/mikaem/fenicstools/wiki/Interpolation-nonmatching-mesh-in-parallel

I have used this with latest FEniCS version.

written
4 months ago by
Matt

Please login to add an answer/comment or follow this question.