[petsc-users] Question about DMPLEX/P4EST with different Sections

Matthew Knepley knepley at gmail.com
Thu Mar 12 18:19:14 CDT 2020


On Thu, Mar 12, 2020 at 7:40 AM Berend van Wachem <berend.vanwachem at ovgu.de>
wrote:

> Dear All,
>
> I have started to use DMPLEX with P4EST for a computational fluid
> dynamics application. I am solving a coupled system of 4 discretised
> equations (for 3 velocity components and one pressure) on a mesh.
> However, next to these 4 variables, I also have a few single field
> variables (such as density and viscosity) defined over the mesh, which I
> don't solve for (they should not be part of the matrix with unknowns).
> Most of these variables are at the cell centers, but in a few cases, it
> want to define them at cell faces.
>
> With just DMPLEX, I solve this by:
>
> DMPlexCreateMesh, so I get an initial DM
> DMPlexCreateSection, indicating the need for 4 variables
> DMSetLocalSection
> DMCreateGlobalVector (and Matrix), so I get an Unknown vector, a RHS
> vector, and a matrix for the 4 variables.
>
> To get a vector for a single variable at the cell center or the cell
> face, I clone the original DM, I define a new Section on it, and then
> create the vector from that which I need (e.g. for density, viscosity or
> a velocity at the cell face).
>
> Then I loop over the mesh, and with MatSetValuesLocal, I set the
> coefficients. After that, I solve the system for multiple timesteps
> (sequential solves) and get the solution vector with the 4 variables
> after each solve.
>
> So-far, this works fine with DMPLEX. However, now I want to use P4EST,
> and I have difficulty defining a variable vector other than the original 4.
>
> I have changed the code structure:
>
> DMPlexCreateMesh, so I get an initial DM
> DMPlexCreateSection, indicating the need for 4 variables
> DMSetLocalSection
> DMForestSetBaseDM(DM, DMForest) to create a DMForest
> DMCreateGlobalVector (and Matrix), so I get a Unknown vector, a RHS
> vector, and a matrix for the 4 variables
>
> then I perform multiple time-steps,
>    DMForestTemplate(DMForest ->  DMForestPost)
>    Adapt DMForestPost
>    DMCreateGlovalVector(DMForestPost, RefinedUnknownVector)
>    DMForestTransferVec(UnknownVector , RefinedUnknownVector)
>    DMForestPost -> DMForest
> and then DMConvert(DMForest,DMPLEX,DM)
> and I can solve the system as usual. That also seems to work.
>
> But my conceptual question: how can I convert the other variable vectors
> (obtained with a different section on the same DM) such as density and
> viscosity and faceVelocity within this framework?
>

Here is my current thinking about DMs. A DM is a function space overlaying
a topology. Much to my dismay, we
do not have a topology object, so it hides inside DM. DMClone() creates a
shallow copy of the topology. We use
this to have any number of data layouts through PetscSection, laying over
the same underlying topology.

So for each layout you have, make a separate clone. Then things like
TransferVec() will respond to the layout in
that clone. Certainly it works this way in Plex. I admit to not having
tried this for TransferVec(), but let me know if
you have any problems.

BTW, I usually use a dm for the solution, which I give to the solver, say
SNESSetDM(snes, dm), and then clone
it as dmAux which has the layout for all the auxiliary fields that are not
involved in the solve. The Plex examples
all use this form.

  Thanks,

     Matt


> The DMForest has the same Section as the original DM and will thus have
> the space for exactly 4 variables per cell. I tried pushing another
> section on the DMForest and DMForestPost, but that does not seem to
> work. Please find attached a working example with code to do this, but I
> get the error:
>
> PETSC ERROR: PetscSectionGetChart() line 513 in
> /usr/local/petsc-3.12.4/src/vec/is/section/interface/section.c Wrong
> type of object: Parameter # 1
>
> So, I is there a way to DMForestTransferVec my other vectors from one
> DMForest to DMForestPost. How can I do this?
>
> Many thanks for your help!
>
> Best wishes, Berend.
>


-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200312/f1ca57d4/attachment.html>


More information about the petsc-users mailing list