[petsc-users] DMPlexCreateFromCellList and hybrid meshes

Cedric Doucet cedric.doucet at inria.fr
Fri Jan 3 03:17:13 CST 2014


Hello, 
sorry, we talked about it few months ago. 
For the moment, it is assumed in DMPlexCreateFromCellList function that cells have all the same number of vertices. 
In other words, it means that meshes containing one and only one type of cell (from a topological viewpoint) can be handled by this function only. 
However, several mesh generators are able to discretize geometries by means of different kinds of cells. 
Resulting meshes are said to be mixed or hybrid because they contain different types of cells. 
To create a DMPlex structure from such a mesh, one needs to slightly modify DMPlexCreateFromCellList prototype. 
To my mind, the simplest way to do that is to redefine numCorners as an integer array instead of a simple integer value. 
Its length should be numCells and it should contain the number of vertices for each cell. 
Note that the length of "cells" parameter should be modified as well. 
But, of course, if you have a better idea about the new prototype, it's ok for me. 
Best regards, 
Cédric Doucet 

----- Mail original -----

> De: "Matthew Knepley" <knepley at gmail.com>
> À: "Cedric Doucet" <cedric.doucet at inria.fr>
> Cc: petsc-users at mcs.anl.gov
> Envoyé: Jeudi 2 Janvier 2014 17:01:24
> Objet: Re: [petsc-users] DMPlexCreateFromCellList and hybrid meshes

> On Thu, Jan 2, 2014 at 8:08 AM, Cedric Doucet <
> cedric.doucet at inria.fr > wrote:

> > Hello,
> 

> > indeed, I need to have a generalized version of
> > DMPlexCreateFromCellList function which can take an hybrid mesh as
> > an input parameter.
> 

> What interface?

> > Modern mesh generators often provide mixed generation
> > functionalities
> > (e.g. gmsh which can generate pyramids and prisms).
> 
> > As a matter of fact, cells are never numbered independently of
> > vertices in hybrid meshes because different generators are used
> > (structured and unstructured ones).
> 
> > From a practical point of view, it is far much easier to let each
> > generator number its own cells without renumbering shared vertices.
> 
> > Therefore, cells of hybrid meshes are sorted in a canonical way:
> > cells of generator 1, cells of generator 2, etc.
> 

> I don't understand what you want here. Its imprecise.

> Matt

> > I deeply think that this new version is very useful for real-life
> > applications.
> 
> > Please let me know when this new version will be available.
> 

> > Thank you very much,
> 

> > Cédric Doucet
> 

> > > De: "Matthew Knepley" < knepley at gmail.com >
> > 
> 
> > > À: "Cedric Doucet" < cedric.doucet at inria.fr >
> > 
> 
> > > Cc: petsc-users at mcs.anl.gov
> > 
> 
> > > Envoyé: Jeudi 31 Octobre 2013 14:13:14
> > 
> 
> > > Objet: Re: [petsc-users] DMPlexCreateFromCellList and hybrid
> > > meshes
> > 
> 

> > > On Thu, Oct 31, 2013 at 5:20 AM, Cedric Doucet <
> > > cedric.doucet at inria.fr > wrote:
> > 
> 

> > > > Thank you very much for your help.
> > > 
> > 
> 
> > > > Do you plan to add this code to Petsc?
> > > 
> > 
> 
> > > > It would be better for us to call an official Petsc function
> > > > than
> > > > maintaining a Petsc-style code into our C++ software.
> > > 
> > 
> 

> > > If this is really what you need, then I will put it in. However,
> > > I
> > > intended this to be used primarily for mesh generators, since
> > > they
> > 
> 
> > > tend to number cells and vertices independently and have the int
> > > and
> > > double types hardwired.
> > 
> 

> > > If you are writing your own code, please consider
> > > DMPlexCreateFromDAG() which has the flexibility for cell topology
> > > that you
> > 
> 
> > > want. The main differences are that it uses PETSc types and a
> > > single
> > > contiguous numbering. Would this work for you?
> > 
> 

> > > Thanks,
> > 
> 

> > > Matt
> > 
> 

> > > > Best regards,
> > > 
> > 
> 

> > > > Cédric Doucet
> > > 
> > 
> 

> > > > > De: "Matthew Knepley" < knepley at gmail.com >
> > > > 
> > > 
> > 
> 
> > > > > À: "Cedric Doucet" < cedric.doucet at inria.fr >
> > > > 
> > > 
> > 
> 
> > > > > Cc: petsc-users at mcs.anl.gov
> > > > 
> > > 
> > 
> 
> > > > > Envoyé: Mardi 29 Octobre 2013 17:24:03
> > > > 
> > > 
> > 
> 
> > > > > Objet: Re: [petsc-users] DMPlexCreateFromCellList and hybrid
> > > > > meshes
> > > > 
> > > 
> > 
> 

> > > > > On Tue, Oct 29, 2013 at 10:24 AM, Cedric Doucet <
> > > > > cedric.doucet at inria.fr > wrote:
> > > > 
> > > 
> > 
> 

