xref: /petsc/src/ts/interface/tsreg.c (revision 3c633725528e547aaaa9b672a746f5d686a276e1)
1af0996ceSBarry Smith #include <petsc/private/tsimpl.h>      /*I "petscts.h"  I*/
23f3760d9SBarry Smith 
30298fd71SBarry Smith PetscFunctionList TSList              = NULL;
4ace3abfcSBarry Smith PetscBool         TSRegisterAllCalled = PETSC_FALSE;
53f3760d9SBarry Smith 
682bf6240SBarry Smith /*@C
78f6c3df8SBarry Smith   TSSetType - Sets the method to be used as the timestepping solver.
83f3760d9SBarry Smith 
9fee21e36SBarry Smith   Collective on TS
10fee21e36SBarry Smith 
11bef22f13SLois Curfman McInnes   Input Parameters:
12bdad233fSMatthew Knepley + ts   - The TS context
13bdad233fSMatthew Knepley - type - A known method
14bef22f13SLois Curfman McInnes 
15ae12b187SLois Curfman McInnes   Options Database Command:
16bdad233fSMatthew Knepley . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
17ae12b187SLois Curfman McInnes 
183f3760d9SBarry Smith    Notes:
19e090d566SSatish Balay    See "petsc/include/petscts.h" for available methods (for instance)
209596e0b4SJed Brown +  TSEULER - Euler
219596e0b4SJed Brown .  TSSUNDIALS - SUNDIALS interface
229596e0b4SJed Brown .  TSBEULER - Backward Euler
239596e0b4SJed Brown -  TSPSEUDO - Pseudo-timestepping
243f3760d9SBarry Smith 
25ae12b187SLois Curfman McInnes    Normally, it is best to use the TSSetFromOptions() command and
26ae12b187SLois Curfman McInnes    then set the TS type from the options database rather than by using
27ae12b187SLois Curfman McInnes    this routine.  Using the options database provides the user with
28ae12b187SLois Curfman McInnes    maximum flexibility in evaluating the many different solvers.
29ae12b187SLois Curfman McInnes    The TSSetType() routine is provided for those situations where it
30ae12b187SLois Curfman McInnes    is necessary to set the timestepping solver independently of the
31ae12b187SLois Curfman McInnes    command line or options database.  This might be the case, for example,
32ae12b187SLois Curfman McInnes    when the choice of solver changes during the execution of the
33ae12b187SLois Curfman McInnes    program, and the user's application is taking responsibility for
34ae12b187SLois Curfman McInnes    choosing the appropriate method.  In other words, this routine is
35d5d37b61SLois Curfman McInnes    not for beginners.
36d5d37b61SLois Curfman McInnes 
37d5d37b61SLois Curfman McInnes    Level: intermediate
383f3760d9SBarry Smith 
398f6c3df8SBarry Smith .seealso: TS, TSSolve(), TSCreate(), TSSetFromOptions(), TSDestroy(), TSType
408f6c3df8SBarry Smith 
413f3760d9SBarry Smith @*/
4219fd82e9SBarry Smith PetscErrorCode  TSSetType(TS ts,TSType type)
433f3760d9SBarry Smith {
446849ba73SBarry Smith   PetscErrorCode (*r)(TS);
45ace3abfcSBarry Smith   PetscBool      match;
46dfbe8321SBarry Smith   PetscErrorCode ierr;
47df8cb225SBarry Smith 
483a40ed3dSBarry Smith   PetscFunctionBegin;
490700a824SBarry Smith   PetscValidHeaderSpecific(ts, TS_CLASSID,1);
50b92453a8SLisandro Dalcin   PetscValidCharPointer(type,2);
51251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
52958c9bccSBarry Smith   if (match) PetscFunctionReturn(0);
53bdad233fSMatthew Knepley 
541c9cd337SJed Brown   ierr = PetscFunctionListFind(TSList,type,&r);CHKERRQ(ierr);
55*3c633725SBarry Smith   PetscCheck(r,PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
56958c9bccSBarry Smith   if (ts->ops->destroy) {
57bdad233fSMatthew Knepley     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
58bdad233fSMatthew Knepley   }
5979531b15SSean Farley   ierr = PetscMemzero(ts->ops,sizeof(*ts->ops));CHKERRQ(ierr);
60825ab935SBarry Smith   ts->usessnes           = PETSC_FALSE;
61b92453a8SLisandro Dalcin   ts->default_adapt_type = TSADAPTNONE;
62bbd56ea5SKarl Rupp 
63277b19d0SLisandro Dalcin   ts->setupcalled = PETSC_FALSE;
64bbd56ea5SKarl Rupp 
65bdad233fSMatthew Knepley   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
66d372ba47SLisandro Dalcin   ierr = (*r)(ts);CHKERRQ(ierr);
673a40ed3dSBarry Smith   PetscFunctionReturn(0);
683f3760d9SBarry Smith }
693f3760d9SBarry Smith 
703f3760d9SBarry Smith /*@C
71fee21e36SBarry Smith   TSGetType - Gets the TS method type (as a string).
723f3760d9SBarry Smith 
73bef22f13SLois Curfman McInnes   Not Collective
74bef22f13SLois Curfman McInnes 
753f3760d9SBarry Smith   Input Parameter:
76bdad233fSMatthew Knepley . ts - The TS
773f3760d9SBarry Smith 
783f3760d9SBarry Smith   Output Parameter:
79bdad233fSMatthew Knepley . type - The name of TS method
803f3760d9SBarry Smith 
81d5d37b61SLois Curfman McInnes   Level: intermediate
82d5d37b61SLois Curfman McInnes 
83bdad233fSMatthew Knepley .seealso TSSetType()
843f3760d9SBarry Smith @*/
8519fd82e9SBarry Smith PetscErrorCode  TSGetType(TS ts, TSType *type)
863f3760d9SBarry Smith {
873a40ed3dSBarry Smith   PetscFunctionBegin;
880700a824SBarry Smith   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
894482741eSBarry Smith   PetscValidPointer(type,2);
907adad957SLisandro Dalcin   *type = ((PetscObject)ts)->type_name;
913a40ed3dSBarry Smith   PetscFunctionReturn(0);
923f3760d9SBarry Smith }
933f3760d9SBarry Smith 
94bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/
953cea93caSBarry Smith 
963cea93caSBarry Smith /*@C
971c84c290SBarry Smith   TSRegister - Adds a creation method to the TS package.
981c84c290SBarry Smith 
991c84c290SBarry Smith   Not Collective
1001c84c290SBarry Smith 
1011c84c290SBarry Smith   Input Parameters:
1021c84c290SBarry Smith + name        - The name of a new user-defined creation routine
1031c84c290SBarry Smith - create_func - The creation routine itself
1041c84c290SBarry Smith 
1051c84c290SBarry Smith   Notes:
1061c84c290SBarry Smith   TSRegister() may be called multiple times to add several user-defined tses.
1071c84c290SBarry Smith 
1081c84c290SBarry Smith   Sample usage:
1091c84c290SBarry Smith .vb
110bdf89e91SBarry Smith   TSRegister("my_ts",  MyTSCreate);
1111c84c290SBarry Smith .ve
1121c84c290SBarry Smith 
1131c84c290SBarry Smith   Then, your ts type can be chosen with the procedural interface via
1141c84c290SBarry Smith .vb
1151c84c290SBarry Smith     TS ts;
1161c84c290SBarry Smith     TSCreate(MPI_Comm, &ts);
1171c84c290SBarry Smith     TSSetType(ts, "my_ts")
1181c84c290SBarry Smith .ve
1191c84c290SBarry Smith   or at runtime via the option
1201c84c290SBarry Smith .vb
1211c84c290SBarry Smith     -ts_type my_ts
1221c84c290SBarry Smith .ve
1233cea93caSBarry Smith 
1247f6c08e0SMatthew Knepley   Level: advanced
1251c84c290SBarry Smith 
1261c84c290SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy()
1273cea93caSBarry Smith @*/
128bdf89e91SBarry Smith PetscErrorCode  TSRegister(const char sname[], PetscErrorCode (*function)(TS))
129bdad233fSMatthew Knepley {
130dfbe8321SBarry Smith   PetscErrorCode ierr;
131bdad233fSMatthew Knepley 
132bdad233fSMatthew Knepley   PetscFunctionBegin;
1331d36bdfdSBarry Smith   ierr = TSInitializePackage();CHKERRQ(ierr);
134a240a19fSJed Brown   ierr = PetscFunctionListAdd(&TSList,sname,function);CHKERRQ(ierr);
135bdad233fSMatthew Knepley   PetscFunctionReturn(0);
136bdad233fSMatthew Knepley }
137bdad233fSMatthew Knepley 
138