Finite Elements support

Experimental html version of Parallel Programming in MPI, OpenMP, and PETSc by Victor Eijkhout. download the textbook at https:/
\[ \newcommand\inv{^{-1}}\newcommand\invt{^{-t}} \newcommand\bbP{\mathbb{P}} \newcommand\bbR{\mathbb{R}} \newcommand\defined{ \mathrel{\lower 5pt \hbox{${\equiv\atop\mathrm{\scriptstyle D}}$}}} \] 34.1 : General Data Management
34.1.1 : Matrix from dmplex
Back to Table of Contents

34 Finite Elements support

34.1 General Data Management

crumb trail: > petsc-fem > General Data Management

ierr = DMCreate(PETSC_COMM_WORLD, &dm);
ierr = DMSetType(dm, DMPLEX);

A DMPLEX is by default two-dimensional. Use

plexprogram  -dm_plex_dim k

for other dimensions. In two dimensions there are three levels of cells:

The default $2\times 2$ grid has, sequentially: \csnippetwithoutput{pdmview}{code/petsc/c}{sphereviewnp1} and parallel: \csnippetwithoutput{pdmview}{code/petsc/c}{sphereviewnp4}

For larger grids:

plexprogram -dm_plex_box_faces 4,4

Graphics output from

plexprogram -dm_view draw -draw_pause 20


plexprogram -dm_view :outputfile.tex:ascii_latex \
            -dm_plex_view_scale 4

\hbox to \textwidth { \hfil }

34.1.1 Matrix from dmplex

crumb trail: > petsc-fem > General Data Management > Matrix from dmplex

Loop over batch of elements (e):
  Loop over element matrix entries (f,fc,g,gc --> i,j:
   Loop over quadrature points (q):
(loops over fields,Nb,Ncomp)
elemMat[i,j] +=
$\psi^{fc}_f(q) g^{(0)}_{fc,gc}(u, \nabla u) \phi^{gc}_g(q)$
     $+ \psi^{fc}_f(q) \cdot g^{(1)}w_{fc,gc,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)$
     $+ \nabla\psi^{fc}_f(q) \cdot g^{(2)}_{fc,gc,df}(u, \nabla u) \phi^{gc}_g(q)$
     $+ \nabla\psi^{fc}_f(q) \cdot g^{(3)}_{fc,gc,df,dg}(u, \nabla u) \nabla\phi^{gc}_g(q)$

// plexsphere.c
ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);
ierr = PetscSectionCreate(PetscObjectComm((PetscObject) dm), &s);
ierr = DMSetLocalSection(dm, s);
ierr = PetscSectionDestroy(&s);

ierr = PetscSectionSetNumFields(s, 1);
ierr = PetscSectionSetFieldComponents(s, 0, 1);
ierr = PetscSectionSetChart(s, vStart, vEnd);
//  printf("start-end: %d -- %d\n",vStart,vEnd);
for (v = vStart; v < vEnd; ++v) {
  ierr = PetscSectionSetDof(s, v, 1);
  ierr = PetscSectionSetFieldDof(s, v, 0, 1);
ierr = PetscSectionSetUp(s);

Back to Table of Contents