Actual source code: dmimpl.h

petsc-main 2021-04-20
Report Typos and Errors


  3: #if !defined(_DMIMPL_H)
  4: #define _DMIMPL_H

  6: #include <petscdm.h>
  7: #include <petsc/private/petscimpl.h>
  8: #include <petsc/private/petscdsimpl.h>
  9: #include <petsc/private/sectionimpl.h>

 11: PETSC_EXTERN PetscBool DMRegisterAllCalled;
 12: PETSC_EXTERN PetscErrorCode DMRegisterAll(void);
 13: typedef PetscErrorCode (*NullSpaceFunc)(DM dm, PetscInt origField, PetscInt field, MatNullSpace *nullSpace);

 15: typedef struct _PetscHashAuxKey
 16: {
 17:   DMLabel  label;
 18:   PetscInt value;
 19: } PetscHashAuxKey;

 21: #define PetscHashAuxKeyHash(key) PetscHashCombine(PetscHashPointer((key).label),PetscHashInt((key).value))

 23: #define PetscHashAuxKeyEqual(k1,k2) (((k1).label == (k2).label) ? ((k1).value == (k2).value) : 0)

 25: PETSC_HASH_MAP(HMapAux, PetscHashAuxKey, Vec, PetscHashAuxKeyHash, PetscHashAuxKeyEqual, NULL)

 27: typedef struct _DMOps *DMOps;
 28: struct _DMOps {
 29:   PetscErrorCode (*view)(DM,PetscViewer);
 30:   PetscErrorCode (*load)(DM,PetscViewer);
 31:   PetscErrorCode (*clone)(DM,DM*);
 32:   PetscErrorCode (*setfromoptions)(PetscOptionItems*,DM);
 33:   PetscErrorCode (*setup)(DM);
 34:   PetscErrorCode (*createlocalsection)(DM);
 35:   PetscErrorCode (*createdefaultconstraints)(DM);
 36:   PetscErrorCode (*createglobalvector)(DM,Vec*);
 37:   PetscErrorCode (*createlocalvector)(DM,Vec*);
 38:   PetscErrorCode (*getlocaltoglobalmapping)(DM);
 39:   PetscErrorCode (*createfieldis)(DM,PetscInt*,char***,IS**);
 40:   PetscErrorCode (*createcoordinatedm)(DM,DM*);
 41:   PetscErrorCode (*createcoordinatefield)(DM,DMField*);

 43:   PetscErrorCode (*getcoloring)(DM,ISColoringType,ISColoring*);
 44:   PetscErrorCode (*creatematrix)(DM, Mat*);
 45:   PetscErrorCode (*createinterpolation)(DM,DM,Mat*,Vec*);
 46:   PetscErrorCode (*createrestriction)(DM,DM,Mat*);
 47:   PetscErrorCode (*createmassmatrix)(DM,DM,Mat*);
 48:   PetscErrorCode (*hascreateinjection)(DM,PetscBool*);
 49:   PetscErrorCode (*createinjection)(DM,DM,Mat*);

 51:   PetscErrorCode (*refine)(DM,MPI_Comm,DM*);
 52:   PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*);
 53:   PetscErrorCode (*refinehierarchy)(DM,PetscInt,DM*);
 54:   PetscErrorCode (*coarsenhierarchy)(DM,PetscInt,DM*);
 55:   PetscErrorCode (*adaptlabel)(DM,DMLabel,DM*);
 56:   PetscErrorCode (*adaptmetric)(DM,Vec,DMLabel,DM*);

 58:   PetscErrorCode (*globaltolocalbegin)(DM,Vec,InsertMode,Vec);
 59:   PetscErrorCode (*globaltolocalend)(DM,Vec,InsertMode,Vec);
 60:   PetscErrorCode (*localtoglobalbegin)(DM,Vec,InsertMode,Vec);
 61:   PetscErrorCode (*localtoglobalend)(DM,Vec,InsertMode,Vec);
 62:   PetscErrorCode (*localtolocalbegin)(DM,Vec,InsertMode,Vec);
 63:   PetscErrorCode (*localtolocalend)(DM,Vec,InsertMode,Vec);

 65:   PetscErrorCode (*destroy)(DM);

 67:   PetscErrorCode (*computevariablebounds)(DM,Vec,Vec);

 69:   PetscErrorCode (*createsubdm)(DM,PetscInt,const PetscInt*,IS*,DM*);
 70:   PetscErrorCode (*createsuperdm)(DM*,PetscInt,IS**,DM*);
 71:   PetscErrorCode (*createfielddecomposition)(DM,PetscInt*,char***,IS**,DM**);
 72:   PetscErrorCode (*createdomaindecomposition)(DM,PetscInt*,char***,IS**,IS**,DM**);
 73:   PetscErrorCode (*createddscatters)(DM,PetscInt,DM*,VecScatter**,VecScatter**,VecScatter**);

 75:   PetscErrorCode (*getdimpoints)(DM,PetscInt,PetscInt*,PetscInt*);
 76:   PetscErrorCode (*locatepoints)(DM,Vec,DMPointLocationType,PetscSF);
 77:   PetscErrorCode (*getneighbors)(DM,PetscInt*,const PetscMPIInt**);
 78:   PetscErrorCode (*getboundingbox)(DM,PetscReal*,PetscReal*);
 79:   PetscErrorCode (*getlocalboundingbox)(DM,PetscReal*,PetscReal*);
 80:   PetscErrorCode (*locatepointssubdomain)(DM,Vec,PetscMPIInt**);

 82:   PetscErrorCode (*projectfunctionlocal)(DM,PetscReal,PetscErrorCode(**)(PetscInt,PetscReal,const PetscReal[],PetscInt,PetscScalar *,void *),void **,InsertMode,Vec);
 83:   PetscErrorCode (*projectfunctionlabellocal)(DM,PetscReal,DMLabel,PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscErrorCode(**)(PetscInt,PetscReal,const PetscReal[],PetscInt,PetscScalar *,void *),void **,InsertMode,Vec);
 84:   PetscErrorCode (*projectfieldlocal)(DM,PetscReal,Vec,void(**)(PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],const PetscScalar[],const PetscScalar[],const PetscInt[],const PetscInt[],const PetscScalar[],const PetscScalar[],const PetscScalar[],PetscReal,const PetscReal[],PetscInt,const PetscScalar[],PetscScalar[]),InsertMode,Vec);
 85:   PetscErrorCode (*projectfieldlabellocal)(DM,PetscReal,DMLabel,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Vec,void(**)(PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],const PetscScalar[],const PetscScalar[],const PetscInt[],const PetscInt[],const PetscScalar[],const PetscScalar[],const PetscScalar[],PetscReal,const PetscReal[],PetscInt,const PetscScalar[],PetscScalar[]),InsertMode,Vec);
 86:   PetscErrorCode (*projectbdfieldlabellocal)(DM,PetscReal,DMLabel,PetscInt,const PetscInt[],PetscInt,const PetscInt[],Vec,void(**)(PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscInt[],const PetscScalar[],const PetscScalar[],const PetscScalar[],const PetscInt[],const PetscInt[],const PetscScalar[],const PetscScalar[],const PetscScalar[],PetscReal,const PetscReal[],const PetscReal[],PetscInt,const PetscScalar[],PetscScalar[]),InsertMode,Vec);
 87:   PetscErrorCode (*computel2diff)(DM,PetscReal,PetscErrorCode(**)(PetscInt, PetscReal,const PetscReal [], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);
 88:   PetscErrorCode (*computel2gradientdiff)(DM,PetscReal,PetscErrorCode(**)(PetscInt,PetscReal,const PetscReal [],const PetscReal[],PetscInt, PetscScalar *,void *),void **,Vec,const PetscReal[],PetscReal *);
 89:   PetscErrorCode (*computel2fielddiff)(DM,PetscReal,PetscErrorCode(**)(PetscInt, PetscReal,const PetscReal [], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);

 91:   PetscErrorCode (*getcompatibility)(DM,DM,PetscBool*,PetscBool*);
 92: };

 94: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);
 95: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinateReal_Internal(DM, PetscInt, const PetscReal[], const PetscReal[], PetscReal[]);
 96: PETSC_EXTERN PetscErrorCode DMLocalizeAddCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);

 98: typedef struct _DMCoarsenHookLink *DMCoarsenHookLink;
 99: struct _DMCoarsenHookLink {
100:   PetscErrorCode (*coarsenhook)(DM,DM,void*);              /* Run once, when coarse DM is created */
101:   PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*); /* Run each time a new problem is restricted to a coarse grid */
102:   void *ctx;
103:   DMCoarsenHookLink next;
104: };

