[petsc-users] DMPlexCreateFromCellList and hybrid meshes

Matthew Knepley knepley at gmail.com
Thu Oct 31 08:13:14 CDT 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131031/c3af5f88/attachment.html>


More information about the petsc-users mailing list