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_SUNDIALS "sundials" 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 PETSCTS_DLLEXPORT TS_COOKIE; 49 50 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSInitializePackage(const char[]); 51 52 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSCreate(MPI_Comm,TS*); 53 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS); 54 55 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS,TSProblemType); 56 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS,TSProblemType*); 57 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSet(TS,PetscErrorCode(*)(TS,PetscInt,PetscReal,Vec,void*),void *,PetscErrorCode (*)(void*)); 58 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorCancel(TS); 59 60 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS,const char[]); 61 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS,const char[]); 62 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS,const char *[]); 63 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetFromOptions(TS); 64 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS); 65 66 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS,Vec); 67 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS,Vec*); 68 69 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS,PetscInt,PetscReal); 70 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS,PetscInt*,PetscReal*); 71 72 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorDefault(TS,PetscInt,PetscReal,Vec,void*); 73 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSolution(TS,PetscInt,PetscReal,Vec,void*); 74 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS,PetscInt *,PetscReal*); 75 76 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS,PetscReal,PetscReal); 77 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS,PetscReal*); 78 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS,PetscReal*); 79 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS,PetscInt*); 80 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS,PetscReal); 81 82 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS,PetscErrorCode (*)(TS,PetscReal,Vec,Vec,void*),void*); 83 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSMatrix(TS,Mat,Mat,PetscErrorCode (*)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void*); 84 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetLHSMatrix(TS,Mat,Mat,PetscErrorCode (*)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void*); 85 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS,Mat,Mat,PetscErrorCode (*)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void*); 86 87 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultComputeJacobianColor(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*); 88 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultComputeJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*); 89 90 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSMatrix(TS,Mat*,Mat*,void**); 91 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS,Mat*,Mat*,void**); 92 93 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS, PetscErrorCode (*)(TS)); 94 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetUpdate(TS, PetscErrorCode (*)(TS, PetscReal, PetscReal *)); 95 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS, PetscErrorCode (*)(TS)); 96 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS); 97 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultUpdate(TS, PetscReal, PetscReal *); 98 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS); 99 100 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoSetTimeStep(TS,PetscErrorCode(*)(TS,PetscReal*,void*),void*); 101 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoDefaultTimeStep(TS,PetscReal*,void*); 102 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoComputeTimeStep(TS,PetscReal *); 103 104 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoSetVerifyTimeStep(TS,PetscErrorCode(*)(TS,Vec,void*,PetscReal*,PetscTruth*),void*); 105 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoDefaultVerifyTimeStep(TS,Vec,void*,PetscReal*,PetscTruth*); 106 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoVerifyTimeStep(TS,Vec,PetscReal*,PetscTruth*); 107 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoSetTimeStepIncrement(TS,PetscReal); 108 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSPseudoIncrementDtFromInitialDt(TS); 109 110 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSFunction(TS,PetscReal,Vec,Vec); 111 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*); 112 113 /* Dynamic creation and loading functions */ 114 extern PetscFList TSList; 115 extern PetscTruth TSRegisterAllCalled; 116 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetType(TS,TSType*); 117 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetType(TS,const TSType); 118 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRegister(const char[], const char[], const char[], PetscErrorCode (*)(TS)); 119 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRegisterAll(const char[]); 120 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRegisterDestroy(void); 121 122 /*MC 123 TSRegisterDynamic - Adds a creation method to the TS package. 124 125 Synopsis: 126 PetscErrorCode TSRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(TS)) 127 128 Not Collective 129 130 Input Parameters: 131 + name - The name of a new user-defined creation routine 132 . path - The path (either absolute or relative) of the library containing this routine 133 . func_name - The name of the creation routine 134 - create_func - The creation routine itself 135 136 Notes: 137 TSRegisterDynamic() may be called multiple times to add several user-defined tses. 138 139 If dynamic libraries are used, then the fourth input argument (create_func) is ignored. 140 141 Sample usage: 142 .vb 143 TSRegisterDynamic("my_ts", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyTSCreate", MyTSCreate); 144 .ve 145 146 Then, your ts type can be chosen with the procedural interface via 147 .vb 148 TSCreate(MPI_Comm, TS *); 149 TSSetType(vec, "my_ts") 150 .ve 151 or at runtime via the option 152 .vb 153 -ts_type my_ts 154 .ve 155 156 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 157 If your function is not being put into a shared library then use TSRegister() instead 158 159 Level: advanced 160 161 .keywords: TS, register 162 .seealso: TSRegisterAll(), TSRegisterDestroy() 163 M*/ 164 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 165 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,0) 166 #else 167 #define TSRegisterDynamic(a,b,c,d) TSRegister(a,b,c,d) 168 #endif 169 170 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS,SNES*); 171 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS,KSP*); 172 173 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSView(TS,PetscViewer); 174 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSViewFromOptions(TS,const char[]); 175 176 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS,void *); 177 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS,void **); 178 179 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGCreate(const char[],const char[],int,int,int,int,PetscDrawLG *); 180 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLG(TS,PetscInt,PetscReal,Vec,void *); 181 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGDestroy(PetscDrawLG); 182 183 /* 184 PETSc interface to Sundials 185 */ 186 #ifdef PETSC_HAVE_SUNDIALS 187 #define SUNDIALS_UNMODIFIED_GS SUNDIALS_CLASSICAL_GS 188 typedef enum { SUNDIALS_ADAMS,SUNDIALS_BDF } TSSundialsType; 189 typedef enum { SUNDIALS_MODIFIED_GS = 0,SUNDIALS_CLASSICAL_GS = 1 } TSSundialsGramSchmidtType; 190 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetType(TS,TSSundialsType); 191 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetPC(TS,PC*); 192 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetTolerance(TS,PetscReal,PetscReal); 193 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetIterations(TS,PetscInt *,PetscInt *); 194 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGramSchmidtType(TS,TSSundialsGramSchmidtType); 195 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGMRESRestart(TS,PetscInt); 196 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetLinearTolerance(TS,PetscReal); 197 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetExactFinalTime(TS,PetscTruth); 198 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetParameters(TS,PetscInt *,long int*[],double*[]); 199 #endif 200 201 EXTERN PetscErrorCode PETSCTS_DLLEXPORT TSRKSetTolerance(TS,PetscReal); 202 203 PETSC_EXTERN_CXX_END 204 #endif 205