Actual source code: stagintern.c

      1: /* DMStag dimension-independent internal functions. If added to the public API, these would move to stagutils.c */

      3: #include <petsc/private/dmstagimpl.h>

      5: /*
      6:   DMStagDuplicateWithoutSetup - duplicate a `DMSTAG` object without setting it up

      8:   Collective

     10:   Input Parameters:
     11: + dm - The original `DM` object
     12: - comm - the MPI communicator for the new DM (`MPI_COMM_NULL` to use the same communicator as `dm`)

     14:   Output Parameter:
     15: . newdm  - The new `DM` object

     17:   Level: developer

     19:   Developer Notes:
     20:   Copies over all of the state for a `DMSTAG` object, except that which is
     21:   populated during `DMSetUp()`.  This function is used within (all) other
     22:   functions that require an un-setup clone, which is common when duplicating,
     23:   coarsening, refining, or creating compatible `DM`s with different fields.  For
     24:   this reason it also accepts an MPI communicator as an argument (though note
     25:   that at the time of this writing, implementations of `DMCoarsen()` and `DMRefine()`
     26:   don't usually seem to respect their "comm" arguments). This function could be
     27:   pushed up to the general `DM` API (and perhaps given a different name).

     29: .seealso: [](ch_stag), `DMSTAG`, `DM`, `DMClone()`, `DMStagCreateCompatibleDMStag()`, `DMCoarsen()`, `DMRefine()`
     30: */
     31: PetscErrorCode DMStagDuplicateWithoutSetup(DM dm, MPI_Comm comm, DM *newdm)
     32: {
     33:   DM_Stag *const stag = (DM_Stag *)dm->data;
     34:   DM_Stag       *newstag;
     35:   PetscInt       dim;
     36:   MPI_Comm       newcomm;

     38:   PetscFunctionBegin;
     40:   newcomm = (comm == MPI_COMM_NULL) ? PetscObjectComm((PetscObject)dm) : comm;
     41:   PetscCall(DMCreate(newcomm, newdm));
     42:   PetscCall(DMGetDimension(dm, &dim));
     43:   PetscCall(DMSetDimension(*newdm, dim));

     45:   /* Call routine to define all data required for setup */
     46:   PetscCall(DMStagInitialize(stag->boundaryType[0], stag->boundaryType[1], stag->boundaryType[2], stag->N[0], stag->N[1], stag->N[2], stag->nRanks[0], stag->nRanks[1], stag->nRanks[2], stag->dof[0], stag->dof[1], stag->dof[2], stag->dof[3], stag->stencilType,
     47:                              stag->stencilWidth, stag->l[0], stag->l[1], stag->l[2], *newdm));

     49:   /* Copy all data unrelated to setup */
     50:   newstag = (DM_Stag *)(*newdm)->data;
     51:   PetscCall(PetscStrallocpy(stag->coordinateDMType, (char **)&newstag->coordinateDMType));
     52:   PetscCall(PetscArraycpy(newstag->refineFactor, stag->refineFactor, DMSTAG_MAX_DIM));

     54:   /* Copy vectype and mattype from original DM */
     55:   PetscCall(DMSetVecType(*newdm, dm->vectype));
     56:   PetscCall(DMSetMatType(*newdm, dm->mattype));
     57:   PetscFunctionReturn(PETSC_SUCCESS);
     58: }

     60: /* Populate data created after DMCreate_Stag() is called, which is used by DMSetUp_Stag(),
     61:    such as the grid dimensions and dof information. Arguments are ignored for dimensions
     62:    less than three. */
     63: PetscErrorCode DMStagInitialize(DMBoundaryType bndx, DMBoundaryType bndy, DMBoundaryType bndz, PetscInt M, PetscInt N, PetscInt P, PetscInt m, PetscInt n, PetscInt p, PetscInt dof0, PetscInt dof1, PetscInt dof2, PetscInt dof3, DMStagStencilType stencilType, PetscInt stencilWidth, const PetscInt lx[], const PetscInt ly[], const PetscInt lz[], DM dm)
     64: {
     65:   PetscFunctionBegin;
     66:   PetscCall(DMSetType(dm, DMSTAG));
     67:   PetscCall(DMStagSetBoundaryTypes(dm, bndx, bndy, bndz));
     68:   PetscCall(DMStagSetGlobalSizes(dm, M, N, P));
     69:   PetscCall(DMStagSetNumRanks(dm, m, n, p));
     70:   PetscCall(DMStagSetStencilType(dm, stencilType));
     71:   PetscCall(DMStagSetStencilWidth(dm, stencilWidth));
     72:   PetscCall(DMStagSetDOF(dm, dof0, dof1, dof2, dof3));
     73:   PetscCall(DMStagSetOwnershipRanges(dm, lx, ly, lz));
     74:   PetscFunctionReturn(PETSC_SUCCESS);
     75: }