Actual source code: dmimpl.h

  1: #pragma once

  3: #include <petscdm.h>
  4: #ifdef PETSC_HAVE_LIBCEED
  5: #include <petscdmceed.h>
  6: #endif
  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:   DMLabel  label;
 17:   PetscInt value;
 18:   PetscInt part;
 19: } PetscHashAuxKey;

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

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

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

 27: struct _n_DMGeneratorFunctionList {
 28:   PetscErrorCode (*generate)(DM, PetscBool, DM *);
 29:   PetscErrorCode (*refine)(DM, PetscReal *, DM *);
 30:   PetscErrorCode (*adapt)(DM, Vec, DMLabel, DMLabel, DM *);
 31:   char                   *name;
 32:   PetscInt                dim;
 33:   DMGeneratorFunctionList next;
 34: };

 36: typedef struct _DMOps *DMOps;
 37: struct _DMOps {
 38:   PetscErrorCode (*view)(DM, PetscViewer);
 39:   PetscErrorCode (*load)(DM, PetscViewer);
 40:   PetscErrorCode (*clone)(DM, DM *);
 41:   PetscErrorCode (*setfromoptions)(DM, PetscOptionItems *);
 42:   PetscErrorCode (*setup)(DM);
 43:   PetscErrorCode (*createlocalsection)(DM);
 44:   PetscErrorCode (*createsectionpermutation)(DM, IS *, PetscBT *);
 45:   PetscErrorCode (*createdefaultconstraints)(DM);
 46:   PetscErrorCode (*createglobalvector)(DM, Vec *);
 47:   PetscErrorCode (*createlocalvector)(DM, Vec *);
 48:   PetscErrorCode (*getlocaltoglobalmapping)(DM);
 49:   PetscErrorCode (*createfieldis)(DM, PetscInt *, char ***, IS **);
 50:   PetscErrorCode (*createcoordinatedm)(DM, DM *);
 51:   PetscErrorCode (*createcoordinatefield)(DM, DMField *);

 53:   PetscErrorCode (*getcoloring)(DM, ISColoringType, ISColoring *);
 54:   PetscErrorCode (*creatematrix)(DM, Mat *);
 55:   PetscErrorCode (*createinterpolation)(DM, DM, Mat *, Vec *);
 56:   PetscErrorCode (*createrestriction)(DM, DM, Mat *);
 57:   PetscErrorCode (*createmassmatrix)(DM, DM, Mat *);
 58:   PetscErrorCode (*createmassmatrixlumped)(DM, Vec *);
 59:   PetscErrorCode (*hascreateinjection)(DM, PetscBool *);
 60:   PetscErrorCode (*createinjection)(DM, DM, Mat *);

 62:   PetscErrorCode (*refine)(DM, MPI_Comm, DM *);
 63:   PetscErrorCode (*coarsen)(DM, MPI_Comm, DM *);
 64:   PetscErrorCode (*refinehierarchy)(DM, PetscInt, DM *);
 65:   PetscErrorCode (*coarsenhierarchy)(DM, PetscInt, DM *);
 66:   PetscErrorCode (*extrude)(DM, PetscInt, DM *);

 68:   PetscErrorCode (*globaltolocalbegin)(DM, Vec, InsertMode, Vec);
 69:   PetscErrorCode (*globaltolocalend)(DM, Vec, InsertMode, Vec);
 70:   PetscErrorCode (*localtoglobalbegin)(DM, Vec, InsertMode, Vec);
 71:   PetscErrorCode (*localtoglobalend)(DM, Vec, InsertMode, Vec);
 72:   PetscErrorCode (*localtolocalbegin)(DM, Vec, InsertMode, Vec);
 73:   PetscErrorCode (*localtolocalend)(DM, Vec, InsertMode, Vec);

 75:   PetscErrorCode (*destroy)(DM);

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

 79:   PetscErrorCode (*createsubdm)(DM, PetscInt, const PetscInt *, IS *, DM *);
 80:   PetscErrorCode (*createsuperdm)(DM *, PetscInt, IS **, DM *);
 81:   PetscErrorCode (*createfielddecomposition)(DM, PetscInt *, char ***, IS **, DM **);
 82:   PetscErrorCode (*createdomaindecomposition)(DM, PetscInt *, char ***, IS **, IS **, DM **);
 83:   PetscErrorCode (*createddscatters)(DM, PetscInt, DM *, VecScatter **, VecScatter **, VecScatter **);

 85:   PetscErrorCode (*getdimpoints)(DM, PetscInt, PetscInt *, PetscInt *);
 86:   PetscErrorCode (*locatepoints)(DM, Vec, DMPointLocationType, PetscSF);
 87:   PetscErrorCode (*getneighbors)(DM, PetscInt *, const PetscMPIInt **);
 88:   PetscErrorCode (*getboundingbox)(DM, PetscReal *, PetscReal *);
 89:   PetscErrorCode (*getlocalboundingbox)(DM, PetscReal[], PetscReal[], PetscInt[], PetscInt[]);
 90:   PetscErrorCode (*locatepointssubdomain)(DM, Vec, PetscMPIInt **);

 92:   PetscErrorCode (*projectfunctionlocal)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, InsertMode, Vec);
 93:   PetscErrorCode (*projectfunctionlabellocal)(DM, PetscReal, DMLabel, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, InsertMode, Vec);
 94:   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);
 95:   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);
 96:   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);
 97:   PetscErrorCode (*computel2diff)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);
 98:   PetscErrorCode (*computel2gradientdiff)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], const PetscReal[], PetscInt, PetscScalar *, void *), void **, Vec, const PetscReal[], PetscReal *);
 99:   PetscErrorCode (*computel2fielddiff)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);

