find parent cells in a refined mesh

Asked by Martin Eigel

Is there a way to determine the corresponding parent cell of a cell in a refined mesh in the sense of
mesh = UnitSquare(5,5)
mesh2 = refine(mesh)
for c in cells(mesh2):
    print "parent cell of ", c.id(), "in mesh is ", c.parent().id()

Does the method Mesh.set_parent do anything else than storing the reference to another mesh?

Cheers,
Martin

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Marie Rognes
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

On 1 June 2012 08:55, Martin Eigel <email address hidden> wrote:
> New question #199071 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/199071
>
> Is there a way to determine the corresponding parent cell of a cell in a refined mesh in the sense of
> mesh = UnitSquare(5,5)
> mesh2 = refine(mesh)
> for c in cells(mesh2):
>    print "parent cell of ", c.id(), "in mesh is ", c.parent().id()
>

No. Refinement needs some work, so it may appear in the future.

Garth

> Does the method Mesh.set_parent do anything else than storing the reference to another mesh?
>
> Cheers,
> Martin
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Anders Logg (logg) said :
#2

B1;3201;0cOn Wed, Jun 13, 2012 at 04:45:46PM -0000, Garth Wells wrote:
> Question #199071 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/199071
>
> Status: Open => Answered
>
> Garth Wells proposed the following answer:
> On 1 June 2012 08:55, Martin Eigel <email address hidden> wrote:
> > New question #199071 on DOLFIN:
> > https://answers.launchpad.net/dolfin/+question/199071
> >
> > Is there a way to determine the corresponding parent cell of a cell in a refined mesh in the sense of
> > mesh = UnitSquare(5,5)
> > mesh2 = refine(mesh)
> > for c in cells(mesh2):
> >    print "parent cell of ", c.id(), "in mesh is ", c.parent().id()
> >
>
> No. Refinement needs some work, so it may appear in the future.

You can follow the progress here:

https://blueprints.launchpad.net/dolfin/+spec/mesh-refinement

Not much to see yet, but I hope that will change in the very near
future.

--
Anders

Revision history for this message
Best Marie Rognes (meg-simula) said :
#3

Actually, if you use local refinement via recursive bisection, maps of parent cells and facets are generated and extractable
via mesh.data().mesh_function("parent_cell") and mesh.data().mesh_function("parent_facet")

In general, if you want to do something related to adaptivity, you might want to have a look at the 'adapt' functionality

  http://fenicsproject.org/documentation/dolfin/1.0.0/cpp/programmers-reference/adaptivity/adapt.html#adapt-h

rather than refine.

However, try this:

from dolfin import *

mesh = UnitSquare(1, 1)
markers = CellFunction("bool", mesh)
markers.set_all(True)
mesh2 = refine(mesh, markers)

info(mesh, True)

info(mesh2.data(), True)
info(mesh2.data().mesh_function("parent_cell"), True)
info(mesh2.data().mesh_function("parent_facet"), True)

plot(mesh)
plot(mesh2, interactive=True)

Revision history for this message
Martin Eigel (meigel) said :
#4

Nice, thanks for the sample code!
Is there any fundamental difference between refine and adapt (despite from the latter being more versatile it seems)?

I will follow the progress with mesh refinement in dolfin closely since this is a pivotal feature we use in our applications.

Cheers,
Martin

Revision history for this message
Martin Eigel (meigel) said :
#5

Thanks Marie Rognes, that solved my question.