Actual source code: meshreg.c

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

 5:  #include src/mesh/meshimpl.h

  7: PetscFList MeshList                       = PETSC_NULL;
  8: PetscTruth MeshRegisterAllCalled          = PETSC_FALSE;
  9: PetscFList MeshSerializeList              = PETSC_NULL;
 10: PetscTruth MeshSerializeRegisterAllCalled = PETSC_FALSE;
 11: PetscFList MeshOrderingList               = PETSC_NULL;
 12: PetscTruth MeshOrderingRegisterAllCalled  = PETSC_FALSE;

 14: /*@C
 15:   MeshSetType - Sets the creation method for the mesh.

 17:   Collective on Mesh

 19:   Input Parameters:
 20: + mesh   - The Mesh context
 21: - method - A known method

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

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

 31:   Normally, it is best to use the MeshSetFromOptions() command and
 32:   then set the Mesh 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 MeshSetType() 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: mesh, set, type
 46: .seealso MeshSetSerializeType()
 47: @*/
 48: int MeshSetType(Mesh mesh, MeshType method)
 49: {
 50:   int      (*r)(Mesh);
 51:   PetscTruth match;
 52:   int        ierr;

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

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

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

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

 75: /*@C
 76:   MeshGetType - Gets the Mesh method type name (as a string).

 78:   Not collective

 80:   Input Parameter:
 81: . mesh - The mesh

 83:   Output Parameter:
 84: . type - The name of Mesh method

 86:   Level: intermediate

 88: .keywords: mesh, get, type, name
 89: .seealso MeshSetType()
 90: @*/
 91: int MeshGetType(Mesh mesh, MeshType *type)
 92: {

 98:   if (MeshRegisterAllCalled == PETSC_FALSE) {
 99:     MeshRegisterAll(PETSC_NULL);
100:   }
101:   *type = mesh->type_name;
102:   return(0);
103: }

105: /*@C
106:   MeshSetSerializeType - Sets the serialization method for the mesh.

108:   Collective on Mesh

110:   Input Parameters:
111: + mesh   - The Mesh context
112: - method - A known method

114:   Options Database Command:
115: . -mesh_serialize_type <method> - Sets the method; use -help for a list
116:                                   of available methods (for instance, tri2d_binary)

118:   Notes:
119:   See "petsc/include/mesh.h" for available methods (for instance)
120: . MESH_SER_TRIANGULAR_2D_BINARY - Triangular 2D mesh to binary file

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

134:   Level: intermediate

136: .keywords: mesh, set, type, serialization
137: .seealso MeshSetType()
138: @*/
139: int MeshSetSerializeType(Mesh mesh, MeshSerializeType method)
140: {
141:   int      (*r)(MPI_Comm, Mesh *, PetscViewer, PetscTruth);
142:   PetscTruth match;
143:   int        ierr;

147:   PetscSerializeCompare((PetscObject) mesh, method, &match);
148:   if (match == PETSC_TRUE) return(0);

150:   /* Get the function pointers for the method requested but do not call */
151:   if (MeshSerializeRegisterAllCalled == PETSC_FALSE) {
152:     MeshSerializeRegisterAll(PETSC_NULL);
153:   }
154:   PetscFListFind(mesh->comm, MeshSerializeList, method, (void (**)(void)) &r);
155:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown mesh serialization type: %s", method);

157:   PetscObjectChangeSerializeName((PetscObject) mesh, method);
158:   return(0);
159: }

161: /*@C
162:   MeshGetSerializeType - Gets the Mesh serialization method (as a string).

164:   Not collective

166:   Input Parameter:
167: . mesh - The mesh

169:   Output Parameter:
170: . type - The name of Mesh serialization method

172:   Level: intermediate

174: .keywords: mesh, get, serialize, type, name
175: .seealso MeshSetType()
176: @*/
177: int MeshGetSerializeType(Mesh mesh, MeshSerializeType *type)
178: {

184:   if (MeshSerializeRegisterAllCalled == PETSC_FALSE) {
185:     MeshSerializeRegisterAll(PETSC_NULL);
186:   }
187:   *type = mesh->serialize_name;
188:   return(0);
189: }

191: /*@C
192:   MeshGetOrdering - Gets a reordering for the mesh

194:   Collective on Mesh

196:   Input Parameters:
197: + mesh     - The mesh
198: - type     - type of reordering, one of the following:
199: $    MATORDERING_NATURAL - Natural
200: $    MATORDERING_ND      - Nested Dissection
201: $    MATORDERING_1WD     - One-way Dissection
202: $    MATORDERING_RCM     - Reverse Cuthill-McKee
203: $    MATORDERING_QMD     - Quotient Minimum Degree

205:   Output Parameter:
206: . ordering - The new node ordering

208:   Options Database Keys:
209:   To specify the ordering through the options database, use one of
210:   the following 
211: $   -mesh_ordering_type natural, -mesh_ordering_type nd, -mesh_ordering_type 1wd, 
212: $   -mesh_ordering_type rcm, -mesh_ordering_type qmd

214:   Level: intermediate

216:   Note:
217:   The user can define additional orderings, see MeshOrderingRegister().

219: .keywords: mesh, set, ordering, reordering, natural, Nested Dissection,
220:            One-way Dissection, Reverse Cuthill-McKee, Quotient Minimum Degree
221: .seealso: MeshOrderingRegister()
222: @*/
223: int MeshGetOrdering(Mesh mesh, MeshOrderingType type, AO *ordering)
224: {
225:   int      (*r)(Mesh, MeshOrderingType, AO*);
226:   char       orderName[256];
227:   PetscTruth opt;
228:   int        ierr;


233:   if (MeshOrderingRegisterAllCalled == PETSC_FALSE) {
234:     MeshOrderingRegisterAll(PETSC_NULL);
235:   }

237:   /* Check for type in command line arguments */
238:   PetscOptionsGetString(mesh->prefix, "-mesh_ordering_type", orderName, 256, &opt);
239:   if (opt == PETSC_TRUE) {
240:     type = orderName;
241:   }

243:    PetscFListFind(mesh->comm, MeshOrderingList, type, (void (**)(void)) &r);
244:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown mesh ordering type: %s", type);
245:   (*r)(mesh, type, ordering);

247:   return(0);
248: }

250: /*--------------------------------------------------------------------------------------------------------------------*/
251: /*@C
252:   MeshRegister - Adds a creation method to the mesh package.

254:   Synopsis:

256:   MeshRegister(char *name, char *path, char *func_name, int (*create_func)(Mesh))

258:   Not Collective

260:   Input Parameters:
261: + name        - The name of a new user-defined creation routine
262: . path        - The path (either absolute or relative) of the library containing this routine
263: . func_name   - The name of the creation routine
264: - create_func - The creation routine itself

266:   Notes:
267:   MeshRegister() may be called multiple times to add several user-defined meshes.

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

271:   Sample usage:
272: .vb
273:   MeshRegisterDynamic("my_mesh", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyMeshCreate", MyMeshCreate);
274: .ve

276:   Then, your mesh type can be chosen with the procedural interface via
277: .vb
278:     MeshCreate(MPI_Comm, Mesh *);
279:     MeshSetType(vec, "my_mesh")
280: .ve
281:   or at runtime via the option
282: .vb
283:     -mesh_type my_mesh
284: .ve

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

288:   Level: advanced

290: .keywords: Mesh, register
291: .seealso: MeshRegisterAll(), MeshRegisterDestroy()
292: @*/
293: int MeshRegister(const char sname[], const char path[], const char name[], int (*function)(Mesh))
294: {
295:   char fullname[256];
296:   int  ierr;

299:   PetscStrcpy(fullname, path);
300:   PetscStrcat(fullname, ":");
301:   PetscStrcat(fullname, name);
302:   PetscFListAdd(&MeshList, sname, fullname, (void (*)(void)) function);
303:   return(0);
304: }

306: /*@C
307:   MeshSerializeRegister - Adds a serialization method to the mesh package.

309:   Synopsis:

311:   MeshSerializeRegister(char *name, char *path, char *func_name,
312:                         int (*serialize_func)(MPI_Comm, Mesh *, PetscViewer, PetscTruth))

314:   Not Collective

316:   Input Parameters:
317: + name           - The name of a new user-defined serialization routine
318: . path           - The path (either absolute or relative) of the library containing this routine
319: . func_name      - The name of the serialization routine
320: - serialize_func - The serialization routine itself

322:   Notes:
323:   MeshSerializeRegister() may be called multiple times to add several user-defined serializers.

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

327:   Sample usage:
328: .vb
329:   MeshSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
330: .ve

332:   Then, your serialization can be chosen with the procedural interface via
333: .vb
334:     MeshSetSerializeType(mesh, "my_store")
335: .ve
336:   or at runtime via the option
337: .vb
338:     -mesh_serialize_type my_store
339: .ve

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

343:   Level: advanced

345: .keywords: mesh, register
346: .seealso: MeshSerializeRegisterAll(), MeshSerializeRegisterDestroy()
347: M*/
348: int MeshSerializeRegister(const char sname[], const char path[], const char name[],
349:                           int (*function)(MPI_Comm, Mesh *, PetscViewer, PetscTruth))
350: {
351:   char fullname[256];
352:   int  ierr;

355:   PetscStrcpy(fullname, path);
356:   PetscStrcat(fullname, ":");
357:   PetscStrcat(fullname, name);
358:   PetscFListAdd(&MeshSerializeList, sname, fullname, (void (*)(void)) function);
359:   return(0);
360: }

362: /*MC
363:   MeshOrderingRegister - Adds an ordering method to the mesh package.

365:   Synopsis:

367:   MeshOrderingRegister(char *order_name, char *path, char *order_func_name,
368:                        int (*order_func)(MPI_Comm, Mesh *, PetscViewer, PetscTruth))

370:   Not Collective

372:   Input Parameters:
373: + order_name      - The name of a new user-defined serialization routine
374: . path            - The path (either absolute or relative) of the library containing this routine
375: . order_func_name - The name of routine to create method context
376: - order_func      - The serialization routine itself

378:   Notes:
379:   MeshOrderingRegister() may be called multiple times to add several user-defined solvers.

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

383:   Sample usage:
384: .vb
385:   MeshOrderingRegister("my_order", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyOrderFunc", MyOrderFunc);
386: .ve

388:   Then, your serialization can be chosen with the procedural interface via
389: $     MeshGetOrdering(mesh, "my_order", &ao)
390:   or at runtime via the option
391: $     -mesh_ordering_type my_order

393:   Level: advanced

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

397: .keywords: mesh, register
398: .seealso: MeshOrderingRegisterAll(), MeshOrderingRegisterDestroy()
399: M*/
400: int MeshOrderingRegister(const char sname[], const char path[], const char name[],
401:                          int (*function)(Mesh, MeshOrderingType, AO *))
402: {
403:   char fullname[256];
404:   int  ierr;

407:   PetscStrcpy(fullname, path);
408:   PetscStrcat(fullname, ":");
409:   PetscStrcat(fullname, name);
410:   PetscFListAdd(&MeshOrderingList, sname, fullname, (void (*)(void)) function);
411:   return(0);
412: }

414: /*-------------------------------------------------------------------------------------------------------------------*/
415: /*@C
416:   MeshRegisterDestroy - Frees the list of creation routines for
417:   meshes that were registered by MeshRegister().

419:   Not collective

421:   Level: advanced

423: .keywords: mesh, register, destroy
424: .seealso: MeshRegister(), MeshRegisterAll(), MeshSerializeRegisterDestroy()
425: @*/
426: int MeshRegisterDestroy()
427: {

431:   if (MeshList != PETSC_NULL) {
432:     PetscFListDestroy(&MeshList);
433:     MeshList = PETSC_NULL;
434:   }
435:   MeshRegisterAllCalled = PETSC_FALSE;
436:   return(0);
437: }

439: /*@C
440:   MeshSerializeRegisterDestroy - Frees the list of serialization routines for
441:   meshes that were registered by FListAdd().

443:   Not collective

445:   Level: advanced

447: .keywords: mesh, serialization, register, destroy
448: .seealso: MeshSerializeRegisterAll(), MeshRegisterDestroy()
449: @*/
450: int MeshSerializeRegisterDestroy()
451: {

455:   if (MeshSerializeList) {
456:     PetscFListDestroy(&MeshSerializeList);
457:     MeshSerializeList = PETSC_NULL;
458:   }
459:   MeshSerializeRegisterAllCalled = PETSC_FALSE;
460:   return(0);
461: }

463: /*@C
464:   MeshOrderingRegisterDestroy - Frees the list of ordering routines for
465:   meshes that were registered by MeshSerializeRegister().

467:   Not collective

469:   Level: advanced

471: .keywords: mesh, ordering, register, destroy
472: .seealso: MeshOrderingRegisterAll(), MeshRegisterDestroy()
473: @*/
474: int MeshOrderingRegisterDestroy()
475: {

479:   if (MeshOrderingList) {
480:     PetscFListDestroy(&MeshOrderingList);
481:     MeshOrderingList = PETSC_NULL;
482:   }
483:   MeshOrderingRegisterAllCalled = PETSC_FALSE;
484:   return(0);
485: }