101:   PetscErrorCode (*getcompatibility)(DM, DM, PetscBool *, PetscBool *);
102: };

104: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);
105: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinateReal_Internal(DM, PetscInt, const PetscReal[], const PetscReal[], PetscReal[]);
106: PETSC_EXTERN PetscErrorCode DMLocalizeAddCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);

108: PETSC_INTERN PetscErrorCode DMCountNonCyclicReferences(PetscObject, PetscInt *);

110: typedef struct _DMCoarsenHookLink *DMCoarsenHookLink;
111: struct _DMCoarsenHookLink {
112:   PetscErrorCode (*coarsenhook)(DM, DM, void *);                 /* Run once, when coarse DM is created */
113:   PetscErrorCode (*restricthook)(DM, Mat, Vec, Mat, DM, void *); /* Run each time a new problem is restricted to a coarse grid */
114:   void             *ctx;
115:   DMCoarsenHookLink next;
116: };

118: typedef struct _DMRefineHookLink *DMRefineHookLink;
119: struct _DMRefineHookLink {
120:   PetscErrorCode (*refinehook)(DM, DM, void *);      /* Run once, when a fine DM is created */
121:   PetscErrorCode (*interphook)(DM, Mat, DM, void *); /* Run each time a new problem is interpolated to a fine grid */
122:   void            *ctx;
123:   DMRefineHookLink next;
124: };

126: typedef struct _DMSubDomainHookLink *DMSubDomainHookLink;
127: struct _DMSubDomainHookLink {
128:   PetscErrorCode (*ddhook)(DM, DM, void *);
129:   PetscErrorCode (*restricthook)(DM, VecScatter, VecScatter, DM, void *);
130:   void               *ctx;
131:   DMSubDomainHookLink next;
132: };

134: typedef struct _DMGlobalToLocalHookLink *DMGlobalToLocalHookLink;
135: struct _DMGlobalToLocalHookLink {
136:   PetscErrorCode (*beginhook)(DM, Vec, InsertMode, Vec, void *);
137:   PetscErrorCode (*endhook)(DM, Vec, InsertMode, Vec, void *);
138:   void                   *ctx;
139:   DMGlobalToLocalHookLink next;
140: };

