Actual source code: gridcreate.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: gridcreate.c,v 1.7 2000/01/10 03:54:25 knepley Exp $";
  3: #endif

 5:  #include src/grid/gridimpl.h

  7: #undef  __FUNCT__
  9: /*@ 
 10:   GridCreate - This function creates an empty grid. The type can then be set with GridSetType().

 12:   Collective on Mesh

 14:   Input Parameter:
 15: . mesh - The Mesh

 17:   Output Parameter:
 18: . grid - The grid

 20:   Options Database Keys:
 21: . -grid_explicit_constraints - Constraints are implemented at the element level instead of through projectors
 22: . -grid_int_type <type>      - The interpolation type, e.g local, l2, etc.

 24:   Level: beginner

 26: .keywords: grid, create
 27: .seealso: GridSetType(), GridSetUp(), GridDestroy(), MeshCreate()
 28: @*/
 29: int GridCreate(Mesh mesh, Grid *grid) {
 30:   MPI_Comm comm;
 31:   Grid     g;
 32:   int      dim;
 33:   int      ierr;

 37:   *grid = PETSC_NULL;
 38: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 39:   GridInitializePackage(PETSC_NULL);
 40: #endif

 42:   PetscObjectGetComm((PetscObject) mesh, &comm);
 43:   PetscHeaderCreate(g, _Grid, struct _GridOps, GRID_COOKIE, -1, "Grid", comm, GridDestroy, GridView);
 44:   PetscLogObjectCreate(g);
 45:   PetscLogObjectMemory(g, sizeof(struct _Grid));
 46:   PetscMemzero(g->ops, sizeof(struct _GridOps));
 47:   g->bops->publish    = PETSC_NULL /* GridPublish_Petsc */;
 48:   g->type_name        = PETSC_NULL;
 49:   g->serialize_name   = PETSC_NULL;

 51:   /* General grid description */
 52:   MeshGetDimension(mesh, &dim);
 53:   g->dim           = dim;
 54:   g->mesh          = mesh;
 55:   g->gridparent    = PETSC_NULL;
 56:   g->setupcalled   = PETSC_FALSE;
 57:   g->bdSetupCalled = PETSC_FALSE;
 58:   g->data          = PETSC_NULL;
 59:   g->usr           = PETSC_NULL;
 60:   PetscObjectReference((PetscObject) mesh);

 62:   /* Field variables */
 63:   g->numFields  = 0;
 64:   g->maxFields  = 1;
 65:   PetscMalloc(g->maxFields * sizeof(Field), &g->fields);

 67:   /* Class structure */
 68:   g->cm = PETSC_NULL;

 70:   /* Default variable orderings */
 71:   g->order    = PETSC_NULL;
 72:   g->locOrder = PETSC_NULL;

 74:   /* Ghost variable scatter */
 75:   g->ghostVec     = PETSC_NULL;
 76:   g->ghostScatter = PETSC_NULL;

 78:   /* Constraint variables */
 79:   g->isConstrained       = PETSC_FALSE;
 80:   g->explicitConstraints = PETSC_FALSE;
 81:   g->numNewFields        = -1;
 82:   g->constraintCM        = PETSC_NULL;
 83:   g->constraintOrder     = PETSC_NULL;
 84:   g->constraintOrdering  = PETSC_NULL;
 85:   g->constraintMatrix    = PETSC_NULL;
 86:   g->constraintCtx       = PETSC_NULL;

 88:   /* Problem variables */
 89:   g->numRhsFuncs = 0;
 90:   g->maxRhsFuncs = 1;
 91:   PetscMalloc(g->maxRhsFuncs * sizeof(GridFunc), &g->rhsFuncs);
 92:   g->numRhsOps   = 0;
 93:   g->maxRhsOps   = 1;
 94:   PetscMalloc(g->maxRhsOps   * sizeof(GridOp),   &g->rhsOps);
 95:   g->numMatOps   = 0;
 96:   g->maxMatOps   = 1;
 97:   PetscMalloc(g->maxMatOps   * sizeof(GridOp),   &g->matOps);

 99:   /* Problem query variables */
100:   g->activeMatOp       = -1;
101:   g->activeNonlinearOp = -1;

103:   /* Assembly variables */
104:   g->numActiveFields  = 0;
105:   g->maxActiveFields  = 1;
106:   PetscMalloc(g->maxActiveFields * sizeof(int), &g->defaultFields);
107:   g->vec              = PETSC_NULL;
108:   g->mat              = PETSC_NULL;
109:   g->ghostElementVec  = PETSC_NULL;
110:   g->ALEActive        = PETSC_FALSE;
111:   g->activeOpTypes[0] = PETSC_TRUE;
112:   g->activeOpTypes[1] = PETSC_TRUE;
113:   g->activeOpTypes[2] = PETSC_TRUE;

115:   /* Boundary condition variables */
116:   g->reduceSystem      = PETSC_FALSE;
117:   g->reduceElement     = PETSC_FALSE;
118:   g->reduceElementArgs = PETSC_FALSE;
119:   g->reductionCM       = PETSC_NULL;
120:   g->reduceOrder       = PETSC_NULL;
121:   g->locReduceOrder    = PETSC_NULL;
122:   g->bdReduceVec       = PETSC_NULL;
123:   g->bdReduceVecOld    = PETSC_NULL;
124:   g->bdReduceVecDiff   = PETSC_NULL;
125:   g->bdReduceVecCur    = PETSC_NULL;
126:   g->bdReduceMat       = PETSC_NULL;
127:   g->reduceVec         = PETSC_NULL;
128:   g->reduceAlpha       = 1.0;
129:   g->reduceContext     = PETSC_NULL;
130:   g->numBC             = 0;
131:   g->maxBC             = 1;
132:   PetscMalloc(g->maxBC      * sizeof(GridBC), &g->bc);
133:   g->numPointBC        = 0;
134:   g->maxPointBC        = 1;
135:   PetscMalloc(g->maxPointBC * sizeof(GridBC), &g->pointBC);

137:   /* Boundary iteration variables */
138:   MeshGetNumBoundaries(mesh, &g->numBd);
139:   PetscMalloc(g->numBd * sizeof(int *), &g->bdSize);
140:   PetscLogObjectMemory(g, g->numBd * sizeof(int *));
141:   PetscMemzero(g->bdSize, g->numBd * sizeof(int *));
142:   g->bdOrder    = PETSC_NULL;
143:   g->bdLocOrder = PETSC_NULL;

145:   /* Setup matrix-free */
146:   g->isMatrixFree      = PETSC_FALSE;
147:   g->matrixFreeArg     = PETSC_NULL;
148:   g->matrixFreeContext = PETSC_NULL;

150:   /* Interpolation variables */
151:   g->interpolationType = INTERPOLATION_LOCAL;

153:   /* Graphics extras */
154:   g->viewField = -1;
155:   g->viewComp  = 0;

157:   *grid = g;
158:   return(0);
159: }

