xref: /petsc/src/ts/interface/tsreg.c (revision 6bf464f92cc51e6fd6163850774a6badb2f63b6b)
13f3760d9SBarry Smith 
2c6db04a5SJed Brown #include <private/tsimpl.h>      /*I "petscts.h"  I*/
33f3760d9SBarry Smith 
4bdad233fSMatthew Knepley PetscFList TSList                       = PETSC_NULL;
5ace3abfcSBarry Smith PetscBool  TSRegisterAllCalled          = PETSC_FALSE;
63f3760d9SBarry Smith 
74a2ae208SSatish Balay #undef __FUNCT__
84a2ae208SSatish Balay #define __FUNCT__ "TSSetType"
982bf6240SBarry Smith /*@C
10ae12b187SLois Curfman McInnes   TSSetType - Sets the method for the timestepping solver.
113f3760d9SBarry Smith 
12fee21e36SBarry Smith   Collective on TS
13fee21e36SBarry Smith 
14bef22f13SLois Curfman McInnes   Input Parameters:
15bdad233fSMatthew Knepley + ts   - The TS context
16bdad233fSMatthew Knepley - type - A known method
17bef22f13SLois Curfman McInnes 
18ae12b187SLois Curfman McInnes   Options Database Command:
19bdad233fSMatthew Knepley . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
20ae12b187SLois Curfman McInnes 
213f3760d9SBarry Smith    Notes:
22e090d566SSatish Balay    See "petsc/include/petscts.h" for available methods (for instance)
239596e0b4SJed Brown +  TSEULER - Euler
249596e0b4SJed Brown .  TSSUNDIALS - SUNDIALS interface
259596e0b4SJed Brown .  TSBEULER - Backward Euler
269596e0b4SJed Brown -  TSPSEUDO - Pseudo-timestepping
273f3760d9SBarry Smith 
28ae12b187SLois Curfman McInnes    Normally, it is best to use the TSSetFromOptions() command and
29ae12b187SLois Curfman McInnes    then set the TS type from the options database rather than by using
30ae12b187SLois Curfman McInnes    this routine.  Using the options database provides the user with
31ae12b187SLois Curfman McInnes    maximum flexibility in evaluating the many different solvers.
32ae12b187SLois Curfman McInnes    The TSSetType() routine is provided for those situations where it
33ae12b187SLois Curfman McInnes    is necessary to set the timestepping solver independently of the
34ae12b187SLois Curfman McInnes    command line or options database.  This might be the case, for example,
35ae12b187SLois Curfman McInnes    when the choice of solver changes during the execution of the
36ae12b187SLois Curfman McInnes    program, and the user's application is taking responsibility for
37ae12b187SLois Curfman McInnes    choosing the appropriate method.  In other words, this routine is
38d5d37b61SLois Curfman McInnes    not for beginners.
39d5d37b61SLois Curfman McInnes 
40d5d37b61SLois Curfman McInnes    Level: intermediate
413f3760d9SBarry Smith 
42ae12b187SLois Curfman McInnes .keywords: TS, set, type
43437fc6d7SBarry Smith 
443f3760d9SBarry Smith @*/
457087cfbeSBarry Smith PetscErrorCode  TSSetType(TS ts,const TSType type)
463f3760d9SBarry Smith {
476849ba73SBarry Smith   PetscErrorCode (*r)(TS);
48ace3abfcSBarry Smith   PetscBool      match;
49dfbe8321SBarry Smith   PetscErrorCode ierr;
50df8cb225SBarry Smith 
513a40ed3dSBarry Smith   PetscFunctionBegin;
520700a824SBarry Smith   PetscValidHeaderSpecific(ts, TS_CLASSID,1);
53bdad233fSMatthew Knepley   ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
54958c9bccSBarry Smith   if (match) PetscFunctionReturn(0);
55bdad233fSMatthew Knepley 
564b91b6eaSBarry Smith   ierr = PetscFListFind( TSList,((PetscObject)ts)->comm, type,PETSC_TRUE, (void (**)(void)) &r);CHKERRQ(ierr);
57e32f2f54SBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
58*6bf464f9SBarry Smith   ierr = KSPDestroy(&ts->ksp);CHKERRQ(ierr);
59*6bf464f9SBarry Smith   ierr = SNESDestroy(&ts->snes);CHKERRQ(ierr);
60958c9bccSBarry Smith   if (ts->ops->destroy) {
61bdad233fSMatthew Knepley     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
62bdad233fSMatthew Knepley   }
63277b19d0SLisandro Dalcin   ts->setupcalled = PETSC_FALSE;
64bdad233fSMatthew Knepley   ierr = (*r)(ts);CHKERRQ(ierr);
65bdad233fSMatthew Knepley   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
669fb22e1aSBarry Smith #if defined(PETSC_HAVE_AMS)
679fb22e1aSBarry Smith   if (PetscAMSPublishAll) {
689fb22e1aSBarry Smith     ierr = PetscObjectAMSPublish((PetscObject)ts);CHKERRQ(ierr);
699fb22e1aSBarry Smith   }
709fb22e1aSBarry Smith #endif
713a40ed3dSBarry Smith   PetscFunctionReturn(0);
723f3760d9SBarry Smith }
733f3760d9SBarry Smith 
744a2ae208SSatish Balay #undef __FUNCT__
754a2ae208SSatish Balay #define __FUNCT__ "TSGetType"
763f3760d9SBarry Smith /*@C
77fee21e36SBarry Smith   TSGetType - Gets the TS method type (as a string).
783f3760d9SBarry Smith 
79bef22f13SLois Curfman McInnes   Not Collective
80bef22f13SLois Curfman McInnes 
813f3760d9SBarry Smith   Input Parameter:
82bdad233fSMatthew Knepley . ts - The TS
833f3760d9SBarry Smith 
843f3760d9SBarry Smith   Output Parameter:
85bdad233fSMatthew Knepley . type - The name of TS method
863f3760d9SBarry Smith 
87d5d37b61SLois Curfman McInnes   Level: intermediate
88d5d37b61SLois Curfman McInnes 
89df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name
90bdad233fSMatthew Knepley .seealso TSSetType()
913f3760d9SBarry Smith @*/
927087cfbeSBarry Smith PetscErrorCode  TSGetType(TS ts, const TSType *type)
933f3760d9SBarry Smith {
943a40ed3dSBarry Smith   PetscFunctionBegin;
950700a824SBarry Smith   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
964482741eSBarry Smith   PetscValidPointer(type,2);
977adad957SLisandro Dalcin   *type = ((PetscObject)ts)->type_name;
983a40ed3dSBarry Smith   PetscFunctionReturn(0);
993f3760d9SBarry Smith }
1003f3760d9SBarry Smith 
101bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/
1023cea93caSBarry Smith 
103bdad233fSMatthew Knepley #undef __FUNCT__
104bdad233fSMatthew Knepley #define __FUNCT__ "TSRegister"
1053cea93caSBarry Smith /*@C
1063cea93caSBarry Smith   TSRegister - See TSRegisterDynamic()
1073cea93caSBarry Smith 
1087f6c08e0SMatthew Knepley   Level: advanced
1093cea93caSBarry Smith @*/
1107087cfbeSBarry Smith PetscErrorCode  TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
111bdad233fSMatthew Knepley {
112e2d1d2b7SBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
113dfbe8321SBarry Smith   PetscErrorCode ierr;
114bdad233fSMatthew Knepley 
115bdad233fSMatthew Knepley   PetscFunctionBegin;
116bdad233fSMatthew Knepley   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
117bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
118bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
119bdad233fSMatthew Knepley   ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr);
120bdad233fSMatthew Knepley   PetscFunctionReturn(0);
121bdad233fSMatthew Knepley }
122bdad233fSMatthew Knepley 
123bdad233fSMatthew Knepley /*-------------------------------------------------------------------------------------------------------------------*/
124bdad233fSMatthew Knepley #undef __FUNCT__
125bdad233fSMatthew Knepley #define __FUNCT__ "TSRegisterDestroy"
126bdad233fSMatthew Knepley /*@C
1273cea93caSBarry Smith    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
128bdad233fSMatthew Knepley 
129bdad233fSMatthew Knepley    Not Collective
130bdad233fSMatthew Knepley 
131bdad233fSMatthew Knepley    Level: advanced
132bdad233fSMatthew Knepley 
133bdad233fSMatthew Knepley .keywords: TS, timestepper, register, destroy
134437fc6d7SBarry Smith .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
135bdad233fSMatthew Knepley @*/
1367087cfbeSBarry Smith PetscErrorCode  TSRegisterDestroy(void)
137bdad233fSMatthew Knepley {
138dfbe8321SBarry Smith   PetscErrorCode ierr;
139bdad233fSMatthew Knepley 
140bdad233fSMatthew Knepley   PetscFunctionBegin;
1411441b1d3SBarry Smith   ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr);
142bdad233fSMatthew Knepley   TSRegisterAllCalled = PETSC_FALSE;
143bdad233fSMatthew Knepley   PetscFunctionReturn(0);
144bdad233fSMatthew Knepley }
145bdad233fSMatthew Knepley 
146