142: typedef struct _DMLocalToGlobalHookLink *DMLocalToGlobalHookLink;
143: struct _DMLocalToGlobalHookLink {
144:   PetscErrorCode (*beginhook)(DM, Vec, InsertMode, Vec, void *);
145:   PetscErrorCode (*endhook)(DM, Vec, InsertMode, Vec, void *);
146:   void                   *ctx;
147:   DMLocalToGlobalHookLink next;
148: };

150: typedef enum {
151:   DMVEC_STATUS_IN,
152:   DMVEC_STATUS_OUT
153: } DMVecStatus;
154: typedef struct _DMNamedVecLink *DMNamedVecLink;
155: struct _DMNamedVecLink {
156:   Vec            X;
157:   char          *name;
158:   DMVecStatus    status;
159:   DMNamedVecLink next;
160: };

162: typedef struct _DMWorkLink *DMWorkLink;
163: struct _DMWorkLink {
164:   size_t     bytes;
165:   void      *mem;
166:   DMWorkLink next;
167: };

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

171: struct _n_DMLabelLink {
172:   DMLabel                label;
173:   PetscBool              output;
174:   struct _n_DMLabelLink *next;
175: };
176: typedef struct _n_DMLabelLink *DMLabelLink;

178: typedef struct _n_Boundary *DMBoundary;

180: struct _n_Boundary {
181:   DSBoundary dsboundary;
182:   DMLabel    label;
183:   DMBoundary next;
184: };

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

193: typedef struct _n_Space {
194:   PetscDS ds;     /* Approximation space in this domain */
195:   PetscDS dsIn;   /* Approximation space for input to this domain (now only used for cohesive cells) */
196:   DMLabel label;  /* Label defining the domain of definition of the discretization */
197:   IS      fields; /* Map from DS field numbers to original field numbers in the DM */
198: } DMSpace;

200: struct _p_UniversalLabel {
201:   DMLabel   label;   /* The universal label */
202:   PetscInt  Nl;      /* Number of labels encoded */
203:   char    **names;   /* The label names */
204:   PetscInt *indices; /* The original indices in the input DM */
205:   PetscInt  Nv;      /* Total number of values in all the labels */
206:   PetscInt *bits;    /* Starting bit for values of each label */
207:   PetscInt *masks;   /* Masks to pull out label value bits for each label */
208:   PetscInt *offsets; /* Starting offset for label values for each label */
209:   PetscInt *values;  /* Original label values before renumbering */
210: };

212: PETSC_INTERN PetscErrorCode DMDestroyLabelLinkList_Internal(DM);

214: #define MAXDMMONITORS 5

216: typedef struct {
217:   PetscInt dim;   /* The dimension of the embedding space */
218:   DM       dm;    /* Layout for coordinates */
219:   Vec      x;     /* Coordinate values in global vector */
220:   Vec      xl;    /* Coordinate values in local  vector */
221:   DMField  field; /* Coordinates as an abstract field */
222: } DMCoordinates;

