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: /* Note: this is an internal function but we provide a man page in case it's made public */
7: /*@C
8: DMStagDuplicateWithoutSetup - duplicate a DMStag object without setting it up
10: Collective
12: Input Parameters:
13: + dm - The original DM object
14: - comm - the MPI communicator for the new DM (MPI_COMM_NULL to use the same communicator as dm)
16: Output Parameter:
17: . newdm - The new DM object
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 DMs 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: Level: developer
31: .seealso: DMClone(), DMStagCreateCompatibleDMStag(), DMCoarsen(), DMRefine()
32: @*/
33: PetscErrorCode DMStagDuplicateWithoutSetup(DM dm, MPI_Comm comm, DM *newdm)
34: {
35: DM_Stag * const stag = (DM_Stag*)dm->data;
36: DM_Stag *newstag;
37: PetscInt dim;
38: MPI_Comm newcomm;
41: newcomm = (comm == MPI_COMM_NULL) ? PetscObjectComm((PetscObject)dm) : comm;
42: DMCreate(newcomm,newdm);
43: DMGetDimension(dm,&dim);
44: DMSetDimension(*newdm,dim);
46: /* Call routine to define all data required for setup */
47: 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,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: PetscStrallocpy(stag->coordinateDMType,(char**)&newstag->coordinateDMType);
52: return 0;
53: }
55: /* Populate data created after DMCreate_Stag() is called, which is used by DMSetUp_Stag(),
56: such as the grid dimensions and dof information. Arguments are ignored for dimensions
57: less than three. */
58: 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)
59: {
60: DMSetType(dm,DMSTAG);
61: DMStagSetBoundaryTypes(dm,bndx,bndy,bndz);
62: DMStagSetGlobalSizes(dm,M,N,P);
63: DMStagSetNumRanks(dm,m,n,p);
64: DMStagSetStencilType(dm,stencilType);
65: DMStagSetStencilWidth(dm,stencilWidth);
66: DMStagSetDOF(dm,dof0,dof1,dof2,dof3);
67: DMStagSetOwnershipRanges(dm,lx,ly,lz);
68: return 0;
69: }