Actual source code: tsreg.c
1: #include <private/tsimpl.h> /*I "petscts.h" I*/
3: PetscFList TSList = PETSC_NULL;
4: PetscBool TSRegisterAllCalled = PETSC_FALSE;
8: /*@C
9: TSSetType - Sets the method for the timestepping solver.
11: Collective on TS
13: Input Parameters:
14: + ts - The TS context
15: - type - A known method
17: Options Database Command:
18: . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
20: Notes:
21: See "petsc/include/petscts.h" for available methods (for instance)
22: + TSEULER - Euler
23: . TSSUNDIALS - SUNDIALS interface
24: . TSBEULER - Backward Euler
25: - TSPSEUDO - Pseudo-timestepping
27: Normally, it is best to use the TSSetFromOptions() command and
28: then set the TS type from the options database rather than by using
29: this routine. Using the options database provides the user with
30: maximum flexibility in evaluating the many different solvers.
31: The TSSetType() routine is provided for those situations where it
32: is necessary to set the timestepping solver independently of the
33: command line or options database. This might be the case, for example,
34: when the choice of solver changes during the execution of the
35: program, and the user's application is taking responsibility for
36: choosing the appropriate method. In other words, this routine is
37: not for beginners.
39: Level: intermediate
41: .keywords: TS, set, type
43: @*/
44: PetscErrorCode TSSetType(TS ts,const TSType type)
45: {
46: PetscErrorCode (*r)(TS);
47: PetscBool match;
52: PetscTypeCompare((PetscObject) ts, type, &match);
53: if (match) return(0);
55: PetscFListFind( TSList,((PetscObject)ts)->comm, type,PETSC_TRUE, (void (**)(void)) &r);
56: if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
57: if (ts->ops->destroy) {
58: (*(ts)->ops->destroy)(ts);
59: }
60: PetscMemzero(ts->ops,sizeof(*ts->ops));
61: ts->setupcalled = PETSC_FALSE;
62: PetscObjectChangeTypeName((PetscObject)ts, type);
63: (*r)(ts);
64: #if defined(PETSC_HAVE_AMS)
65: if (PetscAMSPublishAll) {
66: PetscObjectAMSPublish((PetscObject)ts);
67: }
68: #endif
69: return(0);
70: }
74: /*@C
75: TSGetType - Gets the TS method type (as a string).
77: Not Collective
79: Input Parameter:
80: . ts - The TS
82: Output Parameter:
83: . type - The name of TS method
85: Level: intermediate
87: .keywords: TS, timestepper, get, type, name
88: .seealso TSSetType()
89: @*/
90: PetscErrorCode TSGetType(TS ts, const TSType *type)
91: {
95: *type = ((PetscObject)ts)->type_name;
96: return(0);
97: }
99: /*--------------------------------------------------------------------------------------------------------------------*/
103: /*@C
104: TSRegister - See TSRegisterDynamic()
106: Level: advanced
107: @*/
108: PetscErrorCode TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
109: {
110: char fullname[PETSC_MAX_PATH_LEN];
114: PetscStrcpy(fullname, path);
115: PetscStrcat(fullname, ":");
116: PetscStrcat(fullname, name);
117: PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);
118: return(0);
119: }
121: /*-------------------------------------------------------------------------------------------------------------------*/
124: /*@C
125: TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
127: Not Collective
129: Level: advanced
131: .keywords: TS, timestepper, register, destroy
132: .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
133: @*/
134: PetscErrorCode TSRegisterDestroy(void)
135: {
139: PetscFListDestroy(&TSList);
140: TSRegisterAllCalled = PETSC_FALSE;
141: return(0);
142: }