Actual source code: dmimpl.h

      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 _DMOps *DMOps;
     16: struct _DMOps {
     17:   PetscErrorCode (*view)(DM,PetscViewer);
     18:   PetscErrorCode (*load)(DM,PetscViewer);
     19:   PetscErrorCode (*clone)(DM,DM*);
     20:   PetscErrorCode (*setfromoptions)(PetscOptionItems*,DM);
     21:   PetscErrorCode (*setup)(DM);
     22:   PetscErrorCode (*createlocalsection)(DM);
     23:   PetscErrorCode (*createdefaultconstraints)(DM);
     24:   PetscErrorCode (*createglobalvector)(DM,Vec*);
     25:   PetscErrorCode (*createlocalvector)(DM,Vec*);
     26:   PetscErrorCode (*getlocaltoglobalmapping)(DM);
     27:   PetscErrorCode (*createfieldis)(DM,PetscInt*,char***,IS**);
     28:   PetscErrorCode (*createcoordinatedm)(DM,DM*);
     29:   PetscErrorCode (*createcoordinatefield)(DM,DMField*);

     31:   PetscErrorCode (*getcoloring)(DM,ISColoringType,ISColoring*);
     32:   PetscErrorCode (*creatematrix)(DM, Mat*);
     33:   PetscErrorCode (*createinterpolation)(DM,DM,Mat*,Vec*);
     34:   PetscErrorCode (*createrestriction)(DM,DM,Mat*);
     35:   PetscErrorCode (*createmassmatrix)(DM,DM,Mat*);
     36:   PetscErrorCode (*hascreateinjection)(DM,PetscBool*);
     37:   PetscErrorCode (*createinjection)(DM,DM,Mat*);

     39:   PetscErrorCode (*refine)(DM,MPI_Comm,DM*);
     40:   PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*);
     41:   PetscErrorCode (*refinehierarchy)(DM,PetscInt,DM*);
     42:   PetscErrorCode (*coarsenhierarchy)(DM,PetscInt,DM*);
     43:   PetscErrorCode (*adaptlabel)(DM,DMLabel,DM*);
     44:   PetscErrorCode (*adaptmetric)(DM,Vec,DMLabel,DM*);

     46:   PetscErrorCode (*globaltolocalbegin)(DM,Vec,InsertMode,Vec);
     47:   PetscErrorCode (*globaltolocalend)(DM,Vec,InsertMode,Vec);
     48:   PetscErrorCode (*localtoglobalbegin)(DM,Vec,InsertMode,Vec);
     49:   PetscErrorCode (*localtoglobalend)(DM,Vec,InsertMode,Vec);
     50:   PetscErrorCode (*localtolocalbegin)(DM,Vec,InsertMode,Vec);
     51:   PetscErrorCode (*localtolocalend)(DM,Vec,InsertMode,Vec);

     53:   PetscErrorCode (*destroy)(DM);

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

     57:   PetscErrorCode (*createsubdm)(DM,PetscInt,const PetscInt*,IS*,DM*);
     58:   PetscErrorCode (*createsuperdm)(DM*,PetscInt,IS**,DM*);
     59:   PetscErrorCode (*createfielddecomposition)(DM,PetscInt*,char***,IS**,DM**);
     60:   PetscErrorCode (*createdomaindecomposition)(DM,PetscInt*,char***,IS**,IS**,DM**);
     61:   PetscErrorCode (*createddscatters)(DM,PetscInt,DM*,VecScatter**,VecScatter**,VecScatter**);

     63:   PetscErrorCode (*getdimpoints)(DM,PetscInt,PetscInt*,PetscInt*);
     64:   PetscErrorCode (*locatepoints)(DM,Vec,DMPointLocationType,PetscSF);
     65:   PetscErrorCode (*getneighbors)(DM,PetscInt*,const PetscMPIInt**);
     66:   PetscErrorCode (*getboundingbox)(DM,PetscReal*,PetscReal*);
     67:   PetscErrorCode (*getlocalboundingbox)(DM,PetscReal*,PetscReal*);
     68:   PetscErrorCode (*locatepointssubdomain)(DM,Vec,PetscMPIInt**);

     70:   PetscErrorCode (*projectfunctionlocal)(DM,PetscReal,PetscErrorCode(**)(PetscInt,PetscReal,const PetscReal[],PetscInt,PetscScalar *,void *),void **,InsertMode,Vec);
     71:   PetscErrorCode (*projectfunctionlabellocal)(DM,PetscReal,DMLabel,PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscErrorCode(**)(PetscInt,PetscReal,const PetscReal[],PetscInt,PetscScalar *,void *),void **,InsertMode,Vec);
     72:   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);
     73:   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);
     74:   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);
     75:   PetscErrorCode (*computel2diff)(DM,PetscReal,PetscErrorCode(**)(PetscInt, PetscReal,const PetscReal [], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);
     76:   PetscErrorCode (*computel2gradientdiff)(DM,PetscReal,PetscErrorCode(**)(PetscInt,PetscReal,const PetscReal [],const PetscReal[],PetscInt, PetscScalar *,void *),void **,Vec,const PetscReal[],PetscReal *);
     77:   PetscErrorCode (*computel2fielddiff)(DM,PetscReal,PetscErrorCode(**)(PetscInt, PetscReal,const PetscReal [], PetscInt, PetscScalar *, void *), void **, Vec, PetscReal *);

     79:   PetscErrorCode (*getcompatibility)(DM,DM,PetscBool*,PetscBool*);
     80: };

     82: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);
     83: PETSC_EXTERN PetscErrorCode DMLocalizeCoordinateReal_Internal(DM, PetscInt, const PetscReal[], const PetscReal[], PetscReal[]);
     84: PETSC_EXTERN PetscErrorCode DMLocalizeAddCoordinate_Internal(DM, PetscInt, const PetscScalar[], const PetscScalar[], PetscScalar[]);

     86: typedef struct _DMCoarsenHookLink *DMCoarsenHookLink;
     87: struct _DMCoarsenHookLink {
     88:   PetscErrorCode (*coarsenhook)(DM,DM,void*);              /* Run once, when coarse DM is created */
     89:   PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*); /* Run each time a new problem is restricted to a coarse grid */
     90:   void *ctx;
     91:   DMCoarsenHookLink next;
     92: };

     94: typedef struct _DMRefineHookLink *DMRefineHookLink;
     95: struct _DMRefineHookLink {
     96:   PetscErrorCode (*refinehook)(DM,DM,void*);     /* Run once, when a fine DM is created */
     97:   PetscErrorCode (*interphook)(DM,Mat,DM,void*); /* Run each time a new problem is interpolated to a fine grid */
     98:   void *ctx;
     99:   DMRefineHookLink next;
    100: };

    102: typedef struct _DMSubDomainHookLink *DMSubDomainHookLink;
    103: struct _DMSubDomainHookLink {
    104:   PetscErrorCode (*ddhook)(DM,DM,void*);
    105:   PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*);
    106:   void *ctx;
    107:   DMSubDomainHookLink next;
    108: };

    110: typedef struct _DMGlobalToLocalHookLink *DMGlobalToLocalHookLink;
    111: struct _DMGlobalToLocalHookLink {
    112:   PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*);
    113:   PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*);
    114:   void *ctx;
    115:   DMGlobalToLocalHookLink next;
    116: };

    118: typedef struct _DMLocalToGlobalHookLink *DMLocalToGlobalHookLink;
    119: struct _DMLocalToGlobalHookLink {
    120:   PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*);
    121:   PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*);
    122:   void *ctx;
    123:   DMLocalToGlobalHookLink next;
    124: };

    126: typedef enum {DMVEC_STATUS_IN,DMVEC_STATUS_OUT} DMVecStatus;
    127: typedef struct _DMNamedVecLink *DMNamedVecLink;
    128: struct _DMNamedVecLink {
    129:   Vec X;
    130:   char *name;
    131:   DMVecStatus status;
    132:   DMNamedVecLink next;
    133: };

    135: typedef struct _DMWorkLink *DMWorkLink;
    136: struct _DMWorkLink {
    137:   size_t     bytes;
    138:   void       *mem;
    139:   DMWorkLink next;
    140: };

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

    144: struct _n_DMLabelLink {
    145:   DMLabel              label;
    146:   PetscBool            output;
    147:   struct _n_DMLabelLink *next;
    148: };
    149: typedef struct _n_DMLabelLink *DMLabelLink;

    151: typedef struct _n_Boundary *DMBoundary;

    153: struct _n_Boundary {
    154:   DSBoundary  dsboundary;
    155:   DMLabel     label;
    156:   DMBoundary  next;
    157: };

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

    166: typedef struct _n_Space {
    167:   PetscDS ds;     /* Approximation space in this domain */
    168:   DMLabel label;  /* Label defining the domain of definition of the discretization */
    169:   IS      fields; /* Map from DS field numbers to original field numbers in the DM */
    170: } DMSpace;

    172: struct _p_UniversalLabel {
    173:   DMLabel    label;   /* The universal label */
    174:   PetscInt   Nl;      /* Number of labels encoded */
    175:   char     **names;   /* The label names */
    176:   PetscInt  *indices; /* The original indices in the input DM */
    177:   PetscInt   Nv;      /* Total number of values in all the labels */
    178:   PetscInt  *bits;    /* Starting bit for values of each label */
    179:   PetscInt  *masks;   /* Masks to pull out label value bits for each label */
    180:   PetscInt  *offsets; /* Starting offset for label values for each label */
    181:   PetscInt  *values;  /* Original label values before renumbering */
    182: };

    184: PETSC_INTERN PetscErrorCode DMDestroyLabelLinkList_Internal(DM);

    186: #define MAXDMMONITORS 5

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

    270:   PetscObject             dmksp,dmsnes,dmts;
    271: };

    273: PETSC_EXTERN PetscLogEvent DM_Convert;
    274: PETSC_EXTERN PetscLogEvent DM_GlobalToLocal;
    275: PETSC_EXTERN PetscLogEvent DM_LocalToGlobal;
    276: PETSC_EXTERN PetscLogEvent DM_LocatePoints;
    277: PETSC_EXTERN PetscLogEvent DM_Coarsen;
    278: PETSC_EXTERN PetscLogEvent DM_Refine;
    279: PETSC_EXTERN PetscLogEvent DM_CreateInterpolation;
    280: PETSC_EXTERN PetscLogEvent DM_CreateRestriction;
    281: PETSC_EXTERN PetscLogEvent DM_CreateInjection;
    282: PETSC_EXTERN PetscLogEvent DM_CreateMatrix;
    283: PETSC_EXTERN PetscLogEvent DM_Load;
    284: PETSC_EXTERN PetscLogEvent DM_AdaptInterpolator;

    286: PETSC_EXTERN PetscErrorCode DMCreateGlobalVector_Section_Private(DM,Vec*);
    287: PETSC_EXTERN PetscErrorCode DMCreateLocalVector_Section_Private(DM,Vec*);

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

    291: /*

    293:           Composite Vectors

    295:       Single global representation
    296:       Individual global representations
    297:       Single local representation
    298:       Individual local representations

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

    302:        DM da_u, da_v, da_p

    304:        DM dm_velocities

    306:        DM dm

    308:        DMDACreate(,&da_u);
    309:        DMDACreate(,&da_v);
    310:        DMCompositeCreate(,&dm_velocities);
    311:        DMCompositeAddDM(dm_velocities,(DM)du);
    312:        DMCompositeAddDM(dm_velocities,(DM)dv);

    314:        DMDACreate(,&da_p);
    315:        DMCompositeCreate(,&dm_velocities);
    316:        DMCompositeAddDM(dm,(DM)dm_velocities);
    317:        DMCompositeAddDM(dm,(DM)dm_p);

    320:     Access parts of composite vectors (Composite only)
    321:     ---------------------------------
    322:       DMCompositeGetAccess  - access the global vector as subvectors and array (for redundant arrays)
    323:       ADD for local vector -

    325:     Element access
    326:     --------------
    327:       From global vectors
    328:          -DAVecGetArray   - for DMDA
    329:          -VecGetArray - for DMSliced
    330:          ADD for DMComposite???  maybe

    332:       From individual vector
    333:           -DAVecGetArray - for DMDA
    334:           -VecGetArray -for sliced
    335:          ADD for DMComposite??? maybe

    337:       From single local vector
    338:           ADD         * single local vector as arrays?

    340:    Communication
    341:    -------------
    342:       DMGlobalToLocal - global vector to single local vector

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

    346:    Obtaining vectors
    347:    -----------------
    348:       DMCreateGlobal/Local
    349:       DMGetGlobal/Local
    350:       DMCompositeGetLocalVectors   - gives individual local work vectors and arrays

    353: ?????   individual global vectors   ????

    355: */

    357: #if defined(PETSC_HAVE_HDF5)
    358: PETSC_EXTERN PetscErrorCode DMSequenceLoad_HDF5_Internal(DM, const char *, PetscInt, PetscScalar *, PetscViewer);
    359: #endif

    361: PETSC_STATIC_INLINE PetscErrorCode DMGetLocalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
    362: {
    364: #if defined(PETSC_USE_DEBUG)
    365:   {
    366:     PetscInt       dof;
    368:     *start = *end = 0; /* Silence overzealous compiler warning */
    369:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
    370:     PetscSectionGetOffset(dm->localSection, point, start);
    371:     PetscSectionGetDof(dm->localSection, point, &dof);
    372:     *end = *start + dof;
    373:   }
    374: #else
    375:   {
    376:     const PetscSection s = dm->localSection;
    377:     *start = s->atlasOff[point - s->pStart];
    378:     *end   = *start + s->atlasDof[point - s->pStart];
    379:   }
    380: #endif
    381:   return(0);
    382: }

    384: PETSC_STATIC_INLINE PetscErrorCode DMGetLocalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
    385: {
    387: #if defined(PETSC_USE_DEBUG)
    388:   {
    389:     PetscInt       dof;
    391:     *start = *end = 0; /* Silence overzealous compiler warning */
    392:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
    393:     PetscSectionGetFieldOffset(dm->localSection, point, field, start);
    394:     PetscSectionGetFieldDof(dm->localSection, point, field, &dof);
    395:     *end = *start + dof;
    396:   }
    397: #else
    398:   {
    399:     const PetscSection s = dm->localSection->field[field];
    400:     *start = s->atlasOff[point - s->pStart];
    401:     *end   = *start + s->atlasDof[point - s->pStart];
    402:   }
    403: #endif
    404:   return(0);
    405: }

    407: PETSC_STATIC_INLINE PetscErrorCode DMGetGlobalOffset_Private(DM dm, PetscInt point, PetscInt *start, PetscInt *end)
    408: {
    410: #if defined(PETSC_USE_DEBUG)
    411:   {
    413:     PetscInt       dof,cdof;
    414:     *start = *end = 0; /* Silence overzealous compiler warning */
    415:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
    416:     if (!dm->globalSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be created automatically by DMGetGlobalSection()");
    417:     PetscSectionGetOffset(dm->globalSection, point, start);
    418:     PetscSectionGetDof(dm->globalSection, point, &dof);
    419:     PetscSectionGetConstraintDof(dm->globalSection, point, &cdof);
    420:     *end = *start + dof - cdof + (dof < 0 ? 1 : 0);
    421:   }
    422: #else
    423:   {
    424:     const PetscSection s    = dm->globalSection;
    425:     const PetscInt     dof  = s->atlasDof[point - s->pStart];
    426:     const PetscInt     cdof = s->bc ? s->bc->atlasDof[point - s->bc->pStart] : 0;
    427:     *start = s->atlasOff[point - s->pStart];
    428:     *end   = *start + dof - cdof + (dof < 0 ? 1 : 0);
    429:   }
    430: #endif
    431:   return(0);
    432: }

    434: PETSC_STATIC_INLINE PetscErrorCode DMGetGlobalFieldOffset_Private(DM dm, PetscInt point, PetscInt field, PetscInt *start, PetscInt *end)
    435: {
    437: #if defined(PETSC_USE_DEBUG)
    438:   {
    439:     PetscInt       loff, lfoff, fdof, fcdof, ffcdof, f;
    441:     *start = *end = 0; /* Silence overzealous compiler warning */
    442:     if (!dm->localSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
    443:     if (!dm->globalSection) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be crated automatically by DMGetGlobalSection()");
    444:     PetscSectionGetOffset(dm->globalSection, point, start);
    445:     PetscSectionGetOffset(dm->localSection, point, &loff);
    446:     PetscSectionGetFieldOffset(dm->localSection, point, field, &lfoff);
    447:     PetscSectionGetFieldDof(dm->localSection, point, field, &fdof);
    448:     PetscSectionGetFieldConstraintDof(dm->localSection, point, field, &fcdof);
    449:     *start = *start < 0 ? *start - (lfoff-loff) : *start + lfoff-loff;
    450:     for (f = 0; f < field; ++f) {
    451:       PetscSectionGetFieldConstraintDof(dm->localSection, point, f, &ffcdof);
    452:       *start = *start < 0 ? *start + ffcdof : *start - ffcdof;
    453:     }
    454:     *end   = *start < 0 ? *start - (fdof-fcdof) : *start + fdof-fcdof;
    455:   }
    456: #else
    457:   {
    458:     const PetscSection s     = dm->localSection;
    459:     const PetscSection fs    = dm->localSection->field[field];
    460:     const PetscSection gs    = dm->globalSection;
    461:     const PetscInt     loff  = s->atlasOff[point - s->pStart];
    462:     const PetscInt     goff  = gs->atlasOff[point - s->pStart];
    463:     const PetscInt     lfoff = fs->atlasOff[point - s->pStart];
    464:     const PetscInt     fdof  = fs->atlasDof[point - s->pStart];
    465:     const PetscInt     fcdof = fs->bc ? fs->bc->atlasDof[point - fs->bc->pStart] : 0;
    466:     PetscInt           ffcdof = 0, f;

    468:     for (f = 0; f < field; ++f) {
    469:       const PetscSection ffs = dm->localSection->field[f];
    470:       ffcdof += ffs->bc ? ffs->bc->atlasDof[point - ffs->bc->pStart] : 0;
    471:     }
    472:     *start = goff + (goff < 0 ? loff-lfoff + ffcdof : lfoff-loff - ffcdof);
    473:     *end   = *start < 0 ? *start - (fdof-fcdof) : *start + fdof-fcdof;
    474:   }
    475: #endif
    476:   return(0);
    477: }

    479: PETSC_EXTERN PetscErrorCode DMGetBasisTransformDM_Internal(DM, DM *);
    480: PETSC_EXTERN PetscErrorCode DMGetBasisTransformVec_Internal(DM, Vec *);
    481: PETSC_INTERN PetscErrorCode DMConstructBasisTransform_Internal(DM);

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

    486: PETSC_INTERN PetscErrorCode DMSetLabelValue_Fast(DM, DMLabel*, const char[], PetscInt, PetscInt);

    488: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreate(DM, DMUniversalLabel *);
    489: PETSC_EXTERN PetscErrorCode DMUniversalLabelDestroy(DMUniversalLabel *);
    490: PETSC_EXTERN PetscErrorCode DMUniversalLabelGetLabel(DMUniversalLabel, DMLabel *);
    491: PETSC_EXTERN PetscErrorCode DMUniversalLabelCreateLabels(DMUniversalLabel, PetscBool, DM);
    492: PETSC_EXTERN PetscErrorCode DMUniversalLabelSetLabelValue(DMUniversalLabel, DM, PetscBool, PetscInt, PetscInt);

    494: #endif