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

addressing cells of a subdomain

0 votes

Hi,

Apologies for the beginner-level questions:

Following from my previous question on mesh refinement, could you please guide me as to how I could address the cells in a particular subdomain? I consulted the FEniCS book, and the refine example I came across referred to setting a condition on cell midpoint from a corner of the computational domain. Unsure how I could set a condition so that cells belonging to one subdomain are addressed only.

Many thanks,

asked Jul 13, 2013 by hnili FEniCS Novice (590 points)

1 Answer

+1 vote
 
Best answer

I guess from your vague question that you want set CellFunction to be used for refine function.

cell_markers = CellFunction("bool", mesh)
cell_markers.set_all(False)

Then do this

for c in cells(mesh):
   if condition(c):
        cell_markers[c] = True

or this

class MyDomain(SubDomain):
    def inside(self, x, on_boundary):
        return condition(x)
my_domain = MyDomain()
my_domain.mark(cell_markers, True)

where condition(c) or condition(x) is your condition on c or x. Note that first approach is more universal as you can base your condition on whatever property Cell possesses. Second approach marks cell whose vertices and midpoint fulfills condition(x).

Finally

mesh = refine(mesh, cell_markers)
answered Jul 13, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Jul 19, 2013 by Jan Blechta

Thanks! Yes, my question was whether I could set the condition (explicitly) in terms of x rather than c.

...