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: /*@
8: MeshCreate - This function creates an empty mesh. The type can then be set with MeshSetType().
10: Collective on MPI_Comm
12: Input Parameter:
13: . comm - The communicator for the mesh object
15: Output Parameter:
16: . mesh - The mesh
18: Options Database Keys:
19: . -mesh_reorder - The flag to renumber the mesh nodes
20: . -mesh_ordering_type <type> - The type of node numbering, such as tri_2d_rcm, etc.
22: Level: beginner
24: .keywords: mesh, create
25: .seealso: MeshSetType(), MeshSetUp(), MeshDestroy(), GridCreate()
26: @*/
27: int MeshCreate(MPI_Comm comm, Mesh *mesh)
28: {
29: Mesh m;
30: int ierr;
34: *mesh = PETSC_NULL;
35: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
36: MeshInitializePackage(PETSC_NULL);
37: #endif
39: PetscHeaderCreate(m, _Mesh, struct _MeshOps, MESH_COOKIE, -1, "Mesh", comm, MeshDestroy, MeshView);
40: PetscLogObjectCreate(m);
41: PetscLogObjectMemory(m, sizeof(struct _Mesh));
42: PetscMemzero(m->ops, sizeof(struct _MeshOps));
43: m->bops->publish = PETSC_NULL /* MeshPublish_Petsc */;
44: m->type_name = PETSC_NULL;
45: m->serialize_name = PETSC_NULL;
47: m->dim = -1;
48: m->setupcalled = PETSC_FALSE;
49: m->data = PETSC_NULL;
50: m->usr = PETSC_NULL;
52: /* Domain information */
53: m->startX = m->startY = m->startZ = 0.0;
54: m->endX = m->endY = m->endZ = 0.0;
55: m->sizeX = m->sizeY = m->sizeZ = 0.0;
56: m->locStartX = m->locStartY = m->locStartZ = 0.0;
57: m->locEndX = m->locEndY = m->locEndZ = 0.0;
58: m->locSizeX = m->locSizeY = m->locSizeZ = 0.0;
59: m->isPeriodic = PETSC_FALSE;
60: m->isPeriodicDim[0] = PETSC_FALSE;
61: m->isPeriodicDim[1] = PETSC_FALSE;
62: m->isPeriodicDim[2] = PETSC_FALSE;
64: /* Mesh boundary information */
65: m->bdCtx = PETSC_NULL;
66: m->bdCtxNew = PETSC_NULL;
68: /* Mesh generator information */
69: m->nodeOrdering = PETSC_NULL;
71: /* Mesh information */
72: m->numBd = 0;
73: m->numVertices = 0;
74: m->numNodes = 0;
75: m->numBdNodes = 0;
76: m->numEdges = 0;
77: m->numBdEdges = 0;
78: m->numFaces = 0;
79: m->numBdFaces = 0;
80: m->numCells = 0;
81: m->numHoles = 0;
82: m->numCorners = 0;
83: m->numCellCorners = 0;
84: m->maxDegree = 0;
85: m->holes = 0;
87: /* Iterator support */
88: m->activeBd = -1;
89: m->activeBdOld = -1;
90: m->activeBdNode = -1;
91: m->activeBdNodeClass = -1;
93: /* Quality limits */
94: m->maxAspectRatio = 1.0;
96: /* Partitioning support */
97: m->part = PETSC_NULL;
98: m->partitioned = PETSC_FALSE;
100: /* Coarsening support */
101: m->coarseMap = PETSC_NULL;
103: /* Graphics support */
104: m->highlightElement = -1;
106: /* Support calculations */
107: m->support = PETSC_NULL;
108: m->supportTaken = PETSC_FALSE;
110: /* Movement support */
111: m->isMoving = PETSC_FALSE;
113: *mesh = m;
114: return(0);
115: }
117: /*@
118: MeshSerialize - This function stores or recreates a mesh using a viewer for a binary file.
120: Collective on MPI_Comm
122: Input Parameters:
123: + comm - The communicator for the mesh object
124: . viewer - The viewer context
125: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
127: Output Parameter:
128: . mesh - The mesh
130: Level: beginner
132: .keywords: mesh, serialize
133: .seealso: PartitionSerialize(), GridSerialize()
134: @*/
135: int MeshSerialize(MPI_Comm comm, Mesh *mesh, PetscViewer viewer, PetscTruth store)
136: {
137: int (*serialize)(MPI_Comm, Mesh *, PetscViewer, PetscTruth);
138: int fd, len;
139: char *name;
140: PetscTruth match;
141: int ierr;
147: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
148: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
149: PetscViewerBinaryGetDescriptor(viewer, &fd);
151: if (!MeshSerializeRegisterAllCalled) {
152: MeshSerializeRegisterAll(PETSC_NULL);
153: }
154: if (!MeshSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
156: if (store) {
158: PetscStrlen((*mesh)->class_name, &len);
159: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
160: PetscBinaryWrite(fd, (*mesh)->class_name, len, PETSC_CHAR, 0);
161: PetscStrlen((*mesh)->serialize_name, &len);
162: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
163: PetscBinaryWrite(fd, (*mesh)->serialize_name, len, PETSC_CHAR, 0);
164: PetscFListFind(comm, MeshSerializeList, (*mesh)->serialize_name, (void (**)(void)) &serialize);
165: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
166: (*serialize)(comm, mesh, viewer, store);
167: } else {
168: PetscBinaryRead(fd, &len, 1, PETSC_INT);
169: PetscMalloc((len+1) * sizeof(char), &name);
170: name[len] = 0;
171: PetscBinaryRead(fd, name, len, PETSC_CHAR);
172: PetscStrcmp(name, "Mesh", &match);
173: PetscFree(name);
174: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-mesh object");
175: /* Dispatch to the correct routine */
176: PetscBinaryRead(fd, &len, 1, PETSC_INT);
177: PetscMalloc((len+1) * sizeof(char), &name);
178: name[len] = 0;
179: PetscBinaryRead(fd, name, len, PETSC_CHAR);
180: PetscFListFind(comm, MeshSerializeList, name, (void (**)(void)) &serialize);
181: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
182: (*serialize)(comm, mesh, viewer, store);
183: PetscStrfree((*mesh)->serialize_name);
184: (*mesh)->serialize_name = name;
185: }
187: return(0);
188: }