get cell indices in subdomain

Asked by Chaffra Affouda

Waht is the correct way to find the cell indices belonging to a subdomain?

 I am running the code below with works well in 1D but I am afraid it might not work for 2D/3D. Do the indices in the array of the cell function correspond to the cell indices in the mesh?

mesh = UnitSquare(10,10)

def inside(x, on_boundary):
    return (x[0] >= 0.5)

region = AutoSubDomain(inside_function=inside)

subdomains = CellFunction('uint',mesh)
subdomains.set_all(0)
region.mark(subdomains,1)

cells = numpy.where(subdomains.array() == 1)[0]

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Best Johan Hake (johan-hake) said :
#1

On 10/19/2012 06:35 PM, Chaffra Affouda wrote:
> New question #211699 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/211699
>
> Waht is the correct way to find the cell indices belonging to a
> subdomain?
>
> I am running the code below with works well in 1D but I am afraid it
> might not work for 2D/3D. Do the indices in the array of the cell
> function correspond to the cell indices in the mesh?
>

mesh = UnitSquare(10,10)

def inside(x, on_boundary):
    return (x[0] >= 0.5)

region = AutoSubDomain(inside_function=inside)

subdomains = CellFunction('uint', mesh, 0)
region.mark(subdomains,1)

indices = [cell.index() for cell in SubsetIterator(subdomains, 1)]

Revision history for this message
Chaffra Affouda (chaffra) said :
#2

Thanks Johan Hake, that solved my question.