[petsc-users] PetscSections and DMPlex's

Matthew Knepley knepley at gmail.com
Mon Feb 28 14:03:24 CST 2022


On Mon, Feb 28, 2022 at 2:15 PM Ferrand, Jesus A. <FERRANJ2 at my.erau.edu>
wrote:

> Dear PETSc team:
>
> I am working on an FEA code that solves the elasticity equation using P1
> elements. I want to write Vecs to ParaView in .vtk format. I can output the
> displacements by defining a PetscSection that assigned dof over the
> vertices of my mesh. I can export this Vec using PetscViewerVTKAddField()
> and DMPlexVTKWriteAll(). Now I want to export strains and stresses using
> the same VTK functions, but these Vecs need a different PetscSection (one
> that assigns dof over the cells). My concern is that to output
> displacements I attached the PetscSection to the DMPlex using
> DMSetLocalSection(). I'm not sure if I can define another local section for
> my cell-based strains and stresses and set it as a local section .
>

1. I think this is possible, and will try to lay it out below. However, VTK
is not a great format, so I will offer another, more flexible solution,
afterwards.

    The way to do this is to call DMClone(dm, &sdm) to get another DM with
the same topology. Then set the Section to be your cellwise section
    for strains. Then you just output that vector into the same VTK file.
Since the topology is the same, this will work.

2. We have converted from VTK to HDF5 for Paraview. It is _much_ more
flexible.

    You have the same two DMs, and you output one of them to the HDF5 file
suing DMView(), and all the fields using VecView(). I usually use
     DMViewFromOptions() and VecViewFromOptions() and then something like

       -dm_view hdf5:sol.h5 -disp_vec_view hdf5:sol.h5::append
-strain_vec_view hdf5:sol.h5::append

   and then process that file to make an XDMF file sol.xmf

       $PETSC_DIR/lib/petc/bin/petsc_gen_xdmf.py sol.h5

    All the fields will show up in Paraview when you load sol.xmf. This
approach handles multiple timesteps, multiple meshes, mesh change, and many
other things.

      THanks,

         Matt


>  My questions are:
>
>    - Could I perhaps do this with DMSetGlobalSection()?
>    - Can a DM hold multiple PetscSections (say multiple local sections
>    and multiple global sections)?
>       - If so, how can select individual ones to properly output Vecs
>       with DMPlexVTKWriteAll()?
>       - Does the local PetscSection depend on the Global one or vice
>    versa?
>    - Can I avoid having to define a PetscSection altogether for my
>    cell-based Vecs if I use DMCreateGlobalVector()?
>       - I got this idea from the source code of DMPlexCreateRankField(),
>       which I successfully use to visualize my mesh partition.
>
> Sorry for the mouthful.
>
> Sincerely:
>
> *J.A. Ferrand*
>
> Embry-Riddle Aeronautical University - Daytona Beach FL
>
> M.Sc. Aerospace Engineering | May 2022
>
> B.Sc. Aerospace Engineering
>
> B.Sc. Computational Mathematics
>
>
>
> Sigma Gamma Tau
>
> Tau Beta Pi
>
> Honors Program
>
>
>
> *Phone:* (386)-843-1829
>
> *Email(s):* ferranj2 at my.erau.edu
>
>     jesus.ferrand at gmail.com
>


-- 
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/20220228/e902a81b/attachment.html>


More information about the petsc-users mailing list