Hi, I have a mesh with different subdomains. I wanted to know how I can find the subdomain marker for each cell or how I can find which cell belongs to which subdomain ? Is it possible to Iterate through all cell and find the marker value for each cell ?
Hi.
It is not clear what version of FEniCS you are using and there is no MWE.
For DOLFINx you can check, among others,
https://fenicsproject.discourse.group/t/mesh-refinement-in-dolfinx/11733/2
For DOLFINx, the marking is performed over the edges belonging to a desired cell criterion. Maybe @dokken can explain further.
For Legacy DOLFIN you can check, among others,
https://fenicsproject.discourse.group/t/mesh-refinement-not-working/3199/3
https://fenicsproject.discourse.group/t/mesh-refinement-adapt-vs-refine/8711/4
Here, the markers are stored as booleans in a MeshFunction
. Hence, you can access the markers by iterating over the cells:
"""
Taken from https://fenicsproject.discourse.group/t/mesh-refinement-adapt-vs-refine/8711/4
"""
from dolfin import *
import matplotlib.pyplot as plt
n_elem = 1
n_ref = 2
mesh = UnitSquareMesh(n_elem, n_elem, "crossed")
Praf = Point(0.20981, 0.10987652, 0.0)
fig, axs = plt.subplots(nrows=n_ref+1, ncols=1, constrained_layout=True)
plt.sca(axs[0])
plot(mesh)
plt.scatter(Praf.x(), Praf.y())
for i_ref in range(n_ref):
print("-------------------------------------")
print("Refinement "+str(i_ref))
print("-------------------------------------")
print(" ")
markers = MeshFunction("bool", mesh, mesh.topology().dim(), False)
for cell in cells(mesh):
markers[cell] = cell.contains(Praf)
if markers[cell]:
print(cell.get_vertex_coordinates())
print(markers[cell])
2 Likes