Actual source code: fieldClassMapCreate.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: fieldClassMapCreate.c,v 1.3 2000/01/10 03:54:17 knepley Exp $";
3: #endif
5: #include src/grid/gridimpl.h
7: /*@
8: FieldClassMapCreate - This function creates an empty field class map.
10: Collective on MPI_Comm
12: Input Parameter:
13: . comm - The communicator for the object
15: Output Parameter:
16: . map - The map
18: Level: beginner
20: .keywords: class, field class, class map, create
21: .seealso: FieldClassMapSetType()
22: @*/
23: int FieldClassMapCreate(MPI_Comm comm, FieldClassMap *map)
24: {
25: FieldClassMap cm;
26: int ierr;
30: *map = PETSC_NULL;
31: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
32: GridInitializePackage(PETSC_NULL);
33: #endif
35: PetscHeaderCreate(cm, _FieldClassMap, FieldClassMapOps, CLASS_MAP_COOKIE, -1, "FieldClassMap", comm,
36: FieldClassMapDestroy, FieldClassMapView);
37: PetscLogObjectCreate(cm);
38: PetscLogObjectMemory(cm, sizeof(struct _FieldClassMap));
39: PetscMemzero(cm->ops, sizeof(FieldClassMapOps));
40: cm->bops->publish = PETSC_NULL /* FieldClassMapPublish_Petsc */;
41: cm->type_name = PETSC_NULL;
42: cm->serialize_name = PETSC_NULL;
43: cm->data = PETSC_NULL;
45: /* Initialize fields */
46: cm->numFields = 0;
47: cm->fields = PETSC_NULL;
48: cm->numNodes = 0;
49: cm->numGhostNodes = 0;
50: cm->numOverlapNodes = 0;
51: cm->numClasses = 0;
52: cm->fieldClasses = PETSC_NULL;
53: cm->classes = PETSC_NULL;
54: cm->classSizes = PETSC_NULL;
55: cm->isReduced = PETSC_FALSE;
56: cm->reduceFieldClasses = PETSC_NULL;
57: cm->isConstrained = PETSC_FALSE;
58: cm->isClassConstrained = PETSC_NULL;
59: cm->classSizeDiffs = PETSC_NULL;
60: cm->mapSize = 0;
61: cm->numOldClasses = 0;
62: cm->classMap = PETSC_NULL;
64: *map = cm;
65: return(0);
66: }
68: /*@
69: FieldClassMapSerialize - This function stores or recreates a field class map using a viewer for a binary file.
71: Collective on MPI_Comm
73: Input Parameters:
74: + comm - The communicator for the object
75: . viewer - The viewer context
76: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
78: Output Parameter:
79: . map - The map
81: Level: beginner
83: .keywords: class, field class, class map, serialize
84: .seealso: MeshSerialize(), GridSerialize()
85: @*/
86: int FieldClassMapSerialize(MPI_Comm comm, FieldClassMap *map, PetscViewer viewer, PetscTruth store)
87: {
88: int (*serialize)(MPI_Comm, FieldClassMap *, PetscViewer, PetscTruth);
89: int fd, len;
90: char *name;
91: PetscTruth match;
92: int ierr;
98: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
99: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
100: PetscViewerBinaryGetDescriptor(viewer, &fd);
102: if (store) {
104: PetscStrlen((*map)->class_name, &len);
105: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
106: PetscBinaryWrite(fd, (*map)->class_name, len, PETSC_CHAR, 0);
107: PetscStrlen((*map)->serialize_name, &len);
108: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
109: PetscBinaryWrite(fd, (*map)->serialize_name, len, PETSC_CHAR, 0);
110: PetscFListFind(comm, FieldClassMapSerializeList, (*map)->serialize_name, (void (**)(void)) &serialize);
111: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
112: (*serialize)(comm, map, viewer, store);
113: } else {
114: PetscBinaryRead(fd, &len, 1, PETSC_INT);
115: PetscMalloc((len+1) * sizeof(char), &name);
116: name[len] = 0;
117: PetscBinaryRead(fd, name, len, PETSC_CHAR);
118: PetscStrcmp(name, "FieldClassMap", &match);
119: PetscFree(name);
120: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-fieldClassMap object");
121: /* Dispatch to the correct routine */
122: if (!FieldClassMapSerializeRegisterAllCalled) {
123: FieldClassMapSerializeRegisterAll(PETSC_NULL);
124: }
125: if (!FieldClassMapSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
126: PetscBinaryRead(fd, &len, 1, PETSC_INT);
127: PetscMalloc((len+1) * sizeof(char), &name);
128: name[len] = 0;
129: PetscBinaryRead(fd, name, len, PETSC_CHAR);
130: PetscFListFind(comm, FieldClassMapSerializeList, name, (void (**)(void)) &serialize);
131: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
132: (*serialize)(comm, map, viewer, store);
133: PetscStrfree((*map)->serialize_name);
134: (*map)->serialize_name = name;
135: }
137: return(0);
138: }