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: /*@C
13: DiscretizationSetType - Sets the creation method for the disc.
15: Collective on Discretization
17: Input Parameters:
18: + disc - The Discretization context
19: - method - A known method
21: Options Database Command:
22: . -discretization_type <method> - Sets the method; use -help for a list
23: of available methods (for instance, tri2dlinear)
25: Notes:
26: See "petsc/include/discretization.h" for available methods (for instance)
27: . DISC_TRIANGULAR_2D_LINEAR - Triangular 2D linear discretization
29: Normally, it is best to use the DiscretizationSetFromOptions() command and
30: then set the Discretization type from the options database rather than by using
31: this routine. Using the options database provides the user with
32: maximum flexibility in evaluating the many different solvers.
33: The DiscretizationSetType() routine is provided for those situations
34: where it is necessary to set the application ordering independently of the
35: command line or options database. This might be the case, for example,
36: when the choice of solver changes during the execution of the
37: program, and the user's application is taking responsibility for
38: choosing the appropriate method. In other words, this routine is
39: not for beginners.
41: Level: intermediate
43: .keywords: Discretization, set, type
44: .seealso DiscretizationSetSerializeType()
45: @*/
46: int DiscretizationSetType(Discretization disc, DiscretizationType method) {
47: int (*r)(Discretization);
48: PetscTruth match;
49: int ierr;
53: PetscTypeCompare((PetscObject) disc, method, &match);
54: if (match == PETSC_TRUE) return(0);
56: /* Get the function pointers for the method requested */
57: if (DiscretizationRegisterAllCalled == PETSC_FALSE) {
58: DiscretizationRegisterAll(PETSC_NULL);
59: }
60: PetscFListFind(disc->comm, DiscretizationList, method, (void (**)(void)) &r);
61: if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown disc type: %s", method);
63: if (disc->ops->destroy != PETSC_NULL) {
64: (*disc->ops->destroy)(disc);
65: }
66: (*r)(disc);
68: PetscObjectChangeTypeName((PetscObject) disc, method);
69: return(0);
70: }
72: /*@C
73: DiscretizationGetType - Gets the Discretization method type name (as a string).
75: Not collective
77: Input Parameter:
78: . disc - The discretization
80: Output Parameter:
81: . type - The name of Discretization method
83: Level: intermediate
85: .keywords: Discretization, get, type, name
86: .seealso DiscretizationSetType()
87: @*/
88: int DiscretizationGetType(Discretization disc, DiscretizationType *type) {
94: if (DiscretizationRegisterAllCalled == PETSC_FALSE) {
95: DiscretizationRegisterAll(PETSC_NULL);
96: }
97: *type = disc->type_name;
98: return(0);
99: }
101: /*@C
102: DiscretizationSetSerializeType - Sets the serialization method for the disc.
104: Collective on Discretization
106: Input Parameters:
107: + disc - The Discretization context
108: - method - A known method
110: Options Database Command:
111: . -discretization_serialize_type <method> - Sets the method; use -help for a list
112: of available methods (for instance, tri2dlinear_binary)
114: Notes:
115: See "petsc/include/disc.h" for available methods (for instance)
116: . DISC_SER_TRIANGULAR_2D_LIENAR_BINARY - Triangular 2D linear discretization to binary file
118: Normally, it is best to use the DiscretizationSetFromOptions() command and
119: then set the Discretization type from the options database rather than by using
120: this routine. Using the options database provides the user with
121: maximum flexibility in evaluating the many different solvers.
122: The DiscretizationSetSerializeType() routine is provided for those situations
123: where it is necessary to set the application ordering independently of the
124: command line or options database. This might be the case, for example,
125: when the choice of solver changes during the execution of the
126: program, and the user's application is taking responsibility for
127: choosing the appropriate method. In other words, this routine is
128: not for beginners.
130: Level: intermediate
132: .keywords: Discretization, set, type, serialization
133: .seealso DiscretizationSetType()
134: @*/
135: int DiscretizationSetSerializeType(Discretization disc, DiscretizationSerializeType method) {
136: int (*r)(MPI_Comm, Discretization *, PetscViewer, PetscTruth);
137: PetscTruth match;
138: int ierr;
142: PetscSerializeCompare((PetscObject) disc, method, &match);
143: if (match == PETSC_TRUE) return(0);
145: /* Get the function pointers for the method requested but do not call */
146: if (DiscretizationSerializeRegisterAllCalled == PETSC_FALSE) {
147: DiscretizationSerializeRegisterAll(PETSC_NULL);
148: }
149: PetscFListFind(disc->comm, DiscretizationSerializeList, method, (void (**)(void)) &r);
150: if (!r) SETERRQ1(PETSC_ERR_ARG_WRONG, "Unknown discretization serialization type: %s", method);
152: PetscObjectChangeSerializeName((PetscObject) disc, method);
153: return(0);
154: }
156: /*@C
157: DiscretizationGetSerializeType - Gets the Discretization serialization method (as a string).
159: Not collective
161: Input Parameter:
162: . disc - The discretization
164: Output Parameter:
165: . type - The name of Discretization serialization method
167: Level: intermediate
169: .keywords: Discretization, get, serialize, type, name
170: .seealso DiscretizationSetType()
171: @*/
172: int DiscretizationGetSerializeType(Discretization disc, DiscretizationSerializeType *type) {
178: if (DiscretizationSerializeRegisterAllCalled == PETSC_FALSE) {
179: DiscretizationSerializeRegisterAll(PETSC_NULL);
180: }
181: *type = disc->serialize_name;
182: return(0);
183: }
185: /*--------------------------------------------------------------------------------------------------------------------*/
186: /*@C
187: DiscretizationRegister - Adds a creation method to the discretization package.
189: Synopsis:
191: DiscretizationRegister(char *name, char *path, char *func_name, int (*create_func)(Discretization))
193: Not Collective
195: Input Parameters:
196: + name - The name of a new user-defined creation routine
197: . path - The path (either absolute or relative) of the library containing this routine
198: . func_name - The name of the creation routine
199: - create_func - The creation routine itself
201: Notes:
202: DiscretizationRegister() may be called multiple times to add several user-defined disces.
204: If dynamic libraries are used, then the fourth input argument (create_func) is ignored.
206: Sample usage:
207: .vb
208: DiscretizationRegisterDynamic("my_disc", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyDiscretizationCreate", MyDiscretizationCreate);
209: .ve
211: Then, your disc type can be chosen with the procedural interface via
212: .vb
213: DiscretizationCreate(MPI_Comm, Discretization *);
214: DiscretizationSetType(vec, "my_disc")
215: .ve
216: or at runtime via the option
217: .vb
218: -discretization_type my_disc
219: .ve
221: Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
223: Level: advanced
225: .keywords: Discretizationretization, register
226: .seealso: DiscretizationRegisterAll(), DiscretizationRegisterDestroy()
227: @*/
228: int DiscretizationRegister(const char sname[], const char path[], const char name[], int (*function)(Discretization)) {
229: char fullname[256];
230: int ierr;
233: PetscStrcpy(fullname, path);
234: PetscStrcat(fullname, ":");
235: PetscStrcat(fullname, name);
236: PetscFListAdd(&DiscretizationList, sname, fullname, (void (*)(void)) function);
237: return(0);
238: }
240: /*@C
241: DiscretizationSerializeRegister - Adds a serialization method to the disc package.
243: Synopsis:
245: DiscretizationSerializeRegister(char *name, char *path, char *func_name,
246: int (*serialize_func)(MPI_Comm, Discretization *, PetscViewer, PetscTruth))
248: Not Collective
250: Input Parameters:
251: + name - The name of a new user-defined serialization routine
252: . path - The path (either absolute or relative) of the library containing this routine
253: . func_name - The name of the serialization routine
254: - serialize_func - The serialization routine itself
256: Notes:
257: DiscretizationSerializeRegister() may be called multiple times to add several user-defined serializers.
259: If dynamic libraries are used, then the fourth input argument (serialize_func) is ignored.
261: Sample usage:
262: .vb
263: DiscretizationSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
264: .ve
266: Then, your serialization can be chosen with the procedural interface via
267: .vb
268: DiscretizationSetSerializeType(disc, "my_store")
269: .ve
270: or at runtime via the option
271: .vb
272: -discretization_serialize_type my_store
273: .ve
275: Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
277: Level: advanced
279: .keywords: Discretization, register
280: .seealso: DiscretizationSerializeRegisterAll(), DiscretizationSerializeRegisterDestroy()
281: M*/
282: int DiscretizationSerializeRegister(const char sname[], const char path[], const char name[],
283: int (*function)(MPI_Comm, Discretization *, PetscViewer, PetscTruth))
284: {
285: char fullname[256];
286: int ierr;
289: PetscStrcpy(fullname, path);
290: PetscStrcat(fullname, ":");
291: PetscStrcat(fullname, name);
292: PetscFListAdd(&DiscretizationSerializeList, sname, fullname, (void (*)(void)) function);
293: return(0);
294: }
296: /*-------------------------------------------------------------------------------------------------------------------*/
297: /*@C
298: DiscretizationRegisterDestroy - Frees the list of creation routines for discretizations that were registered by
299: DiscretizationRegister().
301: Not collective
303: Level: advanced
305: .keywords: Discretization, register, destroy
306: .seealso: DiscretizationRegister(), DiscretizationRegisterAll(), DiscretizationSerializeRegisterDestroy()
307: @*/
308: int DiscretizationRegisterDestroy(void) {
312: if (DiscretizationList != PETSC_NULL) {
313: PetscFListDestroy(&DiscretizationList);
314: DiscretizationList = PETSC_NULL;
315: }
316: DiscretizationRegisterAllCalled = PETSC_FALSE;
317: return(0);
318: }
320: /*@C
321: DiscretizationSerializeRegisterDestroy - Frees the list of serialization routines for
322: discretizations that were registered by DiscretizationSerializeRegister().
324: Not collective
326: Level: advanced
328: .keywords: Discretization, serialization, register, destroy
329: .seealso: DiscretizationSerializeRegisterAll(), DiscretizationRegisterDestroy()
330: @*/
331: int DiscretizationSerializeRegisterDestroy() {
335: if (DiscretizationSerializeList != PETSC_NULL) {
336: PetscFListDestroy(&DiscretizationSerializeList);
337: DiscretizationSerializeList = PETSC_NULL;
338: }
339: DiscretizationSerializeRegisterAllCalled = PETSC_FALSE;
340: return(0);
341: }