Actual source code: gridreg.c

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

 5:  #include src/grid/gridimpl.h

  7: PetscFList GridList                       = PETSC_NULL;
  8: PetscTruth GridRegisterAllCalled          = PETSC_FALSE;
  9: PetscFList GridSerializeList              = PETSC_NULL;
 10: PetscTruth GridSerializeRegisterAllCalled = PETSC_FALSE;

 12: #undef __FUNCT__  
 14: /*@C
 15:   GridSetType - Sets the creation method for the grid.

 17:   Collective on Grid

 19:   Input Parameters:
 20: + grid   - The Grid context
 21: - method - A known method

 23:   Options Database Command:
 24: . -grid_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: . GRID_TRIANGULAR_2D - Triangular 2D grid

 31:   Normally, it is best to use the GridSetFromOptions() command and
 32:   then set the Grid 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 GridSetType() 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: grid, set, type
 46: .seealso GridSetSerializeType()
 47: @*/
 48: int GridSetType(Grid grid, GridType method)
 49: {
 50:   int      (*r)(Grid);
 51:   PetscTruth match;
 52:   int        ierr;

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

 59:   /* Get the function pointers for the method requested */
 60:   if (GridRegisterAllCalled == PETSC_FALSE) {
 61:     GridRegisterAll(PETSC_NULL);
 62:   }
 63:   PetscFListFind(grid->comm, GridList, method, (void (**)(void)) &r);
 64:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown grid type: %s", method);

 66:   if (grid->ops->destroy != PETSC_NULL) {
 67:     (*grid->ops->destroy)(grid);
 68:   }
 69:   (*r)(grid);

 71:   PetscObjectChangeTypeName((PetscObject) grid, method);
 72:   return(0);
 73: }

 75: #undef __FUNCT__
 77: /*@C
 78:   GridGetType - Gets the Grid method type name (as a string).

 80:   Not collective

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

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

 88:   Level: intermediate

 90: .keywords: grid, get, type, name
 91: .seealso GridSetType()
 92: @*/
 93: int GridGetType(Grid grid, GridType *type)
 94: {

100:   if (GridRegisterAllCalled == PETSC_FALSE) {
101:     GridRegisterAll(PETSC_NULL);
102:   }
103:   *type = grid->type_name;
104:   return(0);
105: }

