Actual source code: discreg.c

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

 5:  #include src/grid/discretization/discimpl.h

  7: PetscFList DiscretizationList                       = PETSC_NULL;
  8: PetscTruth DiscretizationRegisterAllCalled          = PETSC_FALSE;
  9: PetscFList DiscretizationSerializeList              = PETSC_NULL;
 10: PetscTruth DiscretizationSerializeRegisterAllCalled = PETSC_FALSE;

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

 17:   Collective on Discretization

 19:   Input Parameters:
 20: + disc   - The Discretization context
 21: - method - A known method

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

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

 31:   Normally, it is best to use the DiscretizationSetFromOptions() command and
 32:   then set the Discretization 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 DiscretizationSetType() 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: Discretization, set, type
 46: .seealso DiscretizationSetSerializeType()
 47: @*/
 48: int DiscretizationSetType(Discretization disc, DiscretizationType method) {
 49:   int      (*r)(Discretization);
 50:   PetscTruth match;
 51:   int        ierr;

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

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

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

 70:   PetscObjectChangeTypeName((PetscObject) disc, method);
 71:   return(0);
 72: }

 74: #undef __FUNCT__
 76: /*@C
 77:   DiscretizationGetType - Gets the Discretization method type name (as a string).

 79:   Not collective

 81:   Input Parameter:
 82: . disc - The discretization

 84:   Output Parameter:
 85: . type - The name of Discretization method

 87:   Level: intermediate

 89: .keywords: Discretization, get, type, name
 90: .seealso DiscretizationSetType()
 91: @*/
 92: int DiscretizationGetType(Discretization disc, DiscretizationType *type) {

 98:   if (DiscretizationRegisterAllCalled == PETSC_FALSE) {
 99:     DiscretizationRegisterAll(PETSC_NULL);
100:   }
101:   *type = disc->type_name;
102:   return(0);
103: }

105: #undef __FUNCT__  
107: /*@C
108:   DiscretizationSetSerializeType - Sets the serialization method for the disc.

110:   Collective on Discretization

112:   Input Parameters:
113: + disc   - The Discretization context
114: - method - A known method

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

120:   Notes:
121:   See "petsc/include/disc.h" for available methods (for instance)
122: . DISC_SER_TRIANGULAR_2D_LIENAR_BINARY - Triangular 2D linear discretization to binary file

124:   Normally, it is best to use the DiscretizationSetFromOptions() command and
125:   then set the Discretization 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 DiscretizationSetSerializeType() 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: Discretization, set, type, serialization
139: .seealso DiscretizationSetType()
140: @*/
141: int DiscretizationSetSerializeType(Discretization disc, DiscretizationSerializeType method) {
142:   int      (*r)(MPI_Comm, Discretization *, PetscViewer, PetscTruth);
143:   PetscTruth match;
144:   int        ierr;

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

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

158:   PetscObjectChangeSerializeName((PetscObject) disc, method);
159:   return(0);
160: }

162: #undef __FUNCT__
164: /*@C
165:   DiscretizationGetSerializeType - Gets the Discretization serialization method (as a string).

167:   Not collective

169:   Input Parameter:
170: . disc - The discretization

172:   Output Parameter:
173: . type - The name of Discretization serialization method

175:   Level: intermediate

177: .keywords: Discretization, get, serialize, type, name
178: .seealso DiscretizationSetType()
179: @*/
180: int DiscretizationGetSerializeType(Discretization disc, DiscretizationSerializeType *type) {

186:   if (DiscretizationSerializeRegisterAllCalled == PETSC_FALSE) {
187:     DiscretizationSerializeRegisterAll(PETSC_NULL);
188:   }
189:   *type = disc->serialize_name;
190:   return(0);
191: }

