xref: /petsc/src/ts/interface/tsreg.c (revision 7c4f633dc6bb6149cca88d301ead35a99e103cbb)
163dd3a1aSKris Buschelman #define PETSCTS_DLL
23f3760d9SBarry Smith 
3*7c4f633dSBarry Smith #include "private/tsimpl.h"      /*I "petscts.h"  I*/
43f3760d9SBarry Smith 
5bdad233fSMatthew Knepley PetscFList TSList                       = PETSC_NULL;
64c49b128SBarry Smith PetscTruth TSRegisterAllCalled          = PETSC_FALSE;
73f3760d9SBarry Smith 
84a2ae208SSatish Balay #undef __FUNCT__
94a2ae208SSatish Balay #define __FUNCT__ "TSSetType"
1082bf6240SBarry Smith /*@C
11ae12b187SLois Curfman McInnes   TSSetType - Sets the method for the timestepping solver.
123f3760d9SBarry Smith 
13fee21e36SBarry Smith   Collective on TS
14fee21e36SBarry Smith 
15bef22f13SLois Curfman McInnes   Input Parameters:
16bdad233fSMatthew Knepley + ts   - The TS context
17bdad233fSMatthew Knepley - type - A known method
18bef22f13SLois Curfman McInnes 
19ae12b187SLois Curfman McInnes   Options Database Command:
20bdad233fSMatthew Knepley . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
21ae12b187SLois Curfman McInnes 
223f3760d9SBarry Smith    Notes:
23e090d566SSatish Balay    See "petsc/include/petscts.h" for available methods (for instance)
24d5d37b61SLois Curfman McInnes +  TS_EULER - Euler
250f3b3ca1SHong Zhang .  TS_SUNDIALS - SUNDIALS interface
26bef22f13SLois Curfman McInnes .  TS_BEULER - Backward Euler
27d5d37b61SLois Curfman McInnes -  TS_PSEUDO - Pseudo-timestepping
283f3760d9SBarry Smith 
29ae12b187SLois Curfman McInnes    Normally, it is best to use the TSSetFromOptions() command and
30ae12b187SLois Curfman McInnes    then set the TS type from the options database rather than by using
31ae12b187SLois Curfman McInnes    this routine.  Using the options database provides the user with
32ae12b187SLois Curfman McInnes    maximum flexibility in evaluating the many different solvers.
33ae12b187SLois Curfman McInnes    The TSSetType() routine is provided for those situations where it
34ae12b187SLois Curfman McInnes    is necessary to set the timestepping solver independently of the
35ae12b187SLois Curfman McInnes    command line or options database.  This might be the case, for example,
36ae12b187SLois Curfman McInnes    when the choice of solver changes during the execution of the
37ae12b187SLois Curfman McInnes    program, and the user's application is taking responsibility for
38ae12b187SLois Curfman McInnes    choosing the appropriate method.  In other words, this routine is
39d5d37b61SLois Curfman McInnes    not for beginners.
40d5d37b61SLois Curfman McInnes 
41d5d37b61SLois Curfman McInnes    Level: intermediate
423f3760d9SBarry Smith 
43ae12b187SLois Curfman McInnes .keywords: TS, set, type
44437fc6d7SBarry Smith 
453f3760d9SBarry Smith @*/
46a313700dSBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSSetType(TS ts,const TSType type)
473f3760d9SBarry Smith {
486849ba73SBarry Smith   PetscErrorCode (*r)(TS);
496831982aSBarry Smith   PetscTruth     match;
50dfbe8321SBarry Smith   PetscErrorCode ierr;
51df8cb225SBarry Smith 
523a40ed3dSBarry Smith   PetscFunctionBegin;
534482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
54bdad233fSMatthew Knepley   ierr = PetscTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
55958c9bccSBarry Smith   if (match) PetscFunctionReturn(0);
56bdad233fSMatthew Knepley 
577adad957SLisandro Dalcin   ierr = PetscFListFind( TSList,((PetscObject)ts)->comm, type, (void (**)(void)) &r);CHKERRQ(ierr);
58958c9bccSBarry Smith   if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
59958c9bccSBarry Smith   if (ts->ksp) {
6094b7f48cSBarry Smith     ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);
6194b7f48cSBarry Smith     ts->ksp = PETSC_NULL;
62bdad233fSMatthew Knepley   }
63958c9bccSBarry Smith   if (ts->snes) {
64bdad233fSMatthew Knepley     ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);
65bdad233fSMatthew Knepley     ts->snes = PETSC_NULL;
66bdad233fSMatthew Knepley   }
67958c9bccSBarry Smith   if (ts->ops->destroy) {
68bdad233fSMatthew Knepley     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
69bdad233fSMatthew Knepley   }
70bdad233fSMatthew Knepley   ierr = (*r)(ts);CHKERRQ(ierr);
71bdad233fSMatthew Knepley   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
723a40ed3dSBarry Smith   PetscFunctionReturn(0);
733f3760d9SBarry Smith }
743f3760d9SBarry Smith 
754a2ae208SSatish Balay #undef __FUNCT__
764a2ae208SSatish Balay #define __FUNCT__ "TSGetType"
773f3760d9SBarry Smith /*@C
78fee21e36SBarry Smith   TSGetType - Gets the TS method type (as a string).
793f3760d9SBarry Smith 
80bef22f13SLois Curfman McInnes   Not Collective
81bef22f13SLois Curfman McInnes 
823f3760d9SBarry Smith   Input Parameter:
83bdad233fSMatthew Knepley . ts - The TS
843f3760d9SBarry Smith 
853f3760d9SBarry Smith   Output Parameter:
86bdad233fSMatthew Knepley . type - The name of TS method
873f3760d9SBarry Smith 
88d5d37b61SLois Curfman McInnes   Level: intermediate
89d5d37b61SLois Curfman McInnes 
90df8cb225SBarry Smith .keywords: TS, timestepper, get, type, name
91bdad233fSMatthew Knepley .seealso TSSetType()
923f3760d9SBarry Smith @*/
93a313700dSBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetType(TS ts, const TSType *type)
943f3760d9SBarry Smith {
95dfbe8321SBarry Smith   PetscErrorCode ierr;
963a40ed3dSBarry Smith 
973a40ed3dSBarry Smith   PetscFunctionBegin;
984482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
994482741eSBarry Smith   PetscValidPointer(type,2);
100abc0a331SBarry Smith   if (!TSRegisterAllCalled) {
101bdad233fSMatthew Knepley     ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);
102bdad233fSMatthew Knepley   }
1037adad957SLisandro Dalcin   *type = ((PetscObject)ts)->type_name;
1043a40ed3dSBarry Smith   PetscFunctionReturn(0);
1053f3760d9SBarry Smith }
1063f3760d9SBarry Smith 
107bdad233fSMatthew Knepley /*--------------------------------------------------------------------------------------------------------------------*/
1083cea93caSBarry Smith 
109bdad233fSMatthew Knepley #undef __FUNCT__
110bdad233fSMatthew Knepley #define __FUNCT__ "TSRegister"
1113cea93caSBarry Smith /*@C
1123cea93caSBarry Smith   TSRegister - See TSRegisterDynamic()
1133cea93caSBarry Smith 
1147f6c08e0SMatthew Knepley   Level: advanced
1153cea93caSBarry Smith @*/
11663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
117bdad233fSMatthew Knepley {
118e2d1d2b7SBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
119dfbe8321SBarry Smith   PetscErrorCode ierr;
120bdad233fSMatthew Knepley 
121bdad233fSMatthew Knepley   PetscFunctionBegin;
122bdad233fSMatthew Knepley   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
123bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
124bdad233fSMatthew Knepley   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
125bdad233fSMatthew Knepley   ierr = PetscFListAdd(&TSList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr);
126bdad233fSMatthew Knepley   PetscFunctionReturn(0);
127bdad233fSMatthew Knepley }
128bdad233fSMatthew Knepley 
129bdad233fSMatthew Knepley /*-------------------------------------------------------------------------------------------------------------------*/
130bdad233fSMatthew Knepley #undef __FUNCT__
131bdad233fSMatthew Knepley #define __FUNCT__ "TSRegisterDestroy"
132bdad233fSMatthew Knepley /*@C
1333cea93caSBarry Smith    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
134bdad233fSMatthew Knepley 
135bdad233fSMatthew Knepley    Not Collective
136bdad233fSMatthew Knepley 
137bdad233fSMatthew Knepley    Level: advanced
138bdad233fSMatthew Knepley 
139bdad233fSMatthew Knepley .keywords: TS, timestepper, register, destroy
140437fc6d7SBarry Smith .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
141bdad233fSMatthew Knepley @*/
14263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSRegisterDestroy(void)
143bdad233fSMatthew Knepley {
144dfbe8321SBarry Smith   PetscErrorCode ierr;
145bdad233fSMatthew Knepley 
146bdad233fSMatthew Knepley   PetscFunctionBegin;
1471441b1d3SBarry Smith   ierr = PetscFListDestroy(&TSList);CHKERRQ(ierr);
148bdad233fSMatthew Knepley   TSRegisterAllCalled = PETSC_FALSE;
149bdad233fSMatthew Knepley   PetscFunctionReturn(0);
150bdad233fSMatthew Knepley }
151bdad233fSMatthew Knepley 
152