173f4d377SMatthew Knepley /* $Id: ts.c,v 1.43 2001/09/07 20:12:01 bsmith Exp $ */ 2e090d566SSatish Balay #include "src/ts/tsimpl.h" /*I "petscts.h" I*/ 3d763cef2SBarry Smith 4*d5ba7fb7SMatthew Knepley /* Logging support */ 58ba1e511SMatthew Knepley int TS_COOKIE; 6*d5ba7fb7SMatthew Knepley int TS_Step, TS_PseudoComputeTimeStep, TS_FunctionEval, TS_JacobianEval; 7d405a339SMatthew Knepley 84a2ae208SSatish Balay #undef __FUNCT__ 94a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSJacobian" 10a7a1495cSBarry Smith /*@ 118c385f81SBarry Smith TSComputeRHSJacobian - Computes the Jacobian matrix that has been 12a7a1495cSBarry Smith set with TSSetRHSJacobian(). 13a7a1495cSBarry Smith 14a7a1495cSBarry Smith Collective on TS and Vec 15a7a1495cSBarry Smith 16a7a1495cSBarry Smith Input Parameters: 17a7a1495cSBarry Smith + ts - the SNES context 18a7a1495cSBarry Smith . t - current timestep 19a7a1495cSBarry Smith - x - input vector 20a7a1495cSBarry Smith 21a7a1495cSBarry Smith Output Parameters: 22a7a1495cSBarry Smith + A - Jacobian matrix 23a7a1495cSBarry Smith . B - optional preconditioning matrix 24a7a1495cSBarry Smith - flag - flag indicating matrix structure 25a7a1495cSBarry Smith 26a7a1495cSBarry Smith Notes: 27a7a1495cSBarry Smith Most users should not need to explicitly call this routine, as it 28a7a1495cSBarry Smith is used internally within the nonlinear solvers. 29a7a1495cSBarry Smith 30a7a1495cSBarry Smith See SLESSetOperators() for important information about setting the 31a7a1495cSBarry Smith flag parameter. 32a7a1495cSBarry Smith 33a7a1495cSBarry Smith TSComputeJacobian() is valid only for TS_NONLINEAR 34a7a1495cSBarry Smith 35a7a1495cSBarry Smith Level: developer 36a7a1495cSBarry Smith 37a7a1495cSBarry Smith .keywords: SNES, compute, Jacobian, matrix 38a7a1495cSBarry Smith 39a7a1495cSBarry Smith .seealso: TSSetRHSJacobian(), SLESSetOperators() 40a7a1495cSBarry Smith @*/ 4187828ca2SBarry Smith int TSComputeRHSJacobian(TS ts,PetscReal t,Vec X,Mat *A,Mat *B,MatStructure *flg) 42a7a1495cSBarry Smith { 43a7a1495cSBarry Smith int ierr; 44a7a1495cSBarry Smith 45a7a1495cSBarry Smith PetscFunctionBegin; 46a7a1495cSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 47a7a1495cSBarry Smith PetscValidHeaderSpecific(X,VEC_COOKIE); 48a7a1495cSBarry Smith PetscCheckSameComm(ts,X); 49a7a1495cSBarry Smith if (ts->problem_type != TS_NONLINEAR) { 5029bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"For TS_NONLINEAR only"); 51a7a1495cSBarry Smith } 52000e7ae3SMatthew Knepley if (ts->ops->rhsjacobian) { 53*d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 54a7a1495cSBarry Smith *flg = DIFFERENT_NONZERO_PATTERN; 55a7a1495cSBarry Smith PetscStackPush("TS user Jacobian function"); 56000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr); 57a7a1495cSBarry Smith PetscStackPop; 58*d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 59a7a1495cSBarry Smith /* make sure user returned a correct Jacobian and preconditioner */ 60a7a1495cSBarry Smith PetscValidHeaderSpecific(*A,MAT_COOKIE); 61a7a1495cSBarry Smith PetscValidHeaderSpecific(*B,MAT_COOKIE); 62ef66eb69SBarry Smith } else { 63ef66eb69SBarry Smith ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 64ef66eb69SBarry Smith ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 65ef66eb69SBarry Smith if (*A != *B) { 66ef66eb69SBarry Smith ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 67ef66eb69SBarry Smith ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 68ef66eb69SBarry Smith } 69ef66eb69SBarry Smith } 70a7a1495cSBarry Smith PetscFunctionReturn(0); 71a7a1495cSBarry Smith } 72a7a1495cSBarry Smith 734a2ae208SSatish Balay #undef __FUNCT__ 744a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSFunction" 75d763cef2SBarry Smith /* 76d763cef2SBarry Smith TSComputeRHSFunction - Evaluates the right-hand-side function. 77d763cef2SBarry Smith 78d763cef2SBarry Smith Note: If the user did not provide a function but merely a matrix, 79d763cef2SBarry Smith this routine applies the matrix. 80d763cef2SBarry Smith */ 8187828ca2SBarry Smith int TSComputeRHSFunction(TS ts,PetscReal t,Vec x,Vec y) 82d763cef2SBarry Smith { 83d763cef2SBarry Smith int ierr; 84d763cef2SBarry Smith 85d763cef2SBarry Smith PetscFunctionBegin; 86d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 877c922b88SBarry Smith PetscValidHeader(x); 887c922b88SBarry Smith PetscValidHeader(y); 89d763cef2SBarry Smith 90*d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 91000e7ae3SMatthew Knepley if (ts->ops->rhsfunction) { 92d763cef2SBarry Smith PetscStackPush("TS user right-hand-side function"); 93000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsfunction)(ts,t,x,y,ts->funP);CHKERRQ(ierr); 94d763cef2SBarry Smith PetscStackPop; 957c922b88SBarry Smith } else { 96000e7ae3SMatthew Knepley if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */ 97d763cef2SBarry Smith MatStructure flg; 98d763cef2SBarry Smith PetscStackPush("TS user right-hand-side matrix function"); 99000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->A,&ts->B,&flg,ts->jacP);CHKERRQ(ierr); 100d763cef2SBarry Smith PetscStackPop; 101d763cef2SBarry Smith } 102d763cef2SBarry Smith ierr = MatMult(ts->A,x,y);CHKERRQ(ierr); 1037c922b88SBarry Smith } 104d763cef2SBarry Smith 105d763cef2SBarry Smith /* apply user-provided boundary conditions (only needed if these are time dependent) */ 106d763cef2SBarry Smith ierr = TSComputeRHSBoundaryConditions(ts,t,y);CHKERRQ(ierr); 107*d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 108d763cef2SBarry Smith 109d763cef2SBarry Smith PetscFunctionReturn(0); 110d763cef2SBarry Smith } 111d763cef2SBarry Smith 1124a2ae208SSatish Balay #undef __FUNCT__ 1134a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSFunction" 114d763cef2SBarry Smith /*@C 115d763cef2SBarry Smith TSSetRHSFunction - Sets the routine for evaluating the function, 116d763cef2SBarry Smith F(t,u), where U_t = F(t,u). 117d763cef2SBarry Smith 118d763cef2SBarry Smith Collective on TS 119d763cef2SBarry Smith 120d763cef2SBarry Smith Input Parameters: 121d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 122d763cef2SBarry Smith . f - routine for evaluating the right-hand-side function 123d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 124d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 125d763cef2SBarry Smith 126d763cef2SBarry Smith Calling sequence of func: 12787828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Vec F,void *ctx); 128d763cef2SBarry Smith 129d763cef2SBarry Smith + t - current timestep 130d763cef2SBarry Smith . u - input vector 131d763cef2SBarry Smith . F - function vector 132d763cef2SBarry Smith - ctx - [optional] user-defined function context 133d763cef2SBarry Smith 134d763cef2SBarry Smith Important: 135d763cef2SBarry Smith The user MUST call either this routine or TSSetRHSMatrix(). 136d763cef2SBarry Smith 137d763cef2SBarry Smith Level: beginner 138d763cef2SBarry Smith 139d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, function 140d763cef2SBarry Smith 141d763cef2SBarry Smith .seealso: TSSetRHSMatrix() 142d763cef2SBarry Smith @*/ 14387828ca2SBarry Smith int TSSetRHSFunction(TS ts,int (*f)(TS,PetscReal,Vec,Vec,void*),void *ctx) 144d763cef2SBarry Smith { 145d763cef2SBarry Smith PetscFunctionBegin; 146d763cef2SBarry Smith 147d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 148d763cef2SBarry Smith if (ts->problem_type == TS_LINEAR) { 14929bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Cannot set function for linear problem"); 150d763cef2SBarry Smith } 151000e7ae3SMatthew Knepley ts->ops->rhsfunction = f; 152d763cef2SBarry Smith ts->funP = ctx; 153d763cef2SBarry Smith PetscFunctionReturn(0); 154d763cef2SBarry Smith } 155d763cef2SBarry Smith 1564a2ae208SSatish Balay #undef __FUNCT__ 1574a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSMatrix" 158d763cef2SBarry Smith /*@C 159d763cef2SBarry Smith TSSetRHSMatrix - Sets the function to compute the matrix A, where U_t = A(t) U. 160d763cef2SBarry Smith Also sets the location to store A. 161d763cef2SBarry Smith 162d763cef2SBarry Smith Collective on TS 163d763cef2SBarry Smith 164d763cef2SBarry Smith Input Parameters: 165d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 166d763cef2SBarry Smith . A - matrix 167d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 168d763cef2SBarry Smith . f - the matrix evaluation routine; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 169d763cef2SBarry Smith if A is not a function of t. 170d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 171d763cef2SBarry Smith matrix evaluation routine (may be PETSC_NULL) 172d763cef2SBarry Smith 173d763cef2SBarry Smith Calling sequence of func: 17487828ca2SBarry Smith $ func (TS ts,PetscReal t,Mat *A,Mat *B,int *flag,void *ctx); 175d763cef2SBarry Smith 176d763cef2SBarry Smith + t - current timestep 177d763cef2SBarry Smith . A - matrix A, where U_t = A(t) U 178d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 179d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 180d763cef2SBarry Smith structure (same as flag in SLESSetOperators()) 181d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 182d763cef2SBarry Smith 183d763cef2SBarry Smith Notes: 184d763cef2SBarry Smith See SLESSetOperators() for important information about setting the flag 185d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 186d763cef2SBarry Smith 187d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 188d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 189d763cef2SBarry Smith completely new new matrix structure (not just different matrix elements) 190d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 191d763cef2SBarry Smith throughout the global iterations. 192d763cef2SBarry Smith 193d763cef2SBarry Smith Important: 194d763cef2SBarry Smith The user MUST call either this routine or TSSetRHSFunction(). 195d763cef2SBarry Smith 196d763cef2SBarry Smith Level: beginner 197d763cef2SBarry Smith 198d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, matrix 199d763cef2SBarry Smith 200d763cef2SBarry Smith .seealso: TSSetRHSFunction() 201d763cef2SBarry Smith @*/ 20287828ca2SBarry Smith int TSSetRHSMatrix(TS ts,Mat A,Mat B,int (*f)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void *ctx) 203d763cef2SBarry Smith { 204d763cef2SBarry Smith PetscFunctionBegin; 205d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 206184914b5SBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE); 207184914b5SBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE); 208184914b5SBarry Smith PetscCheckSameComm(ts,A); 209184914b5SBarry Smith PetscCheckSameComm(ts,B); 210d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 21129bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not for nonlinear problems; use TSSetRHSJacobian()"); 212d763cef2SBarry Smith } 213d763cef2SBarry Smith 214000e7ae3SMatthew Knepley ts->ops->rhsmatrix = f; 215d763cef2SBarry Smith ts->jacP = ctx; 216d763cef2SBarry Smith ts->A = A; 217d763cef2SBarry Smith ts->B = B; 218d763cef2SBarry Smith 219d763cef2SBarry Smith PetscFunctionReturn(0); 220d763cef2SBarry Smith } 221d763cef2SBarry Smith 2224a2ae208SSatish Balay #undef __FUNCT__ 2234a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSJacobian" 224d763cef2SBarry Smith /*@C 225d763cef2SBarry Smith TSSetRHSJacobian - Sets the function to compute the Jacobian of F, 226d763cef2SBarry Smith where U_t = F(U,t), as well as the location to store the matrix. 227d763cef2SBarry Smith 228d763cef2SBarry Smith Collective on TS 229d763cef2SBarry Smith 230d763cef2SBarry Smith Input Parameters: 231d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 232d763cef2SBarry Smith . A - Jacobian matrix 233d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 234d763cef2SBarry Smith . f - the Jacobian evaluation routine 235d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 236d763cef2SBarry Smith Jacobian evaluation routine (may be PETSC_NULL) 237d763cef2SBarry Smith 238d763cef2SBarry Smith Calling sequence of func: 23987828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Mat *A,Mat *B,MatStructure *flag,void *ctx); 240d763cef2SBarry Smith 241d763cef2SBarry Smith + t - current timestep 242d763cef2SBarry Smith . u - input vector 243d763cef2SBarry Smith . A - matrix A, where U_t = A(t)u 244d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 245d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 246d763cef2SBarry Smith structure (same as flag in SLESSetOperators()) 247d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 248d763cef2SBarry Smith 249d763cef2SBarry Smith Notes: 250d763cef2SBarry Smith See SLESSetOperators() for important information about setting the flag 251d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 252d763cef2SBarry Smith 253d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 254d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 255d763cef2SBarry Smith completely new new matrix structure (not just different matrix elements) 256d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 257d763cef2SBarry Smith throughout the global iterations. 258d763cef2SBarry Smith 259d763cef2SBarry Smith Level: beginner 260d763cef2SBarry Smith 261d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, Jacobian 262d763cef2SBarry Smith 263d763cef2SBarry Smith .seealso: TSDefaultComputeJacobianColor(), 264d763cef2SBarry Smith SNESDefaultComputeJacobianColor() 265d763cef2SBarry Smith 266d763cef2SBarry Smith @*/ 26787828ca2SBarry Smith int TSSetRHSJacobian(TS ts,Mat A,Mat B,int (*f)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx) 268d763cef2SBarry Smith { 269d763cef2SBarry Smith PetscFunctionBegin; 270d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 271184914b5SBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE); 272184914b5SBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE); 273184914b5SBarry Smith PetscCheckSameComm(ts,A); 274184914b5SBarry Smith PetscCheckSameComm(ts,B); 275d763cef2SBarry Smith if (ts->problem_type != TS_NONLINEAR) { 27629bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not for linear problems; use TSSetRHSMatrix()"); 277d763cef2SBarry Smith } 278d763cef2SBarry Smith 279000e7ae3SMatthew Knepley ts->ops->rhsjacobian = f; 280d763cef2SBarry Smith ts->jacP = ctx; 281d763cef2SBarry Smith ts->A = A; 282d763cef2SBarry Smith ts->B = B; 283d763cef2SBarry Smith PetscFunctionReturn(0); 284d763cef2SBarry Smith } 285d763cef2SBarry Smith 2864a2ae208SSatish Balay #undef __FUNCT__ 2874a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSBoundaryConditions" 288d763cef2SBarry Smith /* 289d763cef2SBarry Smith TSComputeRHSBoundaryConditions - Evaluates the boundary condition function. 290d763cef2SBarry Smith 291d763cef2SBarry Smith Note: If the user did not provide a function but merely a matrix, 292d763cef2SBarry Smith this routine applies the matrix. 293d763cef2SBarry Smith */ 29487828ca2SBarry Smith int TSComputeRHSBoundaryConditions(TS ts,PetscReal t,Vec x) 295d763cef2SBarry Smith { 296d763cef2SBarry Smith int ierr; 297d763cef2SBarry Smith 298d763cef2SBarry Smith PetscFunctionBegin; 299d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 300d763cef2SBarry Smith PetscValidHeader(x); 301184914b5SBarry Smith PetscCheckSameComm(ts,x); 302d763cef2SBarry Smith 303000e7ae3SMatthew Knepley if (ts->ops->rhsbc) { 304d763cef2SBarry Smith PetscStackPush("TS user boundary condition function"); 305000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsbc)(ts,t,x,ts->bcP);CHKERRQ(ierr); 306d763cef2SBarry Smith PetscStackPop; 307d763cef2SBarry Smith PetscFunctionReturn(0); 308d763cef2SBarry Smith } 309d763cef2SBarry Smith 310d763cef2SBarry Smith PetscFunctionReturn(0); 311d763cef2SBarry Smith } 312d763cef2SBarry Smith 3134a2ae208SSatish Balay #undef __FUNCT__ 3144a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSBoundaryConditions" 315d763cef2SBarry Smith /*@C 316d763cef2SBarry Smith TSSetRHSBoundaryConditions - Sets the routine for evaluating the function, 317d763cef2SBarry Smith boundary conditions for the function F. 318d763cef2SBarry Smith 319d763cef2SBarry Smith Collective on TS 320d763cef2SBarry Smith 321d763cef2SBarry Smith Input Parameters: 322d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 323d763cef2SBarry Smith . f - routine for evaluating the boundary condition function 324d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 325d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 326d763cef2SBarry Smith 327d763cef2SBarry Smith Calling sequence of func: 32887828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec F,void *ctx); 329d763cef2SBarry Smith 330d763cef2SBarry Smith + t - current timestep 331d763cef2SBarry Smith . F - function vector 332d763cef2SBarry Smith - ctx - [optional] user-defined function context 333d763cef2SBarry Smith 334d763cef2SBarry Smith Level: intermediate 335d763cef2SBarry Smith 336d763cef2SBarry Smith .keywords: TS, timestep, set, boundary conditions, function 337d763cef2SBarry Smith @*/ 33887828ca2SBarry Smith int TSSetRHSBoundaryConditions(TS ts,int (*f)(TS,PetscReal,Vec,void*),void *ctx) 339d763cef2SBarry Smith { 340d763cef2SBarry Smith PetscFunctionBegin; 341d763cef2SBarry Smith 342d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 343d763cef2SBarry Smith if (ts->problem_type != TS_LINEAR) { 34429bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"For linear problems only"); 345d763cef2SBarry Smith } 346000e7ae3SMatthew Knepley ts->ops->rhsbc = f; 347d763cef2SBarry Smith ts->bcP = ctx; 348d763cef2SBarry Smith PetscFunctionReturn(0); 349d763cef2SBarry Smith } 350d763cef2SBarry Smith 3514a2ae208SSatish Balay #undef __FUNCT__ 3524a2ae208SSatish Balay #define __FUNCT__ "TSView" 3537e2c5f70SBarry Smith /*@C 354d763cef2SBarry Smith TSView - Prints the TS data structure. 355d763cef2SBarry Smith 3564c49b128SBarry Smith Collective on TS 357d763cef2SBarry Smith 358d763cef2SBarry Smith Input Parameters: 359d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 360d763cef2SBarry Smith - viewer - visualization context 361d763cef2SBarry Smith 362d763cef2SBarry Smith Options Database Key: 363d763cef2SBarry Smith . -ts_view - calls TSView() at end of TSStep() 364d763cef2SBarry Smith 365d763cef2SBarry Smith Notes: 366d763cef2SBarry Smith The available visualization contexts include 367b0a32e0cSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 368b0a32e0cSBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 369d763cef2SBarry Smith output where only the first processor opens 370d763cef2SBarry Smith the file. All other processors send their 371d763cef2SBarry Smith data to the first processor to print. 372d763cef2SBarry Smith 373d763cef2SBarry Smith The user can open an alternative visualization context with 374b0a32e0cSBarry Smith PetscViewerASCIIOpen() - output to a specified file. 375d763cef2SBarry Smith 376d763cef2SBarry Smith Level: beginner 377d763cef2SBarry Smith 378d763cef2SBarry Smith .keywords: TS, timestep, view 379d763cef2SBarry Smith 380b0a32e0cSBarry Smith .seealso: PetscViewerASCIIOpen() 381d763cef2SBarry Smith @*/ 382b0a32e0cSBarry Smith int TSView(TS ts,PetscViewer viewer) 383d763cef2SBarry Smith { 384d763cef2SBarry Smith int ierr; 385454a90a3SBarry Smith char *type; 3866831982aSBarry Smith PetscTruth isascii,isstring; 387d763cef2SBarry Smith 388d763cef2SBarry Smith PetscFunctionBegin; 389d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 390b0a32e0cSBarry Smith if (!viewer) viewer = PETSC_VIEWER_STDOUT_(ts->comm); 391b0a32e0cSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE); 3926831982aSBarry Smith PetscCheckSameComm(ts,viewer); 393fd16b177SBarry Smith 394b0a32e0cSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);CHKERRQ(ierr); 395b0a32e0cSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr); 3960f5bd95cSBarry Smith if (isascii) { 397b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"TS Object:\n");CHKERRQ(ierr); 398454a90a3SBarry Smith ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr); 399454a90a3SBarry Smith if (type) { 400b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: %s\n",type);CHKERRQ(ierr); 401184914b5SBarry Smith } else { 402b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: not yet set\n");CHKERRQ(ierr); 403184914b5SBarry Smith } 404000e7ae3SMatthew Knepley if (ts->ops->view) { 405b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 406000e7ae3SMatthew Knepley ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr); 407b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 408d763cef2SBarry Smith } 409b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum steps=%d\n",ts->max_steps);CHKERRQ(ierr); 410b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum time=%g\n",ts->max_time);CHKERRQ(ierr); 411d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 412b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of nonlinear solver iterations=%d\n",ts->nonlinear_its);CHKERRQ(ierr); 413d763cef2SBarry Smith } 414b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of linear solver iterations=%d\n",ts->linear_its);CHKERRQ(ierr); 4150f5bd95cSBarry Smith } else if (isstring) { 416454a90a3SBarry Smith ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr); 417b0a32e0cSBarry Smith ierr = PetscViewerStringSPrintf(viewer," %-7.7s",type);CHKERRQ(ierr); 418d763cef2SBarry Smith } 419b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 420d763cef2SBarry Smith if (ts->sles) {ierr = SLESView(ts->sles,viewer);CHKERRQ(ierr);} 421d763cef2SBarry Smith if (ts->snes) {ierr = SNESView(ts->snes,viewer);CHKERRQ(ierr);} 422b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 423d763cef2SBarry Smith PetscFunctionReturn(0); 424d763cef2SBarry Smith } 425d763cef2SBarry Smith 426d763cef2SBarry Smith 4274a2ae208SSatish Balay #undef __FUNCT__ 4284a2ae208SSatish Balay #define __FUNCT__ "TSSetApplicationContext" 429d763cef2SBarry Smith /*@C 430d763cef2SBarry Smith TSSetApplicationContext - Sets an optional user-defined context for 431d763cef2SBarry Smith the timesteppers. 432d763cef2SBarry Smith 433d763cef2SBarry Smith Collective on TS 434d763cef2SBarry Smith 435d763cef2SBarry Smith Input Parameters: 436d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 437d763cef2SBarry Smith - usrP - optional user context 438d763cef2SBarry Smith 439d763cef2SBarry Smith Level: intermediate 440d763cef2SBarry Smith 441d763cef2SBarry Smith .keywords: TS, timestep, set, application, context 442d763cef2SBarry Smith 443d763cef2SBarry Smith .seealso: TSGetApplicationContext() 444d763cef2SBarry Smith @*/ 445d763cef2SBarry Smith int TSSetApplicationContext(TS ts,void *usrP) 446d763cef2SBarry Smith { 447d763cef2SBarry Smith PetscFunctionBegin; 448d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 449d763cef2SBarry Smith ts->user = usrP; 450d763cef2SBarry Smith PetscFunctionReturn(0); 451d763cef2SBarry Smith } 452d763cef2SBarry Smith 4534a2ae208SSatish Balay #undef __FUNCT__ 4544a2ae208SSatish Balay #define __FUNCT__ "TSGetApplicationContext" 455d763cef2SBarry Smith /*@C 456d763cef2SBarry Smith TSGetApplicationContext - Gets the user-defined context for the 457d763cef2SBarry Smith timestepper. 458d763cef2SBarry Smith 459d763cef2SBarry Smith Not Collective 460d763cef2SBarry Smith 461d763cef2SBarry Smith Input Parameter: 462d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 463d763cef2SBarry Smith 464d763cef2SBarry Smith Output Parameter: 465d763cef2SBarry Smith . usrP - user context 466d763cef2SBarry Smith 467d763cef2SBarry Smith Level: intermediate 468d763cef2SBarry Smith 469d763cef2SBarry Smith .keywords: TS, timestep, get, application, context 470d763cef2SBarry Smith 471d763cef2SBarry Smith .seealso: TSSetApplicationContext() 472d763cef2SBarry Smith @*/ 473d763cef2SBarry Smith int TSGetApplicationContext(TS ts,void **usrP) 474d763cef2SBarry Smith { 475d763cef2SBarry Smith PetscFunctionBegin; 476d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 477d763cef2SBarry Smith *usrP = ts->user; 478d763cef2SBarry Smith PetscFunctionReturn(0); 479d763cef2SBarry Smith } 480d763cef2SBarry Smith 4814a2ae208SSatish Balay #undef __FUNCT__ 4824a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStepNumber" 483d763cef2SBarry Smith /*@ 484d763cef2SBarry Smith TSGetTimeStepNumber - Gets the current number of timesteps. 485d763cef2SBarry Smith 486d763cef2SBarry Smith Not Collective 487d763cef2SBarry Smith 488d763cef2SBarry Smith Input Parameter: 489d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 490d763cef2SBarry Smith 491d763cef2SBarry Smith Output Parameter: 492d763cef2SBarry Smith . iter - number steps so far 493d763cef2SBarry Smith 494d763cef2SBarry Smith Level: intermediate 495d763cef2SBarry Smith 496d763cef2SBarry Smith .keywords: TS, timestep, get, iteration, number 497d763cef2SBarry Smith @*/ 498d763cef2SBarry Smith int TSGetTimeStepNumber(TS ts,int* iter) 499d763cef2SBarry Smith { 500d763cef2SBarry Smith PetscFunctionBegin; 501d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 502d763cef2SBarry Smith *iter = ts->steps; 503d763cef2SBarry Smith PetscFunctionReturn(0); 504d763cef2SBarry Smith } 505d763cef2SBarry Smith 5064a2ae208SSatish Balay #undef __FUNCT__ 5074a2ae208SSatish Balay #define __FUNCT__ "TSSetInitialTimeStep" 508d763cef2SBarry Smith /*@ 509d763cef2SBarry Smith TSSetInitialTimeStep - Sets the initial timestep to be used, 510d763cef2SBarry Smith as well as the initial time. 511d763cef2SBarry Smith 512d763cef2SBarry Smith Collective on TS 513d763cef2SBarry Smith 514d763cef2SBarry Smith Input Parameters: 515d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 516d763cef2SBarry Smith . initial_time - the initial time 517d763cef2SBarry Smith - time_step - the size of the timestep 518d763cef2SBarry Smith 519d763cef2SBarry Smith Level: intermediate 520d763cef2SBarry Smith 521d763cef2SBarry Smith .seealso: TSSetTimeStep(), TSGetTimeStep() 522d763cef2SBarry Smith 523d763cef2SBarry Smith .keywords: TS, set, initial, timestep 524d763cef2SBarry Smith @*/ 52587828ca2SBarry Smith int TSSetInitialTimeStep(TS ts,PetscReal initial_time,PetscReal time_step) 526d763cef2SBarry Smith { 527d763cef2SBarry Smith PetscFunctionBegin; 528d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 529d763cef2SBarry Smith ts->time_step = time_step; 530d763cef2SBarry Smith ts->initial_time_step = time_step; 531d763cef2SBarry Smith ts->ptime = initial_time; 532d763cef2SBarry Smith PetscFunctionReturn(0); 533d763cef2SBarry Smith } 534d763cef2SBarry Smith 5354a2ae208SSatish Balay #undef __FUNCT__ 5364a2ae208SSatish Balay #define __FUNCT__ "TSSetTimeStep" 537d763cef2SBarry Smith /*@ 538d763cef2SBarry Smith TSSetTimeStep - Allows one to reset the timestep at any time, 539d763cef2SBarry Smith useful for simple pseudo-timestepping codes. 540d763cef2SBarry Smith 541d763cef2SBarry Smith Collective on TS 542d763cef2SBarry Smith 543d763cef2SBarry Smith Input Parameters: 544d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 545d763cef2SBarry Smith - time_step - the size of the timestep 546d763cef2SBarry Smith 547d763cef2SBarry Smith Level: intermediate 548d763cef2SBarry Smith 549d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 550d763cef2SBarry Smith 551d763cef2SBarry Smith .keywords: TS, set, timestep 552d763cef2SBarry Smith @*/ 55387828ca2SBarry Smith int TSSetTimeStep(TS ts,PetscReal time_step) 554d763cef2SBarry Smith { 555d763cef2SBarry Smith PetscFunctionBegin; 556d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 557d763cef2SBarry Smith ts->time_step = time_step; 558d763cef2SBarry Smith PetscFunctionReturn(0); 559d763cef2SBarry Smith } 560d763cef2SBarry Smith 5614a2ae208SSatish Balay #undef __FUNCT__ 5624a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStep" 563d763cef2SBarry Smith /*@ 564d763cef2SBarry Smith TSGetTimeStep - Gets the current timestep size. 565d763cef2SBarry Smith 566d763cef2SBarry Smith Not Collective 567d763cef2SBarry Smith 568d763cef2SBarry Smith Input Parameter: 569d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 570d763cef2SBarry Smith 571d763cef2SBarry Smith Output Parameter: 572d763cef2SBarry Smith . dt - the current timestep size 573d763cef2SBarry Smith 574d763cef2SBarry Smith Level: intermediate 575d763cef2SBarry Smith 576d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 577d763cef2SBarry Smith 578d763cef2SBarry Smith .keywords: TS, get, timestep 579d763cef2SBarry Smith @*/ 58087828ca2SBarry Smith int TSGetTimeStep(TS ts,PetscReal* dt) 581d763cef2SBarry Smith { 582d763cef2SBarry Smith PetscFunctionBegin; 583d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 584d763cef2SBarry Smith *dt = ts->time_step; 585d763cef2SBarry Smith PetscFunctionReturn(0); 586d763cef2SBarry Smith } 587d763cef2SBarry Smith 5884a2ae208SSatish Balay #undef __FUNCT__ 5894a2ae208SSatish Balay #define __FUNCT__ "TSGetSolution" 590d763cef2SBarry Smith /*@C 591d763cef2SBarry Smith TSGetSolution - Returns the solution at the present timestep. It 592d763cef2SBarry Smith is valid to call this routine inside the function that you are evaluating 593d763cef2SBarry Smith in order to move to the new timestep. This vector not changed until 594d763cef2SBarry Smith the solution at the next timestep has been calculated. 595d763cef2SBarry Smith 596d763cef2SBarry Smith Not Collective, but Vec returned is parallel if TS is parallel 597d763cef2SBarry Smith 598d763cef2SBarry Smith Input Parameter: 599d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 600d763cef2SBarry Smith 601d763cef2SBarry Smith Output Parameter: 602d763cef2SBarry Smith . v - the vector containing the solution 603d763cef2SBarry Smith 604d763cef2SBarry Smith Level: intermediate 605d763cef2SBarry Smith 606d763cef2SBarry Smith .seealso: TSGetTimeStep() 607d763cef2SBarry Smith 608d763cef2SBarry Smith .keywords: TS, timestep, get, solution 609d763cef2SBarry Smith @*/ 610d763cef2SBarry Smith int TSGetSolution(TS ts,Vec *v) 611d763cef2SBarry Smith { 612d763cef2SBarry Smith PetscFunctionBegin; 613d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 614d763cef2SBarry Smith *v = ts->vec_sol_always; 615d763cef2SBarry Smith PetscFunctionReturn(0); 616d763cef2SBarry Smith } 617d763cef2SBarry Smith 6184a2ae208SSatish Balay #undef __FUNCT__ 6194a2ae208SSatish Balay #define __FUNCT__ "TSPublish_Petsc" 620454a90a3SBarry Smith static int TSPublish_Petsc(PetscObject obj) 621d763cef2SBarry Smith { 622aa482453SBarry Smith #if defined(PETSC_HAVE_AMS) 623454a90a3SBarry Smith TS v = (TS) obj; 624d763cef2SBarry Smith int ierr; 62543d6d2cbSBarry Smith #endif 626d763cef2SBarry Smith 627d763cef2SBarry Smith PetscFunctionBegin; 628d763cef2SBarry Smith 62943d6d2cbSBarry Smith #if defined(PETSC_HAVE_AMS) 630d763cef2SBarry Smith /* if it is already published then return */ 631d763cef2SBarry Smith if (v->amem >=0) PetscFunctionReturn(0); 632d763cef2SBarry Smith 633454a90a3SBarry Smith ierr = PetscObjectPublishBaseBegin(obj);CHKERRQ(ierr); 634d763cef2SBarry Smith ierr = AMS_Memory_add_field((AMS_Memory)v->amem,"Step",&v->steps,1,AMS_INT,AMS_READ, 635d763cef2SBarry Smith AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 636d763cef2SBarry Smith ierr = AMS_Memory_add_field((AMS_Memory)v->amem,"Time",&v->ptime,1,AMS_DOUBLE,AMS_READ, 637d763cef2SBarry Smith AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 638d763cef2SBarry Smith ierr = AMS_Memory_add_field((AMS_Memory)v->amem,"CurrentTimeStep",&v->time_step,1, 639d763cef2SBarry Smith AMS_DOUBLE,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRQ(ierr); 640454a90a3SBarry Smith ierr = PetscObjectPublishBaseEnd(obj);CHKERRQ(ierr); 641d763cef2SBarry Smith #endif 642d763cef2SBarry Smith PetscFunctionReturn(0); 643d763cef2SBarry Smith } 644d763cef2SBarry Smith 645d763cef2SBarry Smith /* -----------------------------------------------------------*/ 646d763cef2SBarry Smith 6474a2ae208SSatish Balay #undef __FUNCT__ 6484a2ae208SSatish Balay #define __FUNCT__ "TSCreate" 649d763cef2SBarry Smith /*@C 650d763cef2SBarry Smith TSCreate - Creates a timestepper context. 651d763cef2SBarry Smith 652d763cef2SBarry Smith Collective on MPI_Comm 653d763cef2SBarry Smith 654d763cef2SBarry Smith Input Parameter: 655d763cef2SBarry Smith + comm - MPI communicator 656d763cef2SBarry Smith - type - One of TS_LINEAR,TS_NONLINEAR 657d763cef2SBarry Smith where these types refer to problems of the forms 658d763cef2SBarry Smith .vb 659d763cef2SBarry Smith U_t = A U 660d763cef2SBarry Smith U_t = A(t) U 661d763cef2SBarry Smith U_t = F(t,U) 662d763cef2SBarry Smith .ve 663d763cef2SBarry Smith 664d763cef2SBarry Smith Output Parameter: 665000e7ae3SMatthew Knepley . ts - the new TS context 666d763cef2SBarry Smith 667d763cef2SBarry Smith Level: beginner 668d763cef2SBarry Smith 669d763cef2SBarry Smith .keywords: TS, timestep, create, context 670d763cef2SBarry Smith 671435da068SBarry Smith .seealso: TSSetUp(), TSStep(), TSDestroy(), TSProblemType, TS 672d763cef2SBarry Smith @*/ 673000e7ae3SMatthew Knepley int TSCreate(MPI_Comm comm, TSProblemType problemtype, TS *ts) 674d763cef2SBarry Smith { 675000e7ae3SMatthew Knepley TS t; 676000e7ae3SMatthew Knepley int ierr; 677d763cef2SBarry Smith 678d763cef2SBarry Smith PetscFunctionBegin; 679000e7ae3SMatthew Knepley PetscValidPointer(ts); 6808ba1e511SMatthew Knepley *ts = PETSC_NULL; 6818ba1e511SMatthew Knepley #ifndef PETSC_USE_DYNAMIC_LIBRARIES 6828ba1e511SMatthew Knepley ierr = TSInitializePackage(PETSC_NULL); CHKERRQ(ierr); 6838ba1e511SMatthew Knepley #endif 6848ba1e511SMatthew Knepley 685000e7ae3SMatthew Knepley PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_COOKIE, -1, "TS", comm, TSDestroy, TSView); 686000e7ae3SMatthew Knepley PetscLogObjectCreate(t); 687000e7ae3SMatthew Knepley PetscLogObjectMemory(t, sizeof(struct _p_TS)); 688000e7ae3SMatthew Knepley ierr = PetscMemzero(t->ops, sizeof(struct _TSOps)); CHKERRQ(ierr); 689000e7ae3SMatthew Knepley t->bops->publish = TSPublish_Petsc; 690000e7ae3SMatthew Knepley t->type_name = PETSC_NULL; 691d763cef2SBarry Smith 692000e7ae3SMatthew Knepley t->problem_type = problemtype; 693000e7ae3SMatthew Knepley t->vec_sol = PETSC_NULL; 694000e7ae3SMatthew Knepley t->vec_sol_always = PETSC_NULL; 695000e7ae3SMatthew Knepley t->numbermonitors = 0; 696000e7ae3SMatthew Knepley t->isGTS = PETSC_FALSE; 6977f5a67d6SMatthew Knepley t->isExplicit = PETSC_NULL; 698000e7ae3SMatthew Knepley t->Iindex = PETSC_NULL; 699000e7ae3SMatthew Knepley t->sles = PETSC_NULL; 700000e7ae3SMatthew Knepley t->A = PETSC_NULL; 701000e7ae3SMatthew Knepley t->B = PETSC_NULL; 702000e7ae3SMatthew Knepley t->snes = PETSC_NULL; 703000e7ae3SMatthew Knepley t->funP = PETSC_NULL; 704000e7ae3SMatthew Knepley t->jacP = PETSC_NULL; 705000e7ae3SMatthew Knepley t->setupcalled = 0; 706000e7ae3SMatthew Knepley t->data = PETSC_NULL; 707000e7ae3SMatthew Knepley t->user = PETSC_NULL; 708000e7ae3SMatthew Knepley t->max_steps = 5000; 709000e7ae3SMatthew Knepley t->max_time = 5.0; 710000e7ae3SMatthew Knepley t->time_step = .1; 711000e7ae3SMatthew Knepley t->time_step_old = t->time_step; 712000e7ae3SMatthew Knepley t->initial_time_step = t->time_step; 713000e7ae3SMatthew Knepley t->steps = 0; 714000e7ae3SMatthew Knepley t->ptime = 0.0; 715000e7ae3SMatthew Knepley t->linear_its = 0; 716000e7ae3SMatthew Knepley t->nonlinear_its = 0; 717000e7ae3SMatthew Knepley t->work = PETSC_NULL; 718000e7ae3SMatthew Knepley t->nwork = 0; 719000e7ae3SMatthew Knepley t->ops->applymatrixbc = TSDefaultSystemMatrixBC; 720000e7ae3SMatthew Knepley t->ops->applyrhsbc = TSDefaultRhsBC; 721000e7ae3SMatthew Knepley t->ops->applysolbc = TSDefaultSolutionBC; 722000e7ae3SMatthew Knepley t->ops->prestep = TSDefaultPreStep; 723000e7ae3SMatthew Knepley t->ops->update = TSDefaultUpdate; 724000e7ae3SMatthew Knepley t->ops->poststep = TSDefaultPostStep; 725000e7ae3SMatthew Knepley t->ops->reform = PETSC_NULL; 726000e7ae3SMatthew Knepley t->ops->reallocate = PETSC_NULL; 727000e7ae3SMatthew Knepley t->ops->serialize = PETSC_NULL; 728000e7ae3SMatthew Knepley 729000e7ae3SMatthew Knepley *ts = t; 730d763cef2SBarry Smith PetscFunctionReturn(0); 731d763cef2SBarry Smith } 732d763cef2SBarry Smith 733d763cef2SBarry Smith /* ----- Routines to initialize and destroy a timestepper ---- */ 734d763cef2SBarry Smith 7354a2ae208SSatish Balay #undef __FUNCT__ 7364a2ae208SSatish Balay #define __FUNCT__ "TSSetUp" 737d763cef2SBarry Smith /*@ 738d763cef2SBarry Smith TSSetUp - Sets up the internal data structures for the later use 739d763cef2SBarry Smith of a timestepper. 740d763cef2SBarry Smith 741d763cef2SBarry Smith Collective on TS 742d763cef2SBarry Smith 743d763cef2SBarry Smith Input Parameter: 744d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 745d763cef2SBarry Smith 746d763cef2SBarry Smith Notes: 747d763cef2SBarry Smith For basic use of the TS solvers the user need not explicitly call 748d763cef2SBarry Smith TSSetUp(), since these actions will automatically occur during 749d763cef2SBarry Smith the call to TSStep(). However, if one wishes to control this 750d763cef2SBarry Smith phase separately, TSSetUp() should be called after TSCreate() 751d763cef2SBarry Smith and optional routines of the form TSSetXXX(), but before TSStep(). 752d763cef2SBarry Smith 753d763cef2SBarry Smith Level: advanced 754d763cef2SBarry Smith 755d763cef2SBarry Smith .keywords: TS, timestep, setup 756d763cef2SBarry Smith 757d763cef2SBarry Smith .seealso: TSCreate(), TSStep(), TSDestroy() 758d763cef2SBarry Smith @*/ 759d763cef2SBarry Smith int TSSetUp(TS ts) 760d763cef2SBarry Smith { 761d763cef2SBarry Smith int ierr; 762d763cef2SBarry Smith 763d763cef2SBarry Smith PetscFunctionBegin; 764d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 76529bbc08cSBarry Smith if (!ts->vec_sol) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call TSSetSolution() first"); 766d763cef2SBarry Smith if (!ts->type_name) { 767d763cef2SBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 768d763cef2SBarry Smith } 769000e7ae3SMatthew Knepley ierr = (*ts->ops->setup)(ts);CHKERRQ(ierr); 770d763cef2SBarry Smith ts->setupcalled = 1; 771d763cef2SBarry Smith PetscFunctionReturn(0); 772d763cef2SBarry Smith } 773d763cef2SBarry Smith 7744a2ae208SSatish Balay #undef __FUNCT__ 7754a2ae208SSatish Balay #define __FUNCT__ "TSDestroy" 776d763cef2SBarry Smith /*@C 777d763cef2SBarry Smith TSDestroy - Destroys the timestepper context that was created 778d763cef2SBarry Smith with TSCreate(). 779d763cef2SBarry Smith 780d763cef2SBarry Smith Collective on TS 781d763cef2SBarry Smith 782d763cef2SBarry Smith Input Parameter: 783d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 784d763cef2SBarry Smith 785d763cef2SBarry Smith Level: beginner 786d763cef2SBarry Smith 787d763cef2SBarry Smith .keywords: TS, timestepper, destroy 788d763cef2SBarry Smith 789d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve() 790d763cef2SBarry Smith @*/ 791d763cef2SBarry Smith int TSDestroy(TS ts) 792d763cef2SBarry Smith { 793329f5518SBarry Smith int ierr,i; 794d763cef2SBarry Smith 795d763cef2SBarry Smith PetscFunctionBegin; 796d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 797d763cef2SBarry Smith if (--ts->refct > 0) PetscFunctionReturn(0); 798d763cef2SBarry Smith 799be0abb6dSBarry Smith /* if memory was published with AMS then destroy it */ 8000f5bd95cSBarry Smith ierr = PetscObjectDepublish(ts);CHKERRQ(ierr); 801be0abb6dSBarry Smith 802d763cef2SBarry Smith if (ts->sles) {ierr = SLESDestroy(ts->sles);CHKERRQ(ierr);} 803d763cef2SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 804000e7ae3SMatthew Knepley ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 805329f5518SBarry Smith for (i=0; i<ts->numbermonitors; i++) { 806329f5518SBarry Smith if (ts->mdestroy[i]) { 807329f5518SBarry Smith ierr = (*ts->mdestroy[i])(ts->monitorcontext[i]);CHKERRQ(ierr); 808329f5518SBarry Smith } 809329f5518SBarry Smith } 810b0a32e0cSBarry Smith PetscLogObjectDestroy((PetscObject)ts); 811d763cef2SBarry Smith PetscHeaderDestroy((PetscObject)ts); 812d763cef2SBarry Smith PetscFunctionReturn(0); 813d763cef2SBarry Smith } 814d763cef2SBarry Smith 8154a2ae208SSatish Balay #undef __FUNCT__ 8164a2ae208SSatish Balay #define __FUNCT__ "TSGetSNES" 817d763cef2SBarry Smith /*@C 818d763cef2SBarry Smith TSGetSNES - Returns the SNES (nonlinear solver) associated with 819d763cef2SBarry Smith a TS (timestepper) context. Valid only for nonlinear problems. 820d763cef2SBarry Smith 821d763cef2SBarry Smith Not Collective, but SNES is parallel if TS is parallel 822d763cef2SBarry Smith 823d763cef2SBarry Smith Input Parameter: 824d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 825d763cef2SBarry Smith 826d763cef2SBarry Smith Output Parameter: 827d763cef2SBarry Smith . snes - the nonlinear solver context 828d763cef2SBarry Smith 829d763cef2SBarry Smith Notes: 830d763cef2SBarry Smith The user can then directly manipulate the SNES context to set various 831d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 832d763cef2SBarry Smith SLES, KSP, and PC contexts as well. 833d763cef2SBarry Smith 834d763cef2SBarry Smith TSGetSNES() does not work for integrators that do not use SNES; in 835d763cef2SBarry Smith this case TSGetSNES() returns PETSC_NULL in snes. 836d763cef2SBarry Smith 837d763cef2SBarry Smith Level: beginner 838d763cef2SBarry Smith 839d763cef2SBarry Smith .keywords: timestep, get, SNES 840d763cef2SBarry Smith @*/ 841d763cef2SBarry Smith int TSGetSNES(TS ts,SNES *snes) 842d763cef2SBarry Smith { 843d763cef2SBarry Smith PetscFunctionBegin; 844d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 84529bbc08cSBarry Smith if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Nonlinear only; use TSGetSLES()"); 846d763cef2SBarry Smith *snes = ts->snes; 847d763cef2SBarry Smith PetscFunctionReturn(0); 848d763cef2SBarry Smith } 849d763cef2SBarry Smith 8504a2ae208SSatish Balay #undef __FUNCT__ 8514a2ae208SSatish Balay #define __FUNCT__ "TSGetSLES" 852d763cef2SBarry Smith /*@C 853d763cef2SBarry Smith TSGetSLES - Returns the SLES (linear solver) associated with 854d763cef2SBarry Smith a TS (timestepper) context. 855d763cef2SBarry Smith 856d763cef2SBarry Smith Not Collective, but SLES is parallel if TS is parallel 857d763cef2SBarry Smith 858d763cef2SBarry Smith Input Parameter: 859d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 860d763cef2SBarry Smith 861d763cef2SBarry Smith Output Parameter: 862d763cef2SBarry Smith . sles - the nonlinear solver context 863d763cef2SBarry Smith 864d763cef2SBarry Smith Notes: 865d763cef2SBarry Smith The user can then directly manipulate the SLES context to set various 866d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 867d763cef2SBarry Smith KSP and PC contexts as well. 868d763cef2SBarry Smith 869d763cef2SBarry Smith TSGetSLES() does not work for integrators that do not use SLES; 870d763cef2SBarry Smith in this case TSGetSLES() returns PETSC_NULL in sles. 871d763cef2SBarry Smith 872d763cef2SBarry Smith Level: beginner 873d763cef2SBarry Smith 874d763cef2SBarry Smith .keywords: timestep, get, SLES 875d763cef2SBarry Smith @*/ 876d763cef2SBarry Smith int TSGetSLES(TS ts,SLES *sles) 877d763cef2SBarry Smith { 878d763cef2SBarry Smith PetscFunctionBegin; 879d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 88029bbc08cSBarry Smith if (ts->problem_type != TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Linear only; use TSGetSNES()"); 881d763cef2SBarry Smith *sles = ts->sles; 882d763cef2SBarry Smith PetscFunctionReturn(0); 883d763cef2SBarry Smith } 884d763cef2SBarry Smith 885d763cef2SBarry Smith /* ----------- Routines to set solver parameters ---------- */ 886d763cef2SBarry Smith 8874a2ae208SSatish Balay #undef __FUNCT__ 8884a2ae208SSatish Balay #define __FUNCT__ "TSSetDuration" 889d763cef2SBarry Smith /*@ 890d763cef2SBarry Smith TSSetDuration - Sets the maximum number of timesteps to use and 891d763cef2SBarry Smith maximum time for iteration. 892d763cef2SBarry Smith 893d763cef2SBarry Smith Collective on TS 894d763cef2SBarry Smith 895d763cef2SBarry Smith Input Parameters: 896d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 897d763cef2SBarry Smith . maxsteps - maximum number of iterations to use 898d763cef2SBarry Smith - maxtime - final time to iterate to 899d763cef2SBarry Smith 900d763cef2SBarry Smith Options Database Keys: 901d763cef2SBarry Smith . -ts_max_steps <maxsteps> - Sets maxsteps 902d763cef2SBarry Smith . -ts_max_time <maxtime> - Sets maxtime 903d763cef2SBarry Smith 904d763cef2SBarry Smith Notes: 905d763cef2SBarry Smith The default maximum number of iterations is 5000. Default time is 5.0 906d763cef2SBarry Smith 907d763cef2SBarry Smith Level: intermediate 908d763cef2SBarry Smith 909d763cef2SBarry Smith .keywords: TS, timestep, set, maximum, iterations 910d763cef2SBarry Smith @*/ 91187828ca2SBarry Smith int TSSetDuration(TS ts,int maxsteps,PetscReal maxtime) 912d763cef2SBarry Smith { 913d763cef2SBarry Smith PetscFunctionBegin; 914d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 915d763cef2SBarry Smith ts->max_steps = maxsteps; 916d763cef2SBarry Smith ts->max_time = maxtime; 917d763cef2SBarry Smith PetscFunctionReturn(0); 918d763cef2SBarry Smith } 919d763cef2SBarry Smith 9204a2ae208SSatish Balay #undef __FUNCT__ 9214a2ae208SSatish Balay #define __FUNCT__ "TSSetSolution" 922d763cef2SBarry Smith /*@ 923d763cef2SBarry Smith TSSetSolution - Sets the initial solution vector 924d763cef2SBarry Smith for use by the TS routines. 925d763cef2SBarry Smith 926d763cef2SBarry Smith Collective on TS and Vec 927d763cef2SBarry Smith 928d763cef2SBarry Smith Input Parameters: 929d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 930d763cef2SBarry Smith - x - the solution vector 931d763cef2SBarry Smith 932d763cef2SBarry Smith Level: beginner 933d763cef2SBarry Smith 934d763cef2SBarry Smith .keywords: TS, timestep, set, solution, initial conditions 935d763cef2SBarry Smith @*/ 936d763cef2SBarry Smith int TSSetSolution(TS ts,Vec x) 937d763cef2SBarry Smith { 938d763cef2SBarry Smith PetscFunctionBegin; 939d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 940d763cef2SBarry Smith ts->vec_sol = ts->vec_sol_always = x; 941d763cef2SBarry Smith PetscFunctionReturn(0); 942d763cef2SBarry Smith } 943d763cef2SBarry Smith 944e74ef692SMatthew Knepley #undef __FUNCT__ 945e74ef692SMatthew Knepley #define __FUNCT__ "TSSetRhsBC" 946000e7ae3SMatthew Knepley /*@ 947000e7ae3SMatthew Knepley TSSetRhsBC - Sets the function which applies boundary conditions 948000e7ae3SMatthew Knepley to the Rhs of each system. 949000e7ae3SMatthew Knepley 950000e7ae3SMatthew Knepley Collective on TS 951000e7ae3SMatthew Knepley 952000e7ae3SMatthew Knepley Input Parameters: 953000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 954000e7ae3SMatthew Knepley - func - The function 955000e7ae3SMatthew Knepley 956000e7ae3SMatthew Knepley Calling sequence of func: 957000e7ae3SMatthew Knepley . func (TS ts, Vec rhs, void *ctx); 958000e7ae3SMatthew Knepley 959000e7ae3SMatthew Knepley + rhs - The current rhs vector 960000e7ae3SMatthew Knepley - ctx - The user-context 961000e7ae3SMatthew Knepley 962000e7ae3SMatthew Knepley Level: intermediate 963000e7ae3SMatthew Knepley 964000e7ae3SMatthew Knepley .keywords: TS, Rhs, boundary conditions 965000e7ae3SMatthew Knepley @*/ 966000e7ae3SMatthew Knepley int TSSetRhsBC(TS ts, int (*func)(TS, Vec, void *)) 967000e7ae3SMatthew Knepley { 968000e7ae3SMatthew Knepley PetscFunctionBegin; 969000e7ae3SMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 970000e7ae3SMatthew Knepley ts->ops->applyrhsbc = func; 971000e7ae3SMatthew Knepley PetscFunctionReturn(0); 972000e7ae3SMatthew Knepley } 973000e7ae3SMatthew Knepley 974e74ef692SMatthew Knepley #undef __FUNCT__ 975e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultRhsBC" 976000e7ae3SMatthew Knepley /*@ 977000e7ae3SMatthew Knepley TSDefaultRhsBC - The default boundary condition function which does nothing. 978000e7ae3SMatthew Knepley 979000e7ae3SMatthew Knepley Collective on TS 980000e7ae3SMatthew Knepley 981000e7ae3SMatthew Knepley Input Parameters: 982000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 983000e7ae3SMatthew Knepley . rhs - The Rhs 984000e7ae3SMatthew Knepley - ctx - The user-context 985000e7ae3SMatthew Knepley 986000e7ae3SMatthew Knepley Level: developer 987000e7ae3SMatthew Knepley 988000e7ae3SMatthew Knepley .keywords: TS, Rhs, boundary conditions 989000e7ae3SMatthew Knepley @*/ 990000e7ae3SMatthew Knepley int TSDefaultRhsBC(TS ts, Vec rhs, void *ctx) 991000e7ae3SMatthew Knepley { 992000e7ae3SMatthew Knepley PetscFunctionBegin; 993000e7ae3SMatthew Knepley PetscFunctionReturn(0); 994000e7ae3SMatthew Knepley } 995000e7ae3SMatthew Knepley 996e74ef692SMatthew Knepley #undef __FUNCT__ 997e74ef692SMatthew Knepley #define __FUNCT__ "TSSetSystemMatrixBC" 998000e7ae3SMatthew Knepley /*@ 999000e7ae3SMatthew Knepley TSSetSystemMatrixBC - Sets the function which applies boundary conditions 1000000e7ae3SMatthew Knepley to the system matrix and preconditioner of each system. 1001000e7ae3SMatthew Knepley 1002000e7ae3SMatthew Knepley Collective on TS 1003000e7ae3SMatthew Knepley 1004000e7ae3SMatthew Knepley Input Parameters: 1005000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1006000e7ae3SMatthew Knepley - func - The function 1007000e7ae3SMatthew Knepley 1008000e7ae3SMatthew Knepley Calling sequence of func: 1009000e7ae3SMatthew Knepley . func (TS ts, Mat A, Mat B, void *ctx); 1010000e7ae3SMatthew Knepley 1011000e7ae3SMatthew Knepley + A - The current system matrix 1012000e7ae3SMatthew Knepley . B - The current preconditioner 1013000e7ae3SMatthew Knepley - ctx - The user-context 1014000e7ae3SMatthew Knepley 1015000e7ae3SMatthew Knepley Level: intermediate 1016000e7ae3SMatthew Knepley 1017000e7ae3SMatthew Knepley .keywords: TS, System matrix, boundary conditions 1018000e7ae3SMatthew Knepley @*/ 1019000e7ae3SMatthew Knepley int TSSetSystemMatrixBC(TS ts, int (*func)(TS, Mat, Mat, void *)) 1020000e7ae3SMatthew Knepley { 1021000e7ae3SMatthew Knepley PetscFunctionBegin; 1022000e7ae3SMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 1023000e7ae3SMatthew Knepley ts->ops->applymatrixbc = func; 1024000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1025000e7ae3SMatthew Knepley } 1026000e7ae3SMatthew Knepley 1027e74ef692SMatthew Knepley #undef __FUNCT__ 1028e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultSystemMatrixBC" 1029000e7ae3SMatthew Knepley /*@ 1030000e7ae3SMatthew Knepley TSDefaultSystemMatrixBC - The default boundary condition function which 1031000e7ae3SMatthew Knepley does nothing. 1032000e7ae3SMatthew Knepley 1033000e7ae3SMatthew Knepley Collective on TS 1034000e7ae3SMatthew Knepley 1035000e7ae3SMatthew Knepley Input Parameters: 1036000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1037000e7ae3SMatthew Knepley . A - The system matrix 1038000e7ae3SMatthew Knepley . B - The preconditioner 1039000e7ae3SMatthew Knepley - ctx - The user-context 1040000e7ae3SMatthew Knepley 1041000e7ae3SMatthew Knepley Level: developer 1042000e7ae3SMatthew Knepley 1043000e7ae3SMatthew Knepley .keywords: TS, System matrix, boundary conditions 1044000e7ae3SMatthew Knepley @*/ 1045000e7ae3SMatthew Knepley int TSDefaultSystemMatrixBC(TS ts, Mat A, Mat B, void *ctx) 1046000e7ae3SMatthew Knepley { 1047000e7ae3SMatthew Knepley PetscFunctionBegin; 1048000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1049000e7ae3SMatthew Knepley } 1050000e7ae3SMatthew Knepley 1051e74ef692SMatthew Knepley #undef __FUNCT__ 1052e74ef692SMatthew Knepley #define __FUNCT__ "TSSetSolutionBC" 1053000e7ae3SMatthew Knepley /*@ 1054000e7ae3SMatthew Knepley TSSetSolutionBC - Sets the function which applies boundary conditions 1055000e7ae3SMatthew Knepley to the solution of each system. This is necessary in nonlinear systems 1056000e7ae3SMatthew Knepley which time dependent boundary conditions. 1057000e7ae3SMatthew Knepley 1058000e7ae3SMatthew Knepley Collective on TS 1059000e7ae3SMatthew Knepley 1060000e7ae3SMatthew Knepley Input Parameters: 1061000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1062000e7ae3SMatthew Knepley - func - The function 1063000e7ae3SMatthew Knepley 1064000e7ae3SMatthew Knepley Calling sequence of func: 1065000e7ae3SMatthew Knepley . func (TS ts, Vec rsol, void *ctx); 1066000e7ae3SMatthew Knepley 1067000e7ae3SMatthew Knepley + sol - The current solution vector 1068000e7ae3SMatthew Knepley - ctx - The user-context 1069000e7ae3SMatthew Knepley 1070000e7ae3SMatthew Knepley Level: intermediate 1071000e7ae3SMatthew Knepley 1072000e7ae3SMatthew Knepley .keywords: TS, solution, boundary conditions 1073000e7ae3SMatthew Knepley @*/ 1074000e7ae3SMatthew Knepley int TSSetSolutionBC(TS ts, int (*func)(TS, Vec, void *)) 1075000e7ae3SMatthew Knepley { 1076000e7ae3SMatthew Knepley PetscFunctionBegin; 1077000e7ae3SMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 1078000e7ae3SMatthew Knepley ts->ops->applysolbc = func; 1079000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1080000e7ae3SMatthew Knepley } 1081000e7ae3SMatthew Knepley 1082e74ef692SMatthew Knepley #undef __FUNCT__ 1083e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultSolutionBC" 1084000e7ae3SMatthew Knepley /*@ 1085000e7ae3SMatthew Knepley TSDefaultSolutionBC - The default boundary condition function which 1086000e7ae3SMatthew Knepley does nothing. 1087000e7ae3SMatthew Knepley 1088000e7ae3SMatthew Knepley Collective on TS 1089000e7ae3SMatthew Knepley 1090000e7ae3SMatthew Knepley Input Parameters: 1091000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1092000e7ae3SMatthew Knepley . sol - The solution 1093000e7ae3SMatthew Knepley - ctx - The user-context 1094000e7ae3SMatthew Knepley 1095000e7ae3SMatthew Knepley Level: developer 1096000e7ae3SMatthew Knepley 1097000e7ae3SMatthew Knepley .keywords: TS, solution, boundary conditions 1098000e7ae3SMatthew Knepley @*/ 1099000e7ae3SMatthew Knepley int TSDefaultSolutionBC(TS ts, Vec sol, void *ctx) 1100000e7ae3SMatthew Knepley { 1101000e7ae3SMatthew Knepley PetscFunctionBegin; 1102000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1103000e7ae3SMatthew Knepley } 1104000e7ae3SMatthew Knepley 1105e74ef692SMatthew Knepley #undef __FUNCT__ 1106e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPreStep" 1107000e7ae3SMatthew Knepley /*@ 1108000e7ae3SMatthew Knepley TSSetPreStep - Sets the general-purpose function 1109000e7ae3SMatthew Knepley called once at the beginning of time stepping. 1110000e7ae3SMatthew Knepley 1111000e7ae3SMatthew Knepley Collective on TS 1112000e7ae3SMatthew Knepley 1113000e7ae3SMatthew Knepley Input Parameters: 1114000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1115000e7ae3SMatthew Knepley - func - The function 1116000e7ae3SMatthew Knepley 1117000e7ae3SMatthew Knepley Calling sequence of func: 1118000e7ae3SMatthew Knepley . func (TS ts); 1119000e7ae3SMatthew Knepley 1120000e7ae3SMatthew Knepley Level: intermediate 1121000e7ae3SMatthew Knepley 1122000e7ae3SMatthew Knepley .keywords: TS, timestep 1123000e7ae3SMatthew Knepley @*/ 1124000e7ae3SMatthew Knepley int TSSetPreStep(TS ts, int (*func)(TS)) 1125000e7ae3SMatthew Knepley { 1126000e7ae3SMatthew Knepley PetscFunctionBegin; 1127000e7ae3SMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 1128000e7ae3SMatthew Knepley ts->ops->prestep = func; 1129000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1130000e7ae3SMatthew Knepley } 1131000e7ae3SMatthew Knepley 1132e74ef692SMatthew Knepley #undef __FUNCT__ 1133e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPreStep" 1134000e7ae3SMatthew Knepley /*@ 1135000e7ae3SMatthew Knepley TSDefaultPreStep - The default pre-stepping function which does nothing. 1136000e7ae3SMatthew Knepley 1137000e7ae3SMatthew Knepley Collective on TS 1138000e7ae3SMatthew Knepley 1139000e7ae3SMatthew Knepley Input Parameters: 1140000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1141000e7ae3SMatthew Knepley 1142000e7ae3SMatthew Knepley Level: developer 1143000e7ae3SMatthew Knepley 1144000e7ae3SMatthew Knepley .keywords: TS, timestep 1145000e7ae3SMatthew Knepley @*/ 1146000e7ae3SMatthew Knepley int TSDefaultPreStep(TS ts) 1147000e7ae3SMatthew Knepley { 1148000e7ae3SMatthew Knepley PetscFunctionBegin; 1149000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1150000e7ae3SMatthew Knepley } 1151000e7ae3SMatthew Knepley 1152e74ef692SMatthew Knepley #undef __FUNCT__ 1153e74ef692SMatthew Knepley #define __FUNCT__ "TSSetUpdate" 1154000e7ae3SMatthew Knepley /*@ 1155000e7ae3SMatthew Knepley TSSetUpdate - Sets the general-purpose update function called 1156000e7ae3SMatthew Knepley at the beginning of every time step. This function can change 1157000e7ae3SMatthew Knepley the time step. 1158000e7ae3SMatthew Knepley 1159000e7ae3SMatthew Knepley Collective on TS 1160000e7ae3SMatthew Knepley 1161000e7ae3SMatthew Knepley Input Parameters: 1162000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1163000e7ae3SMatthew Knepley - func - The function 1164000e7ae3SMatthew Knepley 1165000e7ae3SMatthew Knepley Calling sequence of func: 1166000e7ae3SMatthew Knepley . func (TS ts, double t, double *dt); 1167000e7ae3SMatthew Knepley 1168000e7ae3SMatthew Knepley + t - The current time 1169000e7ae3SMatthew Knepley - dt - The current time step 1170000e7ae3SMatthew Knepley 1171000e7ae3SMatthew Knepley Level: intermediate 1172000e7ae3SMatthew Knepley 1173000e7ae3SMatthew Knepley .keywords: TS, update, timestep 1174000e7ae3SMatthew Knepley @*/ 1175000e7ae3SMatthew Knepley int TSSetUpdate(TS ts, int (*func)(TS, double, double *)) 1176000e7ae3SMatthew Knepley { 1177000e7ae3SMatthew Knepley PetscFunctionBegin; 1178000e7ae3SMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 1179000e7ae3SMatthew Knepley ts->ops->update = func; 1180000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1181000e7ae3SMatthew Knepley } 1182000e7ae3SMatthew Knepley 1183e74ef692SMatthew Knepley #undef __FUNCT__ 1184e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultUpdate" 1185000e7ae3SMatthew Knepley /*@ 1186000e7ae3SMatthew Knepley TSDefaultUpdate - The default update function which does nothing. 1187000e7ae3SMatthew Knepley 1188000e7ae3SMatthew Knepley Collective on TS 1189000e7ae3SMatthew Knepley 1190000e7ae3SMatthew Knepley Input Parameters: 1191000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1192000e7ae3SMatthew Knepley - t - The current time 1193000e7ae3SMatthew Knepley 1194000e7ae3SMatthew Knepley Output Parameters: 1195000e7ae3SMatthew Knepley . dt - The current time step 1196000e7ae3SMatthew Knepley 1197000e7ae3SMatthew Knepley Level: developer 1198000e7ae3SMatthew Knepley 1199000e7ae3SMatthew Knepley .keywords: TS, update, timestep 1200000e7ae3SMatthew Knepley @*/ 1201000e7ae3SMatthew Knepley int TSDefaultUpdate(TS ts, double t, double *dt) 1202000e7ae3SMatthew Knepley { 1203000e7ae3SMatthew Knepley PetscFunctionBegin; 1204000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1205000e7ae3SMatthew Knepley } 1206000e7ae3SMatthew Knepley 1207e74ef692SMatthew Knepley #undef __FUNCT__ 1208e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPostStep" 1209000e7ae3SMatthew Knepley /*@ 1210000e7ae3SMatthew Knepley TSSetPostStep - Sets the general-purpose function 1211000e7ae3SMatthew Knepley called once at the end of time stepping. 1212000e7ae3SMatthew Knepley 1213000e7ae3SMatthew Knepley Collective on TS 1214000e7ae3SMatthew Knepley 1215000e7ae3SMatthew Knepley Input Parameters: 1216000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1217000e7ae3SMatthew Knepley - func - The function 1218000e7ae3SMatthew Knepley 1219000e7ae3SMatthew Knepley Calling sequence of func: 1220000e7ae3SMatthew Knepley . func (TS ts); 1221000e7ae3SMatthew Knepley 1222000e7ae3SMatthew Knepley Level: intermediate 1223000e7ae3SMatthew Knepley 1224000e7ae3SMatthew Knepley .keywords: TS, timestep 1225000e7ae3SMatthew Knepley @*/ 1226000e7ae3SMatthew Knepley int TSSetPostStep(TS ts, int (*func)(TS)) 1227000e7ae3SMatthew Knepley { 1228000e7ae3SMatthew Knepley PetscFunctionBegin; 1229000e7ae3SMatthew Knepley PetscValidHeaderSpecific(ts, TS_COOKIE); 1230000e7ae3SMatthew Knepley ts->ops->poststep = func; 1231000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1232000e7ae3SMatthew Knepley } 1233000e7ae3SMatthew Knepley 1234e74ef692SMatthew Knepley #undef __FUNCT__ 1235e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPostStep" 1236000e7ae3SMatthew Knepley /*@ 1237000e7ae3SMatthew Knepley TSDefaultPostStep - The default post-stepping function which does nothing. 1238000e7ae3SMatthew Knepley 1239000e7ae3SMatthew Knepley Collective on TS 1240000e7ae3SMatthew Knepley 1241000e7ae3SMatthew Knepley Input Parameters: 1242000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1243000e7ae3SMatthew Knepley 1244000e7ae3SMatthew Knepley Level: developer 1245000e7ae3SMatthew Knepley 1246000e7ae3SMatthew Knepley .keywords: TS, timestep 1247000e7ae3SMatthew Knepley @*/ 1248000e7ae3SMatthew Knepley int TSDefaultPostStep(TS ts) 1249000e7ae3SMatthew Knepley { 1250000e7ae3SMatthew Knepley PetscFunctionBegin; 1251000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1252000e7ae3SMatthew Knepley } 1253000e7ae3SMatthew Knepley 1254d763cef2SBarry Smith /* ------------ Routines to set performance monitoring options ----------- */ 1255d763cef2SBarry Smith 12564a2ae208SSatish Balay #undef __FUNCT__ 12574a2ae208SSatish Balay #define __FUNCT__ "TSSetMonitor" 1258d763cef2SBarry Smith /*@C 1259d763cef2SBarry Smith TSSetMonitor - Sets an ADDITIONAL function that is to be used at every 1260d763cef2SBarry Smith timestep to display the iteration's progress. 1261d763cef2SBarry Smith 1262d763cef2SBarry Smith Collective on TS 1263d763cef2SBarry Smith 1264d763cef2SBarry Smith Input Parameters: 1265d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1266d763cef2SBarry Smith . func - monitoring routine 1267329f5518SBarry Smith . mctx - [optional] user-defined context for private data for the 1268b3006f0bSLois Curfman McInnes monitor routine (use PETSC_NULL if no context is desired) 1269b3006f0bSLois Curfman McInnes - monitordestroy - [optional] routine that frees monitor context 1270b3006f0bSLois Curfman McInnes (may be PETSC_NULL) 1271d763cef2SBarry Smith 1272d763cef2SBarry Smith Calling sequence of func: 127387828ca2SBarry Smith $ int func(TS ts,int steps,PetscReal time,Vec x,void *mctx) 1274d763cef2SBarry Smith 1275d763cef2SBarry Smith + ts - the TS context 1276d763cef2SBarry Smith . steps - iteration number 12771f06c33eSBarry Smith . time - current time 1278d763cef2SBarry Smith . x - current iterate 1279d763cef2SBarry Smith - mctx - [optional] monitoring context 1280d763cef2SBarry Smith 1281d763cef2SBarry Smith Notes: 1282d763cef2SBarry Smith This routine adds an additional monitor to the list of monitors that 1283d763cef2SBarry Smith already has been loaded. 1284d763cef2SBarry Smith 1285d763cef2SBarry Smith Level: intermediate 1286d763cef2SBarry Smith 1287d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1288d763cef2SBarry Smith 1289d763cef2SBarry Smith .seealso: TSDefaultMonitor(), TSClearMonitor() 1290d763cef2SBarry Smith @*/ 129187828ca2SBarry Smith int TSSetMonitor(TS ts,int (*monitor)(TS,int,PetscReal,Vec,void*),void *mctx,int (*mdestroy)(void*)) 1292d763cef2SBarry Smith { 1293d763cef2SBarry Smith PetscFunctionBegin; 1294d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1295d763cef2SBarry Smith if (ts->numbermonitors >= MAXTSMONITORS) { 129629bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many monitors set"); 1297d763cef2SBarry Smith } 1298d763cef2SBarry Smith ts->monitor[ts->numbermonitors] = monitor; 1299329f5518SBarry Smith ts->mdestroy[ts->numbermonitors] = mdestroy; 1300d763cef2SBarry Smith ts->monitorcontext[ts->numbermonitors++] = (void*)mctx; 1301d763cef2SBarry Smith PetscFunctionReturn(0); 1302d763cef2SBarry Smith } 1303d763cef2SBarry Smith 13044a2ae208SSatish Balay #undef __FUNCT__ 13054a2ae208SSatish Balay #define __FUNCT__ "TSClearMonitor" 1306d763cef2SBarry Smith /*@C 1307d763cef2SBarry Smith TSClearMonitor - Clears all the monitors that have been set on a time-step object. 1308d763cef2SBarry Smith 1309d763cef2SBarry Smith Collective on TS 1310d763cef2SBarry Smith 1311d763cef2SBarry Smith Input Parameters: 1312d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1313d763cef2SBarry Smith 1314d763cef2SBarry Smith Notes: 1315d763cef2SBarry Smith There is no way to remove a single, specific monitor. 1316d763cef2SBarry Smith 1317d763cef2SBarry Smith Level: intermediate 1318d763cef2SBarry Smith 1319d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1320d763cef2SBarry Smith 1321d763cef2SBarry Smith .seealso: TSDefaultMonitor(), TSSetMonitor() 1322d763cef2SBarry Smith @*/ 1323d763cef2SBarry Smith int TSClearMonitor(TS ts) 1324d763cef2SBarry Smith { 1325d763cef2SBarry Smith PetscFunctionBegin; 1326d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1327d763cef2SBarry Smith ts->numbermonitors = 0; 1328d763cef2SBarry Smith PetscFunctionReturn(0); 1329d763cef2SBarry Smith } 1330d763cef2SBarry Smith 13314a2ae208SSatish Balay #undef __FUNCT__ 13324a2ae208SSatish Balay #define __FUNCT__ "TSDefaultMonitor" 133387828ca2SBarry Smith int TSDefaultMonitor(TS ts,int step,PetscReal ptime,Vec v,void *ctx) 1334d763cef2SBarry Smith { 1335d132466eSBarry Smith int ierr; 1336d132466eSBarry Smith 1337d763cef2SBarry Smith PetscFunctionBegin; 1338142b95e3SSatish Balay ierr = PetscPrintf(ts->comm,"timestep %d dt %g time %g\n",step,ts->time_step,ptime);CHKERRQ(ierr); 1339d763cef2SBarry Smith PetscFunctionReturn(0); 1340d763cef2SBarry Smith } 1341d763cef2SBarry Smith 13424a2ae208SSatish Balay #undef __FUNCT__ 13434a2ae208SSatish Balay #define __FUNCT__ "TSStep" 1344d763cef2SBarry Smith /*@ 1345d763cef2SBarry Smith TSStep - Steps the requested number of timesteps. 1346d763cef2SBarry Smith 1347d763cef2SBarry Smith Collective on TS 1348d763cef2SBarry Smith 1349d763cef2SBarry Smith Input Parameter: 1350d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1351d763cef2SBarry Smith 1352d763cef2SBarry Smith Output Parameters: 1353d763cef2SBarry Smith + steps - number of iterations until termination 1354142b95e3SSatish Balay - ptime - time until termination 1355d763cef2SBarry Smith 1356d763cef2SBarry Smith Level: beginner 1357d763cef2SBarry Smith 1358d763cef2SBarry Smith .keywords: TS, timestep, solve 1359d763cef2SBarry Smith 1360d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSDestroy() 1361d763cef2SBarry Smith @*/ 136287828ca2SBarry Smith int TSStep(TS ts,int *steps,PetscReal *ptime) 1363d763cef2SBarry Smith { 1364d405a339SMatthew Knepley PetscTruth opt; 1365f1af5d2fSBarry Smith int ierr; 1366d763cef2SBarry Smith 1367d763cef2SBarry Smith PetscFunctionBegin; 1368d763cef2SBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE); 1369d405a339SMatthew Knepley if (!ts->setupcalled) { 1370d405a339SMatthew Knepley ierr = TSSetUp(ts); CHKERRQ(ierr); 1371d405a339SMatthew Knepley } 1372d405a339SMatthew Knepley 1373*d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_Step, ts, 0, 0, 0); CHKERRQ(ierr); 1374d405a339SMatthew Knepley ierr = (*ts->ops->prestep)(ts); CHKERRQ(ierr); 1375000e7ae3SMatthew Knepley ierr = (*ts->ops->step)(ts, steps, ptime); CHKERRQ(ierr); 1376d405a339SMatthew Knepley ierr = (*ts->ops->poststep)(ts); CHKERRQ(ierr); 1377*d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_Step, ts, 0, 0, 0); CHKERRQ(ierr); 1378d405a339SMatthew Knepley 1379d405a339SMatthew Knepley ierr = PetscOptionsHasName(ts->prefix, "-ts_view", &opt); CHKERRQ(ierr); 1380d405a339SMatthew Knepley if ((opt == PETSC_TRUE) && !PetscPreLoadingOn) { 1381d405a339SMatthew Knepley ierr = TSView(ts, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); 1382d405a339SMatthew Knepley } 1383d763cef2SBarry Smith PetscFunctionReturn(0); 1384d763cef2SBarry Smith } 1385d763cef2SBarry Smith 13864a2ae208SSatish Balay #undef __FUNCT__ 13874a2ae208SSatish Balay #define __FUNCT__ "TSMonitor" 1388d763cef2SBarry Smith /* 1389d763cef2SBarry Smith Runs the user provided monitor routines, if they exists. 1390d763cef2SBarry Smith */ 139187828ca2SBarry Smith int TSMonitor(TS ts,int step,PetscReal ptime,Vec x) 1392d763cef2SBarry Smith { 1393d763cef2SBarry Smith int i,ierr,n = ts->numbermonitors; 1394d763cef2SBarry Smith 1395d763cef2SBarry Smith PetscFunctionBegin; 1396d763cef2SBarry Smith for (i=0; i<n; i++) { 1397142b95e3SSatish Balay ierr = (*ts->monitor[i])(ts,step,ptime,x,ts->monitorcontext[i]);CHKERRQ(ierr); 1398d763cef2SBarry Smith } 1399d763cef2SBarry Smith PetscFunctionReturn(0); 1400d763cef2SBarry Smith } 1401d763cef2SBarry Smith 1402d763cef2SBarry Smith /* ------------------------------------------------------------------------*/ 1403d763cef2SBarry Smith 14044a2ae208SSatish Balay #undef __FUNCT__ 14054a2ae208SSatish Balay #define __FUNCT__ "TSLGMonitorCreate" 1406d763cef2SBarry Smith /*@C 1407d763cef2SBarry Smith TSLGMonitorCreate - Creates a line graph context for use with 1408d763cef2SBarry Smith TS to monitor convergence of preconditioned residual norms. 1409d763cef2SBarry Smith 1410d763cef2SBarry Smith Collective on TS 1411d763cef2SBarry Smith 1412d763cef2SBarry Smith Input Parameters: 1413d763cef2SBarry Smith + host - the X display to open, or null for the local machine 1414d763cef2SBarry Smith . label - the title to put in the title bar 14157c922b88SBarry Smith . x, y - the screen coordinates of the upper left coordinate of the window 1416d763cef2SBarry Smith - m, n - the screen width and height in pixels 1417d763cef2SBarry Smith 1418d763cef2SBarry Smith Output Parameter: 1419d763cef2SBarry Smith . draw - the drawing context 1420d763cef2SBarry Smith 1421d763cef2SBarry Smith Options Database Key: 1422d763cef2SBarry Smith . -ts_xmonitor - automatically sets line graph monitor 1423d763cef2SBarry Smith 1424d763cef2SBarry Smith Notes: 1425b0a32e0cSBarry Smith Use TSLGMonitorDestroy() to destroy this line graph, not PetscDrawLGDestroy(). 1426d763cef2SBarry Smith 1427d763cef2SBarry Smith Level: intermediate 1428d763cef2SBarry Smith 14297c922b88SBarry Smith .keywords: TS, monitor, line graph, residual, seealso 1430d763cef2SBarry Smith 1431d763cef2SBarry Smith .seealso: TSLGMonitorDestroy(), TSSetMonitor() 14327c922b88SBarry Smith 1433d763cef2SBarry Smith @*/ 1434b0a32e0cSBarry Smith int TSLGMonitorCreate(char *host,char *label,int x,int y,int m,int n,PetscDrawLG *draw) 1435d763cef2SBarry Smith { 1436b0a32e0cSBarry Smith PetscDraw win; 1437d763cef2SBarry Smith int ierr; 1438d763cef2SBarry Smith 1439d763cef2SBarry Smith PetscFunctionBegin; 1440b0a32e0cSBarry Smith ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr); 1441b0a32e0cSBarry Smith ierr = PetscDrawSetType(win,PETSC_DRAW_X);CHKERRQ(ierr); 1442b0a32e0cSBarry Smith ierr = PetscDrawLGCreate(win,1,draw);CHKERRQ(ierr); 1443b0a32e0cSBarry Smith ierr = PetscDrawLGIndicateDataPoints(*draw);CHKERRQ(ierr); 1444d763cef2SBarry Smith 1445b0a32e0cSBarry Smith PetscLogObjectParent(*draw,win); 1446d763cef2SBarry Smith PetscFunctionReturn(0); 1447d763cef2SBarry Smith } 1448d763cef2SBarry Smith 14494a2ae208SSatish Balay #undef __FUNCT__ 14504a2ae208SSatish Balay #define __FUNCT__ "TSLGMonitor" 145187828ca2SBarry Smith int TSLGMonitor(TS ts,int n,PetscReal ptime,Vec v,void *monctx) 1452d763cef2SBarry Smith { 1453b0a32e0cSBarry Smith PetscDrawLG lg = (PetscDrawLG) monctx; 145487828ca2SBarry Smith PetscReal x,y = ptime; 1455d763cef2SBarry Smith int ierr; 1456d763cef2SBarry Smith 1457d763cef2SBarry Smith PetscFunctionBegin; 14587c922b88SBarry Smith if (!monctx) { 14597c922b88SBarry Smith MPI_Comm comm; 1460b0a32e0cSBarry Smith PetscViewer viewer; 14617c922b88SBarry Smith 14627c922b88SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 1463b0a32e0cSBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 1464b0a32e0cSBarry Smith ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr); 14657c922b88SBarry Smith } 14667c922b88SBarry Smith 1467b0a32e0cSBarry Smith if (!n) {ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);} 146887828ca2SBarry Smith x = (PetscReal)n; 1469b0a32e0cSBarry Smith ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr); 1470d763cef2SBarry Smith if (n < 20 || (n % 5)) { 1471b0a32e0cSBarry Smith ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr); 1472d763cef2SBarry Smith } 1473d763cef2SBarry Smith PetscFunctionReturn(0); 1474d763cef2SBarry Smith } 1475d763cef2SBarry Smith 14764a2ae208SSatish Balay #undef __FUNCT__ 14774a2ae208SSatish Balay #define __FUNCT__ "TSLGMonitorDestroy" 1478d763cef2SBarry Smith /*@C 1479d763cef2SBarry Smith TSLGMonitorDestroy - Destroys a line graph context that was created 1480d763cef2SBarry Smith with TSLGMonitorCreate(). 1481d763cef2SBarry Smith 1482b0a32e0cSBarry Smith Collective on PetscDrawLG 1483d763cef2SBarry Smith 1484d763cef2SBarry Smith Input Parameter: 1485d763cef2SBarry Smith . draw - the drawing context 1486d763cef2SBarry Smith 1487d763cef2SBarry Smith Level: intermediate 1488d763cef2SBarry Smith 1489d763cef2SBarry Smith .keywords: TS, monitor, line graph, destroy 1490d763cef2SBarry Smith 1491d763cef2SBarry Smith .seealso: TSLGMonitorCreate(), TSSetMonitor(), TSLGMonitor(); 1492d763cef2SBarry Smith @*/ 1493b0a32e0cSBarry Smith int TSLGMonitorDestroy(PetscDrawLG drawlg) 1494d763cef2SBarry Smith { 1495b0a32e0cSBarry Smith PetscDraw draw; 1496d763cef2SBarry Smith int ierr; 1497d763cef2SBarry Smith 1498d763cef2SBarry Smith PetscFunctionBegin; 1499b0a32e0cSBarry Smith ierr = PetscDrawLGGetDraw(drawlg,&draw);CHKERRQ(ierr); 1500b0a32e0cSBarry Smith ierr = PetscDrawDestroy(draw);CHKERRQ(ierr); 1501b0a32e0cSBarry Smith ierr = PetscDrawLGDestroy(drawlg);CHKERRQ(ierr); 1502d763cef2SBarry Smith PetscFunctionReturn(0); 1503d763cef2SBarry Smith } 1504d763cef2SBarry Smith 15054a2ae208SSatish Balay #undef __FUNCT__ 15064a2ae208SSatish Balay #define __FUNCT__ "TSGetTime" 1507d763cef2SBarry Smith /*@ 1508d763cef2SBarry Smith TSGetTime - Gets the current time. 1509d763cef2SBarry Smith 1510d763cef2SBarry Smith Not Collective 1511d763cef2SBarry Smith 1512d763cef2SBarry Smith Input Parameter: 1513d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1514d763cef2SBarry Smith 1515d763cef2SBarry Smith Output Parameter: 1516d763cef2SBarry Smith . t - the current time 1517d763cef2SBarry Smith 1518d763cef2SBarry Smith Contributed by: Matthew Knepley 1519d763cef2SBarry Smith 1520d763cef2SBarry Smith Level: beginner 1521d763cef2SBarry Smith 1522d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1523d763cef2SBarry Smith 1524d763cef2SBarry Smith .keywords: TS, get, time 1525d763cef2SBarry Smith @*/ 152687828ca2SBarry Smith int TSGetTime(TS ts,PetscReal* t) 1527d763cef2SBarry Smith { 1528d763cef2SBarry Smith PetscFunctionBegin; 1529d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1530d763cef2SBarry Smith *t = ts->ptime; 1531d763cef2SBarry Smith PetscFunctionReturn(0); 1532d763cef2SBarry Smith } 1533d763cef2SBarry Smith 15344a2ae208SSatish Balay #undef __FUNCT__ 15354a2ae208SSatish Balay #define __FUNCT__ "TSGetProblemType" 1536d763cef2SBarry Smith /*@C 1537d763cef2SBarry Smith TSGetProblemType - Returns the problem type of a TS (timestepper) context. 1538d763cef2SBarry Smith 1539d763cef2SBarry Smith Not Collective 1540d763cef2SBarry Smith 1541d763cef2SBarry Smith Input Parameter: 1542d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1543d763cef2SBarry Smith 1544d763cef2SBarry Smith Output Parameter: 1545d763cef2SBarry Smith . type - The problem type, TS_LINEAR or TS_NONLINEAR 1546d763cef2SBarry Smith 1547d763cef2SBarry Smith Level: intermediate 1548d763cef2SBarry Smith 1549d763cef2SBarry Smith Contributed by: Matthew Knepley 1550d763cef2SBarry Smith 1551d763cef2SBarry Smith .keywords: ts, get, type 1552d763cef2SBarry Smith 1553d763cef2SBarry Smith @*/ 1554d763cef2SBarry Smith int TSGetProblemType(TS ts,TSProblemType *type) 1555d763cef2SBarry Smith { 1556d763cef2SBarry Smith PetscFunctionBegin; 1557d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1558d763cef2SBarry Smith *type = ts->problem_type; 1559d763cef2SBarry Smith PetscFunctionReturn(0); 1560d763cef2SBarry Smith } 1561d763cef2SBarry Smith 15624a2ae208SSatish Balay #undef __FUNCT__ 15634a2ae208SSatish Balay #define __FUNCT__ "TSSetOptionsPrefix" 1564d763cef2SBarry Smith /*@C 1565d763cef2SBarry Smith TSSetOptionsPrefix - Sets the prefix used for searching for all 1566d763cef2SBarry Smith TS options in the database. 1567d763cef2SBarry Smith 1568d763cef2SBarry Smith Collective on TS 1569d763cef2SBarry Smith 1570d763cef2SBarry Smith Input Parameter: 1571d763cef2SBarry Smith + ts - The TS context 1572d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1573d763cef2SBarry Smith 1574d763cef2SBarry Smith Notes: 1575d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1576d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1577d763cef2SBarry Smith hyphen. 1578d763cef2SBarry Smith 1579d763cef2SBarry Smith Contributed by: Matthew Knepley 1580d763cef2SBarry Smith 1581d763cef2SBarry Smith Level: advanced 1582d763cef2SBarry Smith 1583d763cef2SBarry Smith .keywords: TS, set, options, prefix, database 1584d763cef2SBarry Smith 1585d763cef2SBarry Smith .seealso: TSSetFromOptions() 1586d763cef2SBarry Smith 1587d763cef2SBarry Smith @*/ 1588d763cef2SBarry Smith int TSSetOptionsPrefix(TS ts,char *prefix) 1589d763cef2SBarry Smith { 1590d763cef2SBarry Smith int ierr; 1591d763cef2SBarry Smith 1592d763cef2SBarry Smith PetscFunctionBegin; 1593d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1594d763cef2SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1595d763cef2SBarry Smith switch(ts->problem_type) { 1596d763cef2SBarry Smith case TS_NONLINEAR: 1597d763cef2SBarry Smith ierr = SNESSetOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 1598d763cef2SBarry Smith break; 1599d763cef2SBarry Smith case TS_LINEAR: 1600d763cef2SBarry Smith ierr = SLESSetOptionsPrefix(ts->sles,prefix);CHKERRQ(ierr); 1601d763cef2SBarry Smith break; 1602d763cef2SBarry Smith } 1603d763cef2SBarry Smith PetscFunctionReturn(0); 1604d763cef2SBarry Smith } 1605d763cef2SBarry Smith 1606d763cef2SBarry Smith 16074a2ae208SSatish Balay #undef __FUNCT__ 16084a2ae208SSatish Balay #define __FUNCT__ "TSAppendOptionsPrefix" 1609d763cef2SBarry Smith /*@C 1610d763cef2SBarry Smith TSAppendOptionsPrefix - Appends to the prefix used for searching for all 1611d763cef2SBarry Smith TS options in the database. 1612d763cef2SBarry Smith 1613d763cef2SBarry Smith Collective on TS 1614d763cef2SBarry Smith 1615d763cef2SBarry Smith Input Parameter: 1616d763cef2SBarry Smith + ts - The TS context 1617d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1618d763cef2SBarry Smith 1619d763cef2SBarry Smith Notes: 1620d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1621d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1622d763cef2SBarry Smith hyphen. 1623d763cef2SBarry Smith 1624d763cef2SBarry Smith Contributed by: Matthew Knepley 1625d763cef2SBarry Smith 1626d763cef2SBarry Smith Level: advanced 1627d763cef2SBarry Smith 1628d763cef2SBarry Smith .keywords: TS, append, options, prefix, database 1629d763cef2SBarry Smith 1630d763cef2SBarry Smith .seealso: TSGetOptionsPrefix() 1631d763cef2SBarry Smith 1632d763cef2SBarry Smith @*/ 1633d763cef2SBarry Smith int TSAppendOptionsPrefix(TS ts,char *prefix) 1634d763cef2SBarry Smith { 1635d763cef2SBarry Smith int ierr; 1636d763cef2SBarry Smith 1637d763cef2SBarry Smith PetscFunctionBegin; 1638d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1639d763cef2SBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1640d763cef2SBarry Smith switch(ts->problem_type) { 1641d763cef2SBarry Smith case TS_NONLINEAR: 1642d763cef2SBarry Smith ierr = SNESAppendOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 1643d763cef2SBarry Smith break; 1644d763cef2SBarry Smith case TS_LINEAR: 1645d763cef2SBarry Smith ierr = SLESAppendOptionsPrefix(ts->sles,prefix);CHKERRQ(ierr); 1646d763cef2SBarry Smith break; 1647d763cef2SBarry Smith } 1648d763cef2SBarry Smith PetscFunctionReturn(0); 1649d763cef2SBarry Smith } 1650d763cef2SBarry Smith 16514a2ae208SSatish Balay #undef __FUNCT__ 16524a2ae208SSatish Balay #define __FUNCT__ "TSGetOptionsPrefix" 1653d763cef2SBarry Smith /*@C 1654d763cef2SBarry Smith TSGetOptionsPrefix - Sets the prefix used for searching for all 1655d763cef2SBarry Smith TS options in the database. 1656d763cef2SBarry Smith 1657d763cef2SBarry Smith Not Collective 1658d763cef2SBarry Smith 1659d763cef2SBarry Smith Input Parameter: 1660d763cef2SBarry Smith . ts - The TS context 1661d763cef2SBarry Smith 1662d763cef2SBarry Smith Output Parameter: 1663d763cef2SBarry Smith . prefix - A pointer to the prefix string used 1664d763cef2SBarry Smith 1665d763cef2SBarry Smith Contributed by: Matthew Knepley 1666d763cef2SBarry Smith 1667d763cef2SBarry Smith Notes: On the fortran side, the user should pass in a string 'prifix' of 1668d763cef2SBarry Smith sufficient length to hold the prefix. 1669d763cef2SBarry Smith 1670d763cef2SBarry Smith Level: intermediate 1671d763cef2SBarry Smith 1672d763cef2SBarry Smith .keywords: TS, get, options, prefix, database 1673d763cef2SBarry Smith 1674d763cef2SBarry Smith .seealso: TSAppendOptionsPrefix() 1675d763cef2SBarry Smith @*/ 1676d763cef2SBarry Smith int TSGetOptionsPrefix(TS ts,char **prefix) 1677d763cef2SBarry Smith { 1678d763cef2SBarry Smith int ierr; 1679d763cef2SBarry Smith 1680d763cef2SBarry Smith PetscFunctionBegin; 1681d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1682d763cef2SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1683d763cef2SBarry Smith PetscFunctionReturn(0); 1684d763cef2SBarry Smith } 1685d763cef2SBarry Smith 16864a2ae208SSatish Balay #undef __FUNCT__ 16874a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSMatrix" 1688d763cef2SBarry Smith /*@C 1689d763cef2SBarry Smith TSGetRHSMatrix - Returns the matrix A at the present timestep. 1690d763cef2SBarry Smith 1691d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1692d763cef2SBarry Smith 1693d763cef2SBarry Smith Input Parameter: 1694d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1695d763cef2SBarry Smith 1696d763cef2SBarry Smith Output Parameters: 1697d763cef2SBarry Smith + A - The matrix A, where U_t = A(t) U 1698d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as A 1699d763cef2SBarry Smith - ctx - User-defined context for matrix evaluation routine 1700d763cef2SBarry Smith 1701d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1702d763cef2SBarry Smith 1703d763cef2SBarry Smith Contributed by: Matthew Knepley 1704d763cef2SBarry Smith 1705d763cef2SBarry Smith Level: intermediate 1706d763cef2SBarry Smith 1707d763cef2SBarry Smith .seealso: TSGetTimeStep(), TSGetTime(), TSGetTimeStepNumber(), TSGetRHSJacobian() 1708d763cef2SBarry Smith 1709d763cef2SBarry Smith .keywords: TS, timestep, get, matrix 1710d763cef2SBarry Smith 1711d763cef2SBarry Smith @*/ 1712d763cef2SBarry Smith int TSGetRHSMatrix(TS ts,Mat *A,Mat *M,void **ctx) 1713d763cef2SBarry Smith { 1714d763cef2SBarry Smith PetscFunctionBegin; 1715d763cef2SBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE); 1716d763cef2SBarry Smith if (A) *A = ts->A; 1717d763cef2SBarry Smith if (M) *M = ts->B; 1718d763cef2SBarry Smith if (ctx) *ctx = ts->jacP; 1719d763cef2SBarry Smith PetscFunctionReturn(0); 1720d763cef2SBarry Smith } 1721d763cef2SBarry Smith 17224a2ae208SSatish Balay #undef __FUNCT__ 17234a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSJacobian" 1724d763cef2SBarry Smith /*@C 1725d763cef2SBarry Smith TSGetRHSJacobian - Returns the Jacobian J at the present timestep. 1726d763cef2SBarry Smith 1727d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1728d763cef2SBarry Smith 1729d763cef2SBarry Smith Input Parameter: 1730d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1731d763cef2SBarry Smith 1732d763cef2SBarry Smith Output Parameters: 1733d763cef2SBarry Smith + J - The Jacobian J of F, where U_t = F(U,t) 1734d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as J 1735d763cef2SBarry Smith - ctx - User-defined context for Jacobian evaluation routine 1736d763cef2SBarry Smith 1737d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1738d763cef2SBarry Smith 1739d763cef2SBarry Smith Contributed by: Matthew Knepley 1740d763cef2SBarry Smith 1741d763cef2SBarry Smith Level: intermediate 1742d763cef2SBarry Smith 1743d763cef2SBarry Smith .seealso: TSGetTimeStep(), TSGetRHSMatrix(), TSGetTime(), TSGetTimeStepNumber() 1744d763cef2SBarry Smith 1745d763cef2SBarry Smith .keywords: TS, timestep, get, matrix, Jacobian 1746d763cef2SBarry Smith @*/ 1747d763cef2SBarry Smith int TSGetRHSJacobian(TS ts,Mat *J,Mat *M,void **ctx) 1748d763cef2SBarry Smith { 1749d763cef2SBarry Smith int ierr; 1750d763cef2SBarry Smith 1751d763cef2SBarry Smith PetscFunctionBegin; 1752d763cef2SBarry Smith ierr = TSGetRHSMatrix(ts,J,M,ctx);CHKERRQ(ierr); 1753d763cef2SBarry Smith PetscFunctionReturn(0); 1754d763cef2SBarry Smith } 1755d763cef2SBarry Smith 1756d763cef2SBarry Smith /*MC 1757f1af5d2fSBarry Smith TSRegisterDynamic - Adds a method to the timestepping solver package. 1758d763cef2SBarry Smith 1759d763cef2SBarry Smith Synopsis: 17603a7fca6bSBarry Smith int TSRegisterDynamic(char *name_solver,char *path,char *name_create,int (*routine_create)(TS)) 1761d763cef2SBarry Smith 1762d763cef2SBarry Smith Not collective 1763d763cef2SBarry Smith 1764d763cef2SBarry Smith Input Parameters: 1765d763cef2SBarry Smith + name_solver - name of a new user-defined solver 1766d763cef2SBarry Smith . path - path (either absolute or relative) the library containing this solver 1767d763cef2SBarry Smith . name_create - name of routine to create method context 1768d763cef2SBarry Smith - routine_create - routine to create method context 1769d763cef2SBarry Smith 1770d763cef2SBarry Smith Notes: 1771f1af5d2fSBarry Smith TSRegisterDynamic() may be called multiple times to add several user-defined solvers. 1772d763cef2SBarry Smith 1773d763cef2SBarry Smith If dynamic libraries are used, then the fourth input argument (routine_create) 1774d763cef2SBarry Smith is ignored. 1775d763cef2SBarry Smith 1776d763cef2SBarry Smith Sample usage: 1777d763cef2SBarry Smith .vb 1778f1af5d2fSBarry Smith TSRegisterDynamic("my_solver",/home/username/my_lib/lib/libO/solaris/mylib.a, 1779d763cef2SBarry Smith "MySolverCreate",MySolverCreate); 1780d763cef2SBarry Smith .ve 1781d763cef2SBarry Smith 1782d763cef2SBarry Smith Then, your solver can be chosen with the procedural interface via 1783d763cef2SBarry Smith $ TSSetType(ts,"my_solver") 1784d763cef2SBarry Smith or at runtime via the option 1785d763cef2SBarry Smith $ -ts_type my_solver 1786d763cef2SBarry Smith 1787d763cef2SBarry Smith Level: advanced 1788d763cef2SBarry Smith 17892aeb12f1SSatish Balay Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, ${BOPT}, 17905ba88a07SLois Curfman McInnes and others of the form ${any_environmental_variable} occuring in pathname will be 17915ba88a07SLois Curfman McInnes replaced with appropriate values. 1792d763cef2SBarry Smith 1793d763cef2SBarry Smith .keywords: TS, register 1794d763cef2SBarry Smith 1795d763cef2SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy() 1796d763cef2SBarry Smith M*/ 1797d763cef2SBarry Smith 17984a2ae208SSatish Balay #undef __FUNCT__ 17994a2ae208SSatish Balay #define __FUNCT__ "TSRegister" 1800000e7ae3SMatthew Knepley int TSRegister(const char sname[], const char path[], const char name[], int (*function)(TS)) 1801d763cef2SBarry Smith { 1802d763cef2SBarry Smith char fullname[256]; 1803549d3d68SSatish Balay int ierr; 1804d763cef2SBarry Smith 1805d763cef2SBarry Smith PetscFunctionBegin; 1806b0a32e0cSBarry Smith ierr = PetscFListConcat(path,name,fullname);CHKERRQ(ierr); 1807c134de8dSSatish Balay ierr = PetscFListAdd(&TSList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr); 1808d763cef2SBarry Smith PetscFunctionReturn(0); 1809d763cef2SBarry Smith } 18101713a123SBarry Smith 18111713a123SBarry Smith #undef __FUNCT__ 18121713a123SBarry Smith #define __FUNCT__ "TSVecViewMonitor" 18131713a123SBarry Smith /*@C 18141713a123SBarry Smith TSVecViewMonitor - Monitors progress of the TS solvers by calling 18151713a123SBarry Smith VecView() for the solution at each timestep 18161713a123SBarry Smith 18171713a123SBarry Smith Collective on TS 18181713a123SBarry Smith 18191713a123SBarry Smith Input Parameters: 18201713a123SBarry Smith + ts - the TS context 18211713a123SBarry Smith . step - current time-step 1822142b95e3SSatish Balay . ptime - current time 18231713a123SBarry Smith - dummy - either a viewer or PETSC_NULL 18241713a123SBarry Smith 18251713a123SBarry Smith Level: intermediate 18261713a123SBarry Smith 18271713a123SBarry Smith .keywords: TS, vector, monitor, view 18281713a123SBarry Smith 18291713a123SBarry Smith .seealso: TSSetMonitor(), TSDefaultMonitor(), VecView() 18301713a123SBarry Smith @*/ 1831142b95e3SSatish Balay int TSVecViewMonitor(TS ts,int step,PetscReal ptime,Vec x,void *dummy) 18321713a123SBarry Smith { 18331713a123SBarry Smith int ierr; 18341713a123SBarry Smith PetscViewer viewer = (PetscViewer) dummy; 18351713a123SBarry Smith 18361713a123SBarry Smith PetscFunctionBegin; 18371713a123SBarry Smith if (!viewer) { 18381713a123SBarry Smith MPI_Comm comm; 18391713a123SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 18401713a123SBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 18411713a123SBarry Smith } 18421713a123SBarry Smith ierr = VecView(x,viewer);CHKERRQ(ierr); 18431713a123SBarry Smith PetscFunctionReturn(0); 18441713a123SBarry Smith } 18451713a123SBarry Smith 18461713a123SBarry Smith 18471713a123SBarry Smith 1848