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.DMDA — Method
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
- PETSc Manual:
DMDA/DMDACreate1d
- PETSc Manual:
DMDA/DMDACreate2d
- PETSc Manual:
DMDA/DMDACreate3d
PETSc.dmda_star_fd_coloring — Method
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:
- Creates an
IS_COLORING_LOCALISColoringviaDMCreateColoringand extracts the per-DOF color vector (ghost-local layout). - Enumerates all STAR-stencil (row, col) pairs for every owned node and records their ghost-local 0-based indices and colors.
- 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 colorsn_local_dofs— number of locally owned DOFs (owned nodes × dof/node)nnz_coo— total number of COO entriesrow_coo_local— ghost-local 0-based row indices (Vector{PetscInt})col_coo_local— ghost-local 0-based column indices (Vector{PetscInt})perturb_cols—perturb_cols[c]: 1-based owned-local column indices with colorc-1; used to scatter+hperturbations.coo_idxs—coo_idxs[c]: 1-based COO entry indices for colorc-1local_rows—local_rows[c]: corresponding 1-based owned-local residual-row indices; used to read(f1-f0)/h.
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
±zneighbors guarded bykk > 1/kk < mz, - extend the flat-index formula with
+ iz*dof*nx_g*ny_g, - reshape
col_colors_matto(dof, nx_g, ny_g, nz_g), - decode
z_ownedin theperturb_colsloop.
PETSc.localinteriorlinearindex — Method
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
PETSc.ndofs — Method
ndofs(da::AbstractPetscDM)Return the number of dofs in for da
External Links
- PETSc Manual:
DMDA/DMDAGetDof
PETSc.reshapelocalarray — Method
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.