193: /*--------------------------------------------------------------------------------------------------------------------*/
194: /*@C
195:   DiscretizationRegister - Adds a creation method to the discretization package.

197:   Synopsis:

199:   DiscretizationRegister(char *name, char *path, char *func_name, int (*create_func)(Discretization))

201:   Not Collective

203:   Input Parameters:
204: + name        - The name of a new user-defined creation routine
205: . path        - The path (either absolute or relative) of the library containing this routine
206: . func_name   - The name of the creation routine
207: - create_func - The creation routine itself

209:   Notes:
210:   DiscretizationRegister() may be called multiple times to add several user-defined disces.

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

214:   Sample usage:
215: .vb
216:   DiscretizationRegisterDynamic("my_disc", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyDiscretizationCreate", MyDiscretizationCreate);
217: .ve

219:   Then, your disc type can be chosen with the procedural interface via
220: .vb
221:     DiscretizationCreate(MPI_Comm, Discretization *);
222:     DiscretizationSetType(vec, "my_disc")
223: .ve
224:   or at runtime via the option
225: .vb
226:     -discretization_type my_disc
227: .ve

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

231:   Level: advanced

233: .keywords: Discretizationretization, register
234: .seealso: DiscretizationRegisterAll(), DiscretizationRegisterDestroy()
235: @*/
236: #undef __FUNCT__  
238: int DiscretizationRegister(const char sname[], const char path[], const char name[], int (*function)(Discretization)) {
239:   char fullname[256];
240:   int  ierr;

243:   PetscStrcpy(fullname, path);
244:   PetscStrcat(fullname, ":");
245:   PetscStrcat(fullname, name);
246:   PetscFListAdd(&DiscretizationList, sname, fullname, (void (*)(void)) function);
247:   return(0);
248: }

250: /*@C
251:   DiscretizationSerializeRegister - Adds a serialization method to the disc package.

253:   Synopsis:

255:   DiscretizationSerializeRegister(char *name, char *path, char *func_name,
256:                         int (*serialize_func)(MPI_Comm, Discretization *, PetscViewer, PetscTruth))

258:   Not Collective

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

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

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

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

276:   Then, your serialization can be chosen with the procedural interface via
277: .vb
278:     DiscretizationSetSerializeType(disc, "my_store")
279: .ve
280:   or at runtime via the option
281: .vb
282:     -discretization_serialize_type my_store
283: .ve

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

287:   Level: advanced

289: .keywords: Discretization, register
290: .seealso: DiscretizationSerializeRegisterAll(), DiscretizationSerializeRegisterDestroy()
291: M*/
292: #undef __FUNCT__  
294: int DiscretizationSerializeRegister(const char sname[], const char path[], const char name[],
295:                                     int (*function)(MPI_Comm, Discretization *, PetscViewer, PetscTruth))
296: {
297:   char fullname[256];
298:   int  ierr;

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

308: /*-------------------------------------------------------------------------------------------------------------------*/
309: #undef __FUNCT__  
311: /*@C
312:   DiscretizationRegisterDestroy - Frees the list of creation routines for discretizations that were registered by
313:   DiscretizationRegister().

315:   Not collective

317:   Level: advanced

319: .keywords: Discretization, register, destroy
320: .seealso: DiscretizationRegister(), DiscretizationRegisterAll(), DiscretizationSerializeRegisterDestroy()
321: @*/
322: int DiscretizationRegisterDestroy(void) {

326:   if (DiscretizationList != PETSC_NULL) {
327:     PetscFListDestroy(&DiscretizationList);
328:     DiscretizationList = PETSC_NULL;
329:   }
330:   DiscretizationRegisterAllCalled = PETSC_FALSE;
331:   return(0);
332: }

334: #undef __FUNCT__  
336: /*@C
337:   DiscretizationSerializeRegisterDestroy - Frees the list of serialization routines for
338:   discretizations that were registered by DiscretizationSerializeRegister().

340:   Not collective

342:   Level: advanced

344: .keywords: Discretization, serialization, register, destroy
345: .seealso: DiscretizationSerializeRegisterAll(), DiscretizationRegisterDestroy()
346: @*/
347: int DiscretizationSerializeRegisterDestroy() {

351:   if (DiscretizationSerializeList != PETSC_NULL) {
352:     PetscFListDestroy(&DiscretizationSerializeList);
353:     DiscretizationSerializeList = PETSC_NULL;
354:   }
355:   DiscretizationSerializeRegisterAllCalled = PETSC_FALSE;
356:   return(0);
357: }