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
6cc4c1da9SBarry Smith /*@
7*0b4b7b1cSBarry Smith TSSetType - Sets the algorithm/method to be used for integrating the ODE with the given `TS`.
83f3760d9SBarry Smith
9c3339decSBarry Smith Collective
10fee21e36SBarry Smith
11bef22f13SLois Curfman McInnes Input Parameters:
12bcf0153eSBarry Smith + ts - The `TS` context
13bdad233fSMatthew Knepley - type - A known method
14bef22f13SLois Curfman McInnes
15bcf0153eSBarry Smith Options Database Key:
16bdad233fSMatthew Knepley . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
17ae12b187SLois Curfman McInnes
18bcf0153eSBarry Smith Level: intermediate
19bcf0153eSBarry Smith
203f3760d9SBarry Smith Notes:
21*0b4b7b1cSBarry Smith See `TSType` for available methods (for instance)
229596e0b4SJed Brown + TSEULER - Euler
239596e0b4SJed Brown . TSBEULER - Backward Euler
249596e0b4SJed Brown - TSPSEUDO - Pseudo-timestepping
253f3760d9SBarry Smith
26bcf0153eSBarry Smith Normally, it is best to use the `TSSetFromOptions()` command and
27bcf0153eSBarry Smith then set the `TS` type from the options database rather than by using
28ae12b187SLois Curfman McInnes this routine. Using the options database provides the user with
29ae12b187SLois Curfman McInnes maximum flexibility in evaluating the many different solvers.
30ae12b187SLois Curfman McInnes The TSSetType() routine is provided for those situations where it
31ae12b187SLois Curfman McInnes is necessary to set the timestepping solver independently of the
32ae12b187SLois Curfman McInnes command line or options database. This might be the case, for example,
33ae12b187SLois Curfman McInnes when the choice of solver changes during the execution of the
34ae12b187SLois Curfman McInnes program, and the user's application is taking responsibility for
35ae12b187SLois Curfman McInnes choosing the appropriate method. In other words, this routine is
36d5d37b61SLois Curfman McInnes not for beginners.
37d5d37b61SLois Curfman McInnes
381cc06b55SBarry Smith .seealso: [](ch_ts), `TS`, `TSSolve()`, `TSCreate()`, `TSSetFromOptions()`, `TSDestroy()`, `TSType`
393f3760d9SBarry Smith @*/
TSSetType(TS ts,TSType type)40d71ae5a4SJacob Faibussowitsch PetscErrorCode TSSetType(TS ts, TSType type)
41d71ae5a4SJacob Faibussowitsch {
426849ba73SBarry Smith PetscErrorCode (*r)(TS);
43ace3abfcSBarry Smith PetscBool match;
44df8cb225SBarry Smith
453a40ed3dSBarry Smith PetscFunctionBegin;
460700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID, 1);
474f572ea9SToby Isaac PetscAssertPointer(type, 2);
489566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)ts, type, &match));
493ba16761SJacob Faibussowitsch if (match) PetscFunctionReturn(PETSC_SUCCESS);
50bdad233fSMatthew Knepley
519566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(TSList, type, &r));
526adde796SStefano Zampini PetscCheck(r, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
53dbbe0bcdSBarry Smith PetscTryTypeMethod(ts, destroy);
549566063dSJacob Faibussowitsch PetscCall(PetscMemzero(ts->ops, sizeof(*ts->ops)));
55825ab935SBarry Smith ts->usessnes = PETSC_FALSE;
56b92453a8SLisandro Dalcin ts->default_adapt_type = TSADAPTNONE;
57bbd56ea5SKarl Rupp
58277b19d0SLisandro Dalcin ts->setupcalled = PETSC_FALSE;
59bbd56ea5SKarl Rupp
609566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)ts, type));
619566063dSJacob Faibussowitsch PetscCall((*r)(ts));
623ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
633f3760d9SBarry Smith }
643f3760d9SBarry Smith
65cc4c1da9SBarry Smith /*@
66*0b4b7b1cSBarry Smith TSGetType - Gets the `TS` method type (as a string) that is being used to solve the ODE with the given `TS`
673f3760d9SBarry Smith
68bef22f13SLois Curfman McInnes Not Collective
69bef22f13SLois Curfman McInnes
703f3760d9SBarry Smith Input Parameter:
71bcf0153eSBarry Smith . ts - The `TS`
723f3760d9SBarry Smith
733f3760d9SBarry Smith Output Parameter:
74*0b4b7b1cSBarry Smith . type - The `TSType`
753f3760d9SBarry Smith
76d5d37b61SLois Curfman McInnes Level: intermediate
77d5d37b61SLois Curfman McInnes
781cc06b55SBarry Smith .seealso: [](ch_ts), `TS`, `TSType`, `TSSetType()`
793f3760d9SBarry Smith @*/
TSGetType(TS ts,TSType * type)80d71ae5a4SJacob Faibussowitsch PetscErrorCode TSGetType(TS ts, TSType *type)
81d71ae5a4SJacob Faibussowitsch {
823a40ed3dSBarry Smith PetscFunctionBegin;
830700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID, 1);
844f572ea9SToby Isaac PetscAssertPointer(type, 2);
857adad957SLisandro Dalcin *type = ((PetscObject)ts)->type_name;
863ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
873f3760d9SBarry Smith }
883f3760d9SBarry Smith
893cea93caSBarry Smith /*@C
90bcf0153eSBarry Smith TSRegister - Adds a creation method to the `TS` package.
911c84c290SBarry Smith
92cc4c1da9SBarry Smith Not Collective, No Fortran Support
931c84c290SBarry Smith
941c84c290SBarry Smith Input Parameters:
952fe279fdSBarry Smith + sname - The name of a new user-defined creation routine
962fe279fdSBarry Smith - function - The creation routine itself
971c84c290SBarry Smith
98bcf0153eSBarry Smith Level: advanced
99bcf0153eSBarry Smith
1001c84c290SBarry Smith Notes:
101bcf0153eSBarry Smith `TSRegister()` may be called multiple times to add several user-defined tses.
1021c84c290SBarry Smith
103b43aa488SJacob Faibussowitsch Example Usage:
1041c84c290SBarry Smith .vb
105bdf89e91SBarry Smith TSRegister("my_ts", MyTSCreate);
1061c84c290SBarry Smith .ve
1071c84c290SBarry Smith
1081c84c290SBarry Smith Then, your ts type can be chosen with the procedural interface via
1091c84c290SBarry Smith .vb
1101c84c290SBarry Smith TS ts;
1111c84c290SBarry Smith TSCreate(MPI_Comm, &ts);
1121c84c290SBarry Smith TSSetType(ts, "my_ts")
1131c84c290SBarry Smith .ve
1141c84c290SBarry Smith or at runtime via the option
1151c84c290SBarry Smith .vb
1161c84c290SBarry Smith -ts_type my_ts
1171c84c290SBarry Smith .ve
1183cea93caSBarry Smith
1191cc06b55SBarry Smith .seealso: [](ch_ts), `TSSetType()`, `TSType`, `TSRegisterAll()`, `TSRegisterDestroy()`
1203cea93caSBarry Smith @*/
TSRegister(const char sname[],PetscErrorCode (* function)(TS))121d71ae5a4SJacob Faibussowitsch PetscErrorCode TSRegister(const char sname[], PetscErrorCode (*function)(TS))
122d71ae5a4SJacob Faibussowitsch {
123bdad233fSMatthew Knepley PetscFunctionBegin;
1249566063dSJacob Faibussowitsch PetscCall(TSInitializePackage());
1259566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&TSList, sname, function));
1263ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS);
127bdad233fSMatthew Knepley }
128