Actual source code: disccreate.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: disccreate.c,v 1.7 2000/01/10 03:54:25 knepley Exp $";
3: #endif
5: #include src/grid/discretization/discimpl.h
7: /*@
8: DiscretizationCreate - This function creates an empty discretization. The type can then be set with DiscretizationSetType().
10: Collective on MPI_Comm
12: Input Parameter:
13: . comm - The communicator
15: Output Parameter:
16: . disc - The disc
18: Level: beginner
20: .keywords: Discretization, create
21: .seealso: DiscretizationSetType(), DiscretizationSetUp(), DiscretizationDestroy(), GridCreate()
22: @*/
23: int DiscretizationCreate(MPI_Comm comm, Discretization *disc) {
24: Discretization d;
25: int ierr;
29: *disc = PETSC_NULL;
30: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
31: GridInitializePackage(PETSC_NULL);
32: #endif
34: PetscHeaderCreate(d, _Discretization, struct _DiscretizationOps, DISCRETIZATION_COOKIE, -1, "Discretization", comm, DiscretizationDestroy, DiscretizationView);
35: PetscLogObjectCreate(d);
36: PetscLogObjectMemory(d, sizeof(struct _Discretization));
37: PetscMemzero(d->ops, sizeof(struct _DiscretizationOps));
38: d->bops->publish = PETSC_NULL /* DiscretizationPublish_Petsc */;
39: d->type_name = PETSC_NULL;
40: d->serialize_name = PETSC_NULL;
42: /* General discretization description */
43: d->data = PETSC_NULL;
44: d->dim = -1;
45: d->funcs = 0;
46: d->comp = 0;
47: d->size = 0;
48: d->field = -1;
50: /* Boundary integration */
51: d->bdDisc = PETSC_NULL;
53: /* Quadrature */
54: d->numQuadPoints = 0;
55: d->quadPoints = PETSC_NULL;
56: d->quadWeights = PETSC_NULL;
57: d->quadShapeFuncs = PETSC_NULL;
58: d->quadShapeFuncDers = PETSC_NULL;
60: /* Operators */
61: d->numOps = 0;
62: d->maxOps = 1;
63: PetscMalloc(d->maxOps * sizeof(Operator), &d->operators);
65: /* Storage */
66: d->funcVal = PETSC_NULL;
67: d->fieldVal = PETSC_NULL;
69: *disc = d;
70: return(0);
71: }
73: /*@
74: DiscretizationSerialize - This function stores or recreates a discretization using a viewer for a binary file.
76: Collective on MPI_Comm
78: Input Parameters:
79: + comm - The communicator for the disc object
80: . viewer - The viewer context
81: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
83: Output Parameter:
84: . disc - The discretization
86: Level: beginner
88: .keywords: Discretization, serialize
89: .seealso: PartitionSerialize(), DiscretizationSerialize()
90: @*/
91: int DiscretizationSerialize(MPI_Comm comm, Discretization *disc, PetscViewer viewer, PetscTruth store)
92: {
93: int (*serialize)(MPI_Comm, Discretization *, PetscViewer, PetscTruth);
94: int fd, len;
95: char *name;
96: PetscTruth match;
97: int ierr;
103: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
104: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
105: PetscViewerBinaryGetDescriptor(viewer, &fd);
107: if (!DiscretizationSerializeRegisterAllCalled) {
108: DiscretizationSerializeRegisterAll(PETSC_NULL);
109: }
110: if (!DiscretizationSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
112: if (store) {
114: PetscStrlen((*disc)->class_name, &len);
115: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
116: PetscBinaryWrite(fd, (*disc)->class_name, len, PETSC_CHAR, 0);
117: PetscStrlen((*disc)->serialize_name, &len);
118: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
119: PetscBinaryWrite(fd, (*disc)->serialize_name, len, PETSC_CHAR, 0);
120: PetscFListFind(comm, DiscretizationSerializeList, (*disc)->serialize_name, (void (**)(void)) &serialize);
121: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
122: (*serialize)(comm, disc, viewer, store);
123: } else {
124: PetscBinaryRead(fd, &len, 1, PETSC_INT);
125: PetscMalloc((len+1) * sizeof(char), &name);
126: name[len] = 0;
127: PetscBinaryRead(fd, name, len, PETSC_CHAR);
128: PetscStrcmp(name, "Discretization", &match);
129: PetscFree(name);
130: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-disc object");
131: /* Dispatch to the correct routine */
132: PetscBinaryRead(fd, &len, 1, PETSC_INT);
133: PetscMalloc((len+1) * sizeof(char), &name);
134: name[len] = 0;
135: PetscBinaryRead(fd, name, len, PETSC_CHAR);
136: PetscFListFind(comm, DiscretizationSerializeList, name, (void (**)(void)) &serialize);
137: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
138: (*serialize)(comm, disc, viewer, store);
139: PetscStrfree((*disc)->serialize_name);
140: (*disc)->serialize_name = name;
141: }
143: return(0);
144: }