xref: /petsc/include/petscts.h (revision 214bc6a2d8e2ea6a1f725944c2fd032dc3e2c3e7)
1 /*
2    User interface for the timestepping package. This 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 TSType char*
31 #define TSEULER           "euler"
32 #define TSBEULER          "beuler"
33 #define TSPSEUDO          "pseudo"
34 #define TSCN              "cn"
35 #define TSSUNDIALS        "sundials"
36 #define TSRK              "rk"
37 #define TSPYTHON          "python"
38 #define TSTHETA           "theta"
39 #define TSALPHA           "alpha"
40 #define TSGL              "gl"
41 #define TSSSP             "ssp"
42 
43 /*E
44     TSProblemType - Determines the type of problem this TS object is to be used to solve
45 
46    Level: beginner
47 
48 .seealso: TSCreate()
49 E*/
50 typedef enum {TS_LINEAR,TS_NONLINEAR} TSProblemType;
51 
52 /* Logging support */
53 extern PetscClassId  TS_CLASSID;
54 
55 extern PetscErrorCode   TSInitializePackage(const char[]);
56 
57 extern PetscErrorCode   TSCreate(MPI_Comm,TS*);
58 extern PetscErrorCode   TSDestroy(TS*);
59 
60 extern PetscErrorCode   TSSetProblemType(TS,TSProblemType);
61 extern PetscErrorCode   TSGetProblemType(TS,TSProblemType*);
62 extern PetscErrorCode   TSMonitorSet(TS,PetscErrorCode(*)(TS,PetscInt,PetscReal,Vec,void*),void *,PetscErrorCode (*)(void**));
63 extern PetscErrorCode   TSMonitorCancel(TS);
64 
65 extern PetscErrorCode   TSSetOptionsPrefix(TS,const char[]);
66 extern PetscErrorCode   TSAppendOptionsPrefix(TS,const char[]);
67 extern PetscErrorCode   TSGetOptionsPrefix(TS,const char *[]);
68 extern PetscErrorCode   TSSetFromOptions(TS);
69 extern PetscErrorCode   TSSetUp(TS);
70 extern PetscErrorCode   TSReset(TS);
71 
72 extern PetscErrorCode   TSSetSolution(TS,Vec);
73 extern PetscErrorCode   TSGetSolution(TS,Vec*);
74 
75 extern PetscErrorCode   TSSetDuration(TS,PetscInt,PetscReal);
76 extern PetscErrorCode   TSGetDuration(TS,PetscInt*,PetscReal*);
77 
78 extern PetscErrorCode   TSMonitorDefault(TS,PetscInt,PetscReal,Vec,void*);
79 extern PetscErrorCode   TSMonitorSolution(TS,PetscInt,PetscReal,Vec,void*);
80 extern PetscErrorCode   TSStep(TS,PetscInt *,PetscReal*);
81 extern PetscErrorCode   TSSolve(TS,Vec);
82 
83 
84 extern PetscErrorCode   TSSetInitialTimeStep(TS,PetscReal,PetscReal);
85 extern PetscErrorCode   TSGetTimeStep(TS,PetscReal*);
86 extern PetscErrorCode   TSGetTime(TS,PetscReal*);
87 extern PetscErrorCode   TSSetTime(TS,PetscReal);
88 extern PetscErrorCode   TSGetTimeStepNumber(TS,PetscInt*);
89 extern PetscErrorCode   TSSetTimeStep(TS,PetscReal);
90 
91 typedef PetscErrorCode (*TSRHSFunction)(TS,PetscReal,Vec,Vec,void*);
92 typedef PetscErrorCode (*TSRHSJacobian)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*);
93 extern PetscErrorCode   TSSetRHSFunction(TS,Vec,TSRHSFunction,void*);
94 extern PetscErrorCode   TSGetRHSFunction(TS,Vec*,TSRHSFunction*,void**);
95 extern PetscErrorCode   TSSetRHSJacobian(TS,Mat,Mat,TSRHSJacobian,void*);
96 extern PetscErrorCode   TSGetRHSJacobian(TS,Mat*,Mat*,TSRHSJacobian*,void**);
97 
98 typedef PetscErrorCode (*TSIFunction)(TS,PetscReal,Vec,Vec,Vec,void*);
99 typedef PetscErrorCode (*TSIJacobian)(TS,PetscReal,Vec,Vec,PetscReal,Mat*,Mat*,MatStructure*,void*);
100 extern PetscErrorCode   TSSetIFunction(TS,Vec,TSIFunction,void*);
101 extern PetscErrorCode   TSGetIFunction(TS,Vec*,TSIFunction*,void**);
102 extern PetscErrorCode   TSSetIJacobian(TS,Mat,Mat,TSIJacobian,void*);
103 extern PetscErrorCode   TSGetIJacobian(TS,Mat*,Mat*,TSIJacobian*,void**);
104 
105 extern PetscErrorCode   TSDefaultComputeJacobianColor(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*);
106 extern PetscErrorCode   TSDefaultComputeJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*);
107 
108 extern PetscErrorCode   TSSetPreStep(TS, PetscErrorCode (*)(TS));
109 extern PetscErrorCode   TSSetPostStep(TS, PetscErrorCode (*)(TS));
110 extern PetscErrorCode   TSPreStep(TS);
111 extern PetscErrorCode   TSPostStep(TS);
112 
113 extern PetscErrorCode   TSPseudoSetTimeStep(TS,PetscErrorCode(*)(TS,PetscReal*,void*),void*);
114 extern PetscErrorCode   TSPseudoDefaultTimeStep(TS,PetscReal*,void*);
115 extern PetscErrorCode   TSPseudoComputeTimeStep(TS,PetscReal *);
116 
117 extern PetscErrorCode   TSPseudoSetVerifyTimeStep(TS,PetscErrorCode(*)(TS,Vec,void*,PetscReal*,PetscBool *),void*);
118 extern PetscErrorCode   TSPseudoDefaultVerifyTimeStep(TS,Vec,void*,PetscReal*,PetscBool *);
119 extern PetscErrorCode   TSPseudoVerifyTimeStep(TS,Vec,PetscReal*,PetscBool *);
120 extern PetscErrorCode   TSPseudoSetTimeStepIncrement(TS,PetscReal);
121 extern PetscErrorCode   TSPseudoIncrementDtFromInitialDt(TS);
122 
123 extern PetscErrorCode   TSPythonSetType(TS,const char[]);
124 
125 extern PetscErrorCode   TSComputeRHSFunction(TS,PetscReal,Vec,Vec);
126 extern PetscErrorCode   TSComputeRHSJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*);
127 extern PetscErrorCode   TSComputeIFunction(TS,PetscReal,Vec,Vec,Vec,PetscBool);
128 extern PetscErrorCode   TSComputeIJacobian(TS,PetscReal,Vec,Vec,PetscReal,Mat*,Mat*,MatStructure*,PetscBool);
129 
130 /* Dynamic creation and loading functions */
131 extern PetscFList TSList;
132 extern PetscBool  TSRegisterAllCalled;
133 extern PetscErrorCode   TSGetType(TS,const TSType*);
134 extern PetscErrorCode   TSSetType(TS,const TSType);
135 extern PetscErrorCode   TSRegister(const char[], const char[], const char[], PetscErrorCode (*)(TS));
136 extern PetscErrorCode   TSRegisterAll(const char[]);
137 extern PetscErrorCode   TSRegisterDestroy(void);
138 
139 /*MC
140   TSRegisterDynamic - Adds a creation method to the TS package.
141 
142   Synopsis:
143   PetscErrorCode TSRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(TS))
144 
145   Not Collective
146 
147   Input Parameters:
148 + name        - The name of a new user-defined creation routine
149 . path        - The path (either absolute or relative) of the library containing this routine
150 . func_name   - The name of the creation routine
151 - create_func - The creation routine itself
152 
153   Notes:
154   TSRegisterDynamic() may be called multiple times to add several user-defined tses.
155 
156   If dynamic libraries are used, then the fourth input argument (create_func) is ignored.
157 
158   Sample usage:
159 .vb
160   TSRegisterDynamic("my_ts", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyTSCreate", MyTSCreate);
161 .ve
162 
163   Then, your ts type can be chosen with the procedural interface via
164 .vb
165     TS ts;
166     TSCreate(MPI_Comm, &ts);
167     TSSetType(ts, "my_ts")
168 .ve
169   or at runtime via the option
170 .vb
171     -ts_type my_ts
172 .ve
173 
174   Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
175         If your function is not being put into a shared library then use TSRegister() instead
176 
177   Level: advanced
178 
179 .keywords: TS, register
180 .seealso: TSRegisterAll(), TSRegisterDestroy()
181 M*/
182 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
183 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,0)
184 #else
185 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,d)
186 #endif
187 
188 extern PetscErrorCode   TSGetSNES(TS,SNES*);
189 extern PetscErrorCode   TSGetKSP(TS,KSP*);
190 
191 extern PetscErrorCode   TSView(TS,PetscViewer);
192 extern PetscErrorCode   TSViewFromOptions(TS,const char[]);
193 
194 extern PetscErrorCode   TSSetApplicationContext(TS,void *);
195 extern PetscErrorCode   TSGetApplicationContext(TS,void *);
196 
197 extern PetscErrorCode   TSMonitorLGCreate(const char[],const char[],int,int,int,int,PetscDrawLG *);
198 extern PetscErrorCode   TSMonitorLG(TS,PetscInt,PetscReal,Vec,void *);
199 extern PetscErrorCode   TSMonitorLGDestroy(PetscDrawLG*);
200 
201 /*S
202    TSGLAdapt - Abstract object that manages time-step adaptivity
203 
204    Level: beginner
205 
206 .seealso: TSGL, TSGLAdaptCreate(), TSGLAdaptType
207 S*/
208 typedef struct _p_TSGLAdapt *TSGLAdapt;
209 
210 /*E
211     TSGLAdaptType - String with the name of TSGLAdapt scheme or the creation function
212        with an optional dynamic library name, for example
213        http://www.mcs.anl.gov/petsc/lib.a:mytsgladaptcreate()
214 
215    Level: beginner
216 
217 .seealso: TSGLAdaptSetType(), TS
218 E*/
219 #define TSGLAdaptType  char*
220 #define TSGLADAPT_NONE "none"
221 #define TSGLADAPT_SIZE "size"
222 #define TSGLADAPT_BOTH "both"
223 
224 /*MC
225    TSGLAdaptRegisterDynamic - adds a TSGLAdapt implementation
226 
227    Synopsis:
228    PetscErrorCode TSGLAdaptRegisterDynamic(const char *name_scheme,const char *path,const char *name_create,PetscErrorCode (*routine_create)(TS))
229 
230    Not Collective
231 
232    Input Parameters:
233 +  name_scheme - name of user-defined adaptivity scheme
234 .  path - path (either absolute or relative) the library containing this scheme
235 .  name_create - name of routine to create method context
236 -  routine_create - routine to create method context
237 
238    Notes:
239    TSGLAdaptRegisterDynamic() may be called multiple times to add several user-defined families.
240 
241    If dynamic libraries are used, then the fourth input argument (routine_create)
242    is ignored.
243 
244    Sample usage:
245 .vb
246    TSGLAdaptRegisterDynamic("my_scheme",/home/username/my_lib/lib/libO/solaris/mylib.a,
247                             "MySchemeCreate",MySchemeCreate);
248 .ve
249 
250    Then, your scheme can be chosen with the procedural interface via
251 $     TSGLAdaptSetType(ts,"my_scheme")
252    or at runtime via the option
253 $     -ts_adapt_type my_scheme
254 
255    Level: advanced
256 
257    Notes: Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
258           and others of the form ${any_environmental_variable} occuring in pathname will be
259           replaced with appropriate values.
260 
261 .keywords: TSGLAdapt, register
262 
263 .seealso: TSGLAdaptRegisterAll()
264 M*/
265 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
266 #  define TSGLAdaptRegisterDynamic(a,b,c,d)  TSGLAdaptRegister(a,b,c,0)
267 #else
268 #  define TSGLAdaptRegisterDynamic(a,b,c,d)  TSGLAdaptRegister(a,b,c,d)
269 #endif
270 
271 extern PetscErrorCode  TSGLAdaptRegister(const char[],const char[],const char[],PetscErrorCode (*)(TSGLAdapt));
272 extern PetscErrorCode  TSGLAdaptRegisterAll(const char[]);
273 extern PetscErrorCode  TSGLAdaptRegisterDestroy(void);
274 extern PetscErrorCode  TSGLAdaptInitializePackage(const char[]);
275 extern PetscErrorCode  TSGLAdaptFinalizePackage(void);
276 extern PetscErrorCode  TSGLAdaptCreate(MPI_Comm,TSGLAdapt*);
277 extern PetscErrorCode  TSGLAdaptSetType(TSGLAdapt,const TSGLAdaptType);
278 extern PetscErrorCode  TSGLAdaptSetOptionsPrefix(TSGLAdapt,const char[]);
279 extern PetscErrorCode  TSGLAdaptChoose(TSGLAdapt,PetscInt,const PetscInt[],const PetscReal[],const PetscReal[],PetscInt,PetscReal,PetscReal,PetscInt*,PetscReal*,PetscBool *);
280 extern PetscErrorCode  TSGLAdaptView(TSGLAdapt,PetscViewer);
281 extern PetscErrorCode  TSGLAdaptSetFromOptions(TSGLAdapt);
282 extern PetscErrorCode  TSGLAdaptDestroy(TSGLAdapt*);
283 
284 /*E
285     TSGLAcceptType - String with the name of TSGLAccept scheme or the function
286        with an optional dynamic library name, for example
287        http://www.mcs.anl.gov/petsc/lib.a:mytsglaccept()
288 
289    Level: beginner
290 
291 .seealso: TSGLSetAcceptType(), TS
292 E*/
293 #define TSGLAcceptType  char*
294 #define TSGLACCEPT_ALWAYS "always"
295 
296 typedef PetscErrorCode (*TSGLAcceptFunction)(TS,PetscReal,PetscReal,const PetscReal[],PetscBool *);
297 extern PetscErrorCode  TSGLAcceptRegister(const char[],const char[],const char[],TSGLAcceptFunction);
298 
299 /*MC
300    TSGLAcceptRegisterDynamic - adds a TSGL acceptance scheme
301 
302    Synopsis:
303    PetscErrorCode TSGLAcceptRegisterDynamic(const char *name_scheme,const char *path,const char *name_create,PetscErrorCode (*routine_create)(TS))
304 
305    Not Collective
306 
307    Input Parameters:
308 +  name_scheme - name of user-defined acceptance scheme
309 .  path - path (either absolute or relative) the library containing this scheme
310 .  name_create - name of routine to create method context
311 -  routine_create - routine to create method context
312 
313    Notes:
314    TSGLAcceptRegisterDynamic() may be called multiple times to add several user-defined families.
315 
316    If dynamic libraries are used, then the fourth input argument (routine_create)
317    is ignored.
318 
319    Sample usage:
320 .vb
321    TSGLAcceptRegisterDynamic("my_scheme",/home/username/my_lib/lib/libO/solaris/mylib.a,
322                              "MySchemeCreate",MySchemeCreate);
323 .ve
324 
325    Then, your scheme can be chosen with the procedural interface via
326 $     TSGLSetAcceptType(ts,"my_scheme")
327    or at runtime via the option
328 $     -ts_gl_accept_type my_scheme
329 
330    Level: advanced
331 
332    Notes: Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
333           and others of the form ${any_environmental_variable} occuring in pathname will be
334           replaced with appropriate values.
335 
336 .keywords: TSGL, TSGLAcceptType, register
337 
338 .seealso: TSGLRegisterAll()
339 M*/
340 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
341 #  define TSGLAcceptRegisterDynamic(a,b,c,d) TSGLAcceptRegister(a,b,c,0)
342 #else
343 #  define TSGLAcceptRegisterDynamic(a,b,c,d) TSGLAcceptRegister(a,b,c,d)
344 #endif
345 
346 /*E
347   TSGLType - family of time integration method within the General Linear class
348 
349   Level: beginner
350 
351 .seealso: TSGLSetType(), TSGLRegister()
352 E*/
353 #define TSGLType char*
354 #define TSGL_IRKS   "irks"
355 
356 /*MC
357    TSGLRegisterDynamic - adds a TSGL implementation
358 
359    Synopsis:
360    PetscErrorCode TSGLRegisterDynamic(const char *name_scheme,const char *path,const char *name_create,PetscErrorCode (*routine_create)(TS))
361 
362    Not Collective
363 
364    Input Parameters:
365 +  name_scheme - name of user-defined general linear scheme
366 .  path - path (either absolute or relative) the library containing this scheme
367 .  name_create - name of routine to create method context
368 -  routine_create - routine to create method context
369 
370    Notes:
371    TSGLRegisterDynamic() may be called multiple times to add several user-defined families.
372 
373    If dynamic libraries are used, then the fourth input argument (routine_create)
374    is ignored.
375 
376    Sample usage:
377 .vb
378    TSGLRegisterDynamic("my_scheme",/home/username/my_lib/lib/libO/solaris/mylib.a,
379                        "MySchemeCreate",MySchemeCreate);
380 .ve
381 
382    Then, your scheme can be chosen with the procedural interface via
383 $     TSGLSetType(ts,"my_scheme")
384    or at runtime via the option
385 $     -ts_gl_type my_scheme
386 
387    Level: advanced
388 
389    Notes: Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
390           and others of the form ${any_environmental_variable} occuring in pathname will be
391           replaced with appropriate values.
392 
393 .keywords: TSGL, register
394 
395 .seealso: TSGLRegisterAll()
396 M*/
397 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
398 #  define TSGLRegisterDynamic(a,b,c,d)       TSGLRegister(a,b,c,0)
399 #else
400 #  define TSGLRegisterDynamic(a,b,c,d)       TSGLRegister(a,b,c,d)
401 #endif
402 
403 extern PetscErrorCode   TSGLRegister(const char[],const char[],const char[],PetscErrorCode(*)(TS));
404 extern PetscErrorCode  TSGLRegisterAll(const char[]);
405 extern PetscErrorCode  TSGLRegisterDestroy(void);
406 extern PetscErrorCode  TSGLInitializePackage(const char[]);
407 extern PetscErrorCode  TSGLFinalizePackage(void);
408 extern PetscErrorCode  TSGLSetType(TS,const TSGLType);
409 extern PetscErrorCode  TSGLGetAdapt(TS,TSGLAdapt*);
410 extern PetscErrorCode  TSGLSetAcceptType(TS,const TSGLAcceptType);
411 
412 /*
413        PETSc interface to Sundials
414 */
415 #ifdef PETSC_HAVE_SUNDIALS
416 typedef enum { SUNDIALS_ADAMS=1,SUNDIALS_BDF=2} TSSundialsLmmType;
417 extern const char *TSSundialsLmmTypes[];
418 typedef enum { SUNDIALS_MODIFIED_GS = 1,SUNDIALS_CLASSICAL_GS = 2 } TSSundialsGramSchmidtType;
419 extern const char *TSSundialsGramSchmidtTypes[];
420 extern PetscErrorCode   TSSundialsSetType(TS,TSSundialsLmmType);
421 extern PetscErrorCode   TSSundialsGetPC(TS,PC*);
422 extern PetscErrorCode   TSSundialsSetTolerance(TS,PetscReal,PetscReal);
423 extern PetscErrorCode   TSSundialsSetMinTimeStep(TS,PetscReal);
424 extern PetscErrorCode   TSSundialsSetMaxTimeStep(TS,PetscReal);
425 extern PetscErrorCode   TSSundialsGetIterations(TS,PetscInt *,PetscInt *);
426 extern PetscErrorCode   TSSundialsSetGramSchmidtType(TS,TSSundialsGramSchmidtType);
427 extern PetscErrorCode   TSSundialsSetGMRESRestart(TS,PetscInt);
428 extern PetscErrorCode   TSSundialsSetLinearTolerance(TS,PetscReal);
429 extern PetscErrorCode   TSSundialsSetExactFinalTime(TS,PetscBool );
430 extern PetscErrorCode   TSSundialsMonitorInternalSteps(TS,PetscBool );
431 extern PetscErrorCode   TSSundialsGetParameters(TS,PetscInt *,long*[],double*[]);
432 #endif
433 
434 extern PetscErrorCode   TSRKSetTolerance(TS,PetscReal);
435 
436 extern PetscErrorCode  TSThetaSetTheta(TS,PetscReal);
437 extern PetscErrorCode  TSThetaGetTheta(TS,PetscReal*);
438 
439 extern PetscErrorCode  TSAlphaSetAdapt(TS,PetscErrorCode(*)(TS,PetscReal,Vec,Vec,PetscReal*,PetscBool*,void*),void*);
440 extern PetscErrorCode  TSAlphaAdaptDefault(TS,PetscReal,Vec,Vec,PetscReal*,PetscBool*,void*);
441 extern PetscErrorCode  TSAlphaSetRadius(TS,PetscReal);
442 extern PetscErrorCode  TSAlphaSetParams(TS,PetscReal,PetscReal,PetscReal);
443 extern PetscErrorCode  TSAlphaGetParams(TS,PetscReal*,PetscReal*,PetscReal*);
444 
445 extern PetscErrorCode  TSSetDM(TS,DM);
446 extern PetscErrorCode  TSGetDM(TS,DM*);
447 
448 extern PetscErrorCode  SNESTSFormFunction(SNES,Vec,Vec,void*);
449 extern PetscErrorCode  SNESTSFormJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
450 
451 PETSC_EXTERN_CXX_END
452 #endif
453