Actual source code: dmimpl.h

  1: #pragma once

  3: #include <petscdm.h>
  4: #if PetscDefined(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);

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

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

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

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

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

 35: typedef struct _DMOps *DMOps;
 36: struct _DMOps {
 37:   PetscErrorCode (*view)(DM, PetscViewer);
 38:   PetscErrorCode (*load)(DM, PetscViewer);
 39:   PetscErrorCode (*clone)(DM, DM *);
 40:   PetscErrorCode (*setfromoptions)(DM, PetscOptionItems);
 41:   PetscErrorCode (*setup)(DM);
 42:   PetscErrorCode (*createlocalsection)(DM);
 43:   PetscErrorCode (*createsectionpermutation)(DM, IS *, PetscBT *);
 44:   PetscErrorCode (*createdefaultconstraints)(DM);
 45:   PetscErrorCode (*createglobalvector)(DM, Vec *);
 46:   PetscErrorCode (*createlocalvector)(DM, Vec *);
 47:   PetscErrorCode (*getlocaltoglobalmapping)(DM);
 48:   PetscErrorCode (*createfieldis)(DM, PetscInt *, char ***, IS **);
 49:   PetscErrorCode (*createcoordinatedm)(DM, DM *);
 50:   PetscErrorCode (*createcellcoordinatedm)(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 *, Vec *);
 59:   PetscErrorCode (*creategradientmatrix)(DM, DM, Mat *);
 60:   PetscErrorCode (*hascreateinjection)(DM, PetscBool *);
 61:   PetscErrorCode (*createinjection)(DM, DM, Mat *);

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

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

 76:   PetscErrorCode (*destroy)(DM);

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

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

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

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

103:   PetscErrorCode (*getcompatibility)(DM, DM, PetscBool *, PetscBool *);
104: };

106: PETSC_INTERN PetscErrorCode DMLocalizeCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);
107: PETSC_INTERN PetscErrorCode DMLocalizeCoordinateReal_Internal(DM, PetscInt, const PetscReal[], const PetscReal[], PetscReal[]);
108: PETSC_INTERN PetscErrorCode DMLocalizeAddCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);

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

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

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

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

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

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

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

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

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

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

180: typedef struct _n_Boundary *DMBoundary;

182: struct _n_Boundary {
183:   DSBoundary dsboundary;
184:   DMLabel    label;
185:   DMBoundary next;
186: };

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

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

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

214: PETSC_INTERN PetscErrorCode DMDestroyLabelLinkList_Internal(DM);

216: #define MAXDMMONITORS 5

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

226: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*NullSpaceFn)(DM dm, PetscInt origField, PetscInt field, MatNullSpace *nullSpace);

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

282:   // Affine transform applied in DMGlobalToLocal
283:   struct {
284:     PetscInt    num_affines;
285:     VecScatter *affine_to_local;
286:     Vec        *affine;
287:     PetscErrorCode (*setup)(DM);
288:   } periodic;
289:   /* Constraints */
290:   struct {
291:     PetscSection section;
292:     Mat          mat;
293:     Vec          bias;
294:   } defaultConstraint;
295:   /* Basis transformation */
296:   DM    transformDM;  /* Layout for basis transformation */
297:   Vec   transform;    /* Basis transformation matrices */
298:   void *transformCtx; /* Basis transformation context */
299:   PetscErrorCode (*transformSetUp)(DM, void *);
300:   PetscErrorCode (*transformDestroy)(DM, void *);
301:   PetscErrorCode (*transformGetMatrix)(DM, const PetscReal[], PetscBool, const PetscScalar **, void *);
302:   /* Coordinates */
303:   DMCoordinates coordinates[2]; /* Coordinates, 0 is default, 1 is possible DG coordinate field for periodicity */
304:   /* Periodicity */
305:   PetscReal *Lstart, *L, *maxCell; /* Size of periodic box and max cell size for determining periodicity */
306:   PetscBool  sparseLocalize;       /* Localize coordinates only for cells near periodic boundary */
307:   /* Null spaces */
308:   NullSpaceFn *nullspaceConstructors;
309:   NullSpaceFn *nearnullspaceConstructors;
310:   /* Fields are represented by objects */
311:   PetscInt     Nf;       /* Number of fields defined on the total domain */
312:   RegionField *fields;   /* Array of discretization fields with regions of validity */
313:   DMBoundary   boundary; /* List of boundary conditions */
314:   PetscInt     Nds;      /* Number of discrete systems defined on the total domain */
315:   DMSpace     *probs;    /* Array of discrete systems */
316:   /* Output structures */
317:   DM        dmBC;              /* The DM with boundary conditions in the global DM */
318:   PetscBool ignorePermOutput;  /* Ignore the local section permutation on output */
319:   PetscInt  outputSequenceNum; /* The current sequence number for output */
320:   PetscReal outputSequenceVal; /* The current sequence value for output */
321:   PetscErrorCode (*monitor[MAXDMMONITORS])(DM, void *);
322:   PetscCtxDestroyFn *monitordestroy[MAXDMMONITORS];
323:   void              *monitorcontext[MAXDMMONITORS];
324:   PetscInt           numbermonitors;
325:   /* Configuration */
326:   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 */

