xref: /petsc/include/petscts.h (revision 6849ba73f22fecb8f92ef896a42e4e8bd4cd6965)
1 /*
2    User interface for the timestepping package. This is package
3    is for use in solving time-dependent PDEs.
4 */
5 #if !defined(__PETSCTS_H)
6 #define __PETSCTS_H
7 #include "petscsnes.h"
8 PETSC_EXTERN_CXX_BEGIN
9 
10 /*S
11      TS - Abstract PETSc object that manages all time-steppers (ODE integrators)
12 
13    Level: beginner
14 
15   Concepts: ODE solvers
16 
17 .seealso:  TSCreate(), TSSetType(), TSType, SNES, KSP, PC
18 S*/
19 typedef struct _p_TS* TS;
20 
21 /*E
22     TSType - String with the name of a PETSc TS method or the creation function
23        with an optional dynamic library name, for example
24        http://www.mcs.anl.gov/petsc/lib.a:mytscreate()
25 
26    Level: beginner
27 
28 .seealso: TSSetType(), TS
29 E*/
30 #define TS_EULER           "euler"
31 #define TS_BEULER          "beuler"
32 #define TS_PSEUDO          "pseudo"
33 #define TS_CRANK_NICHOLSON "crank-nicholson"
34 #define TS_PVODE           "pvode"
35 #define TS_RUNGE_KUTTA     "runge-kutta"
36 #define TSType char*
37 
38 /*E
39     TSProblemType - Determines the type of problem this TS object is to be used to solve
40 
41    Level: beginner
42 
43 .seealso: TSCreate()
44 E*/
45 typedef enum {TS_LINEAR,TS_NONLINEAR} TSProblemType;
46 
47 /* Logging support */
48 extern PetscCookie TS_COOKIE;
49 extern PetscEvent    TS_Step, TS_PseudoComputeTimeStep, TS_FunctionEval, TS_JacobianEval;
50 
51 EXTERN PetscErrorCode TSInitializePackage(const char[]);
52 
53 EXTERN PetscErrorCode TSCreate(MPI_Comm,TS*);
54 EXTERN PetscErrorCode TSDestroy(TS);
55 
56 EXTERN PetscErrorCode TSSetProblemType(TS,TSProblemType);
57 EXTERN PetscErrorCode TSGetProblemType(TS,TSProblemType*);
58 EXTERN PetscErrorCode TSSetMonitor(TS,PetscErrorCode(*)(TS,int,PetscReal,Vec,void*),void *,PetscErrorCode (*)(void*));
59 EXTERN PetscErrorCode TSClearMonitor(TS);
60 
61 EXTERN PetscErrorCode TSSetOptionsPrefix(TS,const char[]);
62 EXTERN PetscErrorCode TSAppendOptionsPrefix(TS,const char[]);
63 EXTERN PetscErrorCode TSGetOptionsPrefix(TS,char *[]);
64 EXTERN PetscErrorCode TSSetFromOptions(TS);
65 EXTERN PetscErrorCode TSSetUp(TS);
66 
67 EXTERN PetscErrorCode TSSetSolution(TS,Vec);
68 EXTERN PetscErrorCode TSGetSolution(TS,Vec*);
69 
70 EXTERN PetscErrorCode TSSetDuration(TS,int,PetscReal);
71 EXTERN PetscErrorCode TSGetDuration(TS,int*,PetscReal*);
72 
73 EXTERN PetscErrorCode TSDefaultMonitor(TS,int,PetscReal,Vec,void*);
74 EXTERN PetscErrorCode TSVecViewMonitor(TS,int,PetscReal,Vec,void*);
75 EXTERN PetscErrorCode TSStep(TS,int *,PetscReal*);
76 
77 EXTERN PetscErrorCode TSSetInitialTimeStep(TS,PetscReal,PetscReal);
78 EXTERN PetscErrorCode TSGetTimeStep(TS,PetscReal*);
79 EXTERN PetscErrorCode TSGetTime(TS,PetscReal*);
80 EXTERN PetscErrorCode TSGetTimeStepNumber(TS,int*);
81 EXTERN PetscErrorCode TSSetTimeStep(TS,PetscReal);
82 
83 EXTERN PetscErrorCode TSSetRHSFunction(TS,PetscErrorCode (*)(TS,PetscReal,Vec,Vec,void*),void*);
84 EXTERN PetscErrorCode TSSetRHSMatrix(TS,Mat,Mat,PetscErrorCode (*)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void*);
85 EXTERN PetscErrorCode TSSetRHSJacobian(TS,Mat,Mat,PetscErrorCode (*)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void*);
86 EXTERN PetscErrorCode TSSetRHSBoundaryConditions(TS,PetscErrorCode (*)(TS,PetscReal,Vec,void*),void*);
87 
88 EXTERN PetscErrorCode TSDefaultComputeJacobianColor(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*);
89 EXTERN PetscErrorCode TSDefaultComputeJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*);
90 
91 EXTERN PetscErrorCode TSGetRHSMatrix(TS,Mat*,Mat*,void**);
92 EXTERN PetscErrorCode TSGetRHSJacobian(TS,Mat*,Mat*,void**);
93 
94 EXTERN PetscErrorCode TSSetRhsBC(TS, PetscErrorCode (*)(TS, Vec, void *));
95 EXTERN PetscErrorCode TSSetSystemMatrixBC(TS, PetscErrorCode (*)(TS, Mat, Mat, void *));
96 EXTERN PetscErrorCode TSSetSolutionBC(TS, PetscErrorCode (*)(TS, Vec, void *));
97 EXTERN PetscErrorCode TSSetPreStep(TS, PetscErrorCode (*)(TS));
98 EXTERN PetscErrorCode TSSetUpdate(TS, PetscErrorCode (*)(TS, PetscReal, PetscReal *));
99 EXTERN PetscErrorCode TSSetPostStep(TS, PetscErrorCode (*)(TS));
100 EXTERN PetscErrorCode TSDefaultRhsBC(TS, Vec, void *);
101 EXTERN PetscErrorCode TSDefaultSystemMatrixBC(TS, Mat, Mat, void *);
102 EXTERN PetscErrorCode TSDefaultSolutionBC(TS, Vec, void *);
103 EXTERN PetscErrorCode TSDefaultPreStep(TS);
104 EXTERN PetscErrorCode TSDefaultUpdate(TS, PetscReal, PetscReal *);
105 EXTERN PetscErrorCode TSDefaultPostStep(TS);
106 EXTERN PetscErrorCode TSSetIdentity(TS, PetscErrorCode (*)(TS, double, Mat *, void *));
107 
108 EXTERN PetscErrorCode TSPseudoSetTimeStep(TS,PetscErrorCode(*)(TS,PetscReal*,void*),void*);
109 EXTERN PetscErrorCode TSPseudoDefaultTimeStep(TS,PetscReal*,void*);
110 EXTERN PetscErrorCode TSPseudoComputeTimeStep(TS,PetscReal *);
111 
112 EXTERN PetscErrorCode TSPseudoSetVerifyTimeStep(TS,PetscErrorCode(*)(TS,Vec,void*,PetscReal*,int*),void*);
113 EXTERN PetscErrorCode TSPseudoDefaultVerifyTimeStep(TS,Vec,void*,PetscReal*,int*);
114 EXTERN PetscErrorCode TSPseudoVerifyTimeStep(TS,Vec,PetscReal*,int*);
115 EXTERN PetscErrorCode TSPseudoSetTimeStepIncrement(TS,PetscReal);
116 EXTERN PetscErrorCode TSPseudoIncrementDtFromInitialDt(TS);
117 
118 EXTERN PetscErrorCode TSComputeRHSFunction(TS,PetscReal,Vec,Vec);
119 EXTERN PetscErrorCode TSComputeRHSBoundaryConditions(TS,PetscReal,Vec);
120 EXTERN PetscErrorCode TSComputeRHSJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*);
121 
122 /* Dynamic creation and loading functions */
123 extern PetscFList TSList;
124 extern PetscTruth TSRegisterAllCalled;
125 EXTERN PetscErrorCode TSGetType(TS,TSType*);
126 EXTERN PetscErrorCode TSSetType(TS,const TSType);
127 EXTERN PetscErrorCode TSRegister(const char[], const char[], const char[], PetscErrorCode (*)(TS));
128 EXTERN PetscErrorCode TSRegisterAll(const char[]);
129 EXTERN PetscErrorCode TSRegisterDestroy(void);
130 
131 /*MC
132   TSRegisterDynamic - Adds a creation method to the TS package.
133 
134   Synopsis:
135 
136   TSRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(TS))
137 
138   Not Collective
139 
140   Input Parameters:
141 + name        - The name of a new user-defined creation routine
142 . path        - The path (either absolute or relative) of the library containing this routine
143 . func_name   - The name of the creation routine
144 - create_func - The creation routine itself
145 
146   Notes:
147   TSRegisterDynamic() may be called multiple times to add several user-defined tses.
148 
149   If dynamic libraries are used, then the fourth input argument (create_func) is ignored.
150 
151   Sample usage:
152 .vb
153   TSRegisterDynamic("my_ts", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyTSCreate", MyTSCreate);
154 .ve
155 
156   Then, your ts type can be chosen with the procedural interface via
157 .vb
158     TSCreate(MPI_Comm, TS *);
159     TSSetType(vec, "my_ts")
160 .ve
161   or at runtime via the option
162 .vb
163     -ts_type my_ts
164 .ve
165 
166   Notes: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
167         If your function is not being put into a shared library then use TSRegister() instead
168 
169   Level: advanced
170 
171 .keywords: TS, register
172 .seealso: TSRegisterAll(), TSRegisterDestroy()
173 M*/
174 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
175 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,0)
176 #else
177 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,d)
178 #endif
179 
180 EXTERN PetscErrorCode TSGetSNES(TS,SNES*);
181 EXTERN PetscErrorCode TSGetKSP(TS,KSP*);
182 
183 EXTERN PetscErrorCode TSView(TS,PetscViewer);
184 EXTERN PetscErrorCode TSViewFromOptions(TS,const char[]);
185 
186 EXTERN PetscErrorCode TSSetApplicationContext(TS,void *);
187 EXTERN PetscErrorCode TSGetApplicationContext(TS,void **);
188 
189 EXTERN PetscErrorCode TSLGMonitorCreate(const char[],const char[],int,int,int,int,PetscDrawLG *);
190 EXTERN PetscErrorCode TSLGMonitor(TS,int,PetscReal,Vec,void *);
191 EXTERN PetscErrorCode TSLGMonitorDestroy(PetscDrawLG);
192 
193 /*
194        PETSc interface to PVode
195 */
196 #define PVODE_UNMODIFIED_GS PVODE_CLASSICAL_GS
197 typedef enum { PVODE_ADAMS,PVODE_BDF } TSPVodeType;
198 typedef enum { PVODE_MODIFIED_GS = 0,PVODE_CLASSICAL_GS = 1 } TSPVodeGramSchmidtType;
199 EXTERN PetscErrorCode TSPVodeSetType(TS,TSPVodeType);
200 EXTERN PetscErrorCode TSPVodeGetPC(TS,PC*);
201 EXTERN PetscErrorCode TSPVodeSetTolerance(TS,PetscReal,PetscReal);
202 EXTERN PetscErrorCode TSPVodeGetIterations(TS,int *,int *);
203 EXTERN PetscErrorCode TSPVodeSetGramSchmidtType(TS,TSPVodeGramSchmidtType);
204 EXTERN PetscErrorCode TSPVodeSetGMRESRestart(TS,int);
205 EXTERN PetscErrorCode TSPVodeSetLinearTolerance(TS,PetscReal);
206 EXTERN PetscErrorCode TSPVodeSetExactFinalTime(TS,PetscTruth);
207 EXTERN PetscErrorCode TSPVodeGetParameters(TS,int *,long int*[],double*[]);
208 
209 EXTERN PetscErrorCode TSRKSetTolerance(TS,PetscReal);
210 
211 PETSC_EXTERN_CXX_END
212 #endif
213