Actual source code: stag.c

petsc-master 2019-09-16
Report Typos and Errors
  1: /*
  2:    Implementation of DMStag, defining dimension-independent functions in the
  3:    DM API. stag1d.c, stag2d.c, and stag3d.c may include dimension-specific
  4:    implementations of DM API functions, and other files here contain additional
  5:    DMStag-specific API functions (and internal functions).
  6: */
  7:  #include <petsc/private/dmstagimpl.h>
  8:  #include <petscsf.h>

 10: /*MC
 11:   DMSTAG = "stag"

 13:   Level: intermediate

 15: .seealso: DMType, DMCreate(), DMSetType()
 16: M*/

 18: static PetscErrorCode DMDestroy_Stag(DM dm)
 19: {
 21:   DM_Stag        *stag;
 22:   PetscInt       i;

 25:   stag = (DM_Stag*)dm->data;
 26:   for (i=0; i<DMSTAG_MAX_DIM; ++i) {
 27:     PetscFree(stag->l[i]);
 28:   }
 29:   VecScatterDestroy(&stag->gtol);
 30:   VecScatterDestroy(&stag->ltog_injective);
 31:   PetscFree(stag->neighbors);
 32:   PetscFree(stag->locationOffsets);
 33:   PetscFree(stag);
 34:   return(0);
 35: }

 37: static PetscErrorCode DMCreateGlobalVector_Stag(DM dm,Vec *vec)
 38: {
 39:   PetscErrorCode  ierr;
 40:   DM_Stag * const stag = (DM_Stag*)dm->data;

 43:   VecCreateMPI(PetscObjectComm((PetscObject)dm),stag->entries,PETSC_DECIDE,vec);
 44:   VecSetDM(*vec,dm);
 45:   /* Could set some ops, as DMDA does */
 46:   VecSetLocalToGlobalMapping(*vec,dm->ltogmap);
 47:   return(0);
 48: }

 50: static PetscErrorCode DMCreateLocalVector_Stag(DM dm,Vec *vec)
 51: {
 52:   PetscErrorCode  ierr;
 53:   DM_Stag * const stag = (DM_Stag*)dm->data;

 56:   VecCreateSeq(PETSC_COMM_SELF,stag->entriesGhost,vec);
 57:   VecSetBlockSize(*vec,stag->entriesPerElement);
 58:   VecSetDM(*vec,dm);
 59:   return(0);
 60: }

 62: static PetscErrorCode DMCreateMatrix_Stag(DM dm,Mat *mat)
 63: {
 64:   PetscErrorCode         ierr;
 65:   const DM_Stag * const  stag = (DM_Stag*)dm->data;
 66:   MatType                matType;
 67:   PetscBool              isaij,isshell;
 68:   PetscInt               width,nNeighbors,dim;
 69:   ISLocalToGlobalMapping ltogmap;

 72:   DMGetDimension(dm,&dim);
 73:   DMGetMatType(dm,&matType);
 74:   PetscStrcmp(matType,MATAIJ,&isaij);
 75:   PetscStrcmp(matType,MATSHELL,&isshell);

 77:   if (isaij) {
 78:     /* This implementation gives a very dense stencil, which is likely unsuitable for
 79:        real applications. */
 80:     switch (stag->stencilType) {
 81:       case DMSTAG_STENCIL_NONE:
 82:         nNeighbors = 1;
 83:         break;
 84:       case DMSTAG_STENCIL_STAR:
 85:         switch (dim) {
 86:           case 1 :
 87:             nNeighbors = 2*stag->stencilWidth + 1;
 88:             break;
 89:           case 2 :
 90:             nNeighbors = 4*stag->stencilWidth + 3;
 91:             break;
 92:           case 3 :
 93:             nNeighbors = 6*stag->stencilWidth + 5;
 94:             break;
 95:           default : SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Unsupported dimension %d",dim);
 96:         }
 97:         break;
 98:       case DMSTAG_STENCIL_BOX:
 99:         switch (dim) {
100:           case 1 :
101:             nNeighbors = (2*stag->stencilWidth + 1);
102:             break;
103:           case 2 :
104:             nNeighbors = (2*stag->stencilWidth + 1) * (2*stag->stencilWidth + 1);
105:             break;
106:           case 3 :
107:             nNeighbors = (2*stag->stencilWidth + 1) * (2*stag->stencilWidth + 1) * (2*stag->stencilWidth + 1);
108:             break;
109:           default : SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Unsupported dimension %d",dim);
110:         }
111:         break;
112:       default : SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Unsupported stencil");
113:     }
114:     width = (stag->dof[0] + stag->dof[1] + stag->dof[2] + stag->dof[3]) * nNeighbors;
115:     MatCreateAIJ(PETSC_COMM_WORLD,stag->entries,stag->entries,PETSC_DETERMINE,PETSC_DETERMINE,width,NULL,width,NULL,mat);
116:   } else if (isshell) {
117:     MatCreate(PetscObjectComm((PetscObject)dm),mat);
118:     MatSetSizes(*mat,stag->entries,stag->entries,PETSC_DETERMINE,PETSC_DETERMINE);
119:     MatSetType(*mat,MATSHELL);
120:     MatSetUp(*mat);
121:   } else SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Not implemented for Mattype %s",matType);

123:   DMGetLocalToGlobalMapping(dm,&ltogmap);
124:   MatSetLocalToGlobalMapping(*mat,ltogmap,ltogmap);
125:   MatSetDM(*mat,dm);
126:   return(0);
127: }

