Actual source code: dmimpl.h
2: #ifndef _DMIMPL_H
3: #define _DMIMPL_H
5: #include <petscdm.h>
6: #ifdef PETSC_HAVE_LIBCEED
7: #include <petscdmceed.h>
8: #endif
9: #include <petsc/private/petscimpl.h>
10: #include <petsc/private/petscdsimpl.h>
11: #include <petsc/private/sectionimpl.h>
13: PETSC_EXTERN PetscBool DMRegisterAllCalled;
14: PETSC_EXTERN PetscErrorCode DMRegisterAll(void);
15: typedef PetscErrorCode (*NullSpaceFunc)(DM dm, PetscInt origField, PetscInt field, MatNullSpace *nullSpace);
17: typedef struct _PetscHashAuxKey {
18: DMLabel label;
19: PetscInt value;
20: PetscInt part;
21: } PetscHashAuxKey;
23: #define PetscHashAuxKeyHash(key) PetscHashCombine(PetscHashCombine(PetscHashPointer((key).label), PetscHashInt((key).value)), PetscHashInt((key).part))
25: #define PetscHashAuxKeyEqual(k1, k2) (((k1).label == (k2).label) ? (((k1).value == (k2).value) ? ((k1).part == (k2).part) : 0) : 0)
27: PETSC_HASH_MAP(HMapAux, PetscHashAuxKey, Vec, PetscHashAuxKeyHash, PetscHashAuxKeyEqual, NULL)
29: struct _n_DMGeneratorFunctionList {
30: PetscErrorCode (*generate)(DM, PetscBool, DM *);
31: PetscErrorCode (*refine)(DM, PetscReal *, DM *);
32: PetscErrorCode (*adapt)(DM, Vec, DMLabel, DMLabel, DM *);
33: char *name;
34: PetscInt dim;
35: DMGeneratorFunctionList next;
36: };
38: typedef struct _DMOps *DMOps;
39: struct _DMOps {
40: PetscErrorCode (*view)(DM, PetscViewer);
41: PetscErrorCode (*load)(DM, PetscViewer);
42: PetscErrorCode (*clone)(DM, DM *);
43: PetscErrorCode (*setfromoptions)(DM, PetscOptionItems *);
44: PetscErrorCode (*setup)(DM);
45: PetscErrorCode (*createlocalsection)(DM);
46: PetscErrorCode (*createdefaultconstraints)(DM);
47: PetscErrorCode (*createglobalvector)(DM, Vec *);
48: PetscErrorCode (*createlocalvector)(DM, Vec *);
49: PetscErrorCode (*getlocaltoglobalmapping)(DM);
50: PetscErrorCode (*createfieldis)(DM, PetscInt *, char ***, IS **);
51: PetscErrorCode (*createcoordinatedm)(DM, DM *);
52: PetscErrorCode (*createcoordinatefield)(DM, DMField *);
54: PetscErrorCode (*getcoloring)(DM, ISColoringType, ISColoring *);
55: PetscErrorCode (*creatematrix)(DM, Mat *);
56: PetscErrorCode (*createinterpolation)(DM, DM, Mat *, Vec *);
57: PetscErrorCode (*createrestriction)(DM, DM, Mat *);
58: PetscErrorCode (*createmassmatrix)(DM, DM, Mat *);
59: PetscErrorCode (*createmassmatrixlumped)(DM, Vec *);
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 *);
91: PetscErrorCode (*locatepointssubdomain)(DM, Vec, PetscMPIInt **);
93: PetscErrorCode (*projectfunctionlocal)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, InsertMode, Vec);
94: PetscErrorCode (*projectfunctionlabellocal)(DM, PetscReal, DMLabel, PetscInt, const PetscInt[], PetscInt, const PetscInt[], PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, InsertMode, Vec);
95: 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);
96: 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);
97: 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);
98: PetscErrorCode (*computel2diff)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);
99: PetscErrorCode (*computel2gradientdiff)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], const PetscReal[], PetscInt, PetscScalar *, void *), void **, Vec, const PetscReal[], PetscReal *);
100: PetscErrorCode (*computel2fielddiff)(DM, PetscReal, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);
102: PetscErrorCode (*getcompatibility)(DM, DM, PetscBool *, PetscBool *);
103: };
105: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);
106: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinateReal_Internal(DM, PetscInt, const PetscReal[], const PetscReal[], PetscReal[]);
107: PETSC_EXTERN PetscErrorCode DMLocalizeAddCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);
109: PETSC_INTERN PetscErrorCode DMCountNonCyclicReferences(PetscObject, PetscInt *);
111: typedef struct _DMCoarsenHookLink *DMCoarsenHookLink;
112: struct _DMCoarsenHookLink {
113: PetscErrorCode (*coarsenhook)(DM, DM, void *); /* Run once, when coarse DM is created */
114: PetscErrorCode (*restricthook)(DM, Mat, Vec, Mat, DM, void *); /* Run each time a new problem is restricted to a coarse grid */
115: void *ctx;
116: DMCoarsenHookLink next;
117: };
119: typedef struct _DMRefineHookLink *DMRefineHookLink;
120: struct _DMRefineHookLink {
121: PetscErrorCode (*refinehook)(DM, DM, void *); /* Run once, when a fine DM is created */
122: PetscErrorCode (*interphook)(DM, Mat, DM, void *); /* Run each time a new problem is interpolated to a fine grid */
123: void *ctx;
124: DMRefineHookLink next;
125: };
127: typedef struct _DMSubDomainHookLink *DMSubDomainHookLink;
128: struct _DMSubDomainHookLink {
129: PetscErrorCode (*ddhook)(DM, DM, void *);
130: PetscErrorCode (*restricthook)(DM, VecScatter, VecScatter, DM, void *);
131: void *ctx;
132: DMSubDomainHookLink next;
133: };
135: typedef struct _DMGlobalToLocalHookLink *DMGlobalToLocalHookLink;
136: struct _DMGlobalToLocalHookLink {
137: PetscErrorCode (*beginhook)(DM, Vec, InsertMode, Vec, void *);
138: PetscErrorCode (*endhook)(DM, Vec, InsertMode, Vec, void *);
139: void *ctx;
140: DMGlobalToLocalHookLink next;
141: };
143: typedef struct _DMLocalToGlobalHookLink *DMLocalToGlobalHookLink;
144: struct _DMLocalToGlobalHookLink {
145: PetscErrorCode (*beginhook)(DM, Vec, InsertMode, Vec, void *);
146: PetscErrorCode (*endhook)(DM, Vec, InsertMode, Vec, void *);
147: void *ctx;
148: DMLocalToGlobalHookLink next;
149: };
151: typedef enum {
152: DMVEC_STATUS_IN,
153: DMVEC_STATUS_OUT
154: } DMVecStatus;
155: typedef struct _DMNamedVecLink *DMNamedVecLink;
156: struct _DMNamedVecLink {
157: Vec X;
158: char *name;
159: DMVecStatus status;
160: DMNamedVecLink next;
161: };
163: typedef struct _DMWorkLink *DMWorkLink;
164: struct _DMWorkLink {
165: size_t bytes;
166: void *mem;
167: DMWorkLink next;
168: };
170: #define DM_MAX_WORK_VECTORS 100 /* work vectors available to users via DMGetGlobalVector(), DMGetLocalVector() */
172: struct _n_DMLabelLink {
173: DMLabel label;
174: PetscBool output;
175: struct _n_DMLabelLink *next;
176: };
177: typedef struct _n_DMLabelLink *DMLabelLink;
179: typedef struct _n_Boundary *DMBoundary;
181: struct _n_Boundary {
182: DSBoundary dsboundary;
183: DMLabel label;
184: DMBoundary next;
185: };
187: typedef struct _n_Field {
188: PetscObject disc; /* Field discretization, or a PetscContainer with the field name */
189: DMLabel label; /* Label defining the domain of definition of the field */
190: PetscBool adjacency[2]; /* Flags for defining variable influence (adjacency) for each field [use cone() or support() first, use the transitive closure] */
191: PetscBool avoidTensor; /* Flag to avoid defining field over tensor cells */
192: } RegionField;
194: typedef struct _n_Space {
195: PetscDS ds; /* Approximation space in this domain */
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: ISLocalToGlobalMapping ltogmap;
243: PetscBool prealloc_skip; // Flag indicating the DMCreateMatrix() should not preallocate (only set sizes and local-to-global)
244: PetscBool prealloc_only; /* Flag indicating the DMCreateMatrix() should only preallocate, not fill the matrix */
245: PetscBool structure_only; /* Flag indicating the DMCreateMatrix() create matrix structure without values */
246: 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 */
247: 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 */
248: PetscBool setfromoptionscalled;
249: void *data;
250: /* Hierarchy / Submeshes */
251: DM coarseMesh;
252: DM fineMesh;
253: DMCoarsenHookLink coarsenhook; /* For transferring auxiliary problem data to coarser grids */
254: DMRefineHookLink refinehook;
255: DMSubDomainHookLink subdomainhook;
256: DMGlobalToLocalHookLink gtolhook;
257: DMLocalToGlobalHookLink ltoghook;
258: /* Topology */
259: PetscInt dim; /* The topological dimension */
260: /* Auxiliary data */
261: PetscHMapAux auxData; /* Auxiliary DM and Vec for region denoted by the key */
262: /* Flexible communication */
263: PetscSF sfMigration; /* SF for point distribution created during distribution */
264: PetscSF sf; /* SF for parallel point overlap */
265: PetscSF sectionSF; /* SF for parallel dof overlap using section */
266: PetscSF sfNatural; /* SF mapping to the "natural" ordering */
267: PetscBool useNatural; /* Create the natural SF */
268: /* Allows a non-standard data layout */
269: PetscBool adjacency[2]; /* [use cone() or support() first, use the transitive closure] */
270: PetscSection localSection; /* Layout for local vectors */
271: PetscSection globalSection; /* Layout for global vectors */
272: PetscLayout map;
273: /* Constraints */
274: struct {
275: PetscSection section;
276: Mat mat;
277: Vec bias;
278: } defaultConstraint;
279: /* Basis transformation */
280: DM transformDM; /* Layout for basis transformation */
281: Vec transform; /* Basis transformation matrices */
282: void *transformCtx; /* Basis transformation context */
283: PetscErrorCode (*transformSetUp)(DM, void *);
284: PetscErrorCode (*transformDestroy)(DM, void *);
285: PetscErrorCode (*transformGetMatrix)(DM, const PetscReal[], PetscBool, const PetscScalar **, void *);
286: /* Coordinates */
287: DMCoordinates coordinates[2]; /* Coordinates, 0 is default, 1 is possible DG coordinate field for periodicity */
288: /* Periodicity */
289: PetscReal *Lstart, *L, *maxCell; /* Size of periodic box and max cell size for determining periodicity */
290: PetscBool sparseLocalize; /* Localize coordinates only for cells near periodic boundary */
291: /* Null spaces -- of course I should make this have a variable number of fields */
292: NullSpaceFunc nullspaceConstructors[10];
293: NullSpaceFunc nearnullspaceConstructors[10];
294: /* Fields are represented by objects */
295: PetscInt Nf; /* Number of fields defined on the total domain */
296: RegionField *fields; /* Array of discretization fields with regions of validity */
297: DMBoundary boundary; /* List of boundary conditions */
298: PetscInt Nds; /* Number of discrete systems defined on the total domain */
299: DMSpace *probs; /* Array of discrete systems */
300: /* Output structures */
301: DM dmBC; /* The DM with boundary conditions in the global DM */
302: PetscInt outputSequenceNum; /* The current sequence number for output */
303: PetscReal outputSequenceVal; /* The current sequence value for output */
304: PetscErrorCode (*monitor[MAXDMMONITORS])(DM, void *);
305: PetscErrorCode (*monitordestroy[MAXDMMONITORS])(void **);
306: void *monitorcontext[MAXDMMONITORS];
307: PetscInt numbermonitors;
309: PetscObject dmksp, dmsnes, dmts;
310: #ifdef PETSC_HAVE_LIBCEED
311: Ceed ceed; /* LibCEED context */
312: CeedElemRestriction ceedERestrict; /* Map from the local vector (Lvector) to the cells (Evector) */
313: #endif
314: };
316: PETSC_EXTERN PetscLogEvent DM_Convert;
317: PETSC_EXTERN PetscLogEvent DM_GlobalToLocal;
318: PETSC_EXTERN PetscLogEvent DM_LocalToGlobal;
319: PETSC_EXTERN PetscLogEvent DM_LocatePoints;
320: PETSC_EXTERN PetscLogEvent DM_Coarsen;
321: PETSC_EXTERN PetscLogEvent DM_Refine;
322: PETSC_EXTERN PetscLogEvent DM_CreateInterpolation;
323: PETSC_EXTERN PetscLogEvent DM_CreateRestriction;
324: PETSC_EXTERN PetscLogEvent DM_CreateInjection;
325: PETSC_EXTERN PetscLogEvent DM_CreateMatrix;
326: PETSC_EXTERN PetscLogEvent DM_CreateMassMatrix;
327: PETSC_EXTERN PetscLogEvent DM_Load;
328: PETSC_EXTERN PetscLogEvent DM_AdaptInterpolator;
330: PETSC_EXTERN PetscErrorCode DMCreateGlobalVector_Section_Private(DM, Vec *);
331: PETSC_EXTERN PetscErrorCode DMCreateLocalVector_Section_Private(DM, Vec *);
333: PETSC_EXTERN PetscErrorCode DMView_GLVis(DM, PetscViewer, PetscErrorCode (*)(DM, PetscViewer));
335: /*
337: Composite Vectors
339: Single global representation
340: Individual global representations
341: Single local representation
342: Individual local representations
344: Subsets of individual as a single????? Do we handle this by having DMComposite inside composite??????
346: DM da_u, da_v, da_p
348: DM dm_velocities
350: DM dm
352: DMDACreate(,&da_u);
353: DMDACreate(,&da_v);
354: DMCompositeCreate(,&dm_velocities);
355: DMCompositeAddDM(dm_velocities,(DM)du);
356: DMCompositeAddDM(dm_velocities,(DM)dv);
358: DMDACreate(,&da_p);
359: DMCompositeCreate(,&dm_velocities);
360: DMCompositeAddDM(dm,(DM)dm_velocities);
361: DMCompositeAddDM(dm,(DM)dm_p);
363: Access parts of composite vectors (Composite only)
364: ---------------------------------
365: DMCompositeGetAccess - access the global vector as subvectors and array (for redundant arrays)
366: ADD for local vector -
368: Element access
369: --------------
370: From global vectors
371: -DAVecGetArray - for DMDA
372: -VecGetArray - for DMSliced
373: ADD for DMComposite??? maybe
375: From individual vector
376: -DAVecGetArray - for DMDA
377: -VecGetArray -for sliced
378: ADD for DMComposite??? maybe
380: From single local vector
381: ADD * single local vector as arrays?
383: Communication
384: -------------
385: DMGlobalToLocal - global vector to single local vector
387: DMCompositeScatter/Gather - direct to individual local vectors and arrays CHANGE name closer to GlobalToLocal?
389: Obtaining vectors
390: -----------------
391: DMCreateGlobal/Local
392: DMGetGlobal/Local
393: DMCompositeGetLocalVectors - gives individual local work vectors and arrays
395: ????? individual global vectors ????
397: */
399: #if defined(PETSC_HAVE_HDF5)
400: PETSC_EXTERN PetscErrorCode DMSequenceLoad_HDF5_Internal(DM, const char *, PetscInt, PetscScalar *, PetscViewer);
401: #endif
403: static inline PetscErrorCode DMGetLocalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
404: {
406: #if defined(PETSC_USE_DEBUG)
407: {
408: PetscInt dof;
410: *start = *end = 0; /* Silence overzealous compiler warning */
412: PetscSectionGetOffset(dm->localSection, point, start);
413: PetscSectionGetDof(dm->localSection, point, &dof);
414: *end = *start + dof;
415: }
416: #else
417: {
418: const PetscSection s = dm->localSection;
419: *start = s->atlasOff[point - s->pStart];
420: *end = *start + s->atlasDof[point - s->pStart];
421: }
422: #endif
423: return 0;
424: }
426: static inline PetscErrorCode DMGetLocalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
427: {
428: #if defined(PETSC_USE_DEBUG)
429: {
430: PetscInt dof;
431: *start = *end = 0; /* Silence overzealous compiler warning */
433: PetscSectionGetFieldOffset(dm->localSection, point, field, start);
434: PetscSectionGetFieldDof(dm->localSection, point, field, &dof);
435: *end = *start + dof;
436: }
437: #else
438: {
439: const PetscSection s = dm->localSection->field[field];
440: *start = s->atlasOff[point - s->pStart];
441: *end = *start + s->atlasDof[point - s->pStart];
442: }
443: #endif
444: return 0;
445: }
447: static inline PetscErrorCode DMGetGlobalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
448: {
449: #if defined(PETSC_USE_DEBUG)
450: {
451: PetscInt dof, cdof;
452: *start = *end = 0; /* Silence overzealous compiler warning */
455: PetscSectionGetOffset(dm->globalSection, point, start);
456: PetscSectionGetDof(dm->globalSection, point, &dof);
457: PetscSectionGetConstraintDof(dm->globalSection, point, &cdof);
458: *end = *start + dof - cdof + (dof < 0 ? 1 : 0);
459: }
460: #else
461: {
462: const PetscSection s = dm->globalSection;
463: const PetscInt dof = s->atlasDof[point - s->pStart];
464: const PetscInt cdof = s->bc ? s->bc->atlasDof[point - s->bc->pStart] : 0;
465: *start = s->atlasOff[point - s->pStart];
466: *end = *start + dof - cdof + (dof < 0 ? 1 : 0);
467: }
468: #endif
469: return 0;
470: }
472: static inline PetscErrorCode DMGetGlobalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
473: {
474: #if defined(PETSC_USE_DEBUG)
475: {
476: PetscInt loff, lfoff, fdof, fcdof, ffcdof, f;
477: *start = *end = 0; /* Silence overzealous compiler warning */
480: PetscSectionGetOffset(dm->globalSection, point, start);
481: PetscSectionGetOffset(dm->localSection, point, &loff);
482: PetscSectionGetFieldOffset(dm->localSection, point, field, &lfoff);
483: PetscSectionGetFieldDof(dm->localSection, point, field, &fdof);
484: PetscSectionGetFieldConstraintDof(dm->localSection, point, field, &fcdof);
485: *start = *start < 0 ? *start - (lfoff - loff) : *start + lfoff - loff;
486: for (f = 0; f < field; ++f) {
487: PetscSectionGetFieldConstraintDof(dm->localSection, point, f, &ffcdof);
488: *start = *start < 0 ? *start + ffcdof : *start - ffcdof;
489: }
490: *end = *start < 0 ? *start - (fdof - fcdof) : *start + fdof - fcdof;
491: }
492: #else
493: {
494: const PetscSection s = dm->localSection;
495: const PetscSection fs = dm->localSection->field[field];
496: const PetscSection gs = dm->globalSection;
497: const PetscInt loff = s->atlasOff[point - s->pStart];
498: const PetscInt goff = gs->atlasOff[point - s->pStart];
499: const PetscInt lfoff = fs->atlasOff[point - s->pStart];
500: const PetscInt fdof = fs->atlasDof[point - s->pStart];
501: const PetscInt fcdof = fs->bc ? fs->bc->atlasDof[point - fs->bc->pStart] : 0;
502: PetscInt ffcdof = 0, f;
504: for (f = 0; f < field; ++f) {
505: const PetscSection ffs = dm->localSection->field[f];
506: ffcdof += ffs->bc ? ffs->bc->atlasDof[point - ffs->bc->pStart] : 0;
507: }
508: *start = goff + (goff < 0 ? loff - lfoff + ffcdof : lfoff - loff - ffcdof);
509: *end = *start < 0 ? *start - (fdof - fcdof) : *start + fdof - fcdof;
510: }
511: #endif
512: return 0;
513: }
515: PETSC_EXTERN PetscErrorCode DMGetBasisTransformDM_Internal(DM, DM *);
516: PETSC_EXTERN PetscErrorCode DMGetBasisTransformVec_Internal(DM, Vec *);
517: PETSC_INTERN PetscErrorCode DMConstructBasisTransform_Internal(DM);
519: PETSC_INTERN PetscErrorCode DMGetLocalBoundingIndices_DMDA(DM, PetscReal[], PetscReal[]);
520: PETSC_INTERN PetscErrorCode DMSetField_Internal(DM, PetscInt, DMLabel, PetscObject);
522: PETSC_INTERN PetscErrorCode DMSetLabelValue_Fast(DM, DMLabel *, const char[], PetscInt, PetscInt);
524: PETSC_INTERN PetscErrorCode DMCompleteBCLabels_Internal(DM dm);
525: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreate(DM, DMUniversalLabel *);
526: PETSC_EXTERN PetscErrorCode DMUniversalLabelDestroy(DMUniversalLabel *);
527: PETSC_EXTERN PetscErrorCode DMUniversalLabelGetLabel(DMUniversalLabel, DMLabel *);
528: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreateLabels(DMUniversalLabel, PetscBool, DM);
529: PETSC_EXTERN PetscErrorCode DMUniversalLabelSetLabelValue(DMUniversalLabel, DM, PetscBool, PetscInt, PetscInt);
530: PETSC_INTERN PetscInt PetscGCD(PetscInt a, PetscInt b);
532: #endif