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