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 TSCRANK_NICHOLSON "crank-nicholson" 35 #define TSSUNDIALS "sundials" 36 #define TSRUNGE_KUTTA "runge-kutta" 37 #define TSPYTHON "python" 38 #define TSTHETA "theta" 39 #define TSGL "gl" 40 41 /*E 42 TSProblemType - Determines the type of problem this TS object is to be used to solve 43 44 Level: beginner 45 46 .seealso: TSCreate() 47 E*/ 48 typedef enum {TS_LINEAR,TS_NONLINEAR} TSProblemType; 49 50 /* Logging support */ 51 extern PetscCookie PETSCTS_DLLEXPORT TS_COOKIE; 52 53 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSInitializePackage(const char[]); 54 55 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSCreate(MPI_Comm,TS*); 56 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS); 57 58 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS,TSProblemType); 59 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS,TSProblemType*); 60 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSet(TS,PetscErrorCode(*)(TS,PetscInt,PetscReal,Vec,void*),void *,PetscErrorCode (*)(void*)); 61 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorCancel(TS); 62 63 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS,const char[]); 64 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS,const char[]); 65 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS,const char *[]); 66 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetFromOptions(TS); 67 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS); 68 69 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS,Vec); 70 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS,Vec*); 71 72 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS,PetscInt,PetscReal); 73 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS,PetscInt*,PetscReal*); 74 75 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorDefault(TS,PetscInt,PetscReal,Vec,void*); 76 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSolution(TS,PetscInt,PetscReal,Vec,void*); 77 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS,PetscInt *,PetscReal*); 78 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSolve(TS,Vec); 79 80 81 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS,PetscReal,PetscReal); 82 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS,PetscReal*); 83 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS,PetscReal*); 84 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetTime(TS,PetscReal); 85 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS,PetscInt*); 86 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS,PetscReal); 87 88 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS,PetscErrorCode (*)(TS,PetscReal,Vec,Vec,void*),void*); 89 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetMatrices(TS,Mat,PetscErrorCode (*)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),Mat,PetscErrorCode (*)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),MatStructure,void*); 90 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetMatrices(TS,Mat*,Mat*,void**); 91 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS,Mat,Mat,PetscErrorCode (*)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void*); 92 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS,Mat*,Mat*,void**); 93 94 typedef PetscErrorCode (*TSIFunction)(TS,PetscReal,Vec,Vec,Vec,void*); 95 typedef PetscErrorCode (*TSIJacobian)(TS,PetscReal,Vec,Vec,PetscReal,Mat*,Mat*,MatStructure*,void*); 96 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetIFunction(TS,TSIFunction,void*); 97 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetIJacobian(TS,Mat,Mat,TSIJacobian,void*); 98 99 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultComputeJacobianColor(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*); 100 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultComputeJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*); 101 102 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS, PetscErrorCode (*)(TS)); 103 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS, PetscErrorCode (*)(TS)); 104 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS); 105 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultUpdate(TS, PetscReal, PetscReal *); 106 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS); 107 108 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoSetTimeStep(TS,PetscErrorCode(*)(TS,PetscReal*,void*),void*); 109 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoDefaultTimeStep(TS,PetscReal*,void*); 110 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoComputeTimeStep(TS,PetscReal *); 111 112 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoSetVerifyTimeStep(TS,PetscErrorCode(*)(TS,Vec,void*,PetscReal*,PetscTruth*),void*); 113 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoDefaultVerifyTimeStep(TS,Vec,void*,PetscReal*,PetscTruth*); 114 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoVerifyTimeStep(TS,Vec,PetscReal*,PetscTruth*); 115 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoSetTimeStepIncrement(TS,PetscReal); 116 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoIncrementDtFromInitialDt(TS); 117 118 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPythonSetType(TS,const char[]); 119 120 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSFunction(TS,PetscReal,Vec,Vec); 121 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*); 122 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSComputeIFunction(TS,PetscReal,Vec,Vec,Vec); 123 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSComputeIJacobian(TS,PetscReal,Vec,Vec,PetscReal,Mat*,Mat*,MatStructure*); 124 125 /* Dynamic creation and loading functions */ 126 extern PetscFList TSList; 127 extern PetscTruth TSRegisterAllCalled; 128 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetType(TS,const TSType*); 129 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetType(TS,const TSType); 130 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRegister(const char[], const char[], const char[], PetscErrorCode (*)(TS)); 131 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRegisterAll(const char[]); 132 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRegisterDestroy(void); 133 134 /*MC 135 TSRegisterDynamic - Adds a creation method to the TS package. 136 137 Synopsis: 138 PetscErrorCode TSRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(TS)) 139 140 Not Collective 141 142 Input Parameters: 143 + name - The name of a new user-defined creation routine 144 . path - The path (either absolute or relative) of the library containing this routine 145 . func_name - The name of the creation routine 146 - create_func - The creation routine itself 147 148 Notes: 149 TSRegisterDynamic() may be called multiple times to add several user-defined tses. 150 151 If dynamic libraries are used, then the fourth input argument (create_func) is ignored. 152 153 Sample usage: 154 .vb 155 TSRegisterDynamic("my_ts", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyTSCreate", MyTSCreate); 156 .ve 157 158 Then, your ts type can be chosen with the procedural interface via 159 .vb 160 TS ts; 161 TSCreate(MPI_Comm, &ts); 162 TSSetType(ts, "my_ts") 163 .ve 164 or at runtime via the option 165 .vb 166 -ts_type my_ts 167 .ve 168 169 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 170 If your function is not being put into a shared library then use TSRegister() instead 171 172 Level: advanced 173 174 .keywords: TS, register 175 .seealso: TSRegisterAll(), TSRegisterDestroy() 176 M*/ 177 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 178 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,0) 179 #else 180 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,d) 181 #endif 182 183 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS,SNES*); 184 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS,KSP*); 185 186 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSView(TS,PetscViewer); 187 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSViewFromOptions(TS,const char[]); 188 189 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS,void *); 190 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS,void **); 191 192 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGCreate(const char[],const char[],int,int,int,int,PetscDrawLG *); 193 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLG(TS,PetscInt,PetscReal,Vec,void *); 194 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGDestroy(PetscDrawLG); 195 196 /*E 197 TSGLType - family of time integration method within the General Linear class 198 199 Level: beginner 200 201 .seealso: TSGLSetType(), TSGLRegister() 202 E*/ 203 #define TSGLType char* 204 205 #define TSGL_DI "di" 206 207 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGLSetType(TS,const TSGLType); 208 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGLRegister(const char[],const char[],const char[],PetscErrorCode(*)(TS)); 209 210 /* 211 PETSc interface to Sundials 212 */ 213 #ifdef PETSC_HAVE_SUNDIALS 214 typedef enum { SUNDIALS_ADAMS=1,SUNDIALS_BDF=2} TSSundialsLmmType; 215 extern const char *TSSundialsLmmTypes[]; 216 typedef enum { SUNDIALS_MODIFIED_GS = 1,SUNDIALS_CLASSICAL_GS = 2 } TSSundialsGramSchmidtType; 217 extern const char *TSSundialsGramSchmidtTypes[]; 218 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetType(TS,TSSundialsLmmType); 219 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetPC(TS,PC*); 220 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetTolerance(TS,PetscReal,PetscReal); 221 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetIterations(TS,PetscInt *,PetscInt *); 222 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGramSchmidtType(TS,TSSundialsGramSchmidtType); 223 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGMRESRestart(TS,PetscInt); 224 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetLinearTolerance(TS,PetscReal); 225 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetExactFinalTime(TS,PetscTruth); 226 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsMonitorInternalSteps(TS,PetscTruth); 227 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetParameters(TS,PetscInt *,long*[],double*[]); 228 #endif 229 230 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRKSetTolerance(TS,PetscReal); 231 232 PETSC_EXTERN_CXX_END 233 #endif 234