Actual source code: meshcreate.c

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

 5:  #include src/mesh/meshimpl.h

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

 12:   Collective on MPI_Comm

 14:   Input Parameter:
 15: . comm - The communicator for the mesh object

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

 20:   Options Database Keys:
 21: . -mesh_reorder              - The flag to renumber the mesh nodes
 22: . -mesh_ordering_type <type> - The type of node numbering, such as tri_2d_rcm, etc.

 24:   Level: beginner

 26: .keywords: mesh, create
 27: .seealso: MeshSetType(), MeshSetUp(), MeshDestroy(), GridCreate()
 28: @*/
 29: int MeshCreate(MPI_Comm comm, Mesh *mesh)
 30: {
 31:   Mesh m;
 32:   int  ierr;

 36:   *mesh = PETSC_NULL;
 37: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 38:   MeshInitializePackage(PETSC_NULL);
 39: #endif

 41:   PetscHeaderCreate(m, _Mesh, struct _MeshOps, MESH_COOKIE, -1, "Mesh", comm, MeshDestroy, MeshView);
 42:   PetscLogObjectCreate(m);
 43:   PetscLogObjectMemory(m, sizeof(struct _Mesh));
 44:   PetscMemzero(m->ops, sizeof(struct _MeshOps));
 45:   m->bops->publish    = PETSC_NULL /* MeshPublish_Petsc */;
 46:   m->type_name        = PETSC_NULL;
 47:   m->serialize_name   = PETSC_NULL;

 49:   m->dim              = -1;
 50:   m->setupcalled      = PETSC_FALSE;
 51:   m->data             = PETSC_NULL;
 52:   m->usr              = PETSC_NULL;

 54:   /* Domain information */
 55:   m->startX    = m->startY    = m->startZ    = 0.0;
 56:   m->endX      = m->endY      = m->endZ      = 0.0;
 57:   m->sizeX     = m->sizeY     = m->sizeZ     = 0.0;
 58:   m->locStartX = m->locStartY = m->locStartZ = 0.0;
 59:   m->locEndX   = m->locEndY   = m->locEndZ   = 0.0;
 60:   m->locSizeX  = m->locSizeY  = m->locSizeZ  = 0.0;
 61:   m->isPeriodic       = PETSC_FALSE;
 62:   m->isPeriodicDim[0] = PETSC_FALSE;
 63:   m->isPeriodicDim[1] = PETSC_FALSE;
 64:   m->isPeriodicDim[2] = PETSC_FALSE;

 66:   /* Mesh boundary information */
 67:   m->bdCtx    = PETSC_NULL;
 68:   m->bdCtxNew = PETSC_NULL;

 70:   /* Mesh generator information */
 71:   m->nodeOrdering = PETSC_NULL;

 73:   /* Mesh information */
 74:   m->numBd          = 0;
 75:   m->numVertices    = 0;
 76:   m->numNodes       = 0;
 77:   m->numBdNodes     = 0;
 78:   m->numEdges       = 0;
 79:   m->numBdEdges     = 0;
 80:   m->numFaces       = 0;
 81:   m->numBdFaces     = 0;
 82:   m->numCells       = 0;
 83:   m->numHoles       = 0;
 84:   m->numCorners     = 0;
 85:   m->numCellCorners = 0;
 86:   m->maxDegree      = 0;
 87:   m->holes          = 0;

 89:   /* Iterator support */
 90:   m->activeBd          = -1;
 91:   m->activeBdOld       = -1;
 92:   m->activeBdNode      = -1;
 93:   m->activeBdNodeClass = -1;

 95:   /* Quality limits */
 96:   m->maxAspectRatio = 1.0;

 98:   /* Partitioning support */
 99:   m->part        = PETSC_NULL;
100:   m->partitioned = PETSC_FALSE;

102:   /* Coarsening support */
103:   m->coarseMap = PETSC_NULL;

105:   /* Graphics support */
106:   m->highlightElement = -1;

108:   /* Support calculations */
109:   m->support      = PETSC_NULL;
110:   m->supportTaken = PETSC_FALSE;

112:   /* Movement support */
113:   m->isMoving = PETSC_FALSE;

115:   *mesh = m;
116:   return(0);
117: }

119: #undef  __FUNCT__
121: /*@ 
122:   MeshSerialize - This function stores or recreates a mesh using a viewer for a binary file.

124:   Collective on MPI_Comm

126:   Input Parameters:
127: + comm   - The communicator for the mesh object
128: . viewer - The viewer context
129: - store  - This flag is PETSC_TRUE is data is being written, otherwise it will be read

131:   Output Parameter:
132: . mesh   - The mesh

134:   Level: beginner

136: .keywords: mesh, serialize
137: .seealso: PartitionSerialize(), GridSerialize()
138: @*/
139: int MeshSerialize(MPI_Comm comm, Mesh *mesh, PetscViewer viewer, PetscTruth store)
140: {
141:   int      (*serialize)(MPI_Comm, Mesh *, PetscViewer, PetscTruth);
142:   int        fd, len;
143:   char      *name;
144:   PetscTruth match;
145:   int        ierr;


151:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
152:   if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
153:   PetscViewerBinaryGetDescriptor(viewer, &fd);

155:   if (!MeshSerializeRegisterAllCalled) {
156:     MeshSerializeRegisterAll(PETSC_NULL);
157:   }
158:   if (!MeshSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");

160:   if (store) {
162:     PetscStrlen((*mesh)->class_name, &len);
163:     PetscBinaryWrite(fd, &len,                     1,   PETSC_INT,  0);
164:     PetscBinaryWrite(fd,  (*mesh)->class_name,     len, PETSC_CHAR, 0);
165:     PetscStrlen((*mesh)->serialize_name, &len);
166:     PetscBinaryWrite(fd, &len,                     1,   PETSC_INT,  0);
167:     PetscBinaryWrite(fd,  (*mesh)->serialize_name, len, PETSC_CHAR, 0);
168:     PetscFListFind(comm, MeshSerializeList, (*mesh)->serialize_name, (void (**)(void)) &serialize);
169:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
170:     (*serialize)(comm, mesh, viewer, store);
171:   } else {
172:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
173:     PetscMalloc((len+1) * sizeof(char), &name);
174:     name[len] = 0;
175:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
176:     PetscStrcmp(name, "Mesh", &match);
177:     PetscFree(name);
178:     if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-mesh object");
179:     /* Dispatch to the correct routine */
180:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
181:     PetscMalloc((len+1) * sizeof(char), &name);
182:     name[len] = 0;
183:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
184:     PetscFListFind(comm, MeshSerializeList, name, (void (**)(void)) &serialize);
185:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
186:     (*serialize)(comm, mesh, viewer, store);
187:     PetscStrfree((*mesh)->serialize_name);
188:     (*mesh)->serialize_name = name;
189:   }

191:   return(0);
192: }