[petsc-users] DMPlexCreateFromCellList and hybrid meshes

Matthew Knepley knepley at gmail.com
Tue Oct 29 11:24:03 CDT 2013


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


More information about the petsc-users mailing list