328:   PetscObject dmksp, dmsnes, dmts;
329: #if PetscDefined(HAVE_LIBCEED)
330:   Ceed                ceed;          // LibCEED context
331:   CeedElemRestriction ceedERestrict; // Map from the local vector (Lvector) to the cells (Evector)
332: #endif
333:   DMCeed dmceed; // CEED operator and data for this problem
334: };

336: PETSC_EXTERN PetscLogEvent DM_Convert;
337: PETSC_EXTERN PetscLogEvent DM_GlobalToLocal;
338: PETSC_EXTERN PetscLogEvent DM_LocalToGlobal;
339: PETSC_EXTERN PetscLogEvent DM_LocatePoints;
340: PETSC_EXTERN PetscLogEvent DM_Coarsen;
341: PETSC_EXTERN PetscLogEvent DM_Refine;
342: PETSC_EXTERN PetscLogEvent DM_CreateInterpolation;
343: PETSC_EXTERN PetscLogEvent DM_CreateRestriction;
344: PETSC_EXTERN PetscLogEvent DM_CreateInjection;
345: PETSC_EXTERN PetscLogEvent DM_CreateMatrix;
346: PETSC_EXTERN PetscLogEvent DM_CreateMassMatrix;
347: PETSC_EXTERN PetscLogEvent DM_Load;
348: PETSC_EXTERN PetscLogEvent DM_View;
349: PETSC_EXTERN PetscLogEvent DM_AdaptInterpolator;
350: PETSC_EXTERN PetscLogEvent DM_ProjectFunction;

352: PETSC_INTERN PetscErrorCode DMCreateGlobalVector_Section_Private(DM, Vec *);
353: PETSC_INTERN PetscErrorCode DMCreateLocalVector_Section_Private(DM, Vec *);

355: PETSC_INTERN PetscErrorCode DMDestroyCoordinates_Internal(DMCoordinates *);

357: PETSC_INTERN PetscErrorCode DMView_GLVis(DM, PetscViewer, PetscErrorCode (*)(DM, PetscViewer));

359: /*

361:           Composite Vectors

363:       Single global representation
364:       Individual global representations
365:       Single local representation
366:       Individual local representations

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

370:        DM da_u, da_v, da_p

372:        DM dm_velocities

374:        DM dm

376:        DMDACreate(,&da_u);
377:        DMDACreate(,&da_v);
378:        DMCompositeCreate(,&dm_velocities);
379:        DMCompositeAddDM(dm_velocities,(DM)du);
380:        DMCompositeAddDM(dm_velocities,(DM)dv);

382:        DMDACreate(,&da_p);
383:        DMCompositeCreate(,&dm_velocities);
384:        DMCompositeAddDM(dm,(DM)dm_velocities);
385:        DMCompositeAddDM(dm,(DM)dm_p);

387:     Access parts of composite vectors (Composite only)
388:     ---------------------------------
389:       DMCompositeGetAccess  - access the global vector as subvectors and array (for redundant arrays)
390:       ADD for local vector -

392:     Element access
393:     --------------
394:       From global vectors
395:          -DAVecGetArray   - for DMDA
396:          -VecGetArray - for DMSliced
397:          ADD for DMComposite???  maybe

399:       From individual vector
400:           -DAVecGetArray - for DMDA
401:           -VecGetArray -for sliced
402:          ADD for DMComposite??? maybe

404:       From single local vector
405:           ADD         * single local vector as arrays?

407:    Communication
408:    -------------
409:       DMGlobalToLocal - global vector to single local vector

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

413:    Obtaining vectors
414:    -----------------
415:       DMCreateGlobal/Local
416:       DMGetGlobal/Local
417:       DMCompositeGetLocalVectors   - gives individual local work vectors and arrays

419:     ?????   individual global vectors   ????

421: */

