DMDA

The DMDA (Distributed Array) module provides functionality for creating and managing structured grids in 1D, 2D, or 3D.

Overview

DMDA is ideal for problems on regular structured grids where:

  • The grid is logically rectangular
  • Each grid point has the same number of degrees of freedom
  • Stencil operations follow a regular pattern (star or box stencils)

Creating a DMDA

# 2D grid example
da = DMDA(
    petsclib,
    MPI.COMM_WORLD,
    (DM_BOUNDARY_NONE, DM_BOUNDARY_NONE),  # boundary types
    (nx, ny),                               # global dimensions
    1,                                      # degrees of freedom per node
    1,                                      # stencil width
    DMDA_STENCIL_STAR                      # stencil type
)

Functions

PETSc.DMDAMethod
DMDA(
    petsclib::PetscLib
    comm::MPI.Comm,
    boundary_type::NTuple{D, DMBoundaryType},
    global_dim::NTuple{D, Integer},
    dof_per_node::Integer,
    stencil_width::Integer,
    stencil_type;
    points_per_proc::Tuple,
    processors::Tuple,
    setfromoptions = true,
    dmsetup = true,
    prefix = "",
    options...
)

Creates a D-dimensional distributed array with the options specified using keyword arguments.

If keyword argument points_per_proc[k] isa Vector{petsclib.PetscInt} then this specifies the points per processor in dimension k.

If keyword argument processors[k] isa Integer then this specifies the number of processors used in dimension k; ignored when D == 1.

If keyword argument setfromoptions == true then setfromoptions! called.

If keyword argument dmsetup == true then setup! is called.

When D == 1 the stencil_type argument is not required and ignored if specified.

External Links

source
PETSc.dmda_star_fd_coloringMethod
dmda_star_fd_coloring(petsclib, da)

Build all data needed for manual FD coloring of a 2-D DMDA with a STAR stencil, using IS_COLORING_LOCAL and ghost-local COO indexing.

Specifically, this function:

  1. Creates an IS_COLORING_LOCAL ISColoring via DMCreateColoring and extracts the per-DOF color vector (ghost-local layout).
  2. Enumerates all STAR-stencil (row, col) pairs for every owned node and records their ghost-local 0-based indices and colors.
  3. Builds per-color index arrays (perturb_cols, coo_idxs, local_rows) ready for use in an FD coloring Newton loop.

Returns a NamedTuple:

  • n_colors — number of colors
  • n_local_dofs — number of locally owned DOFs (owned nodes × dof/node)
  • nnz_coo — total number of COO entries
  • row_coo_local — ghost-local 0-based row indices (Vector{PetscInt})
  • col_coo_local — ghost-local 0-based column indices (Vector{PetscInt})
  • perturb_colsperturb_cols[c]: 1-based owned-local column indices with color c-1; used to scatter +h perturbations.
  • coo_idxscoo_idxs[c]: 1-based COO entry indices for color c-1
  • local_rowslocal_rows[c]: corresponding 1-based owned-local residual-row indices; used to read (f1-f0)/h.
2-D DMDA STAR stencil only

Neighbor enumeration covers only ±x and ±y directions. The ghost-local flat-index formula is d + ix*dof + iy*dof*nx_g. For a 3-D DMDA:

  • add ±z neighbors guarded by kk > 1 / kk < mz,
  • extend the flat-index formula with + iz*dof*nx_g*ny_g,
  • reshape col_colors_mat to (dof, nx_g, ny_g, nz_g),
  • decode z_owned in the perturb_cols loop.
source
PETSc.localinteriorlinearindexMethod
ind = localinteriorlinearindex(dmda::AbstractPetscDM)

Returns the linear indices associated with the degrees of freedom own by this MPI rank embedded in the ghost index space for the dmda

source
PETSc.reshapelocalarrayMethod
reshapelocalarray(Arr, da::AbstractPetscDM{PetscLib}, ndof = ndofs(da))

Returns an array with the same data as Arr but reshaped as an array that can be addressed with global indexing.

source