> > > > > > Hello,
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > I have a short question about the code I need to modify.
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > As far as I understand, numCorner should be replaced by an
> > > > > > array
> > > > > > numCorners[numCells] containing the number of vertices of
> > > > > > each
> > > > > > cell.
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > The body of DMPlexBuildFromCellList_Private function
> > > > > > becomes
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > ---------------------------------------------------------------------------------------------------------------------------------------
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > ierr = DMPlexSetChart(dm, 0,
> > > > > > numCells+numVertices);CHKERRQ(ierr);
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > maxCorners = 0;
> > > > 
> > > 
> > 
> 
> > > > > > for (c = 0; c < numCells; ++c) {
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > ierr = DMPlexSetConeSize(dm, c,
> > > > > > numCorners[c]);CHKERRQ(ierr);
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > maxCorners = PetscMax(maxCorners, numCorners[c]);
> > > > 
> > > 
> > 
> 
> > > > > > }
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > ierr = DMSetUp(dm);CHKERRQ(ierr);
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > ierr = DMGetWorkArray(dm, maxCorners, PETSC_INT,
> > > > > &cone);CHKERRQ(ierr);
> > > > 
> > > 
> > 
> 
> > > > > > for (c = 0, off = 0; c < numCells; ++c) {
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > for (p = 0; p < numCorners[c]; ++p) {
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > cone[p] = cells[off+p]+numCells;
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > }
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > ierr = DMPlexSetCone(dm, c, cone);CHKERRQ(ierr);
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > off += numCorners[c];
> > > > 
> > > 
> > 
> 
> > > > > > }
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > ierr = DMRestoreWorkArray(dm, maxCorners, PETSC_INT,
> > > > > &cone);CHKERRQ(ierr);
> > > > 
> > > 
> > 
> 
> > > > > > ierr = DMPlexSymmetrize(dm);CHKERRQ(ierr);
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > ierr = DMPlexStratify(dm);CHKERRQ(ierr);
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > Matt
> > > > 
> > > 
> > 
> 

> > > > > > ------------------------------------------------------------------------------------------------------------------------------------------
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > However, I am not quite sure that DMGetWorkArray and
> > > > > > DMRestoreWorkArray should be used like this.
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > I guess that DMRestoreWorkArray behaves like free function
> > > > > > in
> > > > > > ansi
> > > > > > c
> > > > > > but I am not sure.
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > Do you think that calling DMGetWorkArray and
> > > > > > DMRestoreWorkArray
> > > > > > inside a loop is a good thing from the point of view of
> > > > > > computational time and memory management?
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > Note: the best way to do this may be to first sort cells by
> > > > > > numCorners to avoid many calls to DMGetWorkArray and
> > > > > > DMRestoreWorkArray. This is actually what I have in my own
> > > > > > code
> > > > > > but
> > > > > > I would like to maintain Petsc's philosophy.
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > Thanks,
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > Cédric
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > De: "Matthew Knepley" < knepley at gmail.com >
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > À: "Cedric Doucet" < cedric.doucet at inria.fr >
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > Cc: petsc-users at mcs.anl.gov
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > Envoyé: Vendredi 25 Octobre 2013 16:31:59
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > Objet: Re: [petsc-users] DMPlexCreateFromCellList and
> > > > > > > hybrid
> > > > > > > meshes
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > On Fri, Oct 25, 2013 at 7:23 AM, Cedric Doucet <
> > > > > > > cedric.doucet at inria.fr > wrote:
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > > Hello,
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > > I've noticed that DMPlexCreateFromCellList assumes that
> > > > > > > > cells
> > > > > > > > have
> > > > > > > > the same number of vertices (numcorners argument).
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > > What should be done when one wants to create a DMPlex
> > > > > > > > from
> > > > > > > > a
> > > > > > > > mesh
> > > > > > > > containing different types of cells?
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > > Does one have to create several DMPlex structures and
> > > > > > > > merge
> > > > > > > > them?
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > > Does one have to create a unique DMPlex by hand?
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > The code is very short:
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > ierr = DMPlexSetChart(dm, 0,
> > > > > > > numCells+numVertices);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > for (c = 0; c < numCells; ++c) {
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMPlexSetConeSize(dm, c,
> > > > > > > numCorners);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > }
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMSetUp(dm);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMGetWorkArray(dm, numCorners, PETSC_INT,
> > > > > > > &cone);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > for (c = 0; c < numCells; ++c) {
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > for (p = 0; p < numCorners; ++p) {
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > cone[p] = cells[c*numCorners+p]+numCells;
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > }
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMPlexSetCone(dm, c, cone);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > }
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMRestoreWorkArray(dm, numCorners, PETSC_INT,
> > > > > > > &cone);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMPlexSymmetrize(dm);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > ierr = DMPlexStratify(dm);CHKERRQ(ierr);
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > This code is all in plexcreate.c. If you want different
> > > > > > > cells,
> > > > > > > you
> > > > > > > can change numCorners for each cell.
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > I could make a convenience form if necessary.
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > Matt
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > > Thank you very much for your help.
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > > Cédric
> > > > > > > 
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 

> > > > > > > --
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > What most experimenters take for granted before they
> > > > > > > begin
> > > > > > > their
> > > > > > > experiments is infinitely more interesting than any
> > > > > > > results
> > > > > > > to
> > > > > > > which
> > > > > > > their experiments lead.
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > > > -- Norbert Wiener
> > > > > > 
> > > > > 
> > > > 
> > > 
> > 
> 
> > > > > --
> > > > 
> > > 
> > 
> 
> > > > > What most experimenters take for granted before they begin
> > > > > their
> > > > > experiments is infinitely more interesting than any results
> > > > > to
> > > > > which
> > > > > their experiments lead.
> > > > 
> > > 
> > 
> 
> > > > > -- Norbert Wiener
> > > > 
> > > 
> > 
> 
> > > --
> > 
> 
> > > What most experimenters take for granted before they begin their
> > > experiments is infinitely more interesting than any results to
> > > which
> > > their experiments lead.
> > 
> 
> > > -- Norbert Wiener
> > 
> 
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which
> their experiments lead.
> -- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140103/800adf07/attachment-0001.html>


More information about the petsc-users mailing list