129: static PetscErrorCode DMGetCompatibility_Stag(DM dm,DM dm2,PetscBool *compatible,PetscBool *set)
130: {
131:   PetscErrorCode  ierr;
132:   const DM_Stag * const stag  = (DM_Stag*)dm->data;
133:   const DM_Stag * const stag2 = (DM_Stag*)dm2->data;
134:   PetscInt              dim,dim2,i;
135:   MPI_Comm              comm;
136:   PetscMPIInt           sameComm;
137:   DMType                type2;
138:   PetscBool             sameType;

141:   DMGetType(dm2,&type2);
142:   PetscStrcmp(DMSTAG,type2,&sameType);
143:   if (!sameType) {
144:     PetscInfo1((PetscObject)dm,"DMStag compatibility check not implemented with DM of type %s\n",type2);
145:     *set = PETSC_FALSE;
146:     return(0);
147:   }

149:   PetscObjectGetComm((PetscObject)dm,&comm);
150:   MPI_Comm_compare(comm,PetscObjectComm((PetscObject)dm2),&sameComm);
151:   if (sameComm != MPI_IDENT) {
152:     PetscInfo2((PetscObject)dm,"DMStag objects have different communicators: %d != %d\n",comm,PetscObjectComm((PetscObject)dm2));
153:     *set = PETSC_FALSE;
154:     return(0);
155:   }
156:   DMGetDimension(dm ,&dim );
157:   DMGetDimension(dm2,&dim2);
158:   if (dim != dim2) {
159:     PetscInfo((PetscObject)dm,"DMStag objects have different dimensions");
160:     *set = PETSC_TRUE;
161:     *compatible = PETSC_FALSE;
162:     return(0);
163:   }
164:   for (i=0; i<dim; ++i) {
165:     if (stag->N[i] != stag2->N[i]) {
166:       PetscInfo3((PetscObject)dm,"DMStag objects have different global numbers of elements in dimension %D: %D != %D\n",i,stag->n[i],stag2->n[i]);
167:       *set = PETSC_TRUE;
168:       *compatible = PETSC_FALSE;
169:       return(0);
170:     }
171:     if (stag->n[i] != stag2->n[i]) {
172:       PetscInfo3((PetscObject)dm,"DMStag objects have different local numbers of elements in dimension %D: %D != %D\n",i,stag->n[i],stag2->n[i]);
173:       *set = PETSC_TRUE;
174:       *compatible = PETSC_FALSE;
175:       return(0);
176:     }
177:     if (stag->boundaryType[i] != stag2->boundaryType[i]) {
178:       PetscInfo3((PetscObject)dm,"DMStag objects have different boundary types in dimension %d: %s != %s\n",i,stag->boundaryType[i],stag2->boundaryType[i]);
179:       *set = PETSC_TRUE;
180:       *compatible = PETSC_FALSE;
181:       return(0);
182:     }
183:   }
184:   /* Note: we include stencil type and width in the notion of compatibility, as this affects
185:      the "atlas" (local subdomains). This might be irritating in legitimate cases
186:      of wanting to transfer between two other-wise compatible DMs with different
187:      stencil characteristics. */
188:   if (stag->stencilType != stag2->stencilType) {
189:     PetscInfo2((PetscObject)dm,"DMStag objects have different ghost stencil types: %s != %s\n",DMStagStencilTypes[stag->stencilType],DMStagStencilTypes[stag2->stencilType]);
190:     *set = PETSC_TRUE;
191:     *compatible = PETSC_FALSE;
192:     return(0);
193:   }
194:   if (stag->stencilWidth != stag2->stencilWidth) {
195:     PetscInfo2((PetscObject)dm,"DMStag objects have different ghost stencil widths: %D != %D\n",stag->stencilWidth,stag->stencilWidth);
196:     *set = PETSC_TRUE;
197:     *compatible = PETSC_FALSE;
198:     return(0);
199:   }
200:   *set = PETSC_TRUE;
201:   *compatible = PETSC_TRUE;
202:   return(0);
203: }


