xref: /petsc/src/ts/interface/tsreg.c (revision bbd56ea5790821d2a217d362e8e9710702952333)
1b45d2f2cSJed Brown #include <petsc-private/tsimpl.h>      /*I "petscts.h"  I*/
23f3760d9SBarry Smith 
3140e18c1SBarry Smith PetscFunctionList TSList              = PETSC_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 
55140e18c1SBarry Smith   ierr = PetscFunctionListFind(((PetscObject)ts)->comm,TSList, type,PETSC_TRUE, (void (**)(void)) &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);
59*bbd56ea5SKarl Rupp 
60b5c23020SJed Brown     ts->ops->destroy = PETSC_NULL;
61bdad233fSMatthew Knepley   }
6279531b15SSean Farley   ierr = PetscMemzero(ts->ops,sizeof(*ts->ops));CHKERRQ(ierr);
63*bbd56ea5SKarl Rupp 
64277b19d0SLisandro Dalcin   ts->setupcalled = PETSC_FALSE;
65*bbd56ea5SKarl Rupp 
66bdad233fSMatthew Knepley   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
67d372ba47SLisandro Dalcin   ierr = (*r)(ts);CHKERRQ(ierr);
689fb22e1aSBarry Smith #if defined(PETSC_HAVE_AMS)
699fb22e1aSBarry Smith   if (PetscAMSPublishAll) {
709fb22e1aSBarry Smith     ierr = PetscObjectAMSPublish((PetscObject)ts);CHKERRQ(ierr);
719fb22e1aSBarry Smith   }
729fb22e1aSBarry Smith #endif
733a40ed3dSBarry Smith   PetscFunctionReturn(0);
743f3760d9SBarry Smith }
753f3760d9SBarry Smith 
764a2ae208SSatish Balay #undef __FUNCT__
774a2ae208SSatish Balay #define __FUNCT__ "TSGetType"
783f3760d9SBarry Smith /*@C
79fee21e36SBarry Smith   TSGetType - Gets the TS method type (as a string).
803f3760d9SBarry Smith 
81bef22f13SLois Curfman McInnes   Not Collective
82bef22f13SLois Curfman McInnes 
833f3760d9SBarry Smith   Input Parameter:
84bdad233fSMatthew Knepley . ts - The TS
853f3760d9SBarry Smith 
863f3760d9SBarry Smith   Output Parameter:
87bdad233fSMatthew Knepley . type - The name of TS method
883f3760d9SBarry Smith 
89d5d37b61SLois Curfman McInnes   Level: intermediate
90d5d37b61SLois Curfman McInnes 
91df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name
92bdad233fSMatthew Knepley .seealso TSSetType()
933f3760d9SBarry Smith @*/
9419fd82e9SBarry Smith PetscErrorCode  TSGetType(TS ts, TSType *type)
953f3760d9SBarry Smith {
963a40ed3dSBarry Smith   PetscFunctionBegin;
970700a824SBarry Smith   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
984482741eSBarry Smith   PetscValidPointer(type,2);
997adad957SLisandro Dalcin   *type = ((PetscObject)ts)->type_name;
1003a40ed3dSBarry Smith   PetscFunctionReturn(0);
1013f3760d9SBarry Smith }
1023f3760d9SBarry Smith 
103bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/
1043cea93caSBarry Smith 
105bdad233fSMatthew Knepley #undef __FUNCT__
106bdad233fSMatthew Knepley #define __FUNCT__ "TSRegister"
1073cea93caSBarry Smith /*@C
1083cea93caSBarry Smith   TSRegister - See TSRegisterDynamic()
1093cea93caSBarry Smith 
1107f6c08e0SMatthew Knepley   Level: advanced
1113cea93caSBarry Smith @*/
1127087cfbeSBarry Smith PetscErrorCode  TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
113bdad233fSMatthew Knepley {
114e2d1d2b7SBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
115dfbe8321SBarry Smith   PetscErrorCode ierr;
116bdad233fSMatthew Knepley 
117bdad233fSMatthew Knepley   PetscFunctionBegin;
118bdad233fSMatthew Knepley   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
119bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
120bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
121140e18c1SBarry Smith   ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&TSList, sname, fullname, (void (*)(void))function);CHKERRQ(ierr);
122bdad233fSMatthew Knepley   PetscFunctionReturn(0);
123bdad233fSMatthew Knepley }
124bdad233fSMatthew Knepley 
125bdad233fSMatthew Knepley /*-------------------------------------------------------------------------------------------------------------------*/
126bdad233fSMatthew Knepley #undef __FUNCT__
127bdad233fSMatthew Knepley #define __FUNCT__ "TSRegisterDestroy"
128bdad233fSMatthew Knepley /*@C
1293cea93caSBarry Smith    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
130bdad233fSMatthew Knepley 
131bdad233fSMatthew Knepley    Not Collective
132bdad233fSMatthew Knepley 
133bdad233fSMatthew Knepley    Level: advanced
134bdad233fSMatthew Knepley 
135bdad233fSMatthew Knepley .keywords: TS, timestepper, register, destroy
136437fc6d7SBarry Smith .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
137bdad233fSMatthew Knepley @*/
1387087cfbeSBarry Smith PetscErrorCode  TSRegisterDestroy(void)
139bdad233fSMatthew Knepley {
140dfbe8321SBarry Smith   PetscErrorCode ierr;
141bdad233fSMatthew Knepley 
142bdad233fSMatthew Knepley   PetscFunctionBegin;
143140e18c1SBarry Smith   ierr = PetscFunctionListDestroy(&TSList);CHKERRQ(ierr);
144bdad233fSMatthew Knepley   TSRegisterAllCalled = PETSC_FALSE;
145bdad233fSMatthew Knepley   PetscFunctionReturn(0);
146bdad233fSMatthew Knepley }
147