xref: /petsc/src/ts/interface/tsreg.c (revision 97c4aaa0041b17e0788ef5380763993e79c96a23)
1 #define PETSCTS_DLL
2 
3 #include "private/tsimpl.h"      /*I "petscts.h"  I*/
4 
5 PetscFList TSList                       = PETSC_NULL;
6 PetscBool  TSRegisterAllCalled          = PETSC_FALSE;
7 
8 #undef __FUNCT__
9 #define __FUNCT__ "TSSetType"
10 /*@C
11   TSSetType - Sets the method for the timestepping solver.
12 
13   Collective on TS
14 
15   Input Parameters:
16 + ts   - The TS context
17 - type - A known method
18 
19   Options Database Command:
20 . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
21 
22    Notes:
23    See "petsc/include/petscts.h" for available methods (for instance)
24 +  TSEULER - Euler
25 .  TSSUNDIALS - SUNDIALS interface
26 .  TSBEULER - Backward Euler
27 -  TSPSEUDO - Pseudo-timestepping
28 
29    Normally, it is best to use the TSSetFromOptions() command and
30    then set the TS 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 TSSetType() routine is provided for those situations where it
34    is necessary to set the timestepping solver 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.
40 
41    Level: intermediate
42 
43 .keywords: TS, set, type
44 
45 @*/
46 PetscErrorCode PETSCTS_DLLEXPORT TSSetType(TS ts,const TSType type)
47 {
48   PetscErrorCode (*r)(TS);
49   PetscBool      match;
50   PetscErrorCode ierr;
51 
52   PetscFunctionBegin;
53   PetscValidHeaderSpecific(ts, TS_CLASSID,1);
54   ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
55   if (match) PetscFunctionReturn(0);
56 
57   ierr = PetscFListFind( TSList,((PetscObject)ts)->comm, type, (void (**)(void)) &r);CHKERRQ(ierr);
58   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
59   if (ts->ksp) {
60     ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);
61     ts->ksp = PETSC_NULL;
62   }
63   if (ts->snes) {
64     ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);
65     ts->snes = PETSC_NULL;
66   }
67   if (ts->ops->destroy) {
68     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
69   }
70   ierr = (*r)(ts);CHKERRQ(ierr);
71   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
72 #if defined(PETSC_HAVE_AMS)
73   if (PetscAMSPublishAll) {
74     ierr = PetscObjectAMSPublish((PetscObject)ts);CHKERRQ(ierr);
75   }
76 #endif
77   PetscFunctionReturn(0);
78 }
79 
80 #undef __FUNCT__
81 #define __FUNCT__ "TSGetType"
82 /*@C
83   TSGetType - Gets the TS method type (as a string).
84 
85   Not Collective
86 
87   Input Parameter:
88 . ts - The TS
89 
90   Output Parameter:
91 . type - The name of TS method
92 
93   Level: intermediate
94 
95 .keywords: TS, timestepper, get, type, name
96 .seealso TSSetType()
97 @*/
98 PetscErrorCode PETSCTS_DLLEXPORT TSGetType(TS ts, const TSType *type)
99 {
100   PetscFunctionBegin;
101   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
102   PetscValidPointer(type,2);
103   *type = ((PetscObject)ts)->type_name;
104   PetscFunctionReturn(0);
105 }
106 
107 /*--------------------------------------------------------------------------------------------------------------------*/
108 
109 #undef __FUNCT__
110 #define __FUNCT__ "TSRegister"
111 /*@C
112   TSRegister - See TSRegisterDynamic()
113 
114   Level: advanced
115 @*/
116 PetscErrorCode PETSCTS_DLLEXPORT TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
117 {
118   char           fullname[PETSC_MAX_PATH_LEN];
119   PetscErrorCode ierr;
120 
121   PetscFunctionBegin;
122   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
123   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
124   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
125   ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr);
126   PetscFunctionReturn(0);
127 }
128 
129 /*-------------------------------------------------------------------------------------------------------------------*/
130 #undef __FUNCT__
131 #define __FUNCT__ "TSRegisterDestroy"
132 /*@C
133    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
134 
135    Not Collective
136 
137    Level: advanced
138 
139 .keywords: TS, timestepper, register, destroy
140 .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
141 @*/
142 PetscErrorCode PETSCTS_DLLEXPORT TSRegisterDestroy(void)
143 {
144   PetscErrorCode ierr;
145 
146   PetscFunctionBegin;
147   ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr);
148   TSRegisterAllCalled = PETSC_FALSE;
149   PetscFunctionReturn(0);
150 }
151 
152