xref: /petsc/src/ts/interface/tsreg.c (revision d372ba47371068bdce79d7d3cf159aa0df7e4cba)
1c6db04a5SJed Brown #include <private/tsimpl.h>      /*I "petscts.h"  I*/
23f3760d9SBarry Smith 
3bdad233fSMatthew Knepley PetscFList 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 @*/
447087cfbeSBarry Smith PetscErrorCode  TSSetType(TS ts,const 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);
52bdad233fSMatthew Knepley   ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
53958c9bccSBarry Smith   if (match) PetscFunctionReturn(0);
54bdad233fSMatthew Knepley 
554b91b6eaSBarry Smith   ierr = PetscFListFind( TSList,((PetscObject)ts)->comm, 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);
576bf464f9SBarry Smith   ierr = KSPDestroy(&ts->ksp);CHKERRQ(ierr);
586bf464f9SBarry Smith   ierr = SNESDestroy(&ts->snes);CHKERRQ(ierr);
59958c9bccSBarry Smith   if (ts->ops->destroy) {
60bdad233fSMatthew Knepley     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
61bdad233fSMatthew Knepley   }
62277b19d0SLisandro Dalcin   ts->setupcalled = PETSC_FALSE;
63bdad233fSMatthew Knepley   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
64*d372ba47SLisandro Dalcin   ierr = (*r)(ts);CHKERRQ(ierr);
659fb22e1aSBarry Smith #if defined(PETSC_HAVE_AMS)
669fb22e1aSBarry Smith   if (PetscAMSPublishAll) {
679fb22e1aSBarry Smith     ierr = PetscObjectAMSPublish((PetscObject)ts);CHKERRQ(ierr);
689fb22e1aSBarry Smith   }
699fb22e1aSBarry Smith #endif
703a40ed3dSBarry Smith   PetscFunctionReturn(0);
713f3760d9SBarry Smith }
723f3760d9SBarry Smith 
734a2ae208SSatish Balay #undef __FUNCT__
744a2ae208SSatish Balay #define __FUNCT__ "TSGetType"
753f3760d9SBarry Smith /*@C
76fee21e36SBarry Smith   TSGetType - Gets the TS method type (as a string).
773f3760d9SBarry Smith 
78bef22f13SLois Curfman McInnes   Not Collective
79bef22f13SLois Curfman McInnes 
803f3760d9SBarry Smith   Input Parameter:
81bdad233fSMatthew Knepley . ts - The TS
823f3760d9SBarry Smith 
833f3760d9SBarry Smith   Output Parameter:
84bdad233fSMatthew Knepley . type - The name of TS method
853f3760d9SBarry Smith 
86d5d37b61SLois Curfman McInnes   Level: intermediate
87d5d37b61SLois Curfman McInnes 
88df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name
89bdad233fSMatthew Knepley .seealso TSSetType()
903f3760d9SBarry Smith @*/
917087cfbeSBarry Smith PetscErrorCode  TSGetType(TS ts, const TSType *type)
923f3760d9SBarry Smith {
933a40ed3dSBarry Smith   PetscFunctionBegin;
940700a824SBarry Smith   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
954482741eSBarry Smith   PetscValidPointer(type,2);
967adad957SLisandro Dalcin   *type = ((PetscObject)ts)->type_name;
973a40ed3dSBarry Smith   PetscFunctionReturn(0);
983f3760d9SBarry Smith }
993f3760d9SBarry Smith 
100bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/
1013cea93caSBarry Smith 
102bdad233fSMatthew Knepley #undef __FUNCT__
103bdad233fSMatthew Knepley #define __FUNCT__ "TSRegister"
1043cea93caSBarry Smith /*@C
1053cea93caSBarry Smith   TSRegister - See TSRegisterDynamic()
1063cea93caSBarry Smith 
1077f6c08e0SMatthew Knepley   Level: advanced
1083cea93caSBarry Smith @*/
1097087cfbeSBarry Smith PetscErrorCode  TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
110bdad233fSMatthew Knepley {
111e2d1d2b7SBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
112dfbe8321SBarry Smith   PetscErrorCode ierr;
113bdad233fSMatthew Knepley 
114bdad233fSMatthew Knepley   PetscFunctionBegin;
115bdad233fSMatthew Knepley   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
116bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
117bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
118bdad233fSMatthew Knepley   ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr);
119bdad233fSMatthew Knepley   PetscFunctionReturn(0);
120bdad233fSMatthew Knepley }
121bdad233fSMatthew Knepley 
122bdad233fSMatthew Knepley /*-------------------------------------------------------------------------------------------------------------------*/
123bdad233fSMatthew Knepley #undef __FUNCT__
124bdad233fSMatthew Knepley #define __FUNCT__ "TSRegisterDestroy"
125bdad233fSMatthew Knepley /*@C
1263cea93caSBarry Smith    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
127bdad233fSMatthew Knepley 
128bdad233fSMatthew Knepley    Not Collective
129bdad233fSMatthew Knepley 
130bdad233fSMatthew Knepley    Level: advanced
131bdad233fSMatthew Knepley 
132bdad233fSMatthew Knepley .keywords: TS, timestepper, register, destroy
133437fc6d7SBarry Smith .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
134bdad233fSMatthew Knepley @*/
1357087cfbeSBarry Smith PetscErrorCode  TSRegisterDestroy(void)
136bdad233fSMatthew Knepley {
137dfbe8321SBarry Smith   PetscErrorCode ierr;
138bdad233fSMatthew Knepley 
139bdad233fSMatthew Knepley   PetscFunctionBegin;
1401441b1d3SBarry Smith   ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr);
141bdad233fSMatthew Knepley   TSRegisterAllCalled = PETSC_FALSE;
142bdad233fSMatthew Knepley   PetscFunctionReturn(0);
143bdad233fSMatthew Knepley }
144