106: typedef struct _DMRefineHookLink *DMRefineHookLink;
107: struct _DMRefineHookLink {
108:   PetscErrorCode (*refinehook)(DM,DM,void*);     /* Run once, when a fine DM is created */
109:   PetscErrorCode (*interphook)(DM,Mat,DM,void*); /* Run each time a new problem is interpolated to a fine grid */
110:   void *ctx;
111:   DMRefineHookLink next;
112: };

114: typedef struct _DMSubDomainHookLink *DMSubDomainHookLink;
115: struct _DMSubDomainHookLink {
116:   PetscErrorCode (*ddhook)(DM,DM,void*);
117:   PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*);
118:   void *ctx;
119:   DMSubDomainHookLink next;
120: };

122: typedef struct _DMGlobalToLocalHookLink *DMGlobalToLocalHookLink;
123: struct _DMGlobalToLocalHookLink {
124:   PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*);
125:   PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*);
126:   void *ctx;
127:   DMGlobalToLocalHookLink next;
128: };

130: typedef struct _DMLocalToGlobalHookLink *DMLocalToGlobalHookLink;
131: struct _DMLocalToGlobalHookLink {
132:   PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*);
133:   PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*);
134:   void *ctx;
135:   DMLocalToGlobalHookLink next;
136: };

