Actual source code: dmplextransformimpl.h

  1: #pragma once

  3: #include <petsc/private/dmpleximpl.h>
  4: #include <petscdmplextransform.h>
  5: #include <petsc/private/hashmapi.h>

  7: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_SetUp;
  8: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_Apply;
  9: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_SetConeSizes;
 10: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_SetCones;
 11: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_CreateSF;
 12: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_CreateLabels;
 13: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_SetCoordinates;
 14: PETSC_EXTERN PetscLogEvent DMPLEXTRANSFORM_Check;

 16: typedef struct _n_DMPlexTransformOps *DMPlexTransformOps;
 17: struct _n_DMPlexTransformOps {
 18:   PetscErrorCode (*view)(DMPlexTransform, PetscViewer);
 19:   PetscErrorCode (*setfromoptions)(DMPlexTransform, PetscOptionItems);
 20:   PetscErrorCode (*setup)(DMPlexTransform);
 21:   PetscErrorCode (*destroy)(DMPlexTransform);
 22:   PetscErrorCode (*setdimensions)(DMPlexTransform, DM, DM);
 23:   PetscErrorCode (*celltransform)(DMPlexTransform, DMPolytopeType, PetscInt, PetscInt *, PetscInt *, DMPolytopeType *[], PetscInt *[], PetscInt *[], PetscInt *[]);
 24:   PetscErrorCode (*ordersupports)(DMPlexTransform, DM, DM);
 25:   PetscErrorCode (*getsubcellorientation)(DMPlexTransform, DMPolytopeType, PetscInt, PetscInt, DMPolytopeType, PetscInt, PetscInt, PetscInt *, PetscInt *);
 26:   PetscErrorCode (*mapcoordinates)(DMPlexTransform, DMPolytopeType, DMPolytopeType, PetscInt, PetscInt, PetscInt, PetscInt, const PetscScalar[], PetscScalar[]);
 27:   PetscErrorCode (*check)(DMPlexTransform, DM);
 28: };

 30: struct _p_DMPlexTransform {
 31:   PETSCHEADER(struct _n_DMPlexTransformOps);
 32:   void *data;

 34:   DM            dm;            /* This is the DM for which the transform has been computed */
 35:   DMLabel       active;        /* If not NULL, indicates points that are participating in the transform */
 36:   DMLabel       trType;        /* If not NULL, this holds the transformation type for each point */
 37:   PetscBool     setupcalled;   /* true if setup has been called */
 38:   PetscInt     *ctOrderOld;    /* [i] = ct: An array with original cell types in depth order */
 39:   PetscInt     *ctOrderInvOld; /* [ct] = i: An array with the ordinal numbers for each original cell type */
 40:   PetscInt     *ctStart;       /* [ct]: The number for the first cell of each polytope type in the original mesh */
 41:   PetscInt     *ctOrderNew;    /* [i] = ct: An array with produced cell types in depth order */
 42:   PetscInt     *ctOrderInvNew; /* [ct] = i: An array with the ordinal numbers for each produced cell type */
 43:   PetscInt     *ctStartNew;    /* [ctNew]: The number for the first cell of each polytope type in the new mesh */
 44:   PetscInt     *offset;        /* [ct/rt][ctNew]: The offset from ctStartNew[ctNew] in the new point numbering of a point of type ctNew produced from an old point of type ct or refine type rt */
 45:   PetscInt      depth;         /* The depth of the transformed mesh */
 46:   PetscInt     *depthStart;    /* The starting point for each depth stratum */
 47:   PetscInt     *depthEnd;      /* The starting point for the next depth stratum */
 48:   PetscInt     *trNv;          /* The number of transformed vertices in the closure of a cell of each type */
 49:   PetscScalar **trVerts;       /* The transformed vertex coordinates in the closure of a cell of each type */
 50:   PetscInt  ****trSubVerts;    /* The indices for vertices of subcell (rct, r) in a cell of each type */
 51:   PetscFE      *coordFE;       /* Finite element for each cell type, used for localized coordinate interpolation */
 52:   PetscFEGeom **refGeom;       /* Geometry of the reference cell for each cell type */
 53:   PetscReal     redFactor;     // Used to scale maxCell in each direction
 54:   /* Label construction */
 55:   PetscBool labelMatchStrata; /* Flag to restrict labeled points to the same cell type as parents */
 56:   PetscInt  labelReplicaInc;  /* Multiplier to create new label values for replicas v = oldv + r * repInc */
 57: };

 59: typedef struct {
 60:   PetscInt dummy;
 61: } DMPlexTransform_Filter;

 63: typedef enum {
 64:   NORMAL_DEFAULT,
 65:   NORMAL_INPUT,
 66:   NORMAL_COMPUTE,
 67:   NORMAL_COMPUTE_BD
 68: } PlexNormalAlg;
 69: PETSC_EXTERN const char *const PlexNormalAlgs[];

 71: typedef struct {
 72:   /* Inputs */
 73:   PetscInt            dimEx;       /* The dimension of the extruded mesh */
 74:   PetscInt            cdim;        /* The coordinate dimension of the input mesh */
 75:   PetscInt            cdimEx;      /* The coordinate dimension of the extruded mesh */
 76:   PetscInt            layers;      /* The number of extruded layers */
 77:   PetscReal           thickness;   /* The total thickness of the extruded layers */
 78:   PetscInt            Nth;         /* The number of specified thicknesses */
 79:   PetscReal          *thicknesses; /* The input layer thicknesses */
 80:   PetscBool           useTensor;   /* Flag to create tensor cells */
 81:   PlexNormalAlg       normalAlg;   /* Algorithm to use for computing normal */
 82:   PetscReal           normal[3];   /* Surface normal from input */
 83:   DM                  dmNormal;    // DM for normal field
 84:   Vec                 vecNormal;   // Normal at each vertex
 85:   PetscSimplePointFn *normalFunc;  /* A function returning the normal at a given point */
 86:   PetscBool           symmetric;   /* Extrude layers symmetrically about the surface */
 87:   PetscBool           periodic;    /* Connect the extruded layer periodically to the beginning */
 88:   /* Calculated quantities */
 89:   PetscReal       *layerPos; /* The position of each layer relative to the original surface, along the local normal direction */
 90:   PetscInt        *Nt;       /* The array of the number of target types */
 91:   DMPolytopeType **target;   /* The array of target types */
 92:   PetscInt       **size;     /* The array of the number of each target type */
 93:   PetscInt       **cone;     /* The array of cones for each target cell */
 94:   PetscInt       **ornt;     /* The array of orientation for each target cell */
 95:   // Borrowed storage
 96:   const PetscInt *degree; // The root degree of all points in the original mesh
 97: } DMPlexTransform_Extrude;

 99: typedef struct {
100:   PetscInt         debug;     // Debugging level
101:   PetscBool        useTensor; // Flag to create tensor cells
102:   PetscReal        width;     // The width of a cohesive cell
103:   PetscInt        *Nt;        // The array of the number of target types
104:   DMPolytopeType **target;    // The array of target types
105:   PetscInt       **size;      // The array of the number of each target type
106:   PetscInt       **cone;      // The array of cones for each target cell
107:   PetscInt       **ornt;      // The array of orientation for each target cell
108: } DMPlexTransform_Cohesive;