206: /*
207: Note there are several orderings in play here.
208: In all cases, non-element dof are associated with the element that they are below/left/behind, and the order in 2D proceeds vertex/bottom edge/left edge/element (with all dof on each together).
209: Also in all cases, only subdomains which are the last in their dimension have partial elements.

211: 1) "Natural" Ordering (not used). Number adding each full or partial (on the right or top) element, starting at the bottom left (i=0,j=0) and proceeding across the entire domain, row by row to get a global numbering.
212: 2) Global ("PETSc") ordering. The same as natural, but restricted to each domain. So, traverse all elements (again starting at the bottom left and going row-by-row) on rank 0, then continue numbering with rank 1, and so on.
213: 3) Local ordering. Including ghost elements (both interior and on the right/top/front to complete partial elements), use the same convention to create a local numbering.
214: */

216: static PetscErrorCode DMLocalToGlobalBegin_Stag(DM dm,Vec l,InsertMode mode,Vec g)
217: {
218:   PetscErrorCode  ierr;
219:   DM_Stag * const stag = (DM_Stag*)dm->data;

222:   if (mode == ADD_VALUES) {
223:     VecScatterBegin(stag->gtol,l,g,mode,SCATTER_REVERSE);
224:   } else if (mode == INSERT_VALUES) {
225:     if (stag->ltog_injective) {
226:       VecScatterBegin(stag->ltog_injective,l,g,mode,SCATTER_FORWARD);
227:     } else {
228:       VecScatterBegin(stag->gtol,l,g,mode,SCATTER_REVERSE_LOCAL);
229:     }
230:   } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Unsupported InsertMode");
231:   return(0);
232: }

234: static PetscErrorCode DMLocalToGlobalEnd_Stag(DM dm,Vec l,InsertMode mode,Vec g)
235: {
236:   PetscErrorCode  ierr;
237:   DM_Stag * const stag = (DM_Stag*)dm->data;

240:   if (mode == ADD_VALUES) {
241:     VecScatterEnd(stag->gtol,l,g,mode,SCATTER_REVERSE);
242:   } else if (mode == INSERT_VALUES) {
243:     if (stag->ltog_injective) {
244:       VecScatterEnd(stag->ltog_injective,l,g,mode,SCATTER_FORWARD);
245:     } else {
246:       VecScatterEnd(stag->gtol,l,g,mode,SCATTER_REVERSE_LOCAL);
247:     }
248:   } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Unsupported InsertMode");
249:   return(0);
250: }

252: static PetscErrorCode DMGlobalToLocalBegin_Stag(DM dm,Vec g,InsertMode mode,Vec l)
253: {
254:   PetscErrorCode  ierr;
255:   DM_Stag * const stag = (DM_Stag*)dm->data;

258:   VecScatterBegin(stag->gtol,g,l,mode,SCATTER_FORWARD);
259:   return(0);
260: }

262: static PetscErrorCode DMGlobalToLocalEnd_Stag(DM dm,Vec g,InsertMode mode,Vec l)
263: {
264:   PetscErrorCode  ierr;
265:   DM_Stag * const stag = (DM_Stag*)dm->data;

268:   VecScatterEnd(stag->gtol,g,l,mode,SCATTER_FORWARD);
269:   return(0);
270: }

