Actual source code: fieldClassMapReg.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: fieldClassMapReg.c,v 1.2 2000/01/10 03:54:17 knepley Exp $";
  3: #endif

 5:  #include src/grid/gridimpl.h

  7: PetscFList FieldClassMapList                       = 0;
  8: int        FieldClassMapRegisterAllCalled          = 0;
  9: PetscFList FieldClassMapSerializeList              = 0;
 10: int        FieldClassMapSerializeRegisterAllCalled = 0;
 11: PetscFList FieldClassMapOrderingList               = 0;
 12: int        FieldClassMapOrderingRegisterAllCalled  = 0;

 14: #undef __FUNCT__  
 16: /*@C
 17:   FieldClassMapSetType - Sets the creation method for the map.

 19:   Collective on FieldClassMap

 21:   Input Parameters:
 22: + map    - The FieldClassMap context
 23: - method - A known method

 25:   Options Database Command:
 26: . -class_map_type <method> - Sets the method; use -help for a list
 27:                              of available methods (for instance, tri2d)

 29:   Notes:
 30:   See "petsc/include/grid.h" for available methods (for instance)
 31: . CLASS_MAP_TRIANGULAR_2D - Triangular 2D map

 33:   Normally, it is best to use the FieldClassMapSetFromOptions() command and
 34:   then set the FieldClassMap type from the options database rather than by using
 35:   this routine.  Using the options database provides the user with
 36:   maximum flexibility in evaluating the many different solvers.
 37:   The FieldClassMapSetType() routine is provided for those situations
 38:   where it is necessary to set the application ordering independently of the
 39:   command line or options database.  This might be the case, for example,
 40:   when the choice of solver changes during the execution of the
 41:   program, and the user's application is taking responsibility for
 42:   choosing the appropriate method.  In other words, this routine is
 43:   not for beginners.

 45:   Level: intermediate

 47: .keywords: class, field class, class map, set, type
 48: .seealso FieldClassMapSetSerializeType()
 49: @*/
 50: int FieldClassMapSetType(FieldClassMap map, FieldClassMapType method)
 51: {
 52:   int      (*r)(FieldClassMap);
 53:   PetscTruth match;
 54:   int        ierr;

 58:   PetscTypeCompare((PetscObject) map, method, &match);
 59:   if (match == PETSC_TRUE) return(0);

 61:   /* Get the function pointers for the method requested */
 62:   if (!FieldClassMapRegisterAllCalled) {
 63:     FieldClassMapRegisterAll(PETSC_NULL);
 64:   }
 65:   PetscFListFind(map->comm, FieldClassMapList, method, (void (**)(void)) &r);
 66:   if (!r) {
 67:     SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
 68:   }

 70:   if (map->ops->destroy) {
 71:     (*map->ops->destroy)(map);
 72:   }
 73:   (*r)(map);

 75:   PetscObjectChangeTypeName((PetscObject) map, method);
 76:   return(0);
 77: }

 79: #undef __FUNCT__
 81: /*@C
 82:   FieldClassMapGetType - Gets the FieldClassMap method type and name (as a string).

 84:   Not collective

 86:   Input Parameter:
 87: . map  - The map

 89:   Output Parameter:
 90: . type - The name of FieldClassMap method

 92:   Level: intermediate

 94: .keywords: class, field class, class map, get, type
 95: .seealso FieldClassMapSetType()
 96: @*/
 97: int FieldClassMapGetType(FieldClassMap map, FieldClassMapType *type)
 98: {

104:   if (!FieldClassMapRegisterAllCalled) {
105:     FieldClassMapRegisterAll(PETSC_NULL);
106:   }
107:   *type = map->type_name;
108:   return(0);
109: }

111: #undef __FUNCT__  
113: /*@C
114:   FieldClassMapSetSerializeType - Sets the serialization method for the map.

116:   Collective on FieldClassMap

118:   Input Parameters:
119: + map    - The FieldClassMap context
120: - method - A known method

122:   Options Database Command:
123: . -class_map_serialize_type <method> - Sets the method; use -help for a list
124:             8                          of available methods (for instance, tri2d_binary)

126:   Notes:
127:   See "petsc/include/grid.h" for available methods (for instance)
128: . CLASS_MAP_SER_TRIANGULAR_2D_BINARY - Triangular 2D map to binary file

130:   Normally, it is best to use the FieldClassMapSetFromOptions() command and
131:   then set the FieldClassMap type from the options database rather than by using
132:   this routine.  Using the options database provides the user with
133:   maximum flexibility in evaluating the many different solvers.
134:   The FieldClassMapSetSerializeType() routine is provided for those situations
135:   where it is necessary to set the application ordering independently of the
136:   command line or options database.  This might be the case, for example,
137:   when the choice of solver changes during the execution of the
138:   program, and the user's application is taking responsibility for
139:   choosing the appropriate method.  In other words, this routine is
140:   not for beginners.

142:   Level: intermediate

144: .keywords: class, field class, class map, set, type, serialization
145: .seealso FieldClassMapSetType()
146: @*/
147: int FieldClassMapSetSerializeType(FieldClassMap map, FieldClassMapSerializeType method)
148: {
149:   int      (*r)(MPI_Comm, FieldClassMap *, PetscViewer, PetscTruth);
150:   PetscTruth match;
151:   int        ierr;

155:   PetscSerializeCompare((PetscObject) map, method, &match);
156:   if (match == PETSC_TRUE) return(0);

158:   /* Get the function pointers for the method requested but do not call */
159:   if (!FieldClassMapSerializeRegisterAllCalled) {
160:     FieldClassMapSerializeRegisterAll(PETSC_NULL);
161:   }
162:   PetscFListFind(map->comm, FieldClassMapSerializeList, method, (void (**)(void)) &r);
163:   if (!r) {
164:     SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
165:   }

167:   PetscObjectChangeSerializeName((PetscObject) map, method);
168:   return(0);
169: }

171: /*-------------------------------------------------------------------------------------------------------------------*/
172: #undef __FUNCT__  
174: /*@C
175:   FieldClassMapRegisterDestroy - Frees the list of creation routines for
176:   maps that were registered by PetscFListAdd().

178:   Not collective

180:   Level: advanced

182: .keywords: class, field class, class map, register, destroy
183: .seealso: FieldClassMapRegisterAll(), FieldClassMapSerializeRegisterDestroy()
184: @*/
185: int FieldClassMapRegisterDestroy()
186: {

190:   if (FieldClassMapList) {
191:     PetscFListDestroy(&FieldClassMapList);
192:     FieldClassMapList = PETSC_NULL;
193:   }
194:   FieldClassMapRegisterAllCalled = 0;
195:   return(0);
196: }

198: #undef __FUNCT__  
200: /*@C
201:   FieldClassMapSerializeRegisterDestroy - Frees the list of serialization routines for
202:   maps that were registered by PetscFListAdd().

204:   Not collective

206:   Level: advanced

208: .keywords: class, field class, class map, serialization, register, destroy
209: .seealso: FieldClassMapSerializeRegisterAll(), FieldClassMapRegisterDestroy()
210: @*/
211: int FieldClassMapSerializeRegisterDestroy()
212: {

216:   if (FieldClassMapSerializeList) {
217:     PetscFListDestroy(&FieldClassMapSerializeList);
218:     FieldClassMapSerializeList = PETSC_NULL;
219:   }
220:   FieldClassMapSerializeRegisterAllCalled = 0;
221:   return(0);
222: }