110: typedef struct {
111:   PetscInt dummy;
112: } DMPlexRefine_Regular;

114: typedef struct {
115:   PetscInt dummy;
116: } DMPlexRefine_ToBox;

118: typedef struct {
119:   PetscBool reflect; /* Flag to reflect the transformation */
120: } DMPlexRefine_ToSimplex;

122: typedef struct {
123:   PetscInt dummy;
124: } DMPlexRefine_Alfeld;

126: typedef struct {
127:   DMLabel      splitPoints; /* List of edges to be bisected (1), triangles to be divided (2), and tetrahedra to be divided (3) */
128:   PetscSection secEdgeLen;  /* Section for edge length field */
129:   PetscReal   *edgeLen;     /* Storage for edge length field */
130:   /* Cache of generated tetrahedron subdivisions, keyed by the encoded bisection order */
131:   PetscInt         Ncache;      /* Number of cached tetrahedron subdivisions */
132:   PetscInt         maxCache;    /* Capacity of the cache */
133:   PetscInt        *cacheCode;   /* [Ncache] Encoded bisection order */
134:   PetscInt        *cacheNt;     /* [Ncache] Number of target types */
135:   DMPolytopeType **cacheTarget; /* [Ncache] Target types */
136:   PetscInt       **cacheSize;   /* [Ncache] Number of targets of each type */
137:   PetscInt       **cacheCone;   /* [Ncache] Cone specifications */
138:   PetscInt       **cacheOrnt;   /* [Ncache] Cone orientations */
139:   PetscHMapI       cacheMap;    /* Encoded bisection order to cache index */
140:   /* Copy of the values of tr->trType, since DMLabelGetValue() costs O(number of values) */
141:   PetscInt  rtStart; /* Chart start of the DM */
142:   PetscInt  rtEnd;   /* Chart end of the DM */
143:   PetscInt *rt;      /* [rtEnd - rtStart] Refine type of each point */
144: } DMPlexRefine_SBR;

146: typedef struct {
147:   PetscInt dummy;
148: } DMPlexRefine_1D;

150: typedef struct {
151:   PetscInt         n;      /* The number of divisions to produce, so n = 1 gives 2 new cells */
152:   PetscReal        r;      /* The factor increase for cell height */
153:   PetscScalar     *h;      /* The computed cell heights, based on r */
154:   PetscInt        *Nt;     /* The array of the number of target types */
155:   DMPolytopeType **target; /* The array of target types */
156:   PetscInt       **size;   /* The array of the number of each target type */
157:   PetscInt       **cone;   /* The array of cones for each target cell */
158:   PetscInt       **ornt;   /* The array of orientation for each target cell */
159: } DMPlexRefine_BL;

161: PetscErrorCode DMPlexTransformSetDimensions_Internal(DMPlexTransform, DM, DM);
162: PetscErrorCode DMPlexTransformMapCoordinatesBarycenter_Internal(DMPlexTransform, DMPolytopeType, DMPolytopeType, PetscInt, PetscInt, PetscInt, PetscInt, const PetscScalar[], PetscScalar[]);
163: PetscErrorCode DMPlexTransformGetSubcellOrientation_Regular(DMPlexTransform, DMPolytopeType, PetscInt, PetscInt, DMPolytopeType, PetscInt, PetscInt, PetscInt *, PetscInt *);
164: PetscErrorCode DMPlexTransformCellRefine_Regular(DMPlexTransform, DMPolytopeType, PetscInt, PetscInt *, PetscInt *, DMPolytopeType *[], PetscInt *[], PetscInt *[], PetscInt *[]);