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: /*@
8: GridCreate - This function creates an empty grid. The type can then be set with GridSetType().
10: Collective on Mesh
12: Input Parameter:
13: . mesh - The Mesh
15: Output Parameter:
16: . grid - The grid
18: Options Database Keys:
19: . -grid_explicit_constraints - Constraints are implemented at the element level instead of through projectors
20: . -grid_int_type <type> - The interpolation type, e.g local, l2, etc.
22: Level: beginner
24: .keywords: grid, create
25: .seealso: GridSetType(), GridSetUp(), GridDestroy(), MeshCreate()
26: @*/
27: int GridCreate(Mesh mesh, Grid *grid) {
28: MPI_Comm comm;
29: Grid g;
30: int dim;
31: int ierr;
35: *grid = PETSC_NULL;
36: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
37: GridInitializePackage(PETSC_NULL);
38: #endif
40: PetscObjectGetComm((PetscObject) mesh, &comm);
41: PetscHeaderCreate(g, _Grid, struct _GridOps, GRID_COOKIE, -1, "Grid", comm, GridDestroy, GridView);
42: PetscLogObjectCreate(g);
43: PetscLogObjectMemory(g, sizeof(struct _Grid));
44: PetscMemzero(g->ops, sizeof(struct _GridOps));
45: g->bops->publish = PETSC_NULL /* GridPublish_Petsc */;
46: g->type_name = PETSC_NULL;
47: g->serialize_name = PETSC_NULL;
49: /* General grid description */
50: MeshGetDimension(mesh, &dim);
51: g->dim = dim;
52: g->mesh = mesh;
53: g->gridparent = PETSC_NULL;
54: g->setupcalled = PETSC_FALSE;
55: g->bdSetupCalled = PETSC_FALSE;
56: g->data = PETSC_NULL;
57: g->usr = PETSC_NULL;
58: PetscObjectReference((PetscObject) mesh);
60: /* Field variables */
61: g->numFields = 0;
62: g->maxFields = 1;
63: PetscMalloc(g->maxFields * sizeof(Field), &g->fields);
65: /* Class structure */
66: g->cm = PETSC_NULL;
68: /* Default variable orderings */
69: g->order = PETSC_NULL;
70: g->locOrder = PETSC_NULL;
72: /* Ghost variable scatter */
73: g->ghostVec = PETSC_NULL;
74: g->ghostScatter = PETSC_NULL;
76: /* Constraint variables */
77: g->isConstrained = PETSC_FALSE;
78: g->explicitConstraints = PETSC_FALSE;
79: g->numNewFields = -1;
80: g->constraintCM = PETSC_NULL;
81: g->constraintOrder = PETSC_NULL;
82: g->constraintOrdering = PETSC_NULL;
83: g->constraintMatrix = PETSC_NULL;
84: g->constraintCtx = PETSC_NULL;
86: /* Problem variables */
87: g->numRhsFuncs = 0;
88: g->maxRhsFuncs = 1;
89: PetscMalloc(g->maxRhsFuncs * sizeof(GridFunc), &g->rhsFuncs);
90: g->numRhsOps = 0;
91: g->maxRhsOps = 1;
92: PetscMalloc(g->maxRhsOps * sizeof(GridOp), &g->rhsOps);
93: g->numMatOps = 0;
94: g->maxMatOps = 1;
95: PetscMalloc(g->maxMatOps * sizeof(GridOp), &g->matOps);
97: /* Problem query variables */
98: g->activeMatOp = -1;
99: g->activeNonlinearOp = -1;
101: /* Assembly variables */
102: g->numActiveFields = 0;
103: g->maxActiveFields = 1;
104: PetscMalloc(g->maxActiveFields * sizeof(int), &g->defaultFields);
105: g->vec = PETSC_NULL;
106: g->mat = PETSC_NULL;
107: g->ghostElementVec = PETSC_NULL;
108: g->ALEActive = PETSC_FALSE;
109: g->activeOpTypes[0] = PETSC_TRUE;
110: g->activeOpTypes[1] = PETSC_TRUE;
111: g->activeOpTypes[2] = PETSC_TRUE;
113: /* Boundary condition variables */
114: g->reduceSystem = PETSC_FALSE;
115: g->reduceElement = PETSC_FALSE;
116: g->reduceElementArgs = PETSC_FALSE;
117: g->reductionCM = PETSC_NULL;
118: g->reduceOrder = PETSC_NULL;
119: g->locReduceOrder = PETSC_NULL;
120: g->bdReduceVec = PETSC_NULL;
121: g->bdReduceVecOld = PETSC_NULL;
122: g->bdReduceVecDiff = PETSC_NULL;
123: g->bdReduceVecCur = PETSC_NULL;
124: g->bdReduceMat = PETSC_NULL;
125: g->reduceVec = PETSC_NULL;
126: g->reduceAlpha = 1.0;
127: g->reduceContext = PETSC_NULL;
128: g->numBC = 0;
129: g->maxBC = 1;
130: PetscMalloc(g->maxBC * sizeof(GridBC), &g->bc);
131: g->numPointBC = 0;
132: g->maxPointBC = 1;
133: PetscMalloc(g->maxPointBC * sizeof(GridBC), &g->pointBC);
135: /* Boundary iteration variables */
136: MeshGetNumBoundaries(mesh, &g->numBd);
137: PetscMalloc(g->numBd * sizeof(int *), &g->bdSize);
138: PetscLogObjectMemory(g, g->numBd * sizeof(int *));
139: PetscMemzero(g->bdSize, g->numBd * sizeof(int *));
140: g->bdOrder = PETSC_NULL;
141: g->bdLocOrder = PETSC_NULL;
143: /* Setup matrix-free */
144: g->isMatrixFree = PETSC_FALSE;
145: g->matrixFreeArg = PETSC_NULL;
146: g->matrixFreeContext = PETSC_NULL;
148: /* Interpolation variables */
149: g->interpolationType = INTERPOLATION_LOCAL;
151: /* Graphics extras */
152: g->viewField = -1;
153: g->viewComp = 0;
155: *grid = g;
156: return(0);
157: }
159: /*@
160: GridSerialize - This function stores or recreates a grid using a viewer for a binary file.
162: Collective on MPI_Comm
164: Input Parameters:
165: + comm - The communicator for the grid object
166: . viewer - The viewer context
167: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
169: Output Parameter:
170: . grid - The grid
172: Level: beginner
174: .keywords: grid, serialize
175: .seealso: PartitionSerialize(), GridSerialize()
176: @*/
177: int GridSerialize(MPI_Comm comm, Grid *grid, PetscViewer viewer, PetscTruth store)
178: {
179: int (*serialize)(MPI_Comm, Grid *, PetscViewer, PetscTruth);
180: int fd, len;
181: char *name;
182: PetscTruth match;
183: int ierr;
189: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
190: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
191: PetscViewerBinaryGetDescriptor(viewer, &fd);
193: if (!GridSerializeRegisterAllCalled) {
194: GridSerializeRegisterAll(PETSC_NULL);
195: }
196: if (!GridSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
198: if (store) {
200: PetscStrlen((*grid)->class_name, &len);
201: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
202: PetscBinaryWrite(fd, (*grid)->class_name, len, PETSC_CHAR, 0);
203: PetscStrlen((*grid)->serialize_name, &len);
204: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
205: PetscBinaryWrite(fd, (*grid)->serialize_name, len, PETSC_CHAR, 0);
206: PetscFListFind(comm, GridSerializeList, (*grid)->serialize_name, (void (**)(void)) &serialize);
207: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
208: (*serialize)(comm, grid, viewer, store);
209: } else {
210: PetscBinaryRead(fd, &len, 1, PETSC_INT);
211: PetscMalloc((len+1) * sizeof(char), &name);
212: name[len] = 0;
213: PetscBinaryRead(fd, name, len, PETSC_CHAR);
214: PetscStrcmp(name, "Grid", &match);
215: PetscFree(name);
216: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-grid object");
217: /* Dispatch to the correct routine */
218: PetscBinaryRead(fd, &len, 1, PETSC_INT);
219: PetscMalloc((len+1) * sizeof(char), &name);
220: name[len] = 0;
221: PetscBinaryRead(fd, name, len, PETSC_CHAR);
222: PetscFListFind(comm, GridSerializeList, name, (void (**)(void)) &serialize);
223: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
224: (*serialize)(comm, grid, viewer, store);
225: PetscStrfree((*grid)->serialize_name);
226: (*grid)->serialize_name = name;
227: }
229: return(0);
230: }