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 ierr;
34: *grid = PETSC_NULL;
35: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
36: GridInitializePackage(PETSC_NULL);
37: #endif
39: PetscObjectGetComm((PetscObject) mesh, &comm);
40: PetscHeaderCreate(g, _Grid, struct _GridOps, GRID_COOKIE, -1, "Grid", comm, GridDestroy, GridView);
41: PetscLogObjectCreate(g);
42: PetscLogObjectMemory(g, sizeof(struct _Grid));
43: PetscMemzero(g->ops, sizeof(struct _GridOps));
44: g->bops->publish = PETSC_NULL /* GridPublish_Petsc */;
45: g->type_name = PETSC_NULL;
46: g->serialize_name = PETSC_NULL;
48: /* General grid description */
49: g->dim = -1;
50: g->mesh = mesh;
51: g->gridparent = PETSC_NULL;
52: g->setupcalled = PETSC_FALSE;
53: g->bdSetupCalled = PETSC_FALSE;
54: g->data = PETSC_NULL;
55: g->usr = PETSC_NULL;
56: PetscObjectReference((PetscObject) mesh);
58: /* Field variables */
59: g->numFields = 0;
60: g->maxFields = 1;
61: PetscMalloc(g->maxFields * sizeof(Field), &g->fields);
63: /* Class structure */
64: g->cm = PETSC_NULL;
66: /* Default variable orderings */
67: g->order = PETSC_NULL;
68: g->locOrder = PETSC_NULL;
70: /* Ghost variable scatter */
71: g->ghostVec = PETSC_NULL;
72: g->ghostScatter = PETSC_NULL;
74: /* Constraint variables */
75: g->isConstrained = PETSC_FALSE;
76: g->explicitConstraints = PETSC_FALSE;
77: g->numNewFields = -1;
78: g->constraintCM = PETSC_NULL;
79: g->constraintOrder = PETSC_NULL;
80: g->constraintOrdering = PETSC_NULL;
81: g->constraintMatrix = PETSC_NULL;
82: g->constraintCtx = PETSC_NULL;
84: /* Problem variables */
85: g->numRhsFuncs = 0;
86: g->maxRhsFuncs = 1;
87: PetscMalloc(g->maxRhsFuncs * sizeof(GridFunc), &g->rhsFuncs);
88: g->numRhsOps = 0;
89: g->maxRhsOps = 1;
90: PetscMalloc(g->maxRhsOps * sizeof(GridOp), &g->rhsOps);
91: g->numMatOps = 0;
92: g->maxMatOps = 1;
93: PetscMalloc(g->maxMatOps * sizeof(GridOp), &g->matOps);
95: /* Problem query variables */
96: g->activeMatOp = -1;
97: g->activeNonlinearOp = -1;
99: /* Assembly variables */
100: g->numActiveFields = 0;
101: g->maxActiveFields = 1;
102: PetscMalloc(g->maxActiveFields * sizeof(int), &g->defaultFields);
103: g->vec = PETSC_NULL;
104: g->mat = PETSC_NULL;
105: g->ghostElementVec = PETSC_NULL;
106: g->ALEActive = PETSC_FALSE;
107: g->activeOpTypes[0] = PETSC_TRUE;
108: g->activeOpTypes[1] = PETSC_TRUE;
109: g->activeOpTypes[2] = PETSC_TRUE;
111: /* Boundary condition variables */
112: g->reduceSystem = PETSC_FALSE;
113: g->reduceElement = PETSC_FALSE;
114: g->reduceElementArgs = PETSC_FALSE;
115: g->reductionCM = PETSC_NULL;
116: g->reduceOrder = PETSC_NULL;
117: g->locReduceOrder = PETSC_NULL;
118: g->bdReduceVec = PETSC_NULL;
119: g->bdReduceVecOld = PETSC_NULL;
120: g->bdReduceVecDiff = PETSC_NULL;
121: g->bdReduceVecCur = PETSC_NULL;
122: g->bdReduceMat = PETSC_NULL;
123: g->reduceVec = PETSC_NULL;
124: g->reduceAlpha = 1.0;
125: g->reduceContext = PETSC_NULL;
126: g->numBC = 0;
127: g->maxBC = 1;
128: PetscMalloc(g->maxBC * sizeof(GridBC), &g->bc);
129: g->numPointBC = 0;
130: g->maxPointBC = 1;
131: PetscMalloc(g->maxPointBC * sizeof(GridBC), &g->pointBC);
133: /* Boundary iteration variables */
134: MeshGetNumBoundaries(mesh, &g->numBd);
135: PetscMalloc(g->numBd * sizeof(int *), &g->bdSize);
136: PetscLogObjectMemory(g, g->numBd * sizeof(int *));
137: PetscMemzero(g->bdSize, g->numBd * sizeof(int *));
138: g->bdOrder = PETSC_NULL;
139: g->bdLocOrder = PETSC_NULL;
141: /* Setup matrix-free */
142: g->isMatrixFree = PETSC_FALSE;
143: g->matrixFreeArg = PETSC_NULL;
144: g->matrixFreeContext = PETSC_NULL;
146: /* Interpolation variables */
147: g->interpolationType = INTERPOLATION_LOCAL;
149: /* Graphics extras */
150: g->viewField = -1;
151: g->viewComp = 0;
153: *grid = g;
154: return(0);
155: }
157: /*@
158: GridSerialize - This function stores or recreates a grid using a viewer for a binary file.
160: Collective on MPI_Comm
162: Input Parameters:
163: + comm - The communicator for the grid object
164: . viewer - The viewer context
165: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
167: Output Parameter:
168: . grid - The grid
170: Level: beginner
172: .keywords: grid, serialize
173: .seealso: PartitionSerialize(), GridSerialize()
174: @*/
175: int GridSerialize(MPI_Comm comm, Grid *grid, PetscViewer viewer, PetscTruth store)
176: {
177: int (*serialize)(MPI_Comm, Grid *, PetscViewer, PetscTruth);
178: int fd, len;
179: char *name;
180: PetscTruth match;
181: int ierr;
187: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
188: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
189: PetscViewerBinaryGetDescriptor(viewer, &fd);
191: if (!GridSerializeRegisterAllCalled) {
192: GridSerializeRegisterAll(PETSC_NULL);
193: }
194: if (!GridSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
196: if (store) {
198: PetscStrlen((*grid)->class_name, &len);
199: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
200: PetscBinaryWrite(fd, (*grid)->class_name, len, PETSC_CHAR, 0);
201: PetscStrlen((*grid)->serialize_name, &len);
202: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
203: PetscBinaryWrite(fd, (*grid)->serialize_name, len, PETSC_CHAR, 0);
204: PetscFListFind(comm, GridSerializeList, (*grid)->serialize_name, (void (**)(void)) &serialize);
205: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
206: (*serialize)(comm, grid, viewer, store);
207: } else {
208: PetscBinaryRead(fd, &len, 1, PETSC_INT);
209: PetscMalloc((len+1) * sizeof(char), &name);
210: name[len] = 0;
211: PetscBinaryRead(fd, name, len, PETSC_CHAR);
212: PetscStrcmp(name, "Grid", &match);
213: PetscFree(name);
214: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-grid object");
215: /* Dispatch to the correct routine */
216: PetscBinaryRead(fd, &len, 1, PETSC_INT);
217: PetscMalloc((len+1) * sizeof(char), &name);
218: name[len] = 0;
219: PetscBinaryRead(fd, name, len, PETSC_CHAR);
220: PetscFListFind(comm, GridSerializeList, name, (void (**)(void)) &serialize);
221: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
222: (*serialize)(comm, grid, viewer, store);
223: PetscStrfree((*grid)->serialize_name);
224: (*grid)->serialize_name = name;
225: }
227: return(0);
228: }