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: /*@C
 15:   FieldClassMapSetType - Sets the creation method for the map.

 17:   Collective on FieldClassMap

 19:   Input Parameters:
 20: + map    - The FieldClassMap context
 21: - method - A known method

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

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

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

 43:   Level: intermediate

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

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

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

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

 73:   PetscObjectChangeTypeName((PetscObject) map, method);
 74:   return(0);
 75: }

 77: /*@C
 78:   FieldClassMapGetType - Gets the FieldClassMap method type and name (as a string).

 80:   Not collective

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

 85:   Output Parameter:
 86: . type - The name of FieldClassMap method

 88:   Level: intermediate

 90: .keywords: class, field class, class map, get, type
 91: .seealso FieldClassMapSetType()
 92: @*/
 93: int FieldClassMapGetType(FieldClassMap map, FieldClassMapType *type)
 94: {

100:   if (!FieldClassMapRegisterAllCalled) {
101:     FieldClassMapRegisterAll(PETSC_NULL);
102:   }
103:   *type = map->type_name;
104:   return(0);
105: }

107: /*@C
108:   FieldClassMapSetSerializeType - Sets the serialization method for the map.

110:   Collective on FieldClassMap

112:   Input Parameters:
113: + map    - The FieldClassMap context
114: - method - A known method

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

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

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

136:   Level: intermediate

138: .keywords: class, field class, class map, set, type, serialization
139: .seealso FieldClassMapSetType()
140: @*/
141: int FieldClassMapSetSerializeType(FieldClassMap map, FieldClassMapSerializeType method)
142: {
143:   int      (*r)(MPI_Comm, FieldClassMap *, PetscViewer, PetscTruth);
144:   PetscTruth match;
145:   int        ierr;

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

152:   /* Get the function pointers for the method requested but do not call */
153:   if (!FieldClassMapSerializeRegisterAllCalled) {
154:     FieldClassMapSerializeRegisterAll(PETSC_NULL);
155:   }
156:   PetscFListFind(map->comm, FieldClassMapSerializeList, method, (void (**)(void)) &r);
157:   if (!r) {
158:     SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Unknown method: %s", method);
159:   }

161:   PetscObjectChangeSerializeName((PetscObject) map, method);
162:   return(0);
163: }

165: /*-------------------------------------------------------------------------------------------------------------------*/
166: /*@C
167:   FieldClassMapRegisterDestroy - Frees the list of creation routines for
168:   maps that were registered by PetscFListAdd().

170:   Not collective

172:   Level: advanced

174: .keywords: class, field class, class map, register, destroy
175: .seealso: FieldClassMapRegisterAll(), FieldClassMapSerializeRegisterDestroy()
176: @*/
177: int FieldClassMapRegisterDestroy()
178: {

182:   if (FieldClassMapList) {
183:     PetscFListDestroy(&FieldClassMapList);
184:     FieldClassMapList = PETSC_NULL;
185:   }
186:   FieldClassMapRegisterAllCalled = 0;
187:   return(0);
188: }

190: /*@C
191:   FieldClassMapSerializeRegisterDestroy - Frees the list of serialization routines for
192:   maps that were registered by PetscFListAdd().

194:   Not collective

196:   Level: advanced

198: .keywords: class, field class, class map, serialization, register, destroy
199: .seealso: FieldClassMapSerializeRegisterAll(), FieldClassMapRegisterDestroy()
200: @*/
201: int FieldClassMapSerializeRegisterDestroy()
202: {

206:   if (FieldClassMapSerializeList) {
207:     PetscFListDestroy(&FieldClassMapSerializeList);
208:     FieldClassMapSerializeList = PETSC_NULL;
209:   }
210:   FieldClassMapSerializeRegisterAllCalled = 0;
211:   return(0);
212: }