DM

The DM module provides the base functionality for managing distributed data structures in PETSc. It serves as a foundation for various grid managers.

Overview

A DM object encapsulates the topology and data layout of a computational grid, enabling:

  • Parallel data distribution across MPI processes
  • Ghost point management for communication
  • Creation of vectors and matrices with appropriate parallel layouts
  • Multigrid hierarchy management

DM Types in PETSc

PETSc provides several DM implementations for different mesh types:

High-Level Interface Available in PETSc.jl

DM TypeDescriptionStatus
DMDADistributed arrays for structured grids (1D/2D/3D)✅ Full support
DMStagStaggered grids for finite volume/difference methods✅ Full support

Low-Level Interface Only (via LibPETSc)

The following DM types are available through the low-level LibPETSc wrapper but do not yet have a convenient high-level Julia interface:

DM TypeDescriptionUse Case
DMPlexUnstructured meshes with arbitrary topologyFinite elements, complex geometries
DMForestAdaptive mesh refinement (AMR) via p4est/p8estOctree-based adaptivity
DMNetworkGraph/network structuresPower grids, pipe networks
DMSwarmParticle data managementPIC methods, Lagrangian particles
DMProductTensor product of DMsSemi-structured problems
DMSlicedSliced representationLegacy, specialized uses
DMShellUser-defined DMCustom implementations
DMCompositeComposition of multiple DMsMulti-physics coupling
DMRedundantRedundant storage on all ranksSmall coupled systems

Using Low-Level DM Types

For DM types without high-level wrappers, you can use the LibPETSc module directly:

using PETSc
using PETSc.LibPETSc

# Example: Create a DMPlex (low-level)
petsclib = PETSc.petsclibs[1]
dm = LibPETSc.DMPlexCreate(petsclib, MPI.COMM_WORLD)
# ... configure using LibPETSc functions ...
LibPETSc.DMDestroy(petsclib, dm)
Contributing

Contributions to add high-level interfaces for additional DM types are welcome! See the Contributing page for guidelines.

Functions

Base.emptyMethod
empty(da::AbstractPetscDM)

return an uninitialized DMDA struct.

source
Base.sizeMethod
size(dm::AbstractPetscDM)

Return the global size of a DM object as a tuple.

For DMDA and DMStag, returns (M, N, P) where unused dimensions are 1.

source
PETSc.DMGlobalVecMethod
v::PetscVec = DMGlobalVec(dm::AbstractPetscDM{PetscLib}) where {PetscLib}

Returns a global vector v from the dm object.

source
PETSc.DMLocalVecMethod
v::PetscVec = DMLocalVec(dm::AbstractPetscDM{PetscLib}) where {PetscLib}

Returns a local vector v from the dm object.

source
PETSc.MatAIJMethod
MatAIJ(da::AbstractPetscDM)

Create a sparse matrix (AIJ format) with sparsity pattern determined by the DM.

Returns

A PetscMat object compatible with vectors from the DM.

External Links

source
PETSc.destroyMethod
destroy(dm::AbstractPetscDM)

Destroy a DM object and release associated resources.

This function is typically called automatically via finalizers when the object is garbage collected, but can be called explicitly to free resources immediately.

External Links

source
PETSc.dm_global_to_local!Method
dm_global_to_local!(global_vec, local_vec, dm, mode = INSERT_VALUES)

Transfer values from the global_vec to the local_vec associated with the dm object, including ghost point values from neighboring processes.

Arguments

  • global_vec::AbstractPetscVec: Global vector (source)
  • local_vec::AbstractPetscVec: Local vector (destination)
  • dm::AbstractPetscDM: DM object
  • mode::InsertMode: Insert mode, either INSERT_VALUES or ADD_VALUES

External Links

source
PETSc.dm_global_to_localMethod
dm_global_to_local(dm, x_G, x_L, mode = INSERT_VALUES)

Transfer values from the global vector x_G to the local vector x_L, including ghost point values from neighboring processes.

Arguments

  • dm: The DM object
  • x_G: Global vector (source)
  • x_L: Local vector (destination)
  • mode: INSERT_VALUES (default) or ADD_VALUES

External Links

source
PETSc.dm_local_to_global!Method
dm_local_to_global!(local_vec, global_vec, dm, mode = INSERT_VALUES)

Transfer values from the local_vec to the global_vec associated with the dm object.

Arguments

  • local_vec::AbstractPetscVec: Local vector (source)
  • global_vec::AbstractPetscVec: Global vector (destination)
  • dm::AbstractPetscDM: DM object
  • mode::InsertMode: Insert mode, either INSERT_VALUES or ADD_VALUES

External Links

source
PETSc.dm_local_to_globalMethod
dm_local_to_global(dm, x_L, x_G, mode = INSERT_VALUES)

Transfer values from the local vector x_L to the global vector x_G.

Arguments

  • dm: The DM object
  • x_L: Local vector (source)
  • x_G: Global vector (destination)
  • mode: INSERT_VALUES (default) or ADD_VALUES

External Links

source
PETSc.getcornersMethod
lower, upper, size = getcorners(da::AbstractDMDA)

Returns a NamedTuple with the global indices (excluding ghost points) of the lower and upper corners as well as the size. Works for both a DMDA and DMStag object

source
PETSc.getcorners_dmdaMethod
lower, upper, size = getcorners_dmda(da::AbstractDMDA)

Returns a NamedTuple with the global indices (excluding ghost points) of the lower and upper corners as well as the size.

Calls LibPETSc.DMDAGetCorners.

source
PETSc.getghostcornersMethod
lower, upper, size = getghostcorners(da::AbstractDMDA)

Returns a NamedTuple with the global indices (including ghost points) of the lower and upper corners as well as the size. Works for both a DMDA and DMStag object

source
PETSc.getghostcorners_dmdaMethod
lower, upper, size = getghostcorners_dmda(da::AbstractDMDA)

Returns a NamedTuple with the global indices (including ghost points) of the lower and upper corners as well as the size of the local part of the domain.

Calls LibPETSc.DMDAGetCorners.

source
PETSc.getinfoMethod
getinfo(dm::AbstractPetscDM)

Get information about a DMDA.

Returns

A NamedTuple with the following fields:

  • dim: Dimension of the DMDA (1, 2, or 3)
  • global_size: Tuple with global dimensions in each direction of the array
  • mpi_proc_size: Tuple with number of MPI processes in each direction
  • dof: Degrees of freedom per node
  • stencil_width: Width of the stencil
  • boundary_type: Tuple with boundary types in each direction
  • stencil_type: Stencil type, either DMDA_STENCIL_STAR or DMDA_STENCIL_BOX

External Links

source
PETSc.getlocalcoordinatearrayMethod
getlocalcoordinatearray(da::AbstractPetscDM)

Return coordinate arrays for the local portion of the domain.

The returned arrays are OffsetArrays that can be addressed using global indices, accounting for ghost points.

External Links

source
PETSc.setuniformcoordinates_dmda!Method
setuniformcoordinates!(
    da::DMDA
    xyzmin::NTuple{N, Real},
    xyzmax::NTuple{N, Real},
) where {N}

Set uniform coordinates for the da using the lower and upper corners defined by the NTuples xyzmin and xyzmax. If N is less than the dimension of the da then the value of the trailing coordinates is set to 0.

External Links

source