Connecting physical subdomains with difference diffusion coefficient

Hello everyone.
I have 2 rectangles with different physical group.

import gmsh
from fenics import *
import os


gmsh.initialize()
gmsh.model.add("simple_2d")
units = 1

reactangle_1 = gmsh.model.occ.addRectangle(0.0, 0.0, 0.0, units, 0.5*units, tag=1)
reactangle_2 = gmsh.model.occ.addRectangle(0.0, 0.5*units, 0.0, units, 0.5*units, tag=2)

# sycrhonise geometry with gmsh
gmsh.model.occ.synchronize()

# gather all surfaces and curves
surfaces = gmsh.model.occ.getEntities(dim=2)
curves = gmsh.model.occ.getEntities(dim=1)

gmsh.model.addPhysicalGroup(2, [1], 1)
gmsh.model.setPhysicalName(2, 1, "reactangle_1")

gmsh.model.addPhysicalGroup(2, [2], 2)
gmsh.model.setPhysicalName(2, 2, "reactangle_2")

gmsh.model.occ.synchronize()

# gnerate 2D mesh, write mesh and convert to xdmf
gmsh.model.mesh.generate(1)
gmsh.model.mesh.generate(2)
gmsh.write("mesh_2d_minimal.msh")

os.system('dolfin-convert mesh_2d_minimal.msh 02Mesh.xml')

u_in = 0.7
u_out = 0.3

xml_file = "02Mesh.xml"
mesh = Mesh(xml_file)
fd = MeshFunction('size_t', mesh, "02Mesh_facet_region.xml");
materials = MeshFunction('size_t', mesh, "02Mesh_physical_region.xml");
V = FunctionSpace(mesh, 'P', 2)

bc1 = DirichletBC(V, Constant(u_in), fd, 13) #boundry condition on the top
bc2 = DirichletBC(V, Constant(u_out), fd, 14) #boundry condition on the down
bc = [bc1, bc2]
u = TrialFunction(V)
v = TestFunction(V)
u_n = Function(V)

class al(UserExpression):
    def __init__(self,materials, k_0, k_1, **kwargs):
        super().__init__(**kwargs)
        self.materials=materials
        self.k_0 = k_0 
        self.k_1 = k_1
    def eval_cell(self,values,x,cell):
        if self.materials[cell.index] == 1:
            values[0] = self.k_0
        else:
            values[0] = self.k_1
    def value_shape(self):
        return ()
k_0=0.0001
k_1=10
k = al(materials,k_0,k_1,degree=0) 
F = u*v*dx + k*dot(grad(u), grad(v))*dx - u_n*v*dx
a, L = lhs(F), rhs(F)

u = Function(V)
solve(a == L, u, bc)

plot(u) 
plt.show
plt.savefig('f2.png', dpi=500)

But unfortunately, the result shows that these 2 rectangles are not connected!
Even If I have just one boundary condition, like below:

bc1 = DirichletBC(V, Constant(u_in), fd, 13) #boundry condition on the top
solve(a == L, u, bc1)

Again, there is no change in the result!
How can I connect 2 physical groups with different diffusion coefficient?

See Mesh, Submesh , Torus, Boundary - #3 by conpierce8, especially look for gmsh.model.occ.fragment, which is the command that glues together different surfaces/volumes

1 Like