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. 

Best regards, 

Cédric Doucet 

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

> De: "Matthew Knepley" <[email protected]>
> À: "Cedric Doucet" <[email protected]>
> Cc: [email protected]
> 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 <
> [email protected] > 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" < [email protected] >
> > 
> 
> > > À: "Cedric Doucet" < [email protected] >
> > 
> 
> > > Cc: [email protected]
> > 
> 
> > > 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 <
> > > [email protected] > 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

Reply via email to