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: #undef __FUNCT__  
 16: /*@C
 17:   MeshSetType - Sets the creation method for the mesh.

 19:   Collective on Mesh

 21:   Input Parameters:
 22: + mesh   - The Mesh context
 23: - method - A known method

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

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

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

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

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

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

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

 77: #undef __FUNCT__
 79: /*@C
 80:   MeshGetType - Gets the Mesh method type name (as a string).

 82:   Not collective

 84:   Input Parameter:
 85: . mesh - The mesh

 87:   Output Parameter:
 88: . type - The name of Mesh method

 90:   Level: intermediate

 92: .keywords: mesh, get, type, name
 93: .seealso MeshSetType()
 94: @*/
 95: int MeshGetType(Mesh mesh, MeshType *type)
 96: {

102:   if (MeshRegisterAllCalled == PETSC_FALSE) {
103:     MeshRegisterAll(PETSC_NULL);
104:   }
105:   *type = mesh->type_name;
106:   return(0);
107: }

109: #undef __FUNCT__  
111: /*@C
112:   MeshSetSerializeType - Sets the serialization method for the mesh.

114:   Collective on Mesh

116:   Input Parameters:
117: + mesh   - The Mesh context
118: - method - A known method

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

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

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

140:   Level: intermediate

142: .keywords: mesh, set, type, serialization
143: .seealso MeshSetType()
144: @*/
145: int MeshSetSerializeType(Mesh mesh, MeshSerializeType method)
146: {
147:   int      (*r)(MPI_Comm, Mesh *, PetscViewer, PetscTruth);
148:   PetscTruth match;
149:   int        ierr;

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

156:   /* Get the function pointers for the method requested but do not call */
157:   if (MeshSerializeRegisterAllCalled == PETSC_FALSE) {
158:     MeshSerializeRegisterAll(PETSC_NULL);
159:   }
160:   PetscFListFind(mesh->comm, MeshSerializeList, method, (void (**)(void)) &r);
161:   if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown mesh serialization type: %s", method);

163:   PetscObjectChangeSerializeName((PetscObject) mesh, method);
164:   return(0);
165: }

167: #undef __FUNCT__
169: /*@C
170:   MeshGetSerializeType - Gets the Mesh serialization method (as a string).

172:   Not collective

174:   Input Parameter:
175: . mesh - The mesh

177:   Output Parameter:
178: . type - The name of Mesh serialization method

180:   Level: intermediate

182: .keywords: mesh, get, serialize, type, name
183: .seealso MeshSetType()
184: @*/
185: int MeshGetSerializeType(Mesh mesh, MeshSerializeType *type)
186: {

192:   if (MeshSerializeRegisterAllCalled == PETSC_FALSE) {
193:     MeshSerializeRegisterAll(PETSC_NULL);
194:   }
195:   *type = mesh->serialize_name;
196:   return(0);
197: }

199: #undef __FUNCT__  
201: /*@C
202:   MeshGetOrdering - Gets a reordering for the mesh

204:   Collective on Mesh

206:   Input Parameters:
207: + mesh     - The mesh
208: - type     - type of reordering, one of the following:
209: $    MATORDERING_NATURAL - Natural
210: $    MATORDERING_ND      - Nested Dissection
211: $    MATORDERING_1WD     - One-way Dissection
212: $    MATORDERING_RCM     - Reverse Cuthill-McKee
213: $    MATORDERING_QMD     - Quotient Minimum Degree

215:   Output Parameter:
216: . ordering - The new node ordering

218:   Options Database Keys:
219:   To specify the ordering through the options database, use one of
220:   the following 
221: $   -mesh_ordering_type natural, -mesh_ordering_type nd, -mesh_ordering_type 1wd, 
222: $   -mesh_ordering_type rcm, -mesh_ordering_type qmd

224:   Level: intermediate

226:   Note:
227:   The user can define additional orderings, see MeshOrderingRegister().

229: .keywords: mesh, set, ordering, reordering, natural, Nested Dissection,
230:            One-way Dissection, Reverse Cuthill-McKee, Quotient Minimum Degree
231: .seealso: MeshOrderingRegister()
232: @*/
233: int MeshGetOrdering(Mesh mesh, MeshOrderingType type, AO *ordering)
234: {
235:   int      (*r)(Mesh, MeshOrderingType, AO*);
236:   char       orderName[256];
237:   PetscTruth opt;
238:   int        ierr;


243:   if (MeshOrderingRegisterAllCalled == PETSC_FALSE) {
244:     MeshOrderingRegisterAll(PETSC_NULL);
245:   }

247:   /* Check for type in command line arguments */
248:   PetscOptionsGetString(mesh->prefix, "-mesh_ordering_type", orderName, 256, &opt);
249:   if (opt == PETSC_TRUE) {
250:     type = orderName;
251:   }

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

257:   return(0);
258: }

260: /*--------------------------------------------------------------------------------------------------------------------*/
261: /*@C
262:   MeshRegister - Adds a creation method to the mesh package.

264:   Synopsis:

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

268:   Not Collective

270:   Input Parameters:
271: + name        - The name of a new user-defined creation routine
272: . path        - The path (either absolute or relative) of the library containing this routine
273: . func_name   - The name of the creation routine
274: - create_func - The creation routine itself

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

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

281:   Sample usage:
282: .vb
283:   MeshRegisterDynamic("my_mesh", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyMeshCreate", MyMeshCreate);
284: .ve

286:   Then, your mesh type can be chosen with the procedural interface via
287: .vb
288:     MeshCreate(MPI_Comm, Mesh *);
289:     MeshSetType(vec, "my_mesh")
290: .ve
291:   or at runtime via the option
292: .vb
293:     -mesh_type my_mesh
294: .ve

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

298:   Level: advanced

300: .keywords: Mesh, register
301: .seealso: MeshRegisterAll(), MeshRegisterDestroy()
302: @*/
303: #undef __FUNCT__  
305: int MeshRegister(const char sname[], const char path[], const char name[], int (*function)(Mesh))
306: {
307:   char fullname[256];
308:   int  ierr;

311:   PetscStrcpy(fullname, path);
312:   PetscStrcat(fullname, ":");
313:   PetscStrcat(fullname, name);
314:   PetscFListAdd(&MeshList, sname, fullname, (void (*)(void)) function);
315:   return(0);
316: }

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

