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: #undef  __FUNCT__
  9: /*@ 
 10:   FieldClassMapCreate - This function creates an empty field class map.

 12:   Collective on MPI_Comm

 14:   Input Parameter:
 15: . comm - The communicator for the object

 17:   Output Parameter:
 18: . map  - The map

 20:   Level: beginner

 22: .keywords: class, field class, class map, create
 23: .seealso: FieldClassMapSetType()
 24: @*/
 25: int FieldClassMapCreate(MPI_Comm comm, FieldClassMap *map)
 26: {
 27:   FieldClassMap cm;
 28:   int           ierr;

 32:   *map = PETSC_NULL;
 33: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 34:   GridInitializePackage(PETSC_NULL);
 35: #endif

 37:   PetscHeaderCreate(cm, _FieldClassMap, FieldClassMapOps, CLASS_MAP_COOKIE, -1, "FieldClassMap", comm,
 38:                     FieldClassMapDestroy, FieldClassMapView);
 39:   PetscLogObjectCreate(cm);
 40:   PetscLogObjectMemory(cm, sizeof(struct _FieldClassMap));
 41:   PetscMemzero(cm->ops, sizeof(FieldClassMapOps));
 42:   cm->bops->publish  = PETSC_NULL /* FieldClassMapPublish_Petsc */;
 43:   cm->type_name      = PETSC_NULL;
 44:   cm->serialize_name = PETSC_NULL;
 45:   cm->data           = PETSC_NULL;

 47:   /* Initialize fields */
 48:   cm->numFields          = 0;
 49:   cm->fields             = PETSC_NULL;
 50:   cm->numNodes           = 0;
 51:   cm->numGhostNodes      = 0;
 52:   cm->numOverlapNodes    = 0;
 53:   cm->numClasses         = 0;
 54:   cm->fieldClasses       = PETSC_NULL;
 55:   cm->classes            = PETSC_NULL;
 56:   cm->classSizes         = PETSC_NULL;
 57:   cm->isReduced          = PETSC_FALSE;
 58:   cm->reduceFieldClasses = PETSC_NULL;
 59:   cm->isConstrained      = PETSC_FALSE;
 60:   cm->isClassConstrained = PETSC_NULL;
 61:   cm->classSizeDiffs     = PETSC_NULL;
 62:   cm->mapSize            = 0;
 63:   cm->numOldClasses      = 0;
 64:   cm->classMap           = PETSC_NULL;

 66:   *map = cm;
 67:   return(0);
 68: }

 70: #undef  __FUNCT__
 72: /*@ 
 73:   FieldClassMapSerialize - This function stores or recreates a field class map using a viewer for a binary file.

 75:   Collective on MPI_Comm

 77:   Input Parameters:
 78: + comm   - The communicator for the object
 79: . viewer - The viewer context
 80: - store  - This flag is PETSC_TRUE is data is being written, otherwise it will be read

 82:   Output Parameter:
 83: . map    - The map

 85:   Level: beginner

 87: .keywords: class, field class, class map, serialize
 88: .seealso: MeshSerialize(), GridSerialize()
 89: @*/
 90: int FieldClassMapSerialize(MPI_Comm comm, FieldClassMap *map, PetscViewer viewer, PetscTruth store)
 91: {
 92:   int      (*serialize)(MPI_Comm, FieldClassMap *, PetscViewer, PetscTruth);
 93:   int        fd, len;
 94:   char      *name;
 95:   PetscTruth match;
 96:   int        ierr;


102:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
103:   if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
104:   PetscViewerBinaryGetDescriptor(viewer, &fd);

106:   if (store) {
108:     PetscStrlen((*map)->class_name, &len);
109:     PetscBinaryWrite(fd, &len,                    1,   PETSC_INT,  0);
110:     PetscBinaryWrite(fd,  (*map)->class_name,     len, PETSC_CHAR, 0);
111:     PetscStrlen((*map)->serialize_name, &len);
112:     PetscBinaryWrite(fd, &len,                    1,   PETSC_INT,  0);
113:     PetscBinaryWrite(fd,  (*map)->serialize_name, len, PETSC_CHAR, 0);
114:     PetscFListFind(comm, FieldClassMapSerializeList, (*map)->serialize_name, (void (**)(void)) &serialize);
115:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
116:     (*serialize)(comm, map, viewer, store);
117:   } else {
118:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
119:     PetscMalloc((len+1) * sizeof(char), &name);
120:     name[len] = 0;
121:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
122:     PetscStrcmp(name, "FieldClassMap", &match);
123:     PetscFree(name);
124:     if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-fieldClassMap object");
125:     /* Dispatch to the correct routine */
126:     if (!FieldClassMapSerializeRegisterAllCalled) {
127:       FieldClassMapSerializeRegisterAll(PETSC_NULL);
128:     }
129:     if (!FieldClassMapSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
130:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
131:     PetscMalloc((len+1) * sizeof(char), &name);
132:     name[len] = 0;
133:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
134:     PetscFListFind(comm, FieldClassMapSerializeList, name, (void (**)(void)) &serialize);
135:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
136:     (*serialize)(comm, map, viewer, store);
137:     PetscStrfree((*map)->serialize_name);
138:     (*map)->serialize_name = name;
139:   }

141:   return(0);
142: }