423: #if PetscDefined(HAVE_HDF5)
424: PETSC_EXTERN PetscErrorCode DMSequenceLoad_HDF5_Internal(DM, const char[], PetscInt, PetscScalar *, PetscViewer);
425: PETSC_EXTERN PetscErrorCode DMSequenceGetLength_HDF5_Internal(DM, const char[], PetscInt *, PetscViewer);
426: #endif

428: static inline PetscErrorCode DMGetLocalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
429: {
430:   PetscFunctionBeginHot;
431:   if (PetscDefined(USE_DEBUG)) {
432:     PetscInt dof;

434:     *start = *end = 0; /* Silence overzealous compiler warning */
435:     PetscCheck(dm->localSection, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
436:     PetscCall(PetscSectionGetOffset(dm->localSection, point, start));
437:     PetscCall(PetscSectionGetDof(dm->localSection, point, &dof));
438:     *end = *start + dof;
439:   } else {
440:     const PetscSection s = dm->localSection;
441:     *start               = s->atlasOff[point - s->pStart];
442:     *end                 = *start + s->atlasDof[point - s->pStart];
443:   }
444:   PetscFunctionReturn(PETSC_SUCCESS);
445: }

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

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

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

517:     for (f = 0; f < field; ++f) {
518:       const PetscSection ffs = dm->localSection->field[f];
519:       ffcdof += ffs->bc ? ffs->bc->atlasDof[point - ffs->bc->pStart] : 0;
520:     }
521:     *start = goff + (goff < 0 ? loff - lfoff + ffcdof : lfoff - loff - ffcdof);
522:     *end   = *start < 0 ? *start - (fdof - fcdof) : *start + fdof - fcdof;
523:   }
524:   PetscFunctionReturn(PETSC_SUCCESS);
525: }

527: PETSC_INTERN PetscErrorCode DMViewDSFromOptions_Internal(DM, const char[]);
528: PETSC_INTERN PetscErrorCode DMViewSectionFromOptions_Internal(DM, const char[]);

530: PETSC_INTERN PetscErrorCode DMGetCoordinateDegree_Internal(DM, PetscInt *);
531: PETSC_INTERN PetscErrorCode DMGetLocalBoundingBox_Coordinates(DM, PetscReal[], PetscReal[], PetscInt[], PetscInt[]);
532: PETSC_INTERN PetscErrorCode DMGetIsoperiodicPointSF_Internal(DM dm, PetscSF *sf);

534: PETSC_INTERN PetscErrorCode DMGetBasisTransformDM_Internal(DM, DM *);
535: PETSC_INTERN PetscErrorCode DMGetBasisTransformVec_Internal(DM, Vec *);
536: PETSC_INTERN PetscErrorCode DMConstructBasisTransform_Internal(DM);

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

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

544: PETSC_INTERN PetscErrorCode DMCompleteBCLabels_Internal(DM dm);
545: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreate(DM, DMUniversalLabel *);
546: PETSC_EXTERN PetscErrorCode DMUniversalLabelDestroy(DMUniversalLabel *);
547: PETSC_EXTERN PetscErrorCode DMUniversalLabelGetLabel(DMUniversalLabel, DMLabel *);
548: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreateLabels(DMUniversalLabel, PetscBool, DM);
549: PETSC_EXTERN PetscErrorCode DMUniversalLabelSetLabelValue(DMUniversalLabel, DM, PetscBool, PetscInt, PetscInt);