272: /*
273: If a stratum is active (non-zero dof), make it active in the coordinate DM.
274: */
275: static PetscErrorCode DMCreateCoordinateDM_Stag(DM dm,DM *dmc)
276: {
277:   PetscErrorCode  ierr;
278:   DM_Stag * const stag = (DM_Stag*)dm->data;
279:   PetscInt        dim;
280:   PetscBool       isstag,isproduct;


284:   if (!stag->coordinateDMType) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Before creating a coordinate DM, a type must be specified with DMStagSetCoordinateDMType()");

286:   DMGetDimension(dm,&dim);
287:   PetscStrcmp(stag->coordinateDMType,DMSTAG,&isstag);
288:   PetscStrcmp(stag->coordinateDMType,DMPRODUCT,&isproduct);
289:   if (isstag) {
290:     DMStagCreateCompatibleDMStag(dm,
291:         stag->dof[0] > 0 ? dim : 0,
292:         stag->dof[1] > 0 ? dim : 0,
293:         stag->dof[2] > 0 ? dim : 0,
294:         stag->dof[3] > 0 ? dim : 0,
295:         dmc);
296:   } else if (isproduct) {
297:     DMCreate(PETSC_COMM_WORLD,dmc);
298:     DMSetType(*dmc,DMPRODUCT);
299:     DMSetDimension(*dmc,dim);
300:   } else SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Unsupported coordinate DM type %s",stag->coordinateDMType);
301:   return(0);
302: }

304: static PetscErrorCode DMGetNeighbors_Stag(DM dm,PetscInt *nRanks,const PetscMPIInt *ranks[])
305: {
306:   PetscErrorCode  ierr;
307:   DM_Stag * const stag = (DM_Stag*)dm->data;
308:   PetscInt        dim;

311:   DMGetDimension(dm,&dim);
312:   switch (dim) {
313:     case 1: *nRanks = 3; break;
314:     case 2: *nRanks = 9; break;
315:     case 3: *nRanks = 27; break;
316:     default : SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Get neighbors not implemented for dim = %D",dim);
317:   }
318:   *ranks = stag->neighbors;
319:   return(0);
320: }

322: static PetscErrorCode DMView_Stag(DM dm,PetscViewer viewer)
323: {
324:   PetscErrorCode  ierr;
325:   DM_Stag * const stag = (DM_Stag*)dm->data;
326:   PetscBool       isascii,viewAllRanks;
327:   PetscMPIInt     rank,size;
328:   PetscInt        dim,maxRanksToView,i;

331:   MPI_Comm_rank(PetscObjectComm((PetscObject)dm),&rank);
332:   MPI_Comm_size(PetscObjectComm((PetscObject)dm),&size);
333:   DMGetDimension(dm,&dim);
334:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
335:   if (isascii) {
336:     PetscViewerASCIIPrintf(viewer,"Dimension: %D\n",dim);
337:     switch (dim) {
338:       case 1:
339:         PetscViewerASCIIPrintf(viewer,"Global size: %D\n",stag->N[0]);
340:         break;
341:       case 2:
342:         PetscViewerASCIIPrintf(viewer,"Global sizes: %D x %D\n",stag->N[0],stag->N[1]);
343:         PetscViewerASCIIPrintf(viewer,"Parallel decomposition: %D x %D ranks\n",stag->nRanks[0],stag->nRanks[1]);
344:         break;
345:       case 3:
346:         PetscViewerASCIIPrintf(viewer,"Global sizes: %D x %D x %D\n",stag->N[0],stag->N[1],stag->N[2]);
347:         PetscViewerASCIIPrintf(viewer,"Parallel decomposition: %D x %D x %D ranks\n",stag->nRanks[0],stag->nRanks[1],stag->nRanks[2]);
348:         break;
349:       default: SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"not implemented for dim==%D",dim);
350:     }
351:     PetscViewerASCIIPrintf(viewer,"Boundary ghosting:");
352:     for (i=0; i<dim; ++i) {
353:       PetscViewerASCIIPrintf(viewer," %s",DMBoundaryTypes[stag->boundaryType[i]]);
354:     }
355:     PetscViewerASCIIPrintf(viewer,"\n");
356:     PetscViewerASCIIPrintf(viewer,"Elementwise ghost stencil: %s, width %D\n",DMStagStencilTypes[stag->stencilType],stag->stencilWidth);
357:     PetscViewerASCIIPrintf(viewer,"Stratum dof:");
358:     for (i=0; i<dim+1; ++i) {
359:       PetscViewerASCIIPrintf(viewer," %D:%D",i,stag->dof[i]);
360:     }
361:     PetscViewerASCIIPrintf(viewer,"\n");
362:     if(dm->coordinateDM) {
363:       PetscViewerASCIIPrintf(viewer,"Has coordinate DM\n");
364:     }
365:     maxRanksToView = 16;
366:     viewAllRanks = (PetscBool)(size <= maxRanksToView);
367:     if (viewAllRanks) {
368:       PetscViewerASCIIPushSynchronized(viewer);
369:       switch (dim) {
370:         case 1:
371:           PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Local elements : %D (%D with ghosts)\n",rank,stag->n[0],stag->nGhost[0]);
372:           break;
373:         case 2:
374:           PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Rank coordinates (%d,%d)\n",rank,stag->rank[0],stag->rank[1]);
375:           PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Local elements : %D x %D (%D x %D with ghosts)\n",rank,stag->n[0],stag->n[1],stag->nGhost[0],stag->nGhost[1]);
376:           break;
377:         case 3:
378:           PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Rank coordinates (%d,%d,%d)\n",rank,stag->rank[0],stag->rank[1],stag->rank[2]);
379:           PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Local elements : %D x %D x %D (%D x %D x %D with ghosts)\n",rank,stag->n[0],stag->n[1],stag->n[2],stag->nGhost[0],stag->nGhost[1],stag->nGhost[2]);
380:           break;
381:         default: SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"not implemented for dim==%D",dim);
382:       }
383:       PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Local native entries: %d\n",rank,stag->entries     );
384:       PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Local entries total : %d\n",rank,stag->entriesGhost);
385:       PetscViewerFlush(viewer);
386:       PetscViewerASCIIPopSynchronized(viewer);
387:     } else {
388:       PetscViewerASCIIPrintf(viewer,"(Per-rank information omitted since >%D ranks used)\n",maxRanksToView);
389:     }
390:   }
391:   return(0);
392: }