224: struct _p_DM {
225:   PETSCHEADER(struct _DMOps);
226:   Vec            localin[DM_MAX_WORK_VECTORS], localout[DM_MAX_WORK_VECTORS];
227:   Vec            globalin[DM_MAX_WORK_VECTORS], globalout[DM_MAX_WORK_VECTORS];
228:   DMNamedVecLink namedglobal;
229:   DMNamedVecLink namedlocal;
230:   DMWorkLink     workin, workout;
231:   DMLabelLink    labels;        /* Linked list of labels */
232:   DMLabel        depthLabel;    /* Optimized access to depth label */
233:   DMLabel        celltypeLabel; /* Optimized access to celltype label */
234:   void          *ctx;           /* a user context */
235:   PetscErrorCode (*ctxdestroy)(void **);
236:   ISColoringType         coloringtype;
237:   MatFDColoring          fd;
238:   VecType                vectype;    /* type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() */
239:   MatType                mattype;    /* type of matrix created with DMCreateMatrix() */
240:   PetscInt               bind_below; /* Local size threshold (in entries/rows) below which Vec/Mat objects are bound to CPU */
241:   PetscInt               bs;
242:   DMBlockingType         blocking_type;
243:   ISLocalToGlobalMapping ltogmap;
244:   PetscBool              prealloc_skip;      // Flag indicating the DMCreateMatrix() should not preallocate (only set sizes and local-to-global)
245:   PetscBool              prealloc_only;      /* Flag indicating the DMCreateMatrix() should only preallocate, not fill the matrix */
246:   PetscBool              structure_only;     /* Flag indicating the DMCreateMatrix() create matrix structure without values */
247:   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 */
248:   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 */
249:   PetscBool              setfromoptionscalled;
250:   void                  *data;
251:   /* Hierarchy / Submeshes */
252:   DM                      coarseMesh;
253:   DM                      fineMesh;
254:   DMCoarsenHookLink       coarsenhook; /* For transferring auxiliary problem data to coarser grids */
255:   DMRefineHookLink        refinehook;
256:   DMSubDomainHookLink     subdomainhook;
257:   DMGlobalToLocalHookLink gtolhook;
258:   DMLocalToGlobalHookLink ltoghook;
259:   /* Topology */
260:   PetscInt dim; /* The topological dimension */
261:   /* Auxiliary data */
262:   PetscHMapAux auxData; /* Auxiliary DM and Vec for region denoted by the key */
263:   /* Flexible communication */
264:   PetscSF   sfMigration; /* SF for point distribution created during distribution */
265:   PetscSF   sf;          /* SF for parallel point overlap */
266:   PetscSF   sectionSF;   /* SF for parallel dof overlap using section */
267:   PetscSF   sfNatural;   /* SF mapping to the "natural" ordering */
268:   PetscBool useNatural;  /* Create the natural SF */
269:   /* Allows a non-standard data layout */
270:   PetscBool            adjacency[2];       /* [use cone() or support() first, use the transitive closure] */
271:   PetscSection         localSection;       /* Layout for local vectors */
272:   PetscSection         globalSection;      /* Layout for global vectors */
273:   PetscLayout          map;                /* Parallel division of unknowns across processes */
274:   DMReorderDefaultFlag reorderSection;     /* Reorder the local section by default */
275:   MatOrderingType      reorderSectionType; /* The type of reordering */

277:   // Affine transform applied in DMGlobalToLocal
278:   struct {
279:     VecScatter affine_to_local;
280:     Vec        affine;
281:     PetscErrorCode (*setup)(DM);
282:   } periodic;
283:   /* Constraints */
284:   struct {
285:     PetscSection section;
286:     Mat          mat;
287:     Vec          bias;
288:   } defaultConstraint;
289:   /* Basis transformation */
290:   DM    transformDM;  /* Layout for basis transformation */
291:   Vec   transform;    /* Basis transformation matrices */
292:   void *transformCtx; /* Basis transformation context */
293:   PetscErrorCode (*transformSetUp)(DM, void *);
294:   PetscErrorCode (*transformDestroy)(DM, void *);
295:   PetscErrorCode (*transformGetMatrix)(DM, const PetscReal[], PetscBool, const PetscScalar **, void *);
296:   /* Coordinates */
297:   DMCoordinates coordinates[2]; /* Coordinates, 0 is default, 1 is possible DG coordinate field for periodicity */
298:   /* Periodicity */
299:   PetscReal *Lstart, *L, *maxCell; /* Size of periodic box and max cell size for determining periodicity */
300:   PetscBool  sparseLocalize;       /* Localize coordinates only for cells near periodic boundary */
301:   /* Null spaces -- of course I should make this have a variable number of fields */
302:   NullSpaceFunc nullspaceConstructors[10];
303:   NullSpaceFunc nearnullspaceConstructors[10];
304:   /* Fields are represented by objects */
305:   PetscInt     Nf;       /* Number of fields defined on the total domain */
306:   RegionField *fields;   /* Array of discretization fields with regions of validity */
307:   DMBoundary   boundary; /* List of boundary conditions */
308:   PetscInt     Nds;      /* Number of discrete systems defined on the total domain */
309:   DMSpace     *probs;    /* Array of discrete systems */
310:   /* Output structures */
311:   DM        dmBC;              /* The DM with boundary conditions in the global DM */
312:   PetscBool ignorePermOutput;  /* Ignore the local section permutation on output */
313:   PetscInt  outputSequenceNum; /* The current sequence number for output */
314:   PetscReal outputSequenceVal; /* The current sequence value for output */
315:   PetscErrorCode (*monitor[MAXDMMONITORS])(DM, void *);
316:   PetscErrorCode (*monitordestroy[MAXDMMONITORS])(void **);
317:   void    *monitorcontext[MAXDMMONITORS];
318:   PetscInt numbermonitors;
319:   /* Configuration */
320:   PetscBool cloneOpts; /* Flag indicating that this is a linked clone and should not respond to some options. This is currently used to prevent transformations from also affecting the coordinate DM */

322:   PetscObject dmksp, dmsnes, dmts;
323: #ifdef PETSC_HAVE_LIBCEED
324:   Ceed                ceed;          // LibCEED context
325:   CeedElemRestriction ceedERestrict; // Map from the local vector (Lvector) to the cells (Evector)
326: #endif
327:   DMCeed dmceed; // CEED operator and data for this problem
328: };

