Actual source code: gridimpl.h

  1: /* $Id: gridimpl.h,v 1.17 2000/07/16 23:20:00 knepley Exp $ */
  2: /*
  3:   This file includes the definition of structures used in PETSc for 
  4:   grids. This should not be included in users' code.
  5: */

  7: #ifndef __GRIDIMPL_H

 10:  #include mesh.h
 11:  #include grid.h
 12:  #include gvec.h

 14:  #include discretization/discimpl.h

 16: /*-------------------------------------------------------------------------------------------------------------------*/

 18: /*
 19:   ElementVec and ElementMat are auxiliary classes used to simplify the
 20:   finite element interface for the programmer. It will probably not be
 21:   necessary for the user to create these.
 22: */
 23: struct _ElementVec {
 24:   PETSCHEADER(int)
 25:   int          size;          /* Number of test functions per element */
 26:   int          reduceSize;    /* Number of unknowns after reduction */
 27:   int         *indices;       /* Global row indices for data */
 28:   PetscScalar *array;         /* Contains entries for global vector */
 29: };

 31: struct _ElementMat {
 32:   PETSCHEADER(int)
 33:   int          rowSize;       /* Number of test  functions per element */
 34:   int          colSize;       /* Number of basis functions per element */
 35:   int          reduceRowSize; /* Number of test  unknowns after reduction */
 36:   int          reduceColSize; /* Number of basis unknowns after reduction */
 37:   int         *rowIndices;    /* Global row indices for data */
 38:   int         *colIndices;    /* Global column indices for data */
 39:   int         *reduceCols;    /* Element matrix columns of independent variables */
 40:   PetscScalar *array;         /* Contains entries for global matrix */
 41:   int         *tempIndices;   /* Storage for permuting indices */
 42:   PetscScalar *tempArray;     /* Storage for permuting element matrix */
 43: };

 45: /*-------------------------------------------------------------------------------------------------------------------*/

 47: /*-------------------------------------------- Class Structure ------------------------------------------------------*/
 48: typedef struct _FieldClassMapOps {
 49:   int (*setup)(FieldClassMap);
 50:   int (*constrain)(FieldClassMap, Grid, PetscTruth, PetscTruth, FieldClassMap *);
 51:   int (*reduce)(FieldClassMap, Grid, FieldClassMap *);
 52:   int (*destroy)(FieldClassMap);
 53:   int (*view)(FieldClassMap, PetscViewer);
 54: } FieldClassMapOps;

 56: struct _FieldClassMap {
 57:   PETSCHEADER(FieldClassMapOps)
 58:   void      *data;               /*           Type-specific structure */
 59:   /* Field variables */
 60:   int        numFields;          /*  F:       The number of fields */
 61:   int       *fields;             /* [F]:      The fields */
 62:   /* Mesh variables */
 63:   int        numNodes;           /*  N:       The number of nodes in this domain */
 64:   int        numGhostNodes;      /*  NG:      The number of ghost nodes in this domain */
 65:   int        numOverlapNodes;    /*  N+NG:    The number of nodes+ghost nodes in this domain */
 66:   /* Class variables */
 67:   int        numClasses;         /*  C:       The number of node classes */
 68:   int      **fieldClasses;       /* [F][C]:   Classes containing a given field */
 69:   int       *classes;            /* [N+NG]:   List of node classes, i.e. the fields defined on each node */
 70:   int       *classSizes;         /* [C]:      The number of variables on a node of a given class */
 71:   /* Reduction variables */
 72:   PetscTruth isReduced;          /*           The flag for using BC reduction */
 73:   int      **reduceFieldClasses; /* [F][C]:   Classes containing a reduced field */
 74:   /* Constraint variables */
 75:   PetscTruth isConstrained;      /*           The flag for using constraints */
 76:   int       *isClassConstrained; /* [C]:      The flag indicating a class containing constrained fields */
 77:   int       *classSizeDiffs;     /* [C]:      The increment in size (pos or neg) of the class size with the new fields */
 78:   /* Reduction/Constraint map */
 79:   int        mapSize;            /*  MS:      The number of constraints in the classMap */
 80:   int        numOldClasses;      /*  OC:      The number of classes before reduction */
 81:   int      **classMap;           /* [MS][OC]: The class map from unconstrained to constrained classes */
 82: };

 84: /*------------------------------------------- Variable Ordering -----------------------------------------------------*/
 85: /*
 86:   VarOrdering is an auxiliary object which encapsulates a global variable ordering for a local node-based discretization.
 87: */
 88: struct _VarOrdering {
 89:   PETSCHEADER(int)
 90:   /* Sizes */
 91:   int   numVars;           /*          The number of global variables in the ordering */
 92:   int   numLocVars;        /*          The number of local variables in the ordering */
 93:   int   numOverlapVars;    /*          The number of local+ghost variables in the ordering */
 94:   int   numNewVars;        /*          The number of global variables introduced by constraints */
 95:   int   numLocNewVars;     /*          The number of local variables introduced by constraints */
 96:   int   numOverlapNewVars; /*          The number of local+ghost variables introduced by constraints */
 97:   int   numTotalFields;    /*  TF:     The total number of fields on the grid */
 98:   /* Offsets */
 99:   int  *firstVar;          /* [P+1]:   The first variable on each processor and the total number of variables */
100:   int  *offsets;           /* [N+NG]:  The offset of the first variable on each node */
101:   int  *localOffsets;      /* [NG]:    The local offset of each ghost variable in this domain */
102:   int **localStart;        /* [TF][C]: The offset of each field (canonical numbering) on a node of a given class */
103: };

