Hi everyone,
I’m currently trying to read a gmsh-generated mesh for a cuboid channel with 3 different types of boundaries.
$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
3
2 1 "ExcitedBoundary"
2 2 "SoundProofBoundary"
2 3 "AdmittanceBoundary"
$EndPhysicalNames
$Nodes
...
$EndNodes
$Elements
1052
1 2 2 1 1 2 13 3
2 2 2 1 1 3 13 12
3 2 2 1 1 9 6 7
...
11 2 2 2 2 8 5 49
12 2 2 2 2 49 5 58
13 2 2 2 2 17 6 7
14 2 2 2 2 17 90 6
...
I can convert it using
pathname = "./DuctMesh/"
msh = meshio.read(pathname + "DuctMesh.msh")
meshio.write(pathname + "DuctMesh_xdmf.xdmf", meshio.Mesh(points=msh.points,
cells={"triangle": msh.cells["triangle"]}))
meshio.write(pathname + "DuctMesh_xdmf_Boundary.xdmf",
meshio.Mesh(points=msh.points,
cells={"triangle": msh.cells["triangle"]},
cell_data={"triangle": {"name_to_read": msh.cell_data["triangle"]["gmsh:physical"]}}))
and import it to Fenics using
mesh = df.Mesh()
with df.XDMFFile(pathname + "DuctMesh_xdmf.xdmf") as infile:
infile.read(mesh)
mvc = df.MeshValueCollection("size_t", mesh, 2)
print("The MeshValueCollection: ", mvc)
with df.XDMFFile(pathname + "DuctMesh_xdmf_Boundary.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = df.cpp.mesh.MeshFunctionSizet(mesh, mvc)
But i don’t know how to mark my boundaries properly or how to acces them from the previous code.
When I’m using
boundary_markers = df.MeshFunction("size_t", mesh(), mesh.topology().dim() - 1)
and
class OnBoundary(df.SubDomain): # determine whether coordinate is on boundary
def inside(self, x, on_boundary):
return on_boundary
i am not able to mark my boundries in the right way and accesing them properly.
neumann_excited = Bm.OnBoundary() # define Neumann boundary
neumann_excited.mark(boundary_markers, 1) # mark excited neumann boundary as 1
neumann_zero = Bm.OnBoundary()
neumann_zero.mark(boundary_markers, 2) # mark zero neumann boundary as 2
robin = OnBoundary() # define Robin boundary
robin.mark(boundary_markers, 3) # mark robin boundary as 3
When i’m debuggin my boundaries, each point is assigned to each of my boundaries, but i want boundary one to be neumann_excited, etc. …
I am not able to find anythin on how to solve this problem, so i’m asking here and hoping i can get an answer.
Any help is highly appreciated!
Thanks in advance!