138: typedef enum {DMVEC_STATUS_IN,DMVEC_STATUS_OUT} DMVecStatus;
139: typedef struct _DMNamedVecLink *DMNamedVecLink;
140: struct _DMNamedVecLink {
141:   Vec X;
142:   char *name;
143:   DMVecStatus status;
144:   DMNamedVecLink next;
145: };

147: typedef struct _DMWorkLink *DMWorkLink;
148: struct _DMWorkLink {
149:   size_t     bytes;
150:   void       *mem;
151:   DMWorkLink next;
152: };

154: #define DM_MAX_WORK_VECTORS 100 /* work vectors available to users  via DMGetGlobalVector(), DMGetLocalVector() */

156: struct _n_DMLabelLink {
157:   DMLabel              label;
158:   PetscBool            output;
159:   struct _n_DMLabelLink *next;
160: };
161: typedef struct _n_DMLabelLink *DMLabelLink;

163: typedef struct _n_Boundary *DMBoundary;

165: struct _n_Boundary {
166:   DSBoundary  dsboundary;
167:   DMLabel     label;
168:   DMBoundary  next;
169: };

171: typedef struct _n_Field {
172:   PetscObject disc;         /* Field discretization, or a PetscContainer with the field name */
173:   DMLabel     label;        /* Label defining the domain of definition of the field */
174:   PetscBool   adjacency[2]; /* Flags for defining variable influence (adjacency) for each field [use cone() or support() first, use the transitive closure] */
175:   PetscBool   avoidTensor;  /* Flag to avoid defining field over tensor cells */
176: } RegionField;

178: typedef struct _n_Space {
179:   PetscDS ds;     /* Approximation space in this domain */
180:   DMLabel label;  /* Label defining the domain of definition of the discretization */
181:   IS      fields; /* Map from DS field numbers to original field numbers in the DM */
182: } DMSpace;

