Hello all,
I am trying to solve a multi-domain problem. For example, there are two cube domains(domain 1 and domain 2), the interface of two domains is z=0 plane.
I solve one standard Poisson equation on domain 1, the weak formulation is (grad(u), grad(v))=(f, v). The numerical solution on domain 1 is u.
then, I want to solve another Poisson equation on domain 2 by weak formulation: (grad(u_s), grad(v_s))=(f_s, v_s)+(grad(u), grad(v_s)){interface}, where, (grad(u), grad(v_s)){interface} is boundary integral on the interface, u is the numerical solution on domain 1.
my question is how to coding this boundary integral term: (grad(u), grad(v_s))_{interface} ?
If this boundary integral term is (u, v_s)_{interface}, I can solve it by interpolation, see MWE. but if this term have grad, I do not know how to solve it?
Thanks!
Here is MWE
import matplotlib.pyplot as plt
from dolfin import *
from mshr import *
import numpy as np
''' Poisson-1 (this part is standard Poisson equation code, demo_poisson.py)'''
mesh = UnitCubeMesh(16, 16, 16)
V = FunctionSpace(mesh, "Lagrange", 1)
# Define Dirichlet boundary (x = 0 or x = 1)
def boundary(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
# Define boundary condition
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression('10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)',degree=2)
g = Expression('sin(5*x[0])',degree=2)
a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds
# Compute solution
u = Function(V)
solve(a == L, u, bc)
# Save solution in VTK format
file = File("poisson.pvd")
file << u
'''Poisson-2'''
domain_s = Box(Point(0,0,-1), Point(1,1,0))
mesh_s = generate_mesh(domain_s, 32)
# define interface space
class BoundaryX1(SubDomain):
def inside(self, x, on_boundary):
return near(x[2], 0, DOLFIN_EPS)
interface_s = BoundaryX1()
boundary_markers = MeshFunction('size_t', mesh_s, 2, mesh_s.domains())
interface_s.mark(boundary_markers,0)
ds_s = Measure('ds', domain=mesh_s, subdomain_data=boundary_markers)
exteriormesh_s = BoundaryMesh(mesh_s, "exterior")
interfacemesh_s=SubMesh(exteriormesh_s,interface_s)
V_interface_s = FunctionSpace(interfacemesh_s, "Lagrange", 1)
# interpolate u obtained by Poisson-1 to Iu_s
Iu_s=Function(V_interface_s)
Iu_s.set_allow_extrapolation(True)
Iu_s.interpolate(u)
# solve Poisson-2
# Define Dirichlet boundary (x = 0 or x = 1)
def boundary_s(x):
return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS
V_s = FunctionSpace(mesh_s, "Lagrange", 1)
# Define boundary condition
u0_s = Constant(1.0)
bc_s = DirichletBC(V_s, u0_s, boundary_s)
u_s = TrialFunction(V_s)
v_s = TestFunction(V_s)
f_s = Constant(1.0)
a_s = inner(grad(u_s), grad(v_s))*dx
#L_s= Iu_s*v_s*ds_s(0)+f_s*v_s*dx # this works
L_s= dot(grad(Iu_s),grad(v_s))*ds_s(0)+f_s*v_s*dx # this fails
u_s = Function(V_s)
solve(a_s == L_s, u_s, bc_s)
file = File("poisson_s.pvd")
file << u_s