Actual source code: tsreg.c
2: #include src/ts/tsimpl.h
4: PetscFList TSList = PETSC_NULL;
5: PetscTruth TSRegisterAllCalled = PETSC_FALSE;
9: /*@C
10: TSSetType - Sets the method for the timestepping solver.
12: Collective on TS
14: Input Parameters:
15: + ts - The TS context
16: - type - A known method
18: Options Database Command:
19: . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
21: Notes:
22: See "petsc/include/petscts.h" for available methods (for instance)
23: + TS_EULER - Euler
24: . TS_PVODE - PVODE interface
25: . TS_BEULER - Backward Euler
26: - TS_PSEUDO - Pseudo-timestepping
28: Normally, it is best to use the TSSetFromOptions() command and
29: then set the TS type from the options database rather than by using
30: this routine. Using the options database provides the user with
31: maximum flexibility in evaluating the many different solvers.
32: The TSSetType() routine is provided for those situations where it
33: is necessary to set the timestepping solver independently of the
34: command line or options database. This might be the case, for example,
35: when the choice of solver changes during the execution of the
36: program, and the user's application is taking responsibility for
37: choosing the appropriate method. In other words, this routine is
38: not for beginners.
40: Level: intermediate
42: .keywords: TS, set, type
44: @*/
45: PetscErrorCode TSSetType(TS ts, const TSType type)
46: {
47: PetscErrorCode (*r)(TS);
48: PetscTruth match;
53: PetscTypeCompare((PetscObject) ts, type, &match);
54: if (match) return(0);
56: /* Get the function pointers for the method requested */
57: if (TSRegisterAllCalled == PETSC_FALSE) {
58: TSRegisterAll(PETSC_NULL);
59: }
60: PetscFListFind(ts->comm, TSList, type, (void (**)(void)) &r);
61: if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
62: if (ts->ksp) {
63: KSPDestroy(ts->ksp);
64: ts->ksp = PETSC_NULL;
65: }
66: if (ts->snes) {
67: SNESDestroy(ts->snes);
68: ts->snes = PETSC_NULL;
69: }
70: if (ts->ops->destroy) {
71: (*(ts)->ops->destroy)(ts);
72: }
73: (*r)(ts);
74: PetscObjectChangeTypeName((PetscObject)ts, type);
75: return(0);
76: }
80: /*@C
81: TSGetType - Gets the TS method type (as a string).
83: Not Collective
85: Input Parameter:
86: . ts - The TS
88: Output Parameter:
89: . type - The name of TS method
91: Level: intermediate
93: .keywords: TS, timestepper, get, type, name
94: .seealso TSSetType()
95: @*/
96: PetscErrorCode TSGetType(TS ts, TSType *type)
97: {
103: if (TSRegisterAllCalled == PETSC_FALSE) {
104: TSRegisterAll(PETSC_NULL);
105: }
106: *type = ts->type_name;
107: return(0);
108: }
110: /*--------------------------------------------------------------------------------------------------------------------*/
114: /*@C
115: TSRegister - See TSRegisterDynamic()
117: Level: advanced
118: @*/
119: PetscErrorCode TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
120: {
121: char fullname[PETSC_MAX_PATH_LEN];
125: PetscStrcpy(fullname, path);
126: PetscStrcat(fullname, ":");
127: PetscStrcat(fullname, name);
128: PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);
129: return(0);
130: }
132: /*-------------------------------------------------------------------------------------------------------------------*/
135: /*@C
136: TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
138: Not Collective
140: Level: advanced
142: .keywords: TS, timestepper, register, destroy
143: .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
144: @*/
145: PetscErrorCode TSRegisterDestroy(void)
146: {
150: if (TSList != PETSC_NULL) {
151: PetscFListDestroy(&TSList);
152: TSList = PETSC_NULL;
153: }
154: TSRegisterAllCalled = PETSC_FALSE;
155: return(0);
156: }