394: static PetscErrorCode DMSetFromOptions_Stag(PetscOptionItems *PetscOptionsObject,DM dm)
395: {
396:   PetscErrorCode  ierr;
397:   DM_Stag * const stag = (DM_Stag*)dm->data;
398:   PetscInt        dim;

401:   DMGetDimension(dm,&dim);
402:   PetscOptionsHead(PetscOptionsObject,"DMStag Options");
403:   PetscOptionsInt("-stag_grid_x","Number of grid points in x direction","DMStagSetGlobalSizes",stag->N[0],&stag->N[0],NULL);
404:   if (dim > 1) { PetscOptionsInt("-stag_grid_y","Number of grid points in y direction","DMStagSetGlobalSizes",stag->N[1],&stag->N[1],NULL); }
405:   if (dim > 2) { PetscOptionsInt("-stag_grid_z","Number of grid points in z direction","DMStagSetGlobalSizes",stag->N[2],&stag->N[2],NULL); }
406:   PetscOptionsInt("-stag_ranks_x","Number of ranks in x direction","DMStagSetNumRanks",stag->nRanks[0],&stag->nRanks[0],NULL);
407:   if (dim > 1) { PetscOptionsInt("-stag_ranks_y","Number of ranks in y direction","DMStagSetNumRanks",stag->nRanks[1],&stag->nRanks[1],NULL); }
408:   if (dim > 2) { PetscOptionsInt("-stag_ranks_z","Number of ranks in z direction","DMStagSetNumRanks",stag->nRanks[2],&stag->nRanks[2],NULL); }
409:   PetscOptionsInt("-stag_stencil_width","Elementwise stencil width","DMStagSetStencilWidth",stag->stencilWidth,&stag->stencilWidth,NULL);
410:   PetscOptionsEnum("-stag_stencil_type","Elementwise stencil stype","DMStagSetStencilType",DMStagStencilTypes,(PetscEnum)stag->stencilType,(PetscEnum*)&stag->stencilType,NULL);
411:   PetscOptionsEnum("-stag_boundary_type_x","Treatment of (physical) boundaries in x direction","DMStagSetBoundaryTypes",DMBoundaryTypes,(PetscEnum)stag->boundaryType[0],(PetscEnum*)&stag->boundaryType[0],NULL);
412:   PetscOptionsEnum("-stag_boundary_type_y","Treatment of (physical) boundaries in y direction","DMStagSetBoundaryTypes",DMBoundaryTypes,(PetscEnum)stag->boundaryType[1],(PetscEnum*)&stag->boundaryType[1],NULL);
413:   PetscOptionsEnum("-stag_boundary_type_z","Treatment of (physical) boundaries in z direction","DMStagSetBoundaryTypes",DMBoundaryTypes,(PetscEnum)stag->boundaryType[2],(PetscEnum*)&stag->boundaryType[2],NULL);
414:   PetscOptionsInt("-stag_dof_0","Number of dof per 0-cell (vertex/corner)","DMStagSetDOF",stag->dof[0],&stag->dof[0],NULL);
415:   PetscOptionsInt("-stag_dof_1","Number of dof per 1-cell (edge)",         "DMStagSetDOF",stag->dof[1],&stag->dof[1],NULL);
416:   PetscOptionsInt("-stag_dof_2","Number of dof per 2-cell (face)",         "DMStagSetDOF",stag->dof[2],&stag->dof[2],NULL);
417:   PetscOptionsInt("-stag_dof_3","Number of dof per 3-cell (hexahedron)",   "DMStagSetDOF",stag->dof[3],&stag->dof[3],NULL);
418:   PetscOptionsTail();
419:   return(0);
420: }

