This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Identify all cells within subdomain

0 votes

Hello all,

I'm trying to identify all cells within a subdomain, and place them into a dictionary. For example all cells within a circle inside a UnitSquare.

Can anyone tell me the smartest way to do this?

asked Feb 12, 2015 by perthaga FEniCS Novice (180 points)

2 Answers

0 votes
class Observer(SubDomain):
"""Observer domain"""
def inside(self, x, on_boundary):
    return  between(x[0], (6.8, 7.8))

ob = Observer()
submesh = SubMesh(mesh,ob)
indices_cells_in_observer = submesh.data().array("parent_cell_indices",2)
answered Feb 12, 2015 by maxb90 FEniCS Novice (770 points)
0 votes

MiroK tipped me about the SubsetIterator. Posting the solution here.

circ = CompiledSubDomain("(x[0]-0.5)*(x[0]-0.5) + (x[1]-0.5)*(x[1]-0.5) < 0.1*0.1")

subdomains = MeshFunction("size_t", mesh, 2)
subdomains.set_all(0)

circ.mark(subdomains, 1)

marked_cells = SubsetIterator(subdomains, 1)

for cell in marked_cells:
    print cell.index()

plot(subdomains)
interactive()
answered Feb 12, 2015 by perthaga FEniCS Novice (180 points)
...