Actual source code: stagintern.c
1: /* DMStag dimension-independent internal functions. If added to the public API,
2: these would move to stagutils.c */
4: #include <petsc/private/dmstagimpl.h>
6: /*
7: DMStagDuplicateWithoutSetup - duplicate a `DMSTAG` object without setting it up
9: Collective
11: Input Parameters:
12: + dm - The original `DM` object
13: - comm - the MPI communicator for the new DM (`MPI_COMM_NULL` to use the same communicator as `dm`)
15: Output Parameter:
16: . newdm - The new `DM` object
18: Level: developer
20: Developer Notes:
21: Copies over all of the state for a `DMSTAG` object, except that which is
22: populated during `DMSetUp()`. This function is used within (all) other
23: functions that require an un-setup clone, which is common when duplicating,
24: coarsening, refining, or creating compatible `DM`s with different fields. For
25: this reason it also accepts an MPI communicator as an argument (though note
26: that at the time of this writing, implementations of `DMCoarsen()` and `DMRefine()`
27: don't usually seem to respect their "comm" arguments). This function could be
28: pushed up to the general `DM` API (and perhaps given a different name).
30: .seealso: [](ch_stag), `DMSTAG`, `DM`, `DMClone()`, `DMStagCreateCompatibleDMStag()`, `DMCoarsen()`, `DMRefine()`
31: */
32: PetscErrorCode DMStagDuplicateWithoutSetup(DM dm, MPI_Comm comm, DM *newdm)
33: {
34: DM_Stag *const stag = (DM_Stag *)dm->data;
35: DM_Stag *newstag;
36: PetscInt dim;
37: MPI_Comm newcomm;
39: PetscFunctionBegin;
41: newcomm = (comm == MPI_COMM_NULL) ? PetscObjectComm((PetscObject)dm) : comm;
42: PetscCall(DMCreate(newcomm, newdm));
43: PetscCall(DMGetDimension(dm, &dim));
44: PetscCall(DMSetDimension(*newdm, dim));
46: /* Call routine to define all data required for setup */
47: 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,
48: stag->stencilWidth, stag->l[0], stag->l[1], stag->l[2], *newdm));
50: /* Copy all data unrelated to setup */
51: newstag = (DM_Stag *)(*newdm)->data;
52: PetscCall(PetscStrallocpy(stag->coordinateDMType, (char **)&newstag->coordinateDMType));
53: PetscCall(PetscArraycpy(newstag->refineFactor, stag->refineFactor, DMSTAG_MAX_DIM));
55: /* Copy vectype and mattype from original DM */
56: PetscCall(DMSetVecType(*newdm, dm->vectype));
57: PetscCall(DMSetMatType(*newdm, dm->mattype));
58: PetscFunctionReturn(PETSC_SUCCESS);
59: }
61: /* Populate data created after DMCreate_Stag() is called, which is used by DMSetUp_Stag(),
62: such as the grid dimensions and dof information. Arguments are ignored for dimensions
63: less than three. */
64: 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)
65: {
66: PetscFunctionBegin;
67: PetscCall(DMSetType(dm, DMSTAG));
68: PetscCall(DMStagSetBoundaryTypes(dm, bndx, bndy, bndz));
69: PetscCall(DMStagSetGlobalSizes(dm, M, N, P));
70: PetscCall(DMStagSetNumRanks(dm, m, n, p));
71: PetscCall(DMStagSetStencilType(dm, stencilType));
72: PetscCall(DMStagSetStencilWidth(dm, stencilWidth));
73: PetscCall(DMStagSetDOF(dm, dof0, dof1, dof2, dof3));
74: PetscCall(DMStagSetOwnershipRanges(dm, lx, ly, lz));
75: PetscFunctionReturn(PETSC_SUCCESS);
76: }