161: #undef  __FUNCT__
163: /*@ 
164:   GridSerialize - This function stores or recreates a grid using a viewer for a binary file.

166:   Collective on MPI_Comm

168:   Input Parameters:
169: + comm   - The communicator for the grid object
170: . viewer - The viewer context
171: - store  - This flag is PETSC_TRUE is data is being written, otherwise it will be read

173:   Output Parameter:
174: . grid   - The grid

176:   Level: beginner

178: .keywords: grid, serialize
179: .seealso: PartitionSerialize(), GridSerialize()
180: @*/
181: int GridSerialize(MPI_Comm comm, Grid *grid, PetscViewer viewer, PetscTruth store)
182: {
183:   int      (*serialize)(MPI_Comm, Grid *, PetscViewer, PetscTruth);
184:   int        fd, len;
185:   char      *name;
186:   PetscTruth match;
187:   int        ierr;


193:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
194:   if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
195:   PetscViewerBinaryGetDescriptor(viewer, &fd);

197:   if (!GridSerializeRegisterAllCalled) {
198:     GridSerializeRegisterAll(PETSC_NULL);
199:   }
200:   if (!GridSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");

202:   if (store) {
204:     PetscStrlen((*grid)->class_name, &len);
205:     PetscBinaryWrite(fd, &len,                     1,   PETSC_INT,  0);
206:     PetscBinaryWrite(fd,  (*grid)->class_name,     len, PETSC_CHAR, 0);
207:     PetscStrlen((*grid)->serialize_name, &len);
208:     PetscBinaryWrite(fd, &len,                     1,   PETSC_INT,  0);
209:     PetscBinaryWrite(fd,  (*grid)->serialize_name, len, PETSC_CHAR, 0);
210:     PetscFListFind(comm, GridSerializeList, (*grid)->serialize_name, (void (**)(void)) &serialize);
211:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
212:     (*serialize)(comm, grid, viewer, store);
213:   } else {
214:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
215:     PetscMalloc((len+1) * sizeof(char), &name);
216:     name[len] = 0;
217:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
218:     PetscStrcmp(name, "Grid", &match);
219:     PetscFree(name);
220:     if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-grid object");
221:     /* Dispatch to the correct routine */
222:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
223:     PetscMalloc((len+1) * sizeof(char), &name);
224:     name[len] = 0;
225:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
226:     PetscFListFind(comm, GridSerializeList, name, (void (**)(void)) &serialize);
227:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
228:     (*serialize)(comm, grid, viewer, store);
229:     PetscStrfree((*grid)->serialize_name);
230:     (*grid)->serialize_name = name;
231:   }

233:   return(0);
234: }