184: struct _p_UniversalLabel {
185:   DMLabel    label;   /* The universal label */
186:   PetscInt   Nl;      /* Number of labels encoded */
187:   char     **names;   /* The label names */
188:   PetscInt  *indices; /* The original indices in the input DM */
189:   PetscInt   Nv;      /* Total number of values in all the labels */
190:   PetscInt  *bits;    /* Starting bit for values of each label */
191:   PetscInt  *masks;   /* Masks to pull out label value bits for each label */
192:   PetscInt  *offsets; /* Starting offset for label values for each label */
193:   PetscInt  *values;  /* Original label values before renumbering */
194: };

196: PETSC_INTERN PetscErrorCode DMDestroyLabelLinkList_Internal(DM);

198: #define MAXDMMONITORS 5

200: struct _p_DM {
201:   PETSCHEADER(struct _DMOps);
202:   Vec                     localin[DM_MAX_WORK_VECTORS],localout[DM_MAX_WORK_VECTORS];
203:   Vec                     globalin[DM_MAX_WORK_VECTORS],globalout[DM_MAX_WORK_VECTORS];
204:   DMNamedVecLink          namedglobal;
205:   DMNamedVecLink          namedlocal;
206:   DMWorkLink              workin,workout;
207:   DMLabelLink             labels;            /* Linked list of labels */
208:   DMLabel                 depthLabel;        /* Optimized access to depth label */
209:   DMLabel                 celltypeLabel;     /* Optimized access to celltype label */
210:   void                    *ctx;    /* a user context */
211:   PetscErrorCode          (*ctxdestroy)(void**);
212:   ISColoringType          coloringtype;
213:   MatFDColoring           fd;
214:   VecType                 vectype;  /* type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() */
215:   MatType                 mattype;  /* type of matrix created with DMCreateMatrix() */
216:   PetscInt                bs;
217:   ISLocalToGlobalMapping  ltogmap;
218:   PetscBool               prealloc_only; /* Flag indicating the DMCreateMatrix() should only preallocate, not fill the matrix */
219:   PetscBool               structure_only; /* Flag indicating the DMCreateMatrix() create matrix structure without values */
220:   PetscInt                levelup,leveldown;  /* if the DM has been obtained by refining (or coarsening) this indicates how many times that process has been used to generate this DM */
221:   PetscBool               setupcalled;        /* Indicates that the DM has been set up, methods that modify a DM such that a fresh setup is required should reset this flag */
222:   PetscBool               setfromoptionscalled;
223:   void                    *data;
224:   /* Hierarchy / Submeshes */
225:   DM                      coarseMesh;
226:   DM                      fineMesh;
227:   DMCoarsenHookLink       coarsenhook; /* For transfering auxiliary problem data to coarser grids */
228:   DMRefineHookLink        refinehook;
229:   DMSubDomainHookLink     subdomainhook;
230:   DMGlobalToLocalHookLink gtolhook;
231:   DMLocalToGlobalHookLink ltoghook;
232:   /* Topology */
233:   PetscInt                dim;                  /* The topological dimension */
234:   /* Auxiliary data */
235:   PetscHMapAux            auxData;              /* Auxiliary DM and Vec for region denoted by the key */
236:   /* Flexible communication */
237:   PetscSF                 sfMigration;          /* SF for point distribution created during distribution */
238:   PetscSF                 sf;                   /* SF for parallel point overlap */
239:   PetscSF                 sectionSF;            /* SF for parallel dof overlap using section */
240:   PetscSF                 sfNatural;            /* SF mapping to the "natural" ordering */
241:   PetscBool               useNatural;           /* Create the natural SF */
242:   /* Allows a non-standard data layout */
243:   PetscBool               adjacency[2];         /* [use cone() or support() first, use the transitive closure] */
244:   PetscSection            localSection;         /* Layout for local vectors */
245:   PetscSection            globalSection;        /* Layout for global vectors */
246:   PetscLayout             map;
247:   /* Constraints */
248:   PetscSection            defaultConstraintSection;
249:   Mat                     defaultConstraintMat;
250:   /* Basis transformation */
251:   DM                      transformDM;          /* Layout for basis transformation */
252:   Vec                     transform;            /* Basis transformation matrices */
253:   void                   *transformCtx;         /* Basis transformation context */
254:   PetscErrorCode        (*transformSetUp)(DM, void *);
255:   PetscErrorCode        (*transformDestroy)(DM, void *);
256:   PetscErrorCode        (*transformGetMatrix)(DM, const PetscReal[], PetscBool, const PetscScalar **, void *);
257:   /* Coordinates */
258:   PetscInt                dimEmbed;             /* The dimension of the embedding space */
259:   DM                      coordinateDM;         /* Layout for coordinates */
260:   Vec                     coordinates;          /* Coordinate values in global vector */
261:   Vec                     coordinatesLocal;     /* Coordinate values in local  vector */
262:   PetscBool               periodic;             /* Is the DM periodic? */
263:   DMField                 coordinateField;      /* Coordinates as an abstract field */
264:   PetscReal              *L, *maxCell;          /* Size of periodic box and max cell size for determining periodicity */
265:   DMBoundaryType         *bdtype;               /* Indicates type of topological boundary */
266:   /* Null spaces -- of course I should make this have a variable number of fields */
267:   NullSpaceFunc           nullspaceConstructors[10];
268:   NullSpaceFunc           nearnullspaceConstructors[10];
269:   /* Fields are represented by objects */
270:   PetscInt                Nf;                   /* Number of fields defined on the total domain */
271:   RegionField            *fields;               /* Array of discretization fields with regions of validity */
272:   DMBoundary              boundary;             /* List of boundary conditions */
273:   PetscInt                Nds;                  /* Number of discrete systems defined on the total domain */
274:   DMSpace                *probs;                /* Array of discrete systems */
275:   /* Output structures */
276:   DM                      dmBC;                 /* The DM with boundary conditions in the global DM */
277:   PetscInt                outputSequenceNum;    /* The current sequence number for output */
278:   PetscReal               outputSequenceVal;    /* The current sequence value for output */
279:   PetscErrorCode        (*monitor[MAXDMMONITORS])(DM, void *);
280:   PetscErrorCode        (*monitordestroy[MAXDMMONITORS])(void **);
281:   void                   *monitorcontext[MAXDMMONITORS];
282:   PetscInt                numbermonitors;

284:   PetscObject             dmksp,dmsnes,dmts;
285: };

