xref: /petsc/src/ts/interface/tsreg.c (revision 1c9cd33768b1fd01403e37595b64fe66efc857ab)
1b45d2f2cSJed Brown #include <petsc-private/tsimpl.h>      /*I "petscts.h"  I*/
23f3760d9SBarry Smith 
30298fd71SBarry Smith PetscFunctionList TSList              = NULL;
4ace3abfcSBarry Smith PetscBool         TSRegisterAllCalled = PETSC_FALSE;
53f3760d9SBarry Smith 
64a2ae208SSatish Balay #undef __FUNCT__
74a2ae208SSatish Balay #define __FUNCT__ "TSSetType"
882bf6240SBarry Smith /*@C
9ae12b187SLois Curfman McInnes   TSSetType - Sets the method for the timestepping solver.
103f3760d9SBarry Smith 
11fee21e36SBarry Smith   Collective on TS
12fee21e36SBarry Smith 
13bef22f13SLois Curfman McInnes   Input Parameters:
14bdad233fSMatthew Knepley + ts   - The TS context
15bdad233fSMatthew Knepley - type - A known method
16bef22f13SLois Curfman McInnes 
17ae12b187SLois Curfman McInnes   Options Database Command:
18bdad233fSMatthew Knepley . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
19ae12b187SLois Curfman McInnes 
203f3760d9SBarry Smith    Notes:
21e090d566SSatish Balay    See "petsc/include/petscts.h" for available methods (for instance)
229596e0b4SJed Brown +  TSEULER - Euler
239596e0b4SJed Brown .  TSSUNDIALS - SUNDIALS interface
249596e0b4SJed Brown .  TSBEULER - Backward Euler
259596e0b4SJed Brown -  TSPSEUDO - Pseudo-timestepping
263f3760d9SBarry Smith 
27ae12b187SLois Curfman McInnes    Normally, it is best to use the TSSetFromOptions() command and
28ae12b187SLois Curfman McInnes    then set the TS type from the options database rather than by using
29ae12b187SLois Curfman McInnes    this routine.  Using the options database provides the user with
30ae12b187SLois Curfman McInnes    maximum flexibility in evaluating the many different solvers.
31ae12b187SLois Curfman McInnes    The TSSetType() routine is provided for those situations where it
32ae12b187SLois Curfman McInnes    is necessary to set the timestepping solver independently of the
33ae12b187SLois Curfman McInnes    command line or options database.  This might be the case, for example,
34ae12b187SLois Curfman McInnes    when the choice of solver changes during the execution of the
35ae12b187SLois Curfman McInnes    program, and the user's application is taking responsibility for
36ae12b187SLois Curfman McInnes    choosing the appropriate method.  In other words, this routine is
37d5d37b61SLois Curfman McInnes    not for beginners.
38d5d37b61SLois Curfman McInnes 
39d5d37b61SLois Curfman McInnes    Level: intermediate
403f3760d9SBarry Smith 
41ae12b187SLois Curfman McInnes .keywords: TS, set, type
42437fc6d7SBarry Smith 
433f3760d9SBarry Smith @*/
4419fd82e9SBarry Smith PetscErrorCode  TSSetType(TS ts,TSType type)
453f3760d9SBarry Smith {
466849ba73SBarry Smith   PetscErrorCode (*r)(TS);
47ace3abfcSBarry Smith   PetscBool      match;
48dfbe8321SBarry Smith   PetscErrorCode ierr;
49df8cb225SBarry Smith 
503a40ed3dSBarry Smith   PetscFunctionBegin;
510700a824SBarry Smith   PetscValidHeaderSpecific(ts, TS_CLASSID,1);
52251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
53958c9bccSBarry Smith   if (match) PetscFunctionReturn(0);
54bdad233fSMatthew Knepley 
55*1c9cd337SJed Brown   ierr = PetscFunctionListFind(TSList,type,&r);CHKERRQ(ierr);
56e32f2f54SBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
57958c9bccSBarry Smith   if (ts->ops->destroy) {
58bdad233fSMatthew Knepley     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
59bbd56ea5SKarl Rupp 
600298fd71SBarry Smith     ts->ops->destroy = NULL;
61bdad233fSMatthew Knepley   }
6279531b15SSean Farley   ierr = PetscMemzero(ts->ops,sizeof(*ts->ops));CHKERRQ(ierr);
63bbd56ea5SKarl Rupp 
64277b19d0SLisandro Dalcin   ts->setupcalled = PETSC_FALSE;
65bbd56ea5SKarl Rupp 
66bdad233fSMatthew Knepley   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
67d372ba47SLisandro Dalcin   ierr = (*r)(ts);CHKERRQ(ierr);
683a40ed3dSBarry Smith   PetscFunctionReturn(0);
693f3760d9SBarry Smith }
703f3760d9SBarry Smith 
714a2ae208SSatish Balay #undef __FUNCT__
724a2ae208SSatish Balay #define __FUNCT__ "TSGetType"
733f3760d9SBarry Smith /*@C
74fee21e36SBarry Smith   TSGetType - Gets the TS method type (as a string).
753f3760d9SBarry Smith 
76bef22f13SLois Curfman McInnes   Not Collective
77bef22f13SLois Curfman McInnes 
783f3760d9SBarry Smith   Input Parameter:
79bdad233fSMatthew Knepley . ts - The TS
803f3760d9SBarry Smith 
813f3760d9SBarry Smith   Output Parameter:
82bdad233fSMatthew Knepley . type - The name of TS method
833f3760d9SBarry Smith 
84d5d37b61SLois Curfman McInnes   Level: intermediate
85d5d37b61SLois Curfman McInnes 
86df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name
87bdad233fSMatthew Knepley .seealso TSSetType()
883f3760d9SBarry Smith @*/
8919fd82e9SBarry Smith PetscErrorCode  TSGetType(TS ts, TSType *type)
903f3760d9SBarry Smith {
913a40ed3dSBarry Smith   PetscFunctionBegin;
920700a824SBarry Smith   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
934482741eSBarry Smith   PetscValidPointer(type,2);
947adad957SLisandro Dalcin   *type = ((PetscObject)ts)->type_name;
953a40ed3dSBarry Smith   PetscFunctionReturn(0);
963f3760d9SBarry Smith }
973f3760d9SBarry Smith 
98bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/
993cea93caSBarry Smith 
100bdad233fSMatthew Knepley #undef __FUNCT__
101bdad233fSMatthew Knepley #define __FUNCT__ "TSRegister"
1023cea93caSBarry Smith /*@C
1031c84c290SBarry Smith   TSRegister - Adds a creation method to the TS package.
1041c84c290SBarry Smith 
1051c84c290SBarry Smith   Not Collective
1061c84c290SBarry Smith 
1071c84c290SBarry Smith   Input Parameters:
1081c84c290SBarry Smith + name        - The name of a new user-defined creation routine
1091c84c290SBarry Smith - create_func - The creation routine itself
1101c84c290SBarry Smith 
1111c84c290SBarry Smith   Notes:
1121c84c290SBarry Smith   TSRegister() may be called multiple times to add several user-defined tses.
1131c84c290SBarry Smith 
1141c84c290SBarry Smith   Sample usage:
1151c84c290SBarry Smith .vb
116bdf89e91SBarry Smith   TSRegister("my_ts",  MyTSCreate);
1171c84c290SBarry Smith .ve
1181c84c290SBarry Smith 
1191c84c290SBarry Smith   Then, your ts type can be chosen with the procedural interface via
1201c84c290SBarry Smith .vb
1211c84c290SBarry Smith     TS ts;
1221c84c290SBarry Smith     TSCreate(MPI_Comm, &ts);
1231c84c290SBarry Smith     TSSetType(ts, "my_ts")
1241c84c290SBarry Smith .ve
1251c84c290SBarry Smith   or at runtime via the option
1261c84c290SBarry Smith .vb
1271c84c290SBarry Smith     -ts_type my_ts
1281c84c290SBarry Smith .ve
1293cea93caSBarry Smith 
1307f6c08e0SMatthew Knepley   Level: advanced
1311c84c290SBarry Smith 
1321c84c290SBarry Smith .keywords: TS, register
1331c84c290SBarry Smith 
1341c84c290SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy()
1353cea93caSBarry Smith @*/
136bdf89e91SBarry Smith PetscErrorCode  TSRegister(const char sname[], PetscErrorCode (*function)(TS))
137bdad233fSMatthew Knepley {
138dfbe8321SBarry Smith   PetscErrorCode ierr;
139bdad233fSMatthew Knepley 
140bdad233fSMatthew Knepley   PetscFunctionBegin;
141bdf89e91SBarry Smith   ierr = PetscFunctionListAdd(&TSList, sname, (void (*)(void))function);CHKERRQ(ierr);
142bdad233fSMatthew Knepley   PetscFunctionReturn(0);
143bdad233fSMatthew Knepley }
144bdad233fSMatthew Knepley 
145bdad233fSMatthew Knepley /*-------------------------------------------------------------------------------------------------------------------*/
146bdad233fSMatthew Knepley #undef __FUNCT__
147bdad233fSMatthew Knepley #define __FUNCT__ "TSRegisterDestroy"
148bdad233fSMatthew Knepley /*@C
149607a6623SBarry Smith    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()
150bdad233fSMatthew Knepley 
151bdad233fSMatthew Knepley    Not Collective
152bdad233fSMatthew Knepley 
153bdad233fSMatthew Knepley    Level: advanced
154bdad233fSMatthew Knepley 
155bdad233fSMatthew Knepley .keywords: TS, timestepper, register, destroy
156607a6623SBarry Smith .seealso: TSRegister(), TSRegisterAll()
157bdad233fSMatthew Knepley @*/
1587087cfbeSBarry Smith PetscErrorCode  TSRegisterDestroy(void)
159bdad233fSMatthew Knepley {
160dfbe8321SBarry Smith   PetscErrorCode ierr;
161bdad233fSMatthew Knepley 
162bdad233fSMatthew Knepley   PetscFunctionBegin;
163140e18c1SBarry Smith   ierr = PetscFunctionListDestroy(&TSList);CHKERRQ(ierr);
164bdad233fSMatthew Knepley   TSRegisterAllCalled = PETSC_FALSE;
165bdad233fSMatthew Knepley   PetscFunctionReturn(0);
166bdad233fSMatthew Knepley }
167