107: #undef __FUNCT__  
109: /*@C
110:   GridSetSerializeType - Sets the serialization method for the grid.

112:   Collective on Grid

114:   Input Parameters:
115: + grid   - The Grid context
116: - method - A known method

118:   Options Database Command:
119: . -grid_serialize_type <method> - Sets the method; use -help for a list
120:                                   of available methods (for instance, tri2d_binary)

122:   Notes:
123:   See "petsc/include/grid.h" for available methods (for instance)
124: . GRID_SER_TRIANGULAR_2D_BINARY - Triangular 2D grid to binary file

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

138:   Level: intermediate

140: .keywords: grid, set, type, serialization
141: .seealso GridSetType()
142: @*/
143: int GridSetSerializeType(Grid grid, GridSerializeType method)
144: {
145:   int      (*r)(MPI_Comm, Grid *, PetscViewer, PetscTruth);
146:   PetscTruth match;
147:   int        ierr;

151:   PetscSerializeCompare((PetscObject) grid, method, &match);
152:   if (match == PETSC_TRUE) return(0);

154:   /* Get the function pointers for the method requested but do not call */
155:   if (GridSerializeRegisterAllCalled == PETSC_FALSE) {
156:     GridSerializeRegisterAll(PETSC_NULL);
157:   }
158:   PetscFListFind(grid->comm, GridSerializeList, method, (void (**)(void)) &r);
159:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown grid serialization type: %s", method);

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

165: #undef __FUNCT__
167: /*@C
168:   GridGetSerializeType - Gets the Grid serialization method (as a string).

170:   Not collective

172:   Input Parameter:
173: . grid - The grid

175:   Output Parameter:
176: . type - The name of Grid serialization method

178:   Level: intermediate

180: .keywords: grid, get, serialize, type, name
181: .seealso GridSetType()
182: @*/
183: int GridGetSerializeType(Grid grid, GridSerializeType *type)
184: {

190:   if (GridSerializeRegisterAllCalled == PETSC_FALSE) {
191:     GridSerializeRegisterAll(PETSC_NULL);
192:   }
193:   *type = grid->serialize_name;
194:   return(0);
195: }

197: /*--------------------------------------------------------------------------------------------------------------------*/
198: /*@C
199:   GridRegister - Adds a creation method to the grid package.

201:   Synopsis:

203:   GridRegister(char *name, char *path, char *func_name, int (*create_func)(Grid))

205:   Not Collective

207:   Input Parameters:
208: + name        - The name of a new user-defined creation routine
209: . path        - The path (either absolute or relative) of the library containing this routine
210: . func_name   - The name of the creation routine
211: - create_func - The creation routine itself

213:   Notes:
214:   GridRegister() may be called multiple times to add several user-defined grides.

216:   If dynamic libraries are used, then the fourth input argument (create_func) is ignored.

218:   Sample usage:
219: .vb
220:   GridRegisterDynamic("my_grid", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyGridCreate", MyGridCreate);
221: .ve

223:   Then, your grid type can be chosen with the procedural interface via
224: .vb
225:     GridCreate(MPI_Comm, Grid *);
226:     GridSetType(vec, "my_grid")
227: .ve
228:   or at runtime via the option
229: .vb
230:     -grid_type my_grid
231: .ve

233:   Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.

235:   Level: advanced

237: .keywords: Grid, register
238: .seealso: GridRegisterAll(), GridRegisterDestroy()
239: @*/
240: #undef __FUNCT__  
242: int GridRegister(const char sname[], const char path[], const char name[], int (*function)(Grid))
243: {
244:   char fullname[256];
245:   int  ierr;

248:   PetscStrcpy(fullname, path);
249:   PetscStrcat(fullname, ":");
250:   PetscStrcat(fullname, name);
251:   PetscFListAdd(&GridList, sname, fullname, (void (*)(void)) function);
252:   return(0);
253: }

255: /*@C
256:   GridSerializeRegister - Adds a serialization method to the grid package.

258:   Synopsis:

260:   GridSerializeRegister(char *name, char *path, char *func_name,
261:                         int (*serialize_func)(MPI_Comm, Grid *, PetscViewer, PetscTruth))

263:   Not Collective

265:   Input Parameters:
266: + name           - The name of a new user-defined serialization routine
267: . path           - The path (either absolute or relative) of the library containing this routine
268: . func_name      - The name of the serialization routine
269: - serialize_func - The serialization routine itself

271:   Notes:
272:   GridSerializeRegister() may be called multiple times to add several user-defined serializers.

274:   If dynamic libraries are used, then the fourth input argument (serialize_func) is ignored.

276:   Sample usage:
277: .vb
278:   GridSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
279: .ve

281:   Then, your serialization can be chosen with the procedural interface via
282: .vb
283:     GridSetSerializeType(grid, "my_store")
284: .ve
285:   or at runtime via the option
286: .vb
287:     -grid_serialize_type my_store
288: .ve

290:   Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.

292:   Level: advanced

294: .keywords: grid, register
295: .seealso: GridSerializeRegisterAll(), GridSerializeRegisterDestroy()
296: M*/
297: #undef __FUNCT__  
299: int GridSerializeRegister(const char sname[], const char path[], const char name[],
300:                           int (*function)(MPI_Comm, Grid *, PetscViewer, PetscTruth))
301: {
302:   char fullname[256];
303:   int  ierr;

306:   PetscStrcpy(fullname, path);
307:   PetscStrcat(fullname, ":");
308:   PetscStrcat(fullname, name);
309:   PetscFListAdd(&GridSerializeList, sname, fullname, (void (*)(void)) function);
310:   return(0);
311: }

313: /*-------------------------------------------------------------------------------------------------------------------*/
314: #undef __FUNCT__  
316: /*@C
317:   GridRegisterDestroy - Frees the list of creation routines for grids that were registered by GridRegister().

319:   Not collective

321:   Level: advanced

323: .keywords: grid, register, destroy
324: .seealso: GridRegister(), GridRegisterAll(), GridSerializeRegisterDestroy()
325: @*/
326: int GridRegisterDestroy(void)
327: {

331:   if (GridList != PETSC_NULL) {
332:     PetscFListDestroy(&GridList);
333:     GridList = PETSC_NULL;
334:   }
335:   GridRegisterAllCalled = PETSC_FALSE;
336:   return(0);
337: }

339: #undef __FUNCT__  
341: /*@C
342:   GridSerializeRegisterDestroy - Frees the list of serialization routines for
343:   grids that were registered by GridSerializeRegister().

345:   Not collective

347:   Level: advanced

349: .keywords: grid, serialization, register, destroy
350: .seealso: GridSerializeRegisterAll(), GridRegisterDestroy()
351: @*/
352: int GridSerializeRegisterDestroy()
353: {

357:   if (GridSerializeList != PETSC_NULL) {
358:     PetscFListDestroy(&GridSerializeList);
359:     GridSerializeList = PETSC_NULL;
360:   }
361:   GridSerializeRegisterAllCalled = PETSC_FALSE;
362:   return(0);
363: }