287: PETSC_EXTERN PetscLogEvent DM_Convert;
288: PETSC_EXTERN PetscLogEvent DM_GlobalToLocal;
289: PETSC_EXTERN PetscLogEvent DM_LocalToGlobal;
290: PETSC_EXTERN PetscLogEvent DM_LocatePoints;
291: PETSC_EXTERN PetscLogEvent DM_Coarsen;
292: PETSC_EXTERN PetscLogEvent DM_Refine;
293: PETSC_EXTERN PetscLogEvent DM_CreateInterpolation;
294: PETSC_EXTERN PetscLogEvent DM_CreateRestriction;
295: PETSC_EXTERN PetscLogEvent DM_CreateInjection;
296: PETSC_EXTERN PetscLogEvent DM_CreateMatrix;
297: PETSC_EXTERN PetscLogEvent DM_Load;
298: PETSC_EXTERN PetscLogEvent DM_AdaptInterpolator;

300: PETSC_EXTERN PetscErrorCode DMCreateGlobalVector_Section_Private(DM,Vec*);
301: PETSC_EXTERN PetscErrorCode DMCreateLocalVector_Section_Private(DM,Vec*);

303: PETSC_EXTERN PetscErrorCode DMView_GLVis(DM,PetscViewer,PetscErrorCode(*)(DM,PetscViewer));