321:   Synopsis:

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

326:   Not Collective

328:   Input Parameters:
329: + name           - The name of a new user-defined serialization routine
330: . path           - The path (either absolute or relative) of the library containing this routine
331: . func_name      - The name of the serialization routine
332: - serialize_func - The serialization routine itself

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

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

339:   Sample usage:
340: .vb
341:   MeshSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
342: .ve

344:   Then, your serialization can be chosen with the procedural interface via
345: .vb
346:     MeshSetSerializeType(mesh, "my_store")
347: .ve
348:   or at runtime via the option
349: .vb
350:     -mesh_serialize_type my_store
351: .ve

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

355:   Level: advanced

357: .keywords: mesh, register
358: .seealso: MeshSerializeRegisterAll(), MeshSerializeRegisterDestroy()
359: M*/
360: #undef __FUNCT__  
362: int MeshSerializeRegister(const char sname[], const char path[], const char name[],
363:                           int (*function)(MPI_Comm, Mesh *, PetscViewer, PetscTruth))
364: {
365:   char fullname[256];
366:   int  ierr;

369:   PetscStrcpy(fullname, path);
370:   PetscStrcat(fullname, ":");
371:   PetscStrcat(fullname, name);
372:   PetscFListAdd(&MeshSerializeList, sname, fullname, (void (*)(void)) function);
373:   return(0);
374: }

376: /*MC
377:   MeshOrderingRegister - Adds an ordering method to the mesh package.

379:   Synopsis:

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

384:   Not Collective

386:   Input Parameters:
387: + order_name      - The name of a new user-defined serialization routine
388: . path            - The path (either absolute or relative) of the library containing this routine
389: . order_func_name - The name of routine to create method context
390: - order_func      - The serialization routine itself

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

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

397:   Sample usage:
398: .vb
399:   MeshOrderingRegister("my_order", /home/username/my_lib/lib/libO/solaris/mylib.a, "MyOrderFunc", MyOrderFunc);
400: .ve

402:   Then, your serialization can be chosen with the procedural interface via
403: $     MeshGetOrdering(mesh, "my_order", &ao)
404:   or at runtime via the option
405: $     -mesh_ordering_type my_order

407:   Level: advanced

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

411: .keywords: mesh, register
412: .seealso: MeshOrderingRegisterAll(), MeshOrderingRegisterDestroy()
413: M*/
414: #undef __FUNCT__  
416: int MeshOrderingRegister(const char sname[], const char path[], const char name[],
417:                          int (*function)(Mesh, MeshOrderingType, AO *))
418: {
419:   char fullname[256];
420:   int  ierr;

423:   PetscStrcpy(fullname, path);
424:   PetscStrcat(fullname, ":");
425:   PetscStrcat(fullname, name);
426:   PetscFListAdd(&MeshOrderingList, sname, fullname, (void (*)(void)) function);
427:   return(0);
428: }

430: /*-------------------------------------------------------------------------------------------------------------------*/
431: #undef __FUNCT__  
433: /*@C
434:   MeshRegisterDestroy - Frees the list of creation routines for
435:   meshes that were registered by MeshRegister().

437:   Not collective

439:   Level: advanced

441: .keywords: mesh, register, destroy
442: .seealso: MeshRegister(), MeshRegisterAll(), MeshSerializeRegisterDestroy()
443: @*/
444: int MeshRegisterDestroy()
445: {

449:   if (MeshList != PETSC_NULL) {
450:     PetscFListDestroy(&MeshList);
451:     MeshList = PETSC_NULL;
452:   }
453:   MeshRegisterAllCalled = PETSC_FALSE;
454:   return(0);
455: }

457: #undef __FUNCT__  
459: /*@C
460:   MeshSerializeRegisterDestroy - Frees the list of serialization routines for
461:   meshes that were registered by FListAdd().

463:   Not collective

465:   Level: advanced

467: .keywords: mesh, serialization, register, destroy
468: .seealso: MeshSerializeRegisterAll(), MeshRegisterDestroy()
469: @*/
470: int MeshSerializeRegisterDestroy()
471: {

475:   if (MeshSerializeList) {
476:     PetscFListDestroy(&MeshSerializeList);
477:     MeshSerializeList = PETSC_NULL;
478:   }
479:   MeshSerializeRegisterAllCalled = PETSC_FALSE;
480:   return(0);
481: }

483: #undef __FUNCT__  
485: /*@C
486:   MeshOrderingRegisterDestroy - Frees the list of ordering routines for
487:   meshes that were registered by MeshSerializeRegister().

489:   Not collective

491:   Level: advanced

493: .keywords: mesh, ordering, register, destroy
494: .seealso: MeshOrderingRegisterAll(), MeshRegisterDestroy()
495: @*/
496: int MeshOrderingRegisterDestroy()
497: {

501:   if (MeshOrderingList) {
502:     PetscFListDestroy(&MeshOrderingList);
503:     MeshOrderingList = PETSC_NULL;
504:   }
505:   MeshOrderingRegisterAllCalled = PETSC_FALSE;
506:   return(0);
507: }