330: PETSC_EXTERN PetscLogEvent DM_Convert;
331: PETSC_EXTERN PetscLogEvent DM_GlobalToLocal;
332: PETSC_EXTERN PetscLogEvent DM_LocalToGlobal;
333: PETSC_EXTERN PetscLogEvent DM_LocatePoints;
334: PETSC_EXTERN PetscLogEvent DM_Coarsen;
335: PETSC_EXTERN PetscLogEvent DM_Refine;
336: PETSC_EXTERN PetscLogEvent DM_CreateInterpolation;
337: PETSC_EXTERN PetscLogEvent DM_CreateRestriction;
338: PETSC_EXTERN PetscLogEvent DM_CreateInjection;
339: PETSC_EXTERN PetscLogEvent DM_CreateMatrix;
340: PETSC_EXTERN PetscLogEvent DM_CreateMassMatrix;
341: PETSC_EXTERN PetscLogEvent DM_Load;
342: PETSC_EXTERN PetscLogEvent DM_AdaptInterpolator;
343: PETSC_EXTERN PetscLogEvent DM_ProjectFunction;

345: PETSC_EXTERN PetscErrorCode DMCreateGlobalVector_Section_Private(DM, Vec *);
346: PETSC_EXTERN PetscErrorCode DMCreateLocalVector_Section_Private(DM, Vec *);

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

350: /*

352:           Composite Vectors

354:       Single global representation
355:       Individual global representations
356:       Single local representation
357:       Individual local representations

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

361:        DM da_u, da_v, da_p

363:        DM dm_velocities

365:        DM dm

367:        DMDACreate(,&da_u);
368:        DMDACreate(,&da_v);
369:        DMCompositeCreate(,&dm_velocities);
370:        DMCompositeAddDM(dm_velocities,(DM)du);
371:        DMCompositeAddDM(dm_velocities,(DM)dv);

373:        DMDACreate(,&da_p);
374:        DMCompositeCreate(,&dm_velocities);
375:        DMCompositeAddDM(dm,(DM)dm_velocities);
376:        DMCompositeAddDM(dm,(DM)dm_p);

378:     Access parts of composite vectors (Composite only)
379:     ---------------------------------
380:       DMCompositeGetAccess  - access the global vector as subvectors and array (for redundant arrays)
381:       ADD for local vector -

383:     Element access
384:     --------------
385:       From global vectors
386:          -DAVecGetArray   - for DMDA
387:          -VecGetArray - for DMSliced
388:          ADD for DMComposite???  maybe

390:       From individual vector
391:           -DAVecGetArray - for DMDA
392:           -VecGetArray -for sliced
393:          ADD for DMComposite??? maybe

395:       From single local vector
396:           ADD         * single local vector as arrays?

398:    Communication
399:    -------------
400:       DMGlobalToLocal - global vector to single local vector

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

404:    Obtaining vectors
405:    -----------------
406:       DMCreateGlobal/Local
407:       DMGetGlobal/Local
408:       DMCompositeGetLocalVectors   - gives individual local work vectors and arrays

410:     ?????   individual global vectors   ????

412: */