305: /*

307:           Composite Vectors

309:       Single global representation
310:       Individual global representations
311:       Single local representation
312:       Individual local representations

314:       Subsets of individual as a single????? Do we handle this by having DMComposite inside composite??????

316:        DM da_u, da_v, da_p

318:        DM dm_velocities

320:        DM dm

322:        DMDACreate(,&da_u);
323:        DMDACreate(,&da_v);
324:        DMCompositeCreate(,&dm_velocities);
325:        DMCompositeAddDM(dm_velocities,(DM)du);
326:        DMCompositeAddDM(dm_velocities,(DM)dv);

328:        DMDACreate(,&da_p);
329:        DMCompositeCreate(,&dm_velocities);
330:        DMCompositeAddDM(dm,(DM)dm_velocities);
331:        DMCompositeAddDM(dm,(DM)dm_p);


334:     Access parts of composite vectors (Composite only)
335:     ---------------------------------
336:       DMCompositeGetAccess  - access the global vector as subvectors and array (for redundant arrays)
337:       ADD for local vector -

339:     Element access
340:     --------------
341:       From global vectors
342:          -DAVecGetArray   - for DMDA
343:          -VecGetArray - for DMSliced
344:          ADD for DMComposite???  maybe

346:       From individual vector
347:           -DAVecGetArray - for DMDA
348:           -VecGetArray -for sliced
349:          ADD for DMComposite??? maybe

351:       From single local vector
352:           ADD         * single local vector as arrays?

354:    Communication
355:    -------------
356:       DMGlobalToLocal - global vector to single local vector

358:       DMCompositeScatter/Gather - direct to individual local vectors and arrays   CHANGE name closer to GlobalToLocal?

360:    Obtaining vectors
361:    -----------------
362:       DMCreateGlobal/Local
363:       DMGetGlobal/Local
364:       DMCompositeGetLocalVectors   - gives individual local work vectors and arrays


367: ?????   individual global vectors   ????

369: */

371: #if defined(PETSC_HAVE_HDF5)
372: PETSC_EXTERN PetscErrorCode DMSequenceLoad_HDF5_Internal(DM, const char *, PetscInt, PetscScalar *, PetscViewer);
373: #endif

375: PETSC_STATIC_INLINE PetscErrorCode DMGetLocalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
376: {
378: #if defined(PETSC_USE_DEBUG)
379:   {
380:     PetscInt       dof;
382:     *start = *end = 0; /* Silence overzealous compiler warning */
383:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
384:     PetscSectionGetOffset(dm->localSection, point, start);
385:     PetscSectionGetDof(dm->localSection, point, &dof);
386:     *end = *start + dof;
387:   }
388: #else
389:   {
390:     const PetscSection s = dm->localSection;
391:     *start = s->atlasOff[point - s->pStart];
392:     *end   = *start + s->atlasDof[point - s->pStart];
393:   }
394: #endif
395:   return(0);
396: }

398: PETSC_STATIC_INLINE PetscErrorCode DMGetLocalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
399: {
401: #if defined(PETSC_USE_DEBUG)
402:   {
403:     PetscInt       dof;
405:     *start = *end = 0; /* Silence overzealous compiler warning */
406:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
407:     PetscSectionGetFieldOffset(dm->localSection, point, field, start);
408:     PetscSectionGetFieldDof(dm->localSection, point, field, &dof);
409:     *end = *start + dof;
410:   }
411: #else
412:   {
413:     const PetscSection s = dm->localSection->field[field];
414:     *start = s->atlasOff[point - s->pStart];
415:     *end   = *start + s->atlasDof[point - s->pStart];
416:   }
417: #endif
418:   return(0);
419: }