422: /*MC
423:   DMSTAG = "stag" - A DM object, similar to DMDA, representing a "staggered grid" or a structured cell complex.

425:   Level: beginner

427: .seealso: DM, DMPRODUCT, DMDA, DMPLEX, DMStagCreate1d(), DMStagCreate2d(), DMStagCreate3d()
428: M*/

430: PETSC_EXTERN PetscErrorCode DMCreate_Stag(DM dm)
431: {
433:   DM_Stag        *stag;
434:   PetscInt       i,dim;

438:   PetscNewLog(dm,&stag);
439:   dm->data = stag;

441:   stag->gtol                                          = NULL;
442:   stag->ltog_injective                                = NULL;
443:   for (i=0; i<DMSTAG_MAX_STRATA; ++i) stag->dof[i]    = 0;
444:   for (i=0; i<DMSTAG_MAX_DIM;    ++i) stag->l[i]      = NULL;
445:   stag->stencilType                                   = DMSTAG_STENCIL_NONE;
446:   stag->stencilWidth                                  = 0;
447:   for (i=0; i<DMSTAG_MAX_DIM;    ++i) stag->nRanks[i] = -1;
448:   stag->coordinateDMType                              = NULL;

450:   DMGetDimension(dm,&dim);

452:   PetscMemzero(dm->ops,sizeof(*(dm->ops)));
453:   dm->ops->createcoordinatedm  = DMCreateCoordinateDM_Stag;
454:   dm->ops->createglobalvector  = DMCreateGlobalVector_Stag;
455:   dm->ops->createinterpolation = NULL;
456:   dm->ops->createlocalvector   = DMCreateLocalVector_Stag;
457:   dm->ops->creatematrix        = DMCreateMatrix_Stag;
458:   dm->ops->destroy             = DMDestroy_Stag;
459:   dm->ops->getneighbors        = DMGetNeighbors_Stag;
460:   dm->ops->globaltolocalbegin  = DMGlobalToLocalBegin_Stag;
461:   dm->ops->globaltolocalend    = DMGlobalToLocalEnd_Stag;
462:   dm->ops->localtoglobalbegin  = DMLocalToGlobalBegin_Stag;
463:   dm->ops->localtoglobalend    = DMLocalToGlobalEnd_Stag;
464:   dm->ops->setfromoptions      = DMSetFromOptions_Stag;
465:   switch (dim) {
466:     case 1: dm->ops->setup     = DMSetUp_Stag_1d; break;
467:     case 2: dm->ops->setup     = DMSetUp_Stag_2d; break;
468:     case 3: dm->ops->setup     = DMSetUp_Stag_3d; break;
469:     default : SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"Unsupported dimension %d",dim);
470:   }
471:   dm->ops->view                = DMView_Stag;
472:   dm->ops->getcompatibility    = DMGetCompatibility_Stag;
473:   return(0);
474: }