414: #if defined(PETSC_HAVE_HDF5)
415: PETSC_EXTERN PetscErrorCode DMSequenceLoad_HDF5_Internal(DM, const char *, PetscInt, PetscScalar *, PetscViewer);
416: #endif

418: static inline PetscErrorCode DMGetLocalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
419: {
420:   PetscFunctionBeginHot;
421: #if defined(PETSC_USE_DEBUG)
422:   {
423:     PetscInt dof;

425:     *start = *end = 0; /* Silence overzealous compiler warning */
426:     PetscCheck(dm->localSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
427:     PetscCall(PetscSectionGetOffset(dm->localSection, point, start));
428:     PetscCall(PetscSectionGetDof(dm->localSection, point, &dof));
429:     *end = *start + dof;
430:   }
431: #else
432:   {
433:     const PetscSection s = dm->localSection;
434:     *start               = s->atlasOff[point - s->pStart];
435:     *end                 = *start + s->atlasDof[point - s->pStart];
436:   }
437: #endif
438:   PetscFunctionReturn(PETSC_SUCCESS);
439: }

441: static inline PetscErrorCode DMGetLocalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
442: {
443:   PetscFunctionBegin;
444: #if defined(PETSC_USE_DEBUG)
445:   {
446:     PetscInt dof;
447:     *start = *end = 0; /* Silence overzealous compiler warning */
448:     PetscCheck(dm->localSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
449:     PetscCall(PetscSectionGetFieldOffset(dm->localSection, point, field, start));
450:     PetscCall(PetscSectionGetFieldDof(dm->localSection, point, field, &dof));
451:     *end = *start + dof;
452:   }
453: #else
454:   {
455:     const PetscSection s = dm->localSection->field[field];
456:     *start               = s->atlasOff[point - s->pStart];
457:     *end                 = *start + s->atlasDof[point - s->pStart];
458:   }
459: #endif
460:   PetscFunctionReturn(PETSC_SUCCESS);
461: }

463: static inline PetscErrorCode DMGetGlobalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
464: {
465:   PetscFunctionBegin;
466: #if defined(PETSC_USE_DEBUG)
467:   {
468:     PetscInt dof, cdof;
469:     *start = *end = 0; /* Silence overzealous compiler warning */
470:     PetscCheck(dm->localSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
471:     PetscCheck(dm->globalSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be created automatically by DMGetGlobalSection()");
472:     PetscCall(PetscSectionGetOffset(dm->globalSection, point, start));
473:     PetscCall(PetscSectionGetDof(dm->globalSection, point, &dof));
474:     PetscCall(PetscSectionGetConstraintDof(dm->globalSection, point, &cdof));
475:     *end = *start + dof - cdof + (dof < 0 ? 1 : 0);
476:   }
477: #else
478:   {
479:     const PetscSection s    = dm->globalSection;
480:     const PetscInt     dof  = s->atlasDof[point - s->pStart];
481:     const PetscInt     cdof = s->bc ? s->bc->atlasDof[point - s->bc->pStart] : 0;
482:     *start                  = s->atlasOff[point - s->pStart];
483:     *end                    = *start + dof - cdof + (dof < 0 ? 1 : 0);
484:   }
485: #endif
486:   PetscFunctionReturn(PETSC_SUCCESS);
487: }

489: static inline PetscErrorCode DMGetGlobalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
490: {
491:   PetscFunctionBegin;
492: #if defined(PETSC_USE_DEBUG)
493:   {
494:     PetscInt loff, lfoff, fdof, fcdof, ffcdof, f;
495:     *start = *end = 0; /* Silence overzealous compiler warning */
496:     PetscCheck(dm->localSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
497:     PetscCheck(dm->globalSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be created automatically by DMGetGlobalSection()");
498:     PetscCall(PetscSectionGetOffset(dm->globalSection, point, start));
499:     PetscCall(PetscSectionGetOffset(dm->localSection, point, &loff));
500:     PetscCall(PetscSectionGetFieldOffset(dm->localSection, point, field, &lfoff));
501:     PetscCall(PetscSectionGetFieldDof(dm->localSection, point, field, &fdof));
502:     PetscCall(PetscSectionGetFieldConstraintDof(dm->localSection, point, field, &fcdof));
503:     *start = *start < 0 ? *start - (lfoff - loff) : *start + lfoff - loff;
504:     for (f = 0; f < field; ++f) {
505:       PetscCall(PetscSectionGetFieldConstraintDof(dm->localSection, point, f, &ffcdof));
506:       *start = *start < 0 ? *start + ffcdof : *start - ffcdof;
507:     }
508:     *end = *start < 0 ? *start - (fdof - fcdof) : *start + fdof - fcdof;
509:   }
510: #else
511:   {
512:     const PetscSection s      = dm->localSection;
513:     const PetscSection fs     = dm->localSection->field[field];
514:     const PetscSection gs     = dm->globalSection;
515:     const PetscInt     loff   = s->atlasOff[point - s->pStart];
516:     const PetscInt     goff   = gs->atlasOff[point - s->pStart];
517:     const PetscInt     lfoff  = fs->atlasOff[point - s->pStart];
518:     const PetscInt     fdof   = fs->atlasDof[point - s->pStart];
519:     const PetscInt     fcdof  = fs->bc ? fs->bc->atlasDof[point - fs->bc->pStart] : 0;
520:     PetscInt           ffcdof = 0, f;

522:     for (f = 0; f < field; ++f) {
523:       const PetscSection ffs = dm->localSection->field[f];
524:       ffcdof += ffs->bc ? ffs->bc->atlasDof[point - ffs->bc->pStart] : 0;
525:     }
526:     *start = goff + (goff < 0 ? loff - lfoff + ffcdof : lfoff - loff - ffcdof);
527:     *end   = *start < 0 ? *start - (fdof - fcdof) : *start + fdof - fcdof;
528:   }
529: #endif
530:   PetscFunctionReturn(PETSC_SUCCESS);
531: }

533: PETSC_EXTERN PetscErrorCode DMGetCoordinateDegree_Internal(DM, PetscInt *);
534: PETSC_INTERN PetscErrorCode DMGetLocalBoundingBox_Coordinates(DM, PetscReal[], PetscReal[], PetscInt[], PetscInt[]);

536: PETSC_EXTERN PetscErrorCode DMGetBasisTransformDM_Internal(DM, DM *);
537: PETSC_EXTERN PetscErrorCode DMGetBasisTransformVec_Internal(DM, Vec *);
538: PETSC_INTERN PetscErrorCode DMConstructBasisTransform_Internal(DM);

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

543: PETSC_INTERN PetscErrorCode DMSetLabelValue_Fast(DM, DMLabel *, const char[], PetscInt, PetscInt);
544: PETSC_INTERN PetscErrorCode DMGetPoints_Internal(DM, DMLabel, PetscInt, PetscInt, IS *);

546: PETSC_INTERN PetscErrorCode DMCompleteBCLabels_Internal(DM dm);
547: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreate(DM, DMUniversalLabel *);
548: PETSC_EXTERN PetscErrorCode DMUniversalLabelDestroy(DMUniversalLabel *);
549: PETSC_EXTERN PetscErrorCode DMUniversalLabelGetLabel(DMUniversalLabel, DMLabel *);
550: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreateLabels(DMUniversalLabel, PetscBool, DM);
551: PETSC_EXTERN PetscErrorCode DMUniversalLabelSetLabelValue(DMUniversalLabel, DM, PetscBool, PetscInt, PetscInt);
552: PETSC_INTERN PetscInt       PetscGCD(PetscInt a, PetscInt b);