421: PETSC_STATIC_INLINE PetscErrorCode DMGetGlobalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
422: {
424: #if defined(PETSC_USE_DEBUG)
425:   {
427:     PetscInt       dof,cdof;
428:     *start = *end = 0; /* Silence overzealous compiler warning */
429:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
430:     if (!dm->globalSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be created automatically by DMGetGlobalSection()");
431:     PetscSectionGetOffset(dm->globalSection, point, start);
432:     PetscSectionGetDof(dm->globalSection, point, &dof);
433:     PetscSectionGetConstraintDof(dm->globalSection, point, &cdof);
434:     *end = *start + dof - cdof + (dof < 0 ? 1 : 0);
435:   }
436: #else
437:   {
438:     const PetscSection s    = dm->globalSection;
439:     const PetscInt     dof  = s->atlasDof[point - s->pStart];
440:     const PetscInt     cdof = s->bc ? s->bc->atlasDof[point - s->bc->pStart] : 0;
441:     *start = s->atlasOff[point - s->pStart];
442:     *end   = *start + dof - cdof + (dof < 0 ? 1 : 0);
443:   }
444: #endif
445:   return(0);
446: }

448: PETSC_STATIC_INLINE PetscErrorCode DMGetGlobalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
449: {
451: #if defined(PETSC_USE_DEBUG)
452:   {
453:     PetscInt       loff, lfoff, fdof, fcdof, ffcdof, f;
455:     *start = *end = 0; /* Silence overzealous compiler warning */
456:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
457:     if (!dm->globalSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be crated automatically by DMGetGlobalSection()");
458:     PetscSectionGetOffset(dm->globalSection, point, start);
459:     PetscSectionGetOffset(dm->localSection, point, &loff);
460:     PetscSectionGetFieldOffset(dm->localSection, point, field, &lfoff);
461:     PetscSectionGetFieldDof(dm->localSection, point, field, &fdof);
462:     PetscSectionGetFieldConstraintDof(dm->localSection, point, field, &fcdof);
463:     *start = *start < 0 ? *start - (lfoff-loff) : *start + lfoff-loff;
464:     for (f = 0; f < field; ++f) {
465:       PetscSectionGetFieldConstraintDof(dm->localSection, point, f, &ffcdof);
466:       *start = *start < 0 ? *start + ffcdof : *start - ffcdof;
467:     }
468:     *end   = *start < 0 ? *start - (fdof-fcdof) : *start + fdof-fcdof;
469:   }
470: #else
471:   {
472:     const PetscSection s     = dm->localSection;
473:     const PetscSection fs    = dm->localSection->field[field];
474:     const PetscSection gs    = dm->globalSection;
475:     const PetscInt     loff  = s->atlasOff[point - s->pStart];
476:     const PetscInt     goff  = gs->atlasOff[point - s->pStart];
477:     const PetscInt     lfoff = fs->atlasOff[point - s->pStart];
478:     const PetscInt     fdof  = fs->atlasDof[point - s->pStart];
479:     const PetscInt     fcdof = fs->bc ? fs->bc->atlasDof[point - fs->bc->pStart] : 0;
480:     PetscInt           ffcdof = 0, f;

482:     for (f = 0; f < field; ++f) {
483:       const PetscSection ffs = dm->localSection->field[f];
484:       ffcdof += ffs->bc ? ffs->bc->atlasDof[point - ffs->bc->pStart] : 0;
485:     }
486:     *start = goff + (goff < 0 ? loff-lfoff + ffcdof : lfoff-loff - ffcdof);
487:     *end   = *start < 0 ? *start - (fdof-fcdof) : *start + fdof-fcdof;
488:   }
489: #endif
490:   return(0);
491: }

493: PETSC_EXTERN PetscErrorCode DMGetBasisTransformDM_Internal(DM, DM *);
494: PETSC_EXTERN PetscErrorCode DMGetBasisTransformVec_Internal(DM, Vec *);
495: PETSC_INTERN PetscErrorCode DMConstructBasisTransform_Internal(DM);

497: PETSC_INTERN PetscErrorCode DMGetLocalBoundingIndices_DMDA(DM, PetscReal[], PetscReal[]);
498: PETSC_INTERN PetscErrorCode DMSetField_Internal(DM, PetscInt, DMLabel, PetscObject);

500: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreate(DM, DMUniversalLabel *);
501: PETSC_EXTERN PetscErrorCode DMUniversalLabelDestroy(DMUniversalLabel *);
502: PETSC_EXTERN PetscErrorCode DMUniversalLabelGetLabel(DMUniversalLabel, DMLabel *);
503: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreateLabels(DMUniversalLabel, PetscBool, DM);
504: PETSC_EXTERN PetscErrorCode DMUniversalLabelSetLabelValue(DMUniversalLabel, DM, PetscBool, PetscInt, PetscInt);

506: #endif