105: /*
106:   LocalVarOrdering is an auxiliary object which encapsulates a local variable ordering for a node-based discretization.
107: */
108: struct _LocalVarOrdering {
109:   PETSCHEADER(int)
110:   int  numFields;  /*  F    The number of fields in the ordering */
111:   int *fields;     /* [F]   The fields in the ordering */
112:   int  elemSize;   /*       The number of shape functions in the element matrix */
113:   int *elemStart;  /* [TF]: The offset of each field (canonical numbering) in the element matrix/vector (-1 for missing) */
114: };

116: /*-------------------------------------------------------------------------------------------------------------------*/

118: /* Grid Operations - These are the operations associated with all types of grids.
119:    Here is the basic idea. We have a set of multicomponent fields, each with its
120:    own discretization. This discretization is applied to each component of the field.
121:    
122:    Discretizations know:
123:    1) Quadrature
124:    2) Operators

126:    Operators know:
127:    1) The size of their local element matrix
128:    2) Where in the global element matrix their rows and columns start

130:    Each field is continguous in the global element matrix, and the variables on
131:    each node are also contiguous. Thus, the structure is

133:    rows for field 0:
134:      rows for local node 0:
135:               |
136:         <comp[0]> rows
137:               |
138:      rows for local node 1:
139:               |
140:      rows for local node <funcs[0]>:
141:               |
142:    rows for field 1:
143:               |
144:    rows for field <fields>:
145: */
146: struct _GridOps {
147:    int (*gridsetup)(Grid),
148:        (*gridsetupboundary)(Grid),
149:        (*gridsetupconstraints)(Grid, PetscConstraintObject),
150:        (*gridsetupghostscatter)(Grid, VarOrdering, Vec *, VecScatter *),
151:        (*setfromoptions)(Grid),
152:        (*gridduplicate)(Grid, Grid *),
153:        (*gridreform)(Grid, Mesh, GVec, GVec *),
154:        (*gridcopy)(Grid,Grid),
155:        (*destroy)(Grid),
156:        (*view)(Grid, PetscViewer),
157:        (*getboundarystart)(Grid, int, int, PetscTruth, FieldClassMap, int *, int *),
158:        (*getboundarynext)(Grid, int, int, PetscTruth, FieldClassMap, int *, int *),
159:        (*gridreformmesh)(Grid),
160:        (*gridcreategmat)(Grid, VarOrdering, VarOrdering, PetscTruth, GMat *),
161:        (*gridcreatevarordering)(Grid, FieldClassMap, VarOrdering *),
162:        (*gridcreatelocalvarordering)(Grid, int, int *, LocalVarOrdering *),
163:        (*gridcreatevarscatter)(Grid, VarOrdering, GVec, VarOrdering, GVec, VecScatter *),
164:        (*gridvarorderingconstrain)(Grid, int, PetscConstraintObject, FieldClassMap, VarOrdering, VarOrdering *),
165:        (*gridcalcelemvecidx)(Grid, Mesh, int, VarOrdering, VarOrdering, PetscTruth, PetscTruth, ElementVec),
166:        (*gridcalcelemmatidx)(Grid, int, VarOrdering, VarOrdering, VarOrdering, PetscTruth, ElementMat),
167:        (*gridcalcboundaryelemvecidx)(Grid, int, int, int, VarOrdering, VarOrdering, PetscTruth, ElementVec),
168:        (*gridcalcboundaryelemmatidx)(Grid, int, int, int, VarOrdering, VarOrdering, VarOrdering, PetscTruth, ElementMat),
169:        (*gridprojectelemvec)(Grid, Mesh, int, VarOrdering, VarOrdering, PetscTruth, PetscTruth, ElementVec),
170:        (*gvecgetlocalworkgvec)(GVec,GVec*),
171:        (*gvecrestorelocalworkgvec)(GVec,GVec*),
172:        (*gvecgetworkgvec)(GVec,GVec*),
173:        (*gvecrestoreworkgvec)(GVec,GVec*),
174:        (*gvecglobaltolocal)(GVec,InsertMode,GVec),
175:        (*gveclocaltoglobal)(GVec,InsertMode,GVec),
176:        (*gvecview)(GVec, PetscViewer),
177:        (*gridcreaterestriction)(Grid,Grid,GMat*),
178:        (*gvecevaluatefunction)(Grid, GVec, VarOrdering, PointFunction, PetscScalar, void *),
179:        (*gvecevaluatefunctionboundary)(Grid, GVec, int, VarOrdering, PointFunction, PetscScalar, void *),
180:        (*gvecevaluatefunctioncollective)(Grid, GVec, VarOrdering, PointFunction, PetscScalar, void *),
181:        (*gvecevaluatefunctiongalerkin)(Grid, GVec, int, int *, LocalVarOrdering, PointFunction, PetscScalar, void *),
182:        (*gvecevaluatefunctiongalerkincollective)(Grid, GVec, int, int *, LocalVarOrdering, PointFunction, PetscScalar, void *),
183:        (*gvecevaluateboundaryfunctiongalerkin)(Grid, GVec, int, int *, LocalVarOrdering, PointFunction, PetscScalar, void *),
184:        (*gvecevaluateboundaryfunctiongalerkincollective)(Grid, GVec, int, int *, LocalVarOrdering, PointFunction, PetscScalar, void *),
185:        (*gvecevaluateoperatorgalerkin)(Grid, GVec, GVec, GVec, VarOrdering, LocalVarOrdering, VarOrdering,
186:                                        LocalVarOrdering, int, PetscScalar, void *),
187:        (*gvecevaluatenonlinearoperatorgalerkin)(Grid, GVec, GVec, GVec, int, int *, LocalVarOrdering, NonlinearOperator,
188:                                                 PetscScalar, PetscTruth, void *),
189:        (*gvecevaluatesystemmatrix)(Grid, GVec, GVec, GVec, void *),
190:        (*gvecevaluatesystemmatrixdiagonal)(Grid, GVec, GVec, void *),
191:        (*gmatview)(GMat, PetscViewer),
192:        (*gmatevaluateoperatorgalerkin)(Grid, GMat, GVec, VarOrdering, LocalVarOrdering, VarOrdering, LocalVarOrdering, int,
193:                                        PetscScalar, MatAssemblyType, void *),
194:        (*gmatevaluatealeoperatorgalerkin)(Grid, GMat, int, int *, VarOrdering, LocalVarOrdering,
195:                                           int *, VarOrdering, LocalVarOrdering, int, PetscScalar, MatAssemblyType, void *),
196:        (*gmatevaluatealeconstrainedoperatorgalerkin)(Grid, GMat, int, int *, VarOrdering, LocalVarOrdering,
197:                                                      int *, VarOrdering, LocalVarOrdering, int, PetscScalar, MatAssemblyType, void *),
198:        (*gmatevaluateboundaryoperatorgalerkin)(Grid, GMat, GVec, VarOrdering, LocalVarOrdering, VarOrdering, LocalVarOrdering,
199:                                                int, PetscScalar, MatAssemblyType, void *),
200:        (*gridevaluaterhs)(Grid, GVec, GVec, PetscObject),
201:        (*gridevaluatesystemmatrix)(Grid, GVec, GMat *, GMat *, MatStructure *, PetscObject);
202: };

204: typedef struct _Field {
205:   char              *name;               /* The field name */
206:   int                numComp;            /* The number of components */
207:   DiscretizationType discType;           /* The type of discretization */
208:   Discretization     disc;               /* The field discretization */
209:   PetscTruth         isActive;           /* The flag for a field participating in the calculation */
210:   PetscTruth         isConstrained;      /* The flag for a constrained field */
211:   int                constraintCompDiff; /* The difference in components between new and constrained field */
212: } Field;

214: typedef struct _GridFunc {
215:   PointFunction func;  /* The PointFunction */
216:   int           field; /* The field this function acts on */
217:   PetscScalar   alpha; /* A scalar coefficient */
218: } GridFunc;

220: typedef struct _GridOp {
221:   int               op;          /* The operator */
222:   NonlinearOperator nonlinearOp; /* The nonlinear operator */
223:   int               field;       /* The field this operator acts on */
224:   PetscScalar       alpha;       /* A scalar coefficient */
225:   PetscTruth        isALE;       /* The flag for an ALE operator */
226: } GridOp;

228: typedef struct _GridBC {
229:   int           boundary; /* [Only for extended BCs] The boundary to apply the condition along */
230:   int           node;     /* [Only for point BCs]    The node at which to apply the condition */
231:   double        point[3]; /* [Only for point BCs]    The point at which to apply the condition */
232:   int           field;    /* The field to constrain */
233:   PointFunction func;     /* The condition function */
234:   PetscTruth    reduce;   /* The flag for explicit reduction of the system using the constraint */
235: } GridBC;

237: struct _Grid {
238:   PETSCHEADER(struct _GridOps)
239:   /* General grid description */
240:   int                   dim;                    /* grid dimension (1, 2, or 3) */
241:   Mesh                  mesh;                   /* The associated mesh */
242:   Grid                  gridparent;             /* The grid that this was refined from */
243:   PetscTruth            setupcalled;            /* Flag for initialization */
244:   PetscTruth            bdSetupCalled;          /* Flag for boundary initialization */
245:   void                 *data;                   /* NOT USED: Holds implementation-specific information */
246:   void                 *usr;                    /* NOT USED: An optional user-context */
247:   /* Field variables */
248:   int                   numFields;              /*  F:      The number of fields in the problem */
249:   int                   maxFields;              /*          The number of allocated fields */
250:   Field                *fields;                 /* [F]:     The fields defined on the grid */
251:   /* Class variables */
252:   FieldClassMap         cm;                     /* The default class map */
253:   /* Default variable orderings */
254:   VarOrdering           order;                  /* The default variable ordering */
255:   LocalVarOrdering      locOrder;               /* The default local variable ordering */
256:   /* Ghost variable scatter */
257:   Vec                   ghostVec;               /* The local vector of solution variables (including ghosts) */
258:   VecScatter            ghostScatter;           /* The scatter from global vector to local vector with ghost variables */
259:   /* Constraint variables */
260:   PetscTruth            isConstrained;          /* The flag for implementation of constraints */
261:   PetscTruth            explicitConstraints;    /* The flag for directly forming constrained systems */
262:   int                   numNewFields;           /* The number of new fields on this processor */
263:   FieldClassMap         constraintCM;           /* The constrained class map */
264:   VarOrdering           constraintOrder;        /* The variable ordering after constraints are applied */
265:   IS                    constraintOrdering;     /* Reordering with interior variables before those eliminated by constraints */
266:   Mat                   constraintMatrix;       /* The projector from the constrained to the unconstrained system */
267:   Mat                   constraintInverse;      /* The pseudo-inv of the projector from constrained to unconstrained system */
268:   PetscConstraintObject constraintCtx;          /* The user-specific constraint information */
269:   /* Problem variables */
270:   int                   numRhsFuncs;            /* The number of functions in the Rhs */
271:   int                   maxRhsFuncs;            /* The number of allocated functions */
272:   GridFunc             *rhsFuncs;               /* Rhs PointFunctions for each active field */
273:   int                   numRhsOps;              /* The number of operators in the Rhs */
274:   int                   maxRhsOps;              /* The number of allocated operators */
275:   GridOp               *rhsOps;                 /* The operators in the Rhs */
276:   int                   numMatOps;              /* The number of operators in the system matrix */
277:   int                   maxMatOps;              /* The number of allocated operators */
278:   GridOp               *matOps;                 /* The operators in the system matrix */
279:   /* Problem query variables */
280:   int                   activeMatOp;            /* The current matrix operator being queried */
281:   int                   activeNonlinearOp;      /* The current nonlinear operator being queried */
282:   /* Assembly variables */
283:   int                   numActiveFields;        /* The number of fields in the calculation */
284:   int                   maxActiveFields;        /* The number of allocated fields */
285:   int                  *defaultFields;          /* The fields involved in calculation (flagged above) */
286:   ElementVec            vec;                    /* Element vector for finite element computation */
287:   ElementMat            mat;                    /* Element matrix for finite element computation */
288:   ElementVec            ghostElementVec;        /* Element vector of solution variables */
289:   PetscTruth            ALEActive;              /* The flag for activating ALE support */
290:   PetscTruth            activeOpTypes[3];       /* Flags for different function types which contribute to calculation */
291:   /* Boundary condition variables */
292:   PetscTruth            reduceSystem;           /* Flag for reduction in global system */
293:   PetscTruth            reduceElement;          /* Flag for implicit reduction using element matrices */
294:   PetscTruth            reduceElementArgs;      /* Flag for implicit reduction using element matrices of argument vectors */
295:   FieldClassMap         reductionCM;            /* The class map on the space of reduced variables */
296:   VarOrdering           reduceOrder;            /* Variable ordering for eliminated unknowns */
297:   LocalVarOrdering      locReduceOrder;         /* Local variable ordering for eliminated unknowns */
298:   GVec                  bdReduceVec;            /* The solution evaluated on the boundary */
299:   GVec                  bdReduceVecOld;         /* The old solution evaluated on the boundary */
300:   GVec                  bdReduceVecDiff;        /* The difference of bdReduceVec and bdReduceVecOld */
301:   GVec                  bdReduceVecCur;         /* The current solution vector used to reduce the system */
302:   GMat                  bdReduceMat;            /* The block eliminated by boundary conditions */
303:   GVec                  reduceVec;              /* The product of bdReduceMat and bdReduceVec */
304:   PetscScalar           reduceAlpha;            /* Multiplier for reduction values, -1 in a nonlinear system */
305:   void                 *reduceContext;          /* An optional user-context passed to reduction assembly routines */
306:   int                   numBC;                  /* The number of boundary conditions */
307:   int                   maxBC;                  /* The number of allocated boundary conditions */
308:   GridBC               *bc;                     /* The boundary conditions */
309:   int                   numPointBC;             /* The number of boundary conditions to apply */
310:   int                   maxPointBC;             /* Maximum number of boundary conditions to apply */
311:   GridBC               *pointBC;                /* The point boundary conditions */
312:   /* Boundary iteration variables */
313:   int                   numBd;                  /*  B:     The number of boundaries in the problem */
314:   int                 **bdSize;                 /* [B][F]: Size of given boundary for a given field */
315:   VarOrdering           bdOrder;                /*         The global variable ordering along the boundary */
316:   LocalVarOrdering      bdLocOrder;             /*         The local variable ordering for nodes on the boundary */
317:   /* Matrix-free variables */
318:   PetscTruth            isMatrixFree;           /* The flag for construction of matrix-free operators */
319:   GVec                  matrixFreeArg;          /* The argument to the matrix-free operator */
320:   void                 *matrixFreeContext;      /* The application context for the matrix-free operator */
321:   /* Interpolation variables */
322:   InterpolationType     interpolationType;      /* The method used to project existing fields onto new meshes */
323:   /* Graphics Extras */
324:   int                   viewField;              /* The field being visualized */
325:   int                   viewComp;               /* The component being visualized */
326: };

328: #endif /* GRIDIMPL_H */