163dd3a1aSKris Buschelman #define PETSCTS_DLL 263dd3a1aSKris Buschelman 3e090d566SSatish Balay #include "src/ts/tsimpl.h" /*I "petscts.h" I*/ 4d763cef2SBarry Smith 5d5ba7fb7SMatthew Knepley /* Logging support */ 663dd3a1aSKris Buschelman PetscCookie PETSCTS_DLLEXPORT TS_COOKIE = 0; 76849ba73SBarry Smith PetscEvent TS_Step = 0, TS_PseudoComputeTimeStep = 0, TS_FunctionEval = 0, TS_JacobianEval = 0; 8d405a339SMatthew Knepley 94a2ae208SSatish Balay #undef __FUNCT__ 10bdad233fSMatthew Knepley #define __FUNCT__ "TSSetTypeFromOptions" 11bdad233fSMatthew Knepley /* 12bdad233fSMatthew Knepley TSSetTypeFromOptions - Sets the type of ts from user options. 13bdad233fSMatthew Knepley 14bdad233fSMatthew Knepley Collective on TS 15bdad233fSMatthew Knepley 16bdad233fSMatthew Knepley Input Parameter: 17bdad233fSMatthew Knepley . ts - The ts 18bdad233fSMatthew Knepley 19bdad233fSMatthew Knepley Level: intermediate 20bdad233fSMatthew Knepley 21bdad233fSMatthew Knepley .keywords: TS, set, options, database, type 22bdad233fSMatthew Knepley .seealso: TSSetFromOptions(), TSSetType() 23bdad233fSMatthew Knepley */ 246849ba73SBarry Smith static PetscErrorCode TSSetTypeFromOptions(TS ts) 25bdad233fSMatthew Knepley { 26bdad233fSMatthew Knepley PetscTruth opt; 272fc52814SBarry Smith const char *defaultType; 28bdad233fSMatthew Knepley char typeName[256]; 29dfbe8321SBarry Smith PetscErrorCode ierr; 30bdad233fSMatthew Knepley 31bdad233fSMatthew Knepley PetscFunctionBegin; 32abc0a331SBarry Smith if (ts->type_name) { 33bdad233fSMatthew Knepley defaultType = ts->type_name; 34bdad233fSMatthew Knepley } else { 35bdad233fSMatthew Knepley defaultType = TS_EULER; 36bdad233fSMatthew Knepley } 37bdad233fSMatthew Knepley 38bdad233fSMatthew Knepley if (!TSRegisterAllCalled) { 39bdad233fSMatthew Knepley ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr); 40bdad233fSMatthew Knepley } 41bdad233fSMatthew Knepley ierr = PetscOptionsList("-ts_type", "TS method"," TSSetType", TSList, defaultType, typeName, 256, &opt);CHKERRQ(ierr); 42a7cc72afSBarry Smith if (opt) { 43bdad233fSMatthew Knepley ierr = TSSetType(ts, typeName);CHKERRQ(ierr); 44bdad233fSMatthew Knepley } else { 45bdad233fSMatthew Knepley ierr = TSSetType(ts, defaultType);CHKERRQ(ierr); 46bdad233fSMatthew Knepley } 47bdad233fSMatthew Knepley PetscFunctionReturn(0); 48bdad233fSMatthew Knepley } 49bdad233fSMatthew Knepley 50bdad233fSMatthew Knepley #undef __FUNCT__ 51bdad233fSMatthew Knepley #define __FUNCT__ "TSSetFromOptions" 52bdad233fSMatthew Knepley /*@ 53bdad233fSMatthew Knepley TSSetFromOptions - Sets various TS parameters from user options. 54bdad233fSMatthew Knepley 55bdad233fSMatthew Knepley Collective on TS 56bdad233fSMatthew Knepley 57bdad233fSMatthew Knepley Input Parameter: 58bdad233fSMatthew Knepley . ts - the TS context obtained from TSCreate() 59bdad233fSMatthew Knepley 60bdad233fSMatthew Knepley Options Database Keys: 61bdad233fSMatthew Knepley + -ts_type <type> - TS_EULER, TS_BEULER, TS_PVODE, TS_PSEUDO, TS_CRANK_NICHOLSON 62bdad233fSMatthew Knepley . -ts_max_steps maxsteps - maximum number of time-steps to take 63bdad233fSMatthew Knepley . -ts_max_time time - maximum time to compute to 64bdad233fSMatthew Knepley . -ts_dt dt - initial time step 65bdad233fSMatthew Knepley . -ts_monitor - print information at each timestep 66bdad233fSMatthew Knepley - -ts_xmonitor - plot information at each timestep 67bdad233fSMatthew Knepley 68bdad233fSMatthew Knepley Level: beginner 69bdad233fSMatthew Knepley 70bdad233fSMatthew Knepley .keywords: TS, timestep, set, options, database 71bdad233fSMatthew Knepley 72bdad233fSMatthew Knepley .seealso: TSGetType 73bdad233fSMatthew Knepley @*/ 7463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetFromOptions(TS ts) 75bdad233fSMatthew Knepley { 76bdad233fSMatthew Knepley PetscReal dt; 77bdad233fSMatthew Knepley PetscTruth opt; 78dfbe8321SBarry Smith PetscErrorCode ierr; 79bdad233fSMatthew Knepley 80bdad233fSMatthew Knepley PetscFunctionBegin; 814482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 82bdad233fSMatthew Knepley ierr = PetscOptionsBegin(ts->comm, ts->prefix, "Time step options", "TS");CHKERRQ(ierr); 83bdad233fSMatthew Knepley 84bdad233fSMatthew Knepley /* Handle generic TS options */ 85bdad233fSMatthew Knepley ierr = PetscOptionsInt("-ts_max_steps","Maximum number of time steps","TSSetDuration",ts->max_steps,&ts->max_steps,PETSC_NULL);CHKERRQ(ierr); 86bdad233fSMatthew Knepley ierr = PetscOptionsReal("-ts_max_time","Time to run to","TSSetDuration",ts->max_time,&ts->max_time,PETSC_NULL);CHKERRQ(ierr); 87bdad233fSMatthew Knepley ierr = PetscOptionsReal("-ts_init_time","Initial time","TSSetInitialTime", ts->ptime, &ts->ptime, PETSC_NULL);CHKERRQ(ierr); 88bdad233fSMatthew Knepley ierr = PetscOptionsReal("-ts_dt","Initial time step","TSSetInitialTimeStep",ts->initial_time_step,&dt,&opt);CHKERRQ(ierr); 89a7cc72afSBarry Smith if (opt) { 90bdad233fSMatthew Knepley ts->initial_time_step = ts->time_step = dt; 91bdad233fSMatthew Knepley } 92bdad233fSMatthew Knepley 93bdad233fSMatthew Knepley /* Monitor options */ 94bdad233fSMatthew Knepley ierr = PetscOptionsName("-ts_monitor","Monitor timestep size","TSDefaultMonitor",&opt);CHKERRQ(ierr); 95a7cc72afSBarry Smith if (opt) { 96bdad233fSMatthew Knepley ierr = TSSetMonitor(ts,TSDefaultMonitor,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 97bdad233fSMatthew Knepley } 98bdad233fSMatthew Knepley ierr = PetscOptionsName("-ts_xmonitor","Monitor timestep size graphically","TSLGMonitor",&opt);CHKERRQ(ierr); 99a7cc72afSBarry Smith if (opt) { 100bdad233fSMatthew Knepley ierr = TSSetMonitor(ts,TSLGMonitor,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 101bdad233fSMatthew Knepley } 102bdad233fSMatthew Knepley ierr = PetscOptionsName("-ts_vecmonitor","Monitor solution graphically","TSVecViewMonitor",&opt);CHKERRQ(ierr); 103a7cc72afSBarry Smith if (opt) { 104bdad233fSMatthew Knepley ierr = TSSetMonitor(ts,TSVecViewMonitor,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 105bdad233fSMatthew Knepley } 106bdad233fSMatthew Knepley 107bdad233fSMatthew Knepley /* Handle TS type options */ 108bdad233fSMatthew Knepley ierr = TSSetTypeFromOptions(ts);CHKERRQ(ierr); 109bdad233fSMatthew Knepley 110bdad233fSMatthew Knepley /* Handle specific TS options */ 111abc0a331SBarry Smith if (ts->ops->setfromoptions) { 112bdad233fSMatthew Knepley ierr = (*ts->ops->setfromoptions)(ts);CHKERRQ(ierr); 113bdad233fSMatthew Knepley } 114bdad233fSMatthew Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 115bdad233fSMatthew Knepley 116bdad233fSMatthew Knepley /* Handle subobject options */ 117bdad233fSMatthew Knepley switch(ts->problem_type) { 118156fc9a6SMatthew Knepley /* Should check for implicit/explicit */ 119bdad233fSMatthew Knepley case TS_LINEAR: 120abc0a331SBarry Smith if (ts->ksp) { 1217c236d22SBarry Smith ierr = KSPSetOperators(ts->ksp,ts->A,ts->B,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 12294b7f48cSBarry Smith ierr = KSPSetFromOptions(ts->ksp);CHKERRQ(ierr); 123156fc9a6SMatthew Knepley } 124bdad233fSMatthew Knepley break; 125bdad233fSMatthew Knepley case TS_NONLINEAR: 126abc0a331SBarry Smith if (ts->snes) { 1277c236d22SBarry Smith /* this is a bit of a hack, but it gets the matrix information into SNES earlier 1287c236d22SBarry Smith so that SNES and KSP have more information to pick reasonable defaults 1297c236d22SBarry Smith before they allow users to set options */ 1307c236d22SBarry Smith ierr = SNESSetJacobian(ts->snes,ts->A,ts->B,0,ts);CHKERRQ(ierr); 131bdad233fSMatthew Knepley ierr = SNESSetFromOptions(ts->snes);CHKERRQ(ierr); 132156fc9a6SMatthew Knepley } 133bdad233fSMatthew Knepley break; 134bdad233fSMatthew Knepley default: 13577431f27SBarry Smith SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid problem type: %d", (int)ts->problem_type); 136bdad233fSMatthew Knepley } 137bdad233fSMatthew Knepley 138bdad233fSMatthew Knepley PetscFunctionReturn(0); 139bdad233fSMatthew Knepley } 140bdad233fSMatthew Knepley 141bdad233fSMatthew Knepley #undef __FUNCT__ 142bdad233fSMatthew Knepley #define __FUNCT__ "TSViewFromOptions" 143bdad233fSMatthew Knepley /*@ 144bdad233fSMatthew Knepley TSViewFromOptions - This function visualizes the ts based upon user options. 145bdad233fSMatthew Knepley 146bdad233fSMatthew Knepley Collective on TS 147bdad233fSMatthew Knepley 148bdad233fSMatthew Knepley Input Parameter: 149bdad233fSMatthew Knepley . ts - The ts 150bdad233fSMatthew Knepley 151bdad233fSMatthew Knepley Level: intermediate 152bdad233fSMatthew Knepley 153bdad233fSMatthew Knepley .keywords: TS, view, options, database 154bdad233fSMatthew Knepley .seealso: TSSetFromOptions(), TSView() 155bdad233fSMatthew Knepley @*/ 15663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSViewFromOptions(TS ts,const char title[]) 157bdad233fSMatthew Knepley { 158bdad233fSMatthew Knepley PetscViewer viewer; 159bdad233fSMatthew Knepley PetscDraw draw; 160bdad233fSMatthew Knepley PetscTruth opt; 161bdad233fSMatthew Knepley char typeName[1024]; 162e10c49a3SBarry Smith char fileName[PETSC_MAX_PATH_LEN]; 163de4209c5SBarry Smith size_t len; 164dfbe8321SBarry Smith PetscErrorCode ierr; 165bdad233fSMatthew Knepley 166bdad233fSMatthew Knepley PetscFunctionBegin; 167bdad233fSMatthew Knepley ierr = PetscOptionsHasName(ts->prefix, "-ts_view", &opt);CHKERRQ(ierr); 168a7cc72afSBarry Smith if (opt) { 169bdad233fSMatthew Knepley ierr = PetscOptionsGetString(ts->prefix, "-ts_view", typeName, 1024, &opt);CHKERRQ(ierr); 170bdad233fSMatthew Knepley ierr = PetscStrlen(typeName, &len);CHKERRQ(ierr); 171bdad233fSMatthew Knepley if (len > 0) { 172bdad233fSMatthew Knepley ierr = PetscViewerCreate(ts->comm, &viewer);CHKERRQ(ierr); 173bdad233fSMatthew Knepley ierr = PetscViewerSetType(viewer, typeName);CHKERRQ(ierr); 174bdad233fSMatthew Knepley ierr = PetscOptionsGetString(ts->prefix, "-ts_view_file", fileName, 1024, &opt);CHKERRQ(ierr); 175a7cc72afSBarry Smith if (opt) { 176bdad233fSMatthew Knepley ierr = PetscViewerSetFilename(viewer, fileName);CHKERRQ(ierr); 177bdad233fSMatthew Knepley } else { 178bdad233fSMatthew Knepley ierr = PetscViewerSetFilename(viewer, ts->name);CHKERRQ(ierr); 179bdad233fSMatthew Knepley } 180bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 181bdad233fSMatthew Knepley ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 182bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 183bdad233fSMatthew Knepley } else { 184bdad233fSMatthew Knepley ierr = TSView(ts, PETSC_NULL);CHKERRQ(ierr); 185bdad233fSMatthew Knepley } 186bdad233fSMatthew Knepley } 187bdad233fSMatthew Knepley ierr = PetscOptionsHasName(ts->prefix, "-ts_view_draw", &opt);CHKERRQ(ierr); 188a7cc72afSBarry Smith if (opt) { 189bdad233fSMatthew Knepley ierr = PetscViewerDrawOpen(ts->comm, 0, 0, 0, 0, 300, 300, &viewer);CHKERRQ(ierr); 190bdad233fSMatthew Knepley ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr); 191a7cc72afSBarry Smith if (title) { 1921836bdbcSSatish Balay ierr = PetscDrawSetTitle(draw, (char *)title);CHKERRQ(ierr); 193bdad233fSMatthew Knepley } else { 194bdad233fSMatthew Knepley ierr = PetscObjectName((PetscObject) ts);CHKERRQ(ierr); 1951836bdbcSSatish Balay ierr = PetscDrawSetTitle(draw, ts->name);CHKERRQ(ierr); 196bdad233fSMatthew Knepley } 197bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 198bdad233fSMatthew Knepley ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 199bdad233fSMatthew Knepley ierr = PetscDrawPause(draw);CHKERRQ(ierr); 200bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 201bdad233fSMatthew Knepley } 202bdad233fSMatthew Knepley PetscFunctionReturn(0); 203bdad233fSMatthew Knepley } 204bdad233fSMatthew Knepley 205bdad233fSMatthew Knepley #undef __FUNCT__ 2064a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSJacobian" 207a7a1495cSBarry Smith /*@ 2088c385f81SBarry Smith TSComputeRHSJacobian - Computes the Jacobian matrix that has been 209a7a1495cSBarry Smith set with TSSetRHSJacobian(). 210a7a1495cSBarry Smith 211a7a1495cSBarry Smith Collective on TS and Vec 212a7a1495cSBarry Smith 213a7a1495cSBarry Smith Input Parameters: 214a7a1495cSBarry Smith + ts - the SNES context 215a7a1495cSBarry Smith . t - current timestep 216a7a1495cSBarry Smith - x - input vector 217a7a1495cSBarry Smith 218a7a1495cSBarry Smith Output Parameters: 219a7a1495cSBarry Smith + A - Jacobian matrix 220a7a1495cSBarry Smith . B - optional preconditioning matrix 221a7a1495cSBarry Smith - flag - flag indicating matrix structure 222a7a1495cSBarry Smith 223a7a1495cSBarry Smith Notes: 224a7a1495cSBarry Smith Most users should not need to explicitly call this routine, as it 225a7a1495cSBarry Smith is used internally within the nonlinear solvers. 226a7a1495cSBarry Smith 22794b7f48cSBarry Smith See KSPSetOperators() for important information about setting the 228a7a1495cSBarry Smith flag parameter. 229a7a1495cSBarry Smith 230a7a1495cSBarry Smith TSComputeJacobian() is valid only for TS_NONLINEAR 231a7a1495cSBarry Smith 232a7a1495cSBarry Smith Level: developer 233a7a1495cSBarry Smith 234a7a1495cSBarry Smith .keywords: SNES, compute, Jacobian, matrix 235a7a1495cSBarry Smith 23694b7f48cSBarry Smith .seealso: TSSetRHSJacobian(), KSPSetOperators() 237a7a1495cSBarry Smith @*/ 23863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS ts,PetscReal t,Vec X,Mat *A,Mat *B,MatStructure *flg) 239a7a1495cSBarry Smith { 240dfbe8321SBarry Smith PetscErrorCode ierr; 241a7a1495cSBarry Smith 242a7a1495cSBarry Smith PetscFunctionBegin; 2434482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 2444482741eSBarry Smith PetscValidHeaderSpecific(X,VEC_COOKIE,3); 245c9780b6fSBarry Smith PetscCheckSameComm(ts,1,X,3); 246a7a1495cSBarry Smith if (ts->problem_type != TS_NONLINEAR) { 24729bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"For TS_NONLINEAR only"); 248a7a1495cSBarry Smith } 249000e7ae3SMatthew Knepley if (ts->ops->rhsjacobian) { 250d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 251a7a1495cSBarry Smith *flg = DIFFERENT_NONZERO_PATTERN; 252a7a1495cSBarry Smith PetscStackPush("TS user Jacobian function"); 253000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr); 254a7a1495cSBarry Smith PetscStackPop; 255d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 256a7a1495cSBarry Smith /* make sure user returned a correct Jacobian and preconditioner */ 2574482741eSBarry Smith PetscValidHeaderSpecific(*A,MAT_COOKIE,4); 2584482741eSBarry Smith PetscValidHeaderSpecific(*B,MAT_COOKIE,5); 259ef66eb69SBarry Smith } else { 260ef66eb69SBarry Smith ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 261ef66eb69SBarry Smith ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 262ef66eb69SBarry Smith if (*A != *B) { 263ef66eb69SBarry Smith ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 264ef66eb69SBarry Smith ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 265ef66eb69SBarry Smith } 266ef66eb69SBarry Smith } 267a7a1495cSBarry Smith PetscFunctionReturn(0); 268a7a1495cSBarry Smith } 269a7a1495cSBarry Smith 2704a2ae208SSatish Balay #undef __FUNCT__ 2714a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSFunction" 272d763cef2SBarry Smith /* 273d763cef2SBarry Smith TSComputeRHSFunction - Evaluates the right-hand-side function. 274d763cef2SBarry Smith 275d763cef2SBarry Smith Note: If the user did not provide a function but merely a matrix, 276d763cef2SBarry Smith this routine applies the matrix. 277d763cef2SBarry Smith */ 278dfbe8321SBarry Smith PetscErrorCode TSComputeRHSFunction(TS ts,PetscReal t,Vec x,Vec y) 279d763cef2SBarry Smith { 280dfbe8321SBarry Smith PetscErrorCode ierr; 281d763cef2SBarry Smith 282d763cef2SBarry Smith PetscFunctionBegin; 2834482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 2844482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,2); 2854482741eSBarry Smith PetscValidHeaderSpecific(y,VEC_COOKIE,3); 286d763cef2SBarry Smith 287d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 288000e7ae3SMatthew Knepley if (ts->ops->rhsfunction) { 289d763cef2SBarry Smith PetscStackPush("TS user right-hand-side function"); 290000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsfunction)(ts,t,x,y,ts->funP);CHKERRQ(ierr); 291d763cef2SBarry Smith PetscStackPop; 2927c922b88SBarry Smith } else { 293000e7ae3SMatthew Knepley if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */ 294d763cef2SBarry Smith MatStructure flg; 295d763cef2SBarry Smith PetscStackPush("TS user right-hand-side matrix function"); 296000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->A,&ts->B,&flg,ts->jacP);CHKERRQ(ierr); 297d763cef2SBarry Smith PetscStackPop; 298d763cef2SBarry Smith } 299d763cef2SBarry Smith ierr = MatMult(ts->A,x,y);CHKERRQ(ierr); 3007c922b88SBarry Smith } 301d763cef2SBarry Smith 302d763cef2SBarry Smith /* apply user-provided boundary conditions (only needed if these are time dependent) */ 303d763cef2SBarry Smith ierr = TSComputeRHSBoundaryConditions(ts,t,y);CHKERRQ(ierr); 304d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 305d763cef2SBarry Smith 306d763cef2SBarry Smith PetscFunctionReturn(0); 307d763cef2SBarry Smith } 308d763cef2SBarry Smith 3094a2ae208SSatish Balay #undef __FUNCT__ 3104a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSFunction" 311d763cef2SBarry Smith /*@C 312d763cef2SBarry Smith TSSetRHSFunction - Sets the routine for evaluating the function, 313d763cef2SBarry Smith F(t,u), where U_t = F(t,u). 314d763cef2SBarry Smith 315d763cef2SBarry Smith Collective on TS 316d763cef2SBarry Smith 317d763cef2SBarry Smith Input Parameters: 318d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 319d763cef2SBarry Smith . f - routine for evaluating the right-hand-side function 320d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 321d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 322d763cef2SBarry Smith 323d763cef2SBarry Smith Calling sequence of func: 32487828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Vec F,void *ctx); 325d763cef2SBarry Smith 326d763cef2SBarry Smith + t - current timestep 327d763cef2SBarry Smith . u - input vector 328d763cef2SBarry Smith . F - function vector 329d763cef2SBarry Smith - ctx - [optional] user-defined function context 330d763cef2SBarry Smith 331d763cef2SBarry Smith Important: 332d763cef2SBarry Smith The user MUST call either this routine or TSSetRHSMatrix(). 333d763cef2SBarry Smith 334d763cef2SBarry Smith Level: beginner 335d763cef2SBarry Smith 336d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, function 337d763cef2SBarry Smith 338d763cef2SBarry Smith .seealso: TSSetRHSMatrix() 339d763cef2SBarry Smith @*/ 34063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS ts,PetscErrorCode (*f)(TS,PetscReal,Vec,Vec,void*),void *ctx) 341d763cef2SBarry Smith { 342d763cef2SBarry Smith PetscFunctionBegin; 343d763cef2SBarry Smith 3444482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 345d763cef2SBarry Smith if (ts->problem_type == TS_LINEAR) { 34629bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Cannot set function for linear problem"); 347d763cef2SBarry Smith } 348000e7ae3SMatthew Knepley ts->ops->rhsfunction = f; 349d763cef2SBarry Smith ts->funP = ctx; 350d763cef2SBarry Smith PetscFunctionReturn(0); 351d763cef2SBarry Smith } 352d763cef2SBarry Smith 3534a2ae208SSatish Balay #undef __FUNCT__ 3544a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSMatrix" 355d763cef2SBarry Smith /*@C 356d763cef2SBarry Smith TSSetRHSMatrix - Sets the function to compute the matrix A, where U_t = A(t) U. 357d763cef2SBarry Smith Also sets the location to store A. 358d763cef2SBarry Smith 359d763cef2SBarry Smith Collective on TS 360d763cef2SBarry Smith 361d763cef2SBarry Smith Input Parameters: 362d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 363d763cef2SBarry Smith . A - matrix 364d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 365d763cef2SBarry Smith . f - the matrix evaluation routine; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 366d763cef2SBarry Smith if A is not a function of t. 367d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 368d763cef2SBarry Smith matrix evaluation routine (may be PETSC_NULL) 369d763cef2SBarry Smith 370d763cef2SBarry Smith Calling sequence of func: 371a7cc72afSBarry Smith $ func (TS ts,PetscReal t,Mat *A,Mat *B,PetscInt *flag,void *ctx); 372d763cef2SBarry Smith 373d763cef2SBarry Smith + t - current timestep 374d763cef2SBarry Smith . A - matrix A, where U_t = A(t) U 375d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 376d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 37794b7f48cSBarry Smith structure (same as flag in KSPSetOperators()) 378d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 379d763cef2SBarry Smith 380d763cef2SBarry Smith Notes: 38194b7f48cSBarry Smith See KSPSetOperators() for important information about setting the flag 382d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 383d763cef2SBarry Smith 384d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 385d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 386d763cef2SBarry Smith completely new new matrix structure (not just different matrix elements) 387d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 388d763cef2SBarry Smith throughout the global iterations. 389d763cef2SBarry Smith 390d763cef2SBarry Smith Important: 391d763cef2SBarry Smith The user MUST call either this routine or TSSetRHSFunction(). 392d763cef2SBarry Smith 393d763cef2SBarry Smith Level: beginner 394d763cef2SBarry Smith 395d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, matrix 396d763cef2SBarry Smith 397d763cef2SBarry Smith .seealso: TSSetRHSFunction() 398d763cef2SBarry Smith @*/ 39963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSMatrix(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void *ctx) 400d763cef2SBarry Smith { 401d763cef2SBarry Smith PetscFunctionBegin; 4024482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 4034482741eSBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE,2); 4044482741eSBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE,3); 405c9780b6fSBarry Smith PetscCheckSameComm(ts,1,A,2); 406c9780b6fSBarry Smith PetscCheckSameComm(ts,1,B,3); 407d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 40829bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not for nonlinear problems; use TSSetRHSJacobian()"); 409d763cef2SBarry Smith } 410d763cef2SBarry Smith 411000e7ae3SMatthew Knepley ts->ops->rhsmatrix = f; 412d763cef2SBarry Smith ts->jacP = ctx; 413d763cef2SBarry Smith ts->A = A; 414d763cef2SBarry Smith ts->B = B; 415d763cef2SBarry Smith 416d763cef2SBarry Smith PetscFunctionReturn(0); 417d763cef2SBarry Smith } 418d763cef2SBarry Smith 4194a2ae208SSatish Balay #undef __FUNCT__ 4204a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSJacobian" 421d763cef2SBarry Smith /*@C 422d763cef2SBarry Smith TSSetRHSJacobian - Sets the function to compute the Jacobian of F, 423d763cef2SBarry Smith where U_t = F(U,t), as well as the location to store the matrix. 4243c94ec11SBarry Smith Use TSSetRHSMatrix() for linear problems. 425d763cef2SBarry Smith 426d763cef2SBarry Smith Collective on TS 427d763cef2SBarry Smith 428d763cef2SBarry Smith Input Parameters: 429d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 430d763cef2SBarry Smith . A - Jacobian matrix 431d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 432d763cef2SBarry Smith . f - the Jacobian evaluation routine 433d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 434d763cef2SBarry Smith Jacobian evaluation routine (may be PETSC_NULL) 435d763cef2SBarry Smith 436d763cef2SBarry Smith Calling sequence of func: 43787828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Mat *A,Mat *B,MatStructure *flag,void *ctx); 438d763cef2SBarry Smith 439d763cef2SBarry Smith + t - current timestep 440d763cef2SBarry Smith . u - input vector 441d763cef2SBarry Smith . A - matrix A, where U_t = A(t)u 442d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 443d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 44494b7f48cSBarry Smith structure (same as flag in KSPSetOperators()) 445d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 446d763cef2SBarry Smith 447d763cef2SBarry Smith Notes: 44894b7f48cSBarry Smith See KSPSetOperators() for important information about setting the flag 449d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 450d763cef2SBarry Smith 451d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 452d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 453d763cef2SBarry Smith completely new new matrix structure (not just different matrix elements) 454d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 455d763cef2SBarry Smith throughout the global iterations. 456d763cef2SBarry Smith 457d763cef2SBarry Smith Level: beginner 458d763cef2SBarry Smith 459d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, Jacobian 460d763cef2SBarry Smith 461d763cef2SBarry Smith .seealso: TSDefaultComputeJacobianColor(), 4623c94ec11SBarry Smith SNESDefaultComputeJacobianColor(), TSSetRHSFunction(), TSSetRHSMatrix() 463d763cef2SBarry Smith 464d763cef2SBarry Smith @*/ 46563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx) 466d763cef2SBarry Smith { 467d763cef2SBarry Smith PetscFunctionBegin; 4684482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 4694482741eSBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE,2); 4704482741eSBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE,3); 471c9780b6fSBarry Smith PetscCheckSameComm(ts,1,A,2); 472c9780b6fSBarry Smith PetscCheckSameComm(ts,1,B,3); 473d763cef2SBarry Smith if (ts->problem_type != TS_NONLINEAR) { 47429bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not for linear problems; use TSSetRHSMatrix()"); 475d763cef2SBarry Smith } 476d763cef2SBarry Smith 477000e7ae3SMatthew Knepley ts->ops->rhsjacobian = f; 478d763cef2SBarry Smith ts->jacP = ctx; 479d763cef2SBarry Smith ts->A = A; 480d763cef2SBarry Smith ts->B = B; 481d763cef2SBarry Smith PetscFunctionReturn(0); 482d763cef2SBarry Smith } 483d763cef2SBarry Smith 4844a2ae208SSatish Balay #undef __FUNCT__ 4854a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSBoundaryConditions" 486d763cef2SBarry Smith /* 487d763cef2SBarry Smith TSComputeRHSBoundaryConditions - Evaluates the boundary condition function. 488d763cef2SBarry Smith 489d763cef2SBarry Smith Note: If the user did not provide a function but merely a matrix, 490d763cef2SBarry Smith this routine applies the matrix. 491d763cef2SBarry Smith */ 492dfbe8321SBarry Smith PetscErrorCode TSComputeRHSBoundaryConditions(TS ts,PetscReal t,Vec x) 493d763cef2SBarry Smith { 494dfbe8321SBarry Smith PetscErrorCode ierr; 495d763cef2SBarry Smith 496d763cef2SBarry Smith PetscFunctionBegin; 4974482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 4984482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,3); 499c9780b6fSBarry Smith PetscCheckSameComm(ts,1,x,3); 500d763cef2SBarry Smith 501000e7ae3SMatthew Knepley if (ts->ops->rhsbc) { 502d763cef2SBarry Smith PetscStackPush("TS user boundary condition function"); 503000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsbc)(ts,t,x,ts->bcP);CHKERRQ(ierr); 504d763cef2SBarry Smith PetscStackPop; 505d763cef2SBarry Smith PetscFunctionReturn(0); 506d763cef2SBarry Smith } 507d763cef2SBarry Smith 508d763cef2SBarry Smith PetscFunctionReturn(0); 509d763cef2SBarry Smith } 510d763cef2SBarry Smith 5114a2ae208SSatish Balay #undef __FUNCT__ 5124a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSBoundaryConditions" 513d763cef2SBarry Smith /*@C 514d763cef2SBarry Smith TSSetRHSBoundaryConditions - Sets the routine for evaluating the function, 515d763cef2SBarry Smith boundary conditions for the function F. 516d763cef2SBarry Smith 517d763cef2SBarry Smith Collective on TS 518d763cef2SBarry Smith 519d763cef2SBarry Smith Input Parameters: 520d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 521d763cef2SBarry Smith . f - routine for evaluating the boundary condition function 522d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 523d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 524d763cef2SBarry Smith 525d763cef2SBarry Smith Calling sequence of func: 52687828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec F,void *ctx); 527d763cef2SBarry Smith 528d763cef2SBarry Smith + t - current timestep 529d763cef2SBarry Smith . F - function vector 530d763cef2SBarry Smith - ctx - [optional] user-defined function context 531d763cef2SBarry Smith 532d763cef2SBarry Smith Level: intermediate 533d763cef2SBarry Smith 534d763cef2SBarry Smith .keywords: TS, timestep, set, boundary conditions, function 535d763cef2SBarry Smith @*/ 53663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSBoundaryConditions(TS ts,PetscErrorCode (*f)(TS,PetscReal,Vec,void*),void *ctx) 537d763cef2SBarry Smith { 538d763cef2SBarry Smith PetscFunctionBegin; 539d763cef2SBarry Smith 5404482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 541d763cef2SBarry Smith if (ts->problem_type != TS_LINEAR) { 54229bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"For linear problems only"); 543d763cef2SBarry Smith } 544000e7ae3SMatthew Knepley ts->ops->rhsbc = f; 545d763cef2SBarry Smith ts->bcP = ctx; 546d763cef2SBarry Smith PetscFunctionReturn(0); 547d763cef2SBarry Smith } 548d763cef2SBarry Smith 5494a2ae208SSatish Balay #undef __FUNCT__ 5504a2ae208SSatish Balay #define __FUNCT__ "TSView" 5517e2c5f70SBarry Smith /*@C 552d763cef2SBarry Smith TSView - Prints the TS data structure. 553d763cef2SBarry Smith 5544c49b128SBarry Smith Collective on TS 555d763cef2SBarry Smith 556d763cef2SBarry Smith Input Parameters: 557d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 558d763cef2SBarry Smith - viewer - visualization context 559d763cef2SBarry Smith 560d763cef2SBarry Smith Options Database Key: 561d763cef2SBarry Smith . -ts_view - calls TSView() at end of TSStep() 562d763cef2SBarry Smith 563d763cef2SBarry Smith Notes: 564d763cef2SBarry Smith The available visualization contexts include 565b0a32e0cSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 566b0a32e0cSBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 567d763cef2SBarry Smith output where only the first processor opens 568d763cef2SBarry Smith the file. All other processors send their 569d763cef2SBarry Smith data to the first processor to print. 570d763cef2SBarry Smith 571d763cef2SBarry Smith The user can open an alternative visualization context with 572b0a32e0cSBarry Smith PetscViewerASCIIOpen() - output to a specified file. 573d763cef2SBarry Smith 574d763cef2SBarry Smith Level: beginner 575d763cef2SBarry Smith 576d763cef2SBarry Smith .keywords: TS, timestep, view 577d763cef2SBarry Smith 578b0a32e0cSBarry Smith .seealso: PetscViewerASCIIOpen() 579d763cef2SBarry Smith @*/ 58063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSView(TS ts,PetscViewer viewer) 581d763cef2SBarry Smith { 582dfbe8321SBarry Smith PetscErrorCode ierr; 583454a90a3SBarry Smith char *type; 58432077d6dSBarry Smith PetscTruth iascii,isstring; 585d763cef2SBarry Smith 586d763cef2SBarry Smith PetscFunctionBegin; 5874482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 588b0a32e0cSBarry Smith if (!viewer) viewer = PETSC_VIEWER_STDOUT_(ts->comm); 5894482741eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2); 590c9780b6fSBarry Smith PetscCheckSameComm(ts,1,viewer,2); 591fd16b177SBarry Smith 59232077d6dSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 593b0a32e0cSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr); 59432077d6dSBarry Smith if (iascii) { 595b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"TS Object:\n");CHKERRQ(ierr); 596454a90a3SBarry Smith ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr); 597454a90a3SBarry Smith if (type) { 598b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: %s\n",type);CHKERRQ(ierr); 599184914b5SBarry Smith } else { 600b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: not yet set\n");CHKERRQ(ierr); 601184914b5SBarry Smith } 602000e7ae3SMatthew Knepley if (ts->ops->view) { 603b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 604000e7ae3SMatthew Knepley ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr); 605b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 606d763cef2SBarry Smith } 60777431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum steps=%D\n",ts->max_steps);CHKERRQ(ierr); 608b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum time=%g\n",ts->max_time);CHKERRQ(ierr); 609d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 61077431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of nonlinear solver iterations=%D\n",ts->nonlinear_its);CHKERRQ(ierr); 611d763cef2SBarry Smith } 61277431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of linear solver iterations=%D\n",ts->linear_its);CHKERRQ(ierr); 6130f5bd95cSBarry Smith } else if (isstring) { 614454a90a3SBarry Smith ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr); 615b0a32e0cSBarry Smith ierr = PetscViewerStringSPrintf(viewer," %-7.7s",type);CHKERRQ(ierr); 616d763cef2SBarry Smith } 617b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 61894b7f48cSBarry Smith if (ts->ksp) {ierr = KSPView(ts->ksp,viewer);CHKERRQ(ierr);} 619d763cef2SBarry Smith if (ts->snes) {ierr = SNESView(ts->snes,viewer);CHKERRQ(ierr);} 620b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 621d763cef2SBarry Smith PetscFunctionReturn(0); 622d763cef2SBarry Smith } 623d763cef2SBarry Smith 624d763cef2SBarry Smith 6254a2ae208SSatish Balay #undef __FUNCT__ 6264a2ae208SSatish Balay #define __FUNCT__ "TSSetApplicationContext" 627d763cef2SBarry Smith /*@C 628d763cef2SBarry Smith TSSetApplicationContext - Sets an optional user-defined context for 629d763cef2SBarry Smith the timesteppers. 630d763cef2SBarry Smith 631d763cef2SBarry Smith Collective on TS 632d763cef2SBarry Smith 633d763cef2SBarry Smith Input Parameters: 634d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 635d763cef2SBarry Smith - usrP - optional user context 636d763cef2SBarry Smith 637d763cef2SBarry Smith Level: intermediate 638d763cef2SBarry Smith 639d763cef2SBarry Smith .keywords: TS, timestep, set, application, context 640d763cef2SBarry Smith 641d763cef2SBarry Smith .seealso: TSGetApplicationContext() 642d763cef2SBarry Smith @*/ 64363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS ts,void *usrP) 644d763cef2SBarry Smith { 645d763cef2SBarry Smith PetscFunctionBegin; 6464482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 647d763cef2SBarry Smith ts->user = usrP; 648d763cef2SBarry Smith PetscFunctionReturn(0); 649d763cef2SBarry Smith } 650d763cef2SBarry Smith 6514a2ae208SSatish Balay #undef __FUNCT__ 6524a2ae208SSatish Balay #define __FUNCT__ "TSGetApplicationContext" 653d763cef2SBarry Smith /*@C 654d763cef2SBarry Smith TSGetApplicationContext - Gets the user-defined context for the 655d763cef2SBarry Smith timestepper. 656d763cef2SBarry Smith 657d763cef2SBarry Smith Not Collective 658d763cef2SBarry Smith 659d763cef2SBarry Smith Input Parameter: 660d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 661d763cef2SBarry Smith 662d763cef2SBarry Smith Output Parameter: 663d763cef2SBarry Smith . usrP - user context 664d763cef2SBarry Smith 665d763cef2SBarry Smith Level: intermediate 666d763cef2SBarry Smith 667d763cef2SBarry Smith .keywords: TS, timestep, get, application, context 668d763cef2SBarry Smith 669d763cef2SBarry Smith .seealso: TSSetApplicationContext() 670d763cef2SBarry Smith @*/ 67163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS ts,void **usrP) 672d763cef2SBarry Smith { 673d763cef2SBarry Smith PetscFunctionBegin; 6744482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 675d763cef2SBarry Smith *usrP = ts->user; 676d763cef2SBarry Smith PetscFunctionReturn(0); 677d763cef2SBarry Smith } 678d763cef2SBarry Smith 6794a2ae208SSatish Balay #undef __FUNCT__ 6804a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStepNumber" 681d763cef2SBarry Smith /*@ 682d763cef2SBarry Smith TSGetTimeStepNumber - Gets the current number of timesteps. 683d763cef2SBarry Smith 684d763cef2SBarry Smith Not Collective 685d763cef2SBarry Smith 686d763cef2SBarry Smith Input Parameter: 687d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 688d763cef2SBarry Smith 689d763cef2SBarry Smith Output Parameter: 690d763cef2SBarry Smith . iter - number steps so far 691d763cef2SBarry Smith 692d763cef2SBarry Smith Level: intermediate 693d763cef2SBarry Smith 694d763cef2SBarry Smith .keywords: TS, timestep, get, iteration, number 695d763cef2SBarry Smith @*/ 69663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS ts,PetscInt* iter) 697d763cef2SBarry Smith { 698d763cef2SBarry Smith PetscFunctionBegin; 6994482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 7004482741eSBarry Smith PetscValidIntPointer(iter,2); 701d763cef2SBarry Smith *iter = ts->steps; 702d763cef2SBarry Smith PetscFunctionReturn(0); 703d763cef2SBarry Smith } 704d763cef2SBarry Smith 7054a2ae208SSatish Balay #undef __FUNCT__ 7064a2ae208SSatish Balay #define __FUNCT__ "TSSetInitialTimeStep" 707d763cef2SBarry Smith /*@ 708d763cef2SBarry Smith TSSetInitialTimeStep - Sets the initial timestep to be used, 709d763cef2SBarry Smith as well as the initial time. 710d763cef2SBarry Smith 711d763cef2SBarry Smith Collective on TS 712d763cef2SBarry Smith 713d763cef2SBarry Smith Input Parameters: 714d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 715d763cef2SBarry Smith . initial_time - the initial time 716d763cef2SBarry Smith - time_step - the size of the timestep 717d763cef2SBarry Smith 718d763cef2SBarry Smith Level: intermediate 719d763cef2SBarry Smith 720d763cef2SBarry Smith .seealso: TSSetTimeStep(), TSGetTimeStep() 721d763cef2SBarry Smith 722d763cef2SBarry Smith .keywords: TS, set, initial, timestep 723d763cef2SBarry Smith @*/ 72463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS ts,PetscReal initial_time,PetscReal time_step) 725d763cef2SBarry Smith { 726d763cef2SBarry Smith PetscFunctionBegin; 7274482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 728d763cef2SBarry Smith ts->time_step = time_step; 729d763cef2SBarry Smith ts->initial_time_step = time_step; 730d763cef2SBarry Smith ts->ptime = initial_time; 731d763cef2SBarry Smith PetscFunctionReturn(0); 732d763cef2SBarry Smith } 733d763cef2SBarry Smith 7344a2ae208SSatish Balay #undef __FUNCT__ 7354a2ae208SSatish Balay #define __FUNCT__ "TSSetTimeStep" 736d763cef2SBarry Smith /*@ 737d763cef2SBarry Smith TSSetTimeStep - Allows one to reset the timestep at any time, 738d763cef2SBarry Smith useful for simple pseudo-timestepping codes. 739d763cef2SBarry Smith 740d763cef2SBarry Smith Collective on TS 741d763cef2SBarry Smith 742d763cef2SBarry Smith Input Parameters: 743d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 744d763cef2SBarry Smith - time_step - the size of the timestep 745d763cef2SBarry Smith 746d763cef2SBarry Smith Level: intermediate 747d763cef2SBarry Smith 748d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 749d763cef2SBarry Smith 750d763cef2SBarry Smith .keywords: TS, set, timestep 751d763cef2SBarry Smith @*/ 75263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS ts,PetscReal time_step) 753d763cef2SBarry Smith { 754d763cef2SBarry Smith PetscFunctionBegin; 7554482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 756d763cef2SBarry Smith ts->time_step = time_step; 757d763cef2SBarry Smith PetscFunctionReturn(0); 758d763cef2SBarry Smith } 759d763cef2SBarry Smith 7604a2ae208SSatish Balay #undef __FUNCT__ 7614a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStep" 762d763cef2SBarry Smith /*@ 763d763cef2SBarry Smith TSGetTimeStep - Gets the current timestep size. 764d763cef2SBarry Smith 765d763cef2SBarry Smith Not Collective 766d763cef2SBarry Smith 767d763cef2SBarry Smith Input Parameter: 768d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 769d763cef2SBarry Smith 770d763cef2SBarry Smith Output Parameter: 771d763cef2SBarry Smith . dt - the current timestep size 772d763cef2SBarry Smith 773d763cef2SBarry Smith Level: intermediate 774d763cef2SBarry Smith 775d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 776d763cef2SBarry Smith 777d763cef2SBarry Smith .keywords: TS, get, timestep 778d763cef2SBarry Smith @*/ 77963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS ts,PetscReal* dt) 780d763cef2SBarry Smith { 781d763cef2SBarry Smith PetscFunctionBegin; 7824482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 7834482741eSBarry Smith PetscValidDoublePointer(dt,2); 784d763cef2SBarry Smith *dt = ts->time_step; 785d763cef2SBarry Smith PetscFunctionReturn(0); 786d763cef2SBarry Smith } 787d763cef2SBarry Smith 7884a2ae208SSatish Balay #undef __FUNCT__ 7894a2ae208SSatish Balay #define __FUNCT__ "TSGetSolution" 790d763cef2SBarry Smith /*@C 791d763cef2SBarry Smith TSGetSolution - Returns the solution at the present timestep. It 792d763cef2SBarry Smith is valid to call this routine inside the function that you are evaluating 793d763cef2SBarry Smith in order to move to the new timestep. This vector not changed until 794d763cef2SBarry Smith the solution at the next timestep has been calculated. 795d763cef2SBarry Smith 796d763cef2SBarry Smith Not Collective, but Vec returned is parallel if TS is parallel 797d763cef2SBarry Smith 798d763cef2SBarry Smith Input Parameter: 799d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 800d763cef2SBarry Smith 801d763cef2SBarry Smith Output Parameter: 802d763cef2SBarry Smith . v - the vector containing the solution 803d763cef2SBarry Smith 804d763cef2SBarry Smith Level: intermediate 805d763cef2SBarry Smith 806d763cef2SBarry Smith .seealso: TSGetTimeStep() 807d763cef2SBarry Smith 808d763cef2SBarry Smith .keywords: TS, timestep, get, solution 809d763cef2SBarry Smith @*/ 81063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS ts,Vec *v) 811d763cef2SBarry Smith { 812d763cef2SBarry Smith PetscFunctionBegin; 8134482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 8144482741eSBarry Smith PetscValidPointer(v,2); 815d763cef2SBarry Smith *v = ts->vec_sol_always; 816d763cef2SBarry Smith PetscFunctionReturn(0); 817d763cef2SBarry Smith } 818d763cef2SBarry Smith 819bdad233fSMatthew Knepley /* ----- Routines to initialize and destroy a timestepper ---- */ 8204a2ae208SSatish Balay #undef __FUNCT__ 821bdad233fSMatthew Knepley #define __FUNCT__ "TSSetProblemType" 822d763cef2SBarry Smith /*@C 823bdad233fSMatthew Knepley TSSetProblemType - Sets the type of problem to be solved. 824d763cef2SBarry Smith 825bdad233fSMatthew Knepley Not collective 826d763cef2SBarry Smith 827bdad233fSMatthew Knepley Input Parameters: 828bdad233fSMatthew Knepley + ts - The TS 829bdad233fSMatthew Knepley - type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 830d763cef2SBarry Smith .vb 831d763cef2SBarry Smith U_t = A U 832d763cef2SBarry Smith U_t = A(t) U 833d763cef2SBarry Smith U_t = F(t,U) 834d763cef2SBarry Smith .ve 835d763cef2SBarry Smith 836d763cef2SBarry Smith Level: beginner 837d763cef2SBarry Smith 838bdad233fSMatthew Knepley .keywords: TS, problem type 839bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 840d763cef2SBarry Smith @*/ 84163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS ts, TSProblemType type) 842a7cc72afSBarry Smith { 843d763cef2SBarry Smith PetscFunctionBegin; 8444482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 845bdad233fSMatthew Knepley ts->problem_type = type; 846d763cef2SBarry Smith PetscFunctionReturn(0); 847d763cef2SBarry Smith } 848d763cef2SBarry Smith 849bdad233fSMatthew Knepley #undef __FUNCT__ 850bdad233fSMatthew Knepley #define __FUNCT__ "TSGetProblemType" 851bdad233fSMatthew Knepley /*@C 852bdad233fSMatthew Knepley TSGetProblemType - Gets the type of problem to be solved. 853bdad233fSMatthew Knepley 854bdad233fSMatthew Knepley Not collective 855bdad233fSMatthew Knepley 856bdad233fSMatthew Knepley Input Parameter: 857bdad233fSMatthew Knepley . ts - The TS 858bdad233fSMatthew Knepley 859bdad233fSMatthew Knepley Output Parameter: 860bdad233fSMatthew Knepley . type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 861bdad233fSMatthew Knepley .vb 862bdad233fSMatthew Knepley U_t = A U 863bdad233fSMatthew Knepley U_t = A(t) U 864bdad233fSMatthew Knepley U_t = F(t,U) 865bdad233fSMatthew Knepley .ve 866bdad233fSMatthew Knepley 867bdad233fSMatthew Knepley Level: beginner 868bdad233fSMatthew Knepley 869bdad233fSMatthew Knepley .keywords: TS, problem type 870bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 871bdad233fSMatthew Knepley @*/ 87263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS ts, TSProblemType *type) 873a7cc72afSBarry Smith { 874bdad233fSMatthew Knepley PetscFunctionBegin; 8754482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 8764482741eSBarry Smith PetscValidIntPointer(type,2); 877bdad233fSMatthew Knepley *type = ts->problem_type; 878bdad233fSMatthew Knepley PetscFunctionReturn(0); 879bdad233fSMatthew Knepley } 880d763cef2SBarry Smith 8814a2ae208SSatish Balay #undef __FUNCT__ 8824a2ae208SSatish Balay #define __FUNCT__ "TSSetUp" 883d763cef2SBarry Smith /*@ 884d763cef2SBarry Smith TSSetUp - Sets up the internal data structures for the later use 885d763cef2SBarry Smith of a timestepper. 886d763cef2SBarry Smith 887d763cef2SBarry Smith Collective on TS 888d763cef2SBarry Smith 889d763cef2SBarry Smith Input Parameter: 890d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 891d763cef2SBarry Smith 892d763cef2SBarry Smith Notes: 893d763cef2SBarry Smith For basic use of the TS solvers the user need not explicitly call 894d763cef2SBarry Smith TSSetUp(), since these actions will automatically occur during 895d763cef2SBarry Smith the call to TSStep(). However, if one wishes to control this 896d763cef2SBarry Smith phase separately, TSSetUp() should be called after TSCreate() 897d763cef2SBarry Smith and optional routines of the form TSSetXXX(), but before TSStep(). 898d763cef2SBarry Smith 899d763cef2SBarry Smith Level: advanced 900d763cef2SBarry Smith 901d763cef2SBarry Smith .keywords: TS, timestep, setup 902d763cef2SBarry Smith 903d763cef2SBarry Smith .seealso: TSCreate(), TSStep(), TSDestroy() 904d763cef2SBarry Smith @*/ 90563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS ts) 906d763cef2SBarry Smith { 907dfbe8321SBarry Smith PetscErrorCode ierr; 908d763cef2SBarry Smith 909d763cef2SBarry Smith PetscFunctionBegin; 9104482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 91129bbc08cSBarry Smith if (!ts->vec_sol) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call TSSetSolution() first"); 912d763cef2SBarry Smith if (!ts->type_name) { 913d763cef2SBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 914d763cef2SBarry Smith } 915000e7ae3SMatthew Knepley ierr = (*ts->ops->setup)(ts);CHKERRQ(ierr); 916d763cef2SBarry Smith ts->setupcalled = 1; 917d763cef2SBarry Smith PetscFunctionReturn(0); 918d763cef2SBarry Smith } 919d763cef2SBarry Smith 9204a2ae208SSatish Balay #undef __FUNCT__ 9214a2ae208SSatish Balay #define __FUNCT__ "TSDestroy" 922d763cef2SBarry Smith /*@C 923d763cef2SBarry Smith TSDestroy - Destroys the timestepper context that was created 924d763cef2SBarry Smith with TSCreate(). 925d763cef2SBarry Smith 926d763cef2SBarry Smith Collective on TS 927d763cef2SBarry Smith 928d763cef2SBarry Smith Input Parameter: 929d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 930d763cef2SBarry Smith 931d763cef2SBarry Smith Level: beginner 932d763cef2SBarry Smith 933d763cef2SBarry Smith .keywords: TS, timestepper, destroy 934d763cef2SBarry Smith 935d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve() 936d763cef2SBarry Smith @*/ 93763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS ts) 938d763cef2SBarry Smith { 9396849ba73SBarry Smith PetscErrorCode ierr; 940a7cc72afSBarry Smith PetscInt i; 941d763cef2SBarry Smith 942d763cef2SBarry Smith PetscFunctionBegin; 9434482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 944d763cef2SBarry Smith if (--ts->refct > 0) PetscFunctionReturn(0); 945d763cef2SBarry Smith 946be0abb6dSBarry Smith /* if memory was published with AMS then destroy it */ 9470f5bd95cSBarry Smith ierr = PetscObjectDepublish(ts);CHKERRQ(ierr); 948be0abb6dSBarry Smith 94994b7f48cSBarry Smith if (ts->ksp) {ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);} 950d763cef2SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 951000e7ae3SMatthew Knepley ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr); 952329f5518SBarry Smith for (i=0; i<ts->numbermonitors; i++) { 953329f5518SBarry Smith if (ts->mdestroy[i]) { 954329f5518SBarry Smith ierr = (*ts->mdestroy[i])(ts->monitorcontext[i]);CHKERRQ(ierr); 955329f5518SBarry Smith } 956329f5518SBarry Smith } 957a79aaaedSSatish Balay ierr = PetscHeaderDestroy(ts);CHKERRQ(ierr); 958d763cef2SBarry Smith PetscFunctionReturn(0); 959d763cef2SBarry Smith } 960d763cef2SBarry Smith 9614a2ae208SSatish Balay #undef __FUNCT__ 9624a2ae208SSatish Balay #define __FUNCT__ "TSGetSNES" 963d763cef2SBarry Smith /*@C 964d763cef2SBarry Smith TSGetSNES - Returns the SNES (nonlinear solver) associated with 965d763cef2SBarry Smith a TS (timestepper) context. Valid only for nonlinear problems. 966d763cef2SBarry Smith 967d763cef2SBarry Smith Not Collective, but SNES is parallel if TS is parallel 968d763cef2SBarry Smith 969d763cef2SBarry Smith Input Parameter: 970d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 971d763cef2SBarry Smith 972d763cef2SBarry Smith Output Parameter: 973d763cef2SBarry Smith . snes - the nonlinear solver context 974d763cef2SBarry Smith 975d763cef2SBarry Smith Notes: 976d763cef2SBarry Smith The user can then directly manipulate the SNES context to set various 977d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 97894b7f48cSBarry Smith KSP, KSP, and PC contexts as well. 979d763cef2SBarry Smith 980d763cef2SBarry Smith TSGetSNES() does not work for integrators that do not use SNES; in 981d763cef2SBarry Smith this case TSGetSNES() returns PETSC_NULL in snes. 982d763cef2SBarry Smith 983d763cef2SBarry Smith Level: beginner 984d763cef2SBarry Smith 985d763cef2SBarry Smith .keywords: timestep, get, SNES 986d763cef2SBarry Smith @*/ 98763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS ts,SNES *snes) 988d763cef2SBarry Smith { 989d763cef2SBarry Smith PetscFunctionBegin; 9904482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 9914482741eSBarry Smith PetscValidPointer(snes,2); 99294b7f48cSBarry Smith if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Nonlinear only; use TSGetKSP()"); 993d763cef2SBarry Smith *snes = ts->snes; 994d763cef2SBarry Smith PetscFunctionReturn(0); 995d763cef2SBarry Smith } 996d763cef2SBarry Smith 9974a2ae208SSatish Balay #undef __FUNCT__ 99894b7f48cSBarry Smith #define __FUNCT__ "TSGetKSP" 999d763cef2SBarry Smith /*@C 100094b7f48cSBarry Smith TSGetKSP - Returns the KSP (linear solver) associated with 1001d763cef2SBarry Smith a TS (timestepper) context. 1002d763cef2SBarry Smith 100394b7f48cSBarry Smith Not Collective, but KSP is parallel if TS is parallel 1004d763cef2SBarry Smith 1005d763cef2SBarry Smith Input Parameter: 1006d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1007d763cef2SBarry Smith 1008d763cef2SBarry Smith Output Parameter: 100994b7f48cSBarry Smith . ksp - the nonlinear solver context 1010d763cef2SBarry Smith 1011d763cef2SBarry Smith Notes: 101294b7f48cSBarry Smith The user can then directly manipulate the KSP context to set various 1013d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 1014d763cef2SBarry Smith KSP and PC contexts as well. 1015d763cef2SBarry Smith 101694b7f48cSBarry Smith TSGetKSP() does not work for integrators that do not use KSP; 101794b7f48cSBarry Smith in this case TSGetKSP() returns PETSC_NULL in ksp. 1018d763cef2SBarry Smith 1019d763cef2SBarry Smith Level: beginner 1020d763cef2SBarry Smith 102194b7f48cSBarry Smith .keywords: timestep, get, KSP 1022d763cef2SBarry Smith @*/ 102363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS ts,KSP *ksp) 1024d763cef2SBarry Smith { 1025d763cef2SBarry Smith PetscFunctionBegin; 10264482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 10274482741eSBarry Smith PetscValidPointer(ksp,2); 102829bbc08cSBarry Smith if (ts->problem_type != TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Linear only; use TSGetSNES()"); 102994b7f48cSBarry Smith *ksp = ts->ksp; 1030d763cef2SBarry Smith PetscFunctionReturn(0); 1031d763cef2SBarry Smith } 1032d763cef2SBarry Smith 1033d763cef2SBarry Smith /* ----------- Routines to set solver parameters ---------- */ 1034d763cef2SBarry Smith 10354a2ae208SSatish Balay #undef __FUNCT__ 1036adb62b0dSMatthew Knepley #define __FUNCT__ "TSGetDuration" 1037adb62b0dSMatthew Knepley /*@ 1038adb62b0dSMatthew Knepley TSGetDuration - Gets the maximum number of timesteps to use and 1039adb62b0dSMatthew Knepley maximum time for iteration. 1040adb62b0dSMatthew Knepley 1041adb62b0dSMatthew Knepley Collective on TS 1042adb62b0dSMatthew Knepley 1043adb62b0dSMatthew Knepley Input Parameters: 1044adb62b0dSMatthew Knepley + ts - the TS context obtained from TSCreate() 1045adb62b0dSMatthew Knepley . maxsteps - maximum number of iterations to use, or PETSC_NULL 1046adb62b0dSMatthew Knepley - maxtime - final time to iterate to, or PETSC_NULL 1047adb62b0dSMatthew Knepley 1048adb62b0dSMatthew Knepley Level: intermediate 1049adb62b0dSMatthew Knepley 1050adb62b0dSMatthew Knepley .keywords: TS, timestep, get, maximum, iterations, time 1051adb62b0dSMatthew Knepley @*/ 105263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS ts, PetscInt *maxsteps, PetscReal *maxtime) 1053adb62b0dSMatthew Knepley { 1054adb62b0dSMatthew Knepley PetscFunctionBegin; 10554482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1056abc0a331SBarry Smith if (maxsteps) { 10574482741eSBarry Smith PetscValidIntPointer(maxsteps,2); 1058adb62b0dSMatthew Knepley *maxsteps = ts->max_steps; 1059adb62b0dSMatthew Knepley } 1060abc0a331SBarry Smith if (maxtime ) { 10614482741eSBarry Smith PetscValidScalarPointer(maxtime,3); 1062adb62b0dSMatthew Knepley *maxtime = ts->max_time; 1063adb62b0dSMatthew Knepley } 1064adb62b0dSMatthew Knepley PetscFunctionReturn(0); 1065adb62b0dSMatthew Knepley } 1066adb62b0dSMatthew Knepley 1067adb62b0dSMatthew Knepley #undef __FUNCT__ 10684a2ae208SSatish Balay #define __FUNCT__ "TSSetDuration" 1069d763cef2SBarry Smith /*@ 1070d763cef2SBarry Smith TSSetDuration - Sets the maximum number of timesteps to use and 1071d763cef2SBarry Smith maximum time for iteration. 1072d763cef2SBarry Smith 1073d763cef2SBarry Smith Collective on TS 1074d763cef2SBarry Smith 1075d763cef2SBarry Smith Input Parameters: 1076d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1077d763cef2SBarry Smith . maxsteps - maximum number of iterations to use 1078d763cef2SBarry Smith - maxtime - final time to iterate to 1079d763cef2SBarry Smith 1080d763cef2SBarry Smith Options Database Keys: 1081d763cef2SBarry Smith . -ts_max_steps <maxsteps> - Sets maxsteps 1082d763cef2SBarry Smith . -ts_max_time <maxtime> - Sets maxtime 1083d763cef2SBarry Smith 1084d763cef2SBarry Smith Notes: 1085d763cef2SBarry Smith The default maximum number of iterations is 5000. Default time is 5.0 1086d763cef2SBarry Smith 1087d763cef2SBarry Smith Level: intermediate 1088d763cef2SBarry Smith 1089d763cef2SBarry Smith .keywords: TS, timestep, set, maximum, iterations 1090d763cef2SBarry Smith @*/ 109163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS ts,PetscInt maxsteps,PetscReal maxtime) 1092d763cef2SBarry Smith { 1093d763cef2SBarry Smith PetscFunctionBegin; 10944482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1095d763cef2SBarry Smith ts->max_steps = maxsteps; 1096d763cef2SBarry Smith ts->max_time = maxtime; 1097d763cef2SBarry Smith PetscFunctionReturn(0); 1098d763cef2SBarry Smith } 1099d763cef2SBarry Smith 11004a2ae208SSatish Balay #undef __FUNCT__ 11014a2ae208SSatish Balay #define __FUNCT__ "TSSetSolution" 1102d763cef2SBarry Smith /*@ 1103d763cef2SBarry Smith TSSetSolution - Sets the initial solution vector 1104d763cef2SBarry Smith for use by the TS routines. 1105d763cef2SBarry Smith 1106d763cef2SBarry Smith Collective on TS and Vec 1107d763cef2SBarry Smith 1108d763cef2SBarry Smith Input Parameters: 1109d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1110d763cef2SBarry Smith - x - the solution vector 1111d763cef2SBarry Smith 1112d763cef2SBarry Smith Level: beginner 1113d763cef2SBarry Smith 1114d763cef2SBarry Smith .keywords: TS, timestep, set, solution, initial conditions 1115d763cef2SBarry Smith @*/ 111663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS ts,Vec x) 1117d763cef2SBarry Smith { 1118d763cef2SBarry Smith PetscFunctionBegin; 11194482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 11204482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,2); 1121d763cef2SBarry Smith ts->vec_sol = ts->vec_sol_always = x; 1122d763cef2SBarry Smith PetscFunctionReturn(0); 1123d763cef2SBarry Smith } 1124d763cef2SBarry Smith 1125e74ef692SMatthew Knepley #undef __FUNCT__ 1126e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultRhsBC" 1127000e7ae3SMatthew Knepley /*@ 1128000e7ae3SMatthew Knepley TSDefaultRhsBC - The default boundary condition function which does nothing. 1129000e7ae3SMatthew Knepley 1130000e7ae3SMatthew Knepley Collective on TS 1131000e7ae3SMatthew Knepley 1132000e7ae3SMatthew Knepley Input Parameters: 1133000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1134000e7ae3SMatthew Knepley . rhs - The Rhs 1135000e7ae3SMatthew Knepley - ctx - The user-context 1136000e7ae3SMatthew Knepley 1137000e7ae3SMatthew Knepley Level: developer 1138000e7ae3SMatthew Knepley 1139000e7ae3SMatthew Knepley .keywords: TS, Rhs, boundary conditions 1140000e7ae3SMatthew Knepley @*/ 114163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultRhsBC(TS ts, Vec rhs, void *ctx) 1142000e7ae3SMatthew Knepley { 1143000e7ae3SMatthew Knepley PetscFunctionBegin; 1144000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1145000e7ae3SMatthew Knepley } 1146000e7ae3SMatthew Knepley 1147e74ef692SMatthew Knepley #undef __FUNCT__ 1148e74ef692SMatthew Knepley #define __FUNCT__ "TSSetSystemMatrixBC" 1149ac226902SBarry Smith /*@C 1150000e7ae3SMatthew Knepley TSSetSystemMatrixBC - Sets the function which applies boundary conditions 1151000e7ae3SMatthew Knepley to the system matrix and preconditioner of each system. 1152000e7ae3SMatthew Knepley 1153000e7ae3SMatthew Knepley Collective on TS 1154000e7ae3SMatthew Knepley 1155000e7ae3SMatthew Knepley Input Parameters: 1156000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1157000e7ae3SMatthew Knepley - func - The function 1158000e7ae3SMatthew Knepley 1159000e7ae3SMatthew Knepley Calling sequence of func: 1160000e7ae3SMatthew Knepley . func (TS ts, Mat A, Mat B, void *ctx); 1161000e7ae3SMatthew Knepley 1162000e7ae3SMatthew Knepley + A - The current system matrix 1163000e7ae3SMatthew Knepley . B - The current preconditioner 1164000e7ae3SMatthew Knepley - ctx - The user-context 1165000e7ae3SMatthew Knepley 1166000e7ae3SMatthew Knepley Level: intermediate 1167000e7ae3SMatthew Knepley 1168000e7ae3SMatthew Knepley .keywords: TS, System matrix, boundary conditions 1169000e7ae3SMatthew Knepley @*/ 117063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSystemMatrixBC(TS ts, PetscErrorCode (*func)(TS, Mat, Mat, void *)) 1171000e7ae3SMatthew Knepley { 1172000e7ae3SMatthew Knepley PetscFunctionBegin; 11734482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1174000e7ae3SMatthew Knepley ts->ops->applymatrixbc = func; 1175000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1176000e7ae3SMatthew Knepley } 1177000e7ae3SMatthew Knepley 1178e74ef692SMatthew Knepley #undef __FUNCT__ 1179e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultSystemMatrixBC" 1180000e7ae3SMatthew Knepley /*@ 1181000e7ae3SMatthew Knepley TSDefaultSystemMatrixBC - The default boundary condition function which 1182000e7ae3SMatthew Knepley does nothing. 1183000e7ae3SMatthew Knepley 1184000e7ae3SMatthew Knepley Collective on TS 1185000e7ae3SMatthew Knepley 1186000e7ae3SMatthew Knepley Input Parameters: 1187000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1188000e7ae3SMatthew Knepley . A - The system matrix 1189000e7ae3SMatthew Knepley . B - The preconditioner 1190000e7ae3SMatthew Knepley - ctx - The user-context 1191000e7ae3SMatthew Knepley 1192000e7ae3SMatthew Knepley Level: developer 1193000e7ae3SMatthew Knepley 1194000e7ae3SMatthew Knepley .keywords: TS, System matrix, boundary conditions 1195000e7ae3SMatthew Knepley @*/ 119663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultSystemMatrixBC(TS ts, Mat A, Mat B, void *ctx) 1197000e7ae3SMatthew Knepley { 1198000e7ae3SMatthew Knepley PetscFunctionBegin; 1199000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1200000e7ae3SMatthew Knepley } 1201000e7ae3SMatthew Knepley 1202e74ef692SMatthew Knepley #undef __FUNCT__ 1203e74ef692SMatthew Knepley #define __FUNCT__ "TSSetSolutionBC" 1204ac226902SBarry Smith /*@C 1205000e7ae3SMatthew Knepley TSSetSolutionBC - Sets the function which applies boundary conditions 1206000e7ae3SMatthew Knepley to the solution of each system. This is necessary in nonlinear systems 1207000e7ae3SMatthew Knepley which time dependent boundary conditions. 1208000e7ae3SMatthew Knepley 1209000e7ae3SMatthew Knepley Collective on TS 1210000e7ae3SMatthew Knepley 1211000e7ae3SMatthew Knepley Input Parameters: 1212000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1213000e7ae3SMatthew Knepley - func - The function 1214000e7ae3SMatthew Knepley 1215000e7ae3SMatthew Knepley Calling sequence of func: 1216000e7ae3SMatthew Knepley . func (TS ts, Vec rsol, void *ctx); 1217000e7ae3SMatthew Knepley 1218000e7ae3SMatthew Knepley + sol - The current solution vector 1219000e7ae3SMatthew Knepley - ctx - The user-context 1220000e7ae3SMatthew Knepley 1221000e7ae3SMatthew Knepley Level: intermediate 1222000e7ae3SMatthew Knepley 1223000e7ae3SMatthew Knepley .keywords: TS, solution, boundary conditions 1224000e7ae3SMatthew Knepley @*/ 122563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSolutionBC(TS ts, PetscErrorCode (*func)(TS, Vec, void *)) 1226000e7ae3SMatthew Knepley { 1227000e7ae3SMatthew Knepley PetscFunctionBegin; 12284482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1229000e7ae3SMatthew Knepley ts->ops->applysolbc = func; 1230000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1231000e7ae3SMatthew Knepley } 1232000e7ae3SMatthew Knepley 1233e74ef692SMatthew Knepley #undef __FUNCT__ 1234e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultSolutionBC" 1235000e7ae3SMatthew Knepley /*@ 1236000e7ae3SMatthew Knepley TSDefaultSolutionBC - The default boundary condition function which 1237000e7ae3SMatthew Knepley 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 . sol - The solution 1244000e7ae3SMatthew Knepley - ctx - The user-context 1245000e7ae3SMatthew Knepley 1246000e7ae3SMatthew Knepley Level: developer 1247000e7ae3SMatthew Knepley 1248000e7ae3SMatthew Knepley .keywords: TS, solution, boundary conditions 1249000e7ae3SMatthew Knepley @*/ 125063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultSolutionBC(TS ts, Vec sol, void *ctx) 1251000e7ae3SMatthew Knepley { 1252000e7ae3SMatthew Knepley PetscFunctionBegin; 1253000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1254000e7ae3SMatthew Knepley } 1255000e7ae3SMatthew Knepley 1256e74ef692SMatthew Knepley #undef __FUNCT__ 1257e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPreStep" 1258ac226902SBarry Smith /*@C 1259000e7ae3SMatthew Knepley TSSetPreStep - Sets the general-purpose function 1260000e7ae3SMatthew Knepley called once at the beginning of time stepping. 1261000e7ae3SMatthew Knepley 1262000e7ae3SMatthew Knepley Collective on TS 1263000e7ae3SMatthew Knepley 1264000e7ae3SMatthew Knepley Input Parameters: 1265000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1266000e7ae3SMatthew Knepley - func - The function 1267000e7ae3SMatthew Knepley 1268000e7ae3SMatthew Knepley Calling sequence of func: 1269000e7ae3SMatthew Knepley . func (TS ts); 1270000e7ae3SMatthew Knepley 1271000e7ae3SMatthew Knepley Level: intermediate 1272000e7ae3SMatthew Knepley 1273000e7ae3SMatthew Knepley .keywords: TS, timestep 1274000e7ae3SMatthew Knepley @*/ 127563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS ts, PetscErrorCode (*func)(TS)) 1276000e7ae3SMatthew Knepley { 1277000e7ae3SMatthew Knepley PetscFunctionBegin; 12784482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1279000e7ae3SMatthew Knepley ts->ops->prestep = func; 1280000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1281000e7ae3SMatthew Knepley } 1282000e7ae3SMatthew Knepley 1283e74ef692SMatthew Knepley #undef __FUNCT__ 1284e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPreStep" 1285000e7ae3SMatthew Knepley /*@ 1286000e7ae3SMatthew Knepley TSDefaultPreStep - The default pre-stepping function which does nothing. 1287000e7ae3SMatthew Knepley 1288000e7ae3SMatthew Knepley Collective on TS 1289000e7ae3SMatthew Knepley 1290000e7ae3SMatthew Knepley Input Parameters: 1291000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1292000e7ae3SMatthew Knepley 1293000e7ae3SMatthew Knepley Level: developer 1294000e7ae3SMatthew Knepley 1295000e7ae3SMatthew Knepley .keywords: TS, timestep 1296000e7ae3SMatthew Knepley @*/ 129763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS ts) 1298000e7ae3SMatthew Knepley { 1299000e7ae3SMatthew Knepley PetscFunctionBegin; 1300000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1301000e7ae3SMatthew Knepley } 1302000e7ae3SMatthew Knepley 1303e74ef692SMatthew Knepley #undef __FUNCT__ 1304e74ef692SMatthew Knepley #define __FUNCT__ "TSSetUpdate" 1305ac226902SBarry Smith /*@C 1306000e7ae3SMatthew Knepley TSSetUpdate - Sets the general-purpose update function called 1307000e7ae3SMatthew Knepley at the beginning of every time step. This function can change 1308000e7ae3SMatthew Knepley the time step. 1309000e7ae3SMatthew Knepley 1310000e7ae3SMatthew Knepley Collective on TS 1311000e7ae3SMatthew Knepley 1312000e7ae3SMatthew Knepley Input Parameters: 1313000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1314000e7ae3SMatthew Knepley - func - The function 1315000e7ae3SMatthew Knepley 1316000e7ae3SMatthew Knepley Calling sequence of func: 1317000e7ae3SMatthew Knepley . func (TS ts, double t, double *dt); 1318000e7ae3SMatthew Knepley 1319000e7ae3SMatthew Knepley + t - The current time 1320000e7ae3SMatthew Knepley - dt - The current time step 1321000e7ae3SMatthew Knepley 1322000e7ae3SMatthew Knepley Level: intermediate 1323000e7ae3SMatthew Knepley 1324000e7ae3SMatthew Knepley .keywords: TS, update, timestep 1325000e7ae3SMatthew Knepley @*/ 132663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUpdate(TS ts, PetscErrorCode (*func)(TS, PetscReal, PetscReal *)) 1327000e7ae3SMatthew Knepley { 1328000e7ae3SMatthew Knepley PetscFunctionBegin; 13294482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1330000e7ae3SMatthew Knepley ts->ops->update = func; 1331000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1332000e7ae3SMatthew Knepley } 1333000e7ae3SMatthew Knepley 1334e74ef692SMatthew Knepley #undef __FUNCT__ 1335e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultUpdate" 1336000e7ae3SMatthew Knepley /*@ 1337000e7ae3SMatthew Knepley TSDefaultUpdate - The default update function which does nothing. 1338000e7ae3SMatthew Knepley 1339000e7ae3SMatthew Knepley Collective on TS 1340000e7ae3SMatthew Knepley 1341000e7ae3SMatthew Knepley Input Parameters: 1342000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1343000e7ae3SMatthew Knepley - t - The current time 1344000e7ae3SMatthew Knepley 1345000e7ae3SMatthew Knepley Output Parameters: 1346000e7ae3SMatthew Knepley . dt - The current time step 1347000e7ae3SMatthew Knepley 1348000e7ae3SMatthew Knepley Level: developer 1349000e7ae3SMatthew Knepley 1350000e7ae3SMatthew Knepley .keywords: TS, update, timestep 1351000e7ae3SMatthew Knepley @*/ 135263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultUpdate(TS ts, PetscReal t, PetscReal *dt) 1353000e7ae3SMatthew Knepley { 1354000e7ae3SMatthew Knepley PetscFunctionBegin; 1355000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1356000e7ae3SMatthew Knepley } 1357000e7ae3SMatthew Knepley 1358e74ef692SMatthew Knepley #undef __FUNCT__ 1359e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPostStep" 1360ac226902SBarry Smith /*@C 1361000e7ae3SMatthew Knepley TSSetPostStep - Sets the general-purpose function 1362000e7ae3SMatthew Knepley called once at the end of time stepping. 1363000e7ae3SMatthew Knepley 1364000e7ae3SMatthew Knepley Collective on TS 1365000e7ae3SMatthew Knepley 1366000e7ae3SMatthew Knepley Input Parameters: 1367000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1368000e7ae3SMatthew Knepley - func - The function 1369000e7ae3SMatthew Knepley 1370000e7ae3SMatthew Knepley Calling sequence of func: 1371000e7ae3SMatthew Knepley . func (TS ts); 1372000e7ae3SMatthew Knepley 1373000e7ae3SMatthew Knepley Level: intermediate 1374000e7ae3SMatthew Knepley 1375000e7ae3SMatthew Knepley .keywords: TS, timestep 1376000e7ae3SMatthew Knepley @*/ 137763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS ts, PetscErrorCode (*func)(TS)) 1378000e7ae3SMatthew Knepley { 1379000e7ae3SMatthew Knepley PetscFunctionBegin; 13804482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1381000e7ae3SMatthew Knepley ts->ops->poststep = func; 1382000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1383000e7ae3SMatthew Knepley } 1384000e7ae3SMatthew Knepley 1385e74ef692SMatthew Knepley #undef __FUNCT__ 1386e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPostStep" 1387000e7ae3SMatthew Knepley /*@ 1388000e7ae3SMatthew Knepley TSDefaultPostStep - The default post-stepping function which does nothing. 1389000e7ae3SMatthew Knepley 1390000e7ae3SMatthew Knepley Collective on TS 1391000e7ae3SMatthew Knepley 1392000e7ae3SMatthew Knepley Input Parameters: 1393000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1394000e7ae3SMatthew Knepley 1395000e7ae3SMatthew Knepley Level: developer 1396000e7ae3SMatthew Knepley 1397000e7ae3SMatthew Knepley .keywords: TS, timestep 1398000e7ae3SMatthew Knepley @*/ 139963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS ts) 1400000e7ae3SMatthew Knepley { 1401000e7ae3SMatthew Knepley PetscFunctionBegin; 1402000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1403000e7ae3SMatthew Knepley } 1404000e7ae3SMatthew Knepley 1405d763cef2SBarry Smith /* ------------ Routines to set performance monitoring options ----------- */ 1406d763cef2SBarry Smith 14074a2ae208SSatish Balay #undef __FUNCT__ 14084a2ae208SSatish Balay #define __FUNCT__ "TSSetMonitor" 1409d763cef2SBarry Smith /*@C 1410d763cef2SBarry Smith TSSetMonitor - Sets an ADDITIONAL function that is to be used at every 1411d763cef2SBarry Smith timestep to display the iteration's progress. 1412d763cef2SBarry Smith 1413d763cef2SBarry Smith Collective on TS 1414d763cef2SBarry Smith 1415d763cef2SBarry Smith Input Parameters: 1416d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1417d763cef2SBarry Smith . func - monitoring routine 1418329f5518SBarry Smith . mctx - [optional] user-defined context for private data for the 1419b3006f0bSLois Curfman McInnes monitor routine (use PETSC_NULL if no context is desired) 1420b3006f0bSLois Curfman McInnes - monitordestroy - [optional] routine that frees monitor context 1421b3006f0bSLois Curfman McInnes (may be PETSC_NULL) 1422d763cef2SBarry Smith 1423d763cef2SBarry Smith Calling sequence of func: 1424a7cc72afSBarry Smith $ int func(TS ts,PetscInt steps,PetscReal time,Vec x,void *mctx) 1425d763cef2SBarry Smith 1426d763cef2SBarry Smith + ts - the TS context 1427d763cef2SBarry Smith . steps - iteration number 14281f06c33eSBarry Smith . time - current time 1429d763cef2SBarry Smith . x - current iterate 1430d763cef2SBarry Smith - mctx - [optional] monitoring context 1431d763cef2SBarry Smith 1432d763cef2SBarry Smith Notes: 1433d763cef2SBarry Smith This routine adds an additional monitor to the list of monitors that 1434d763cef2SBarry Smith already has been loaded. 1435d763cef2SBarry Smith 1436d763cef2SBarry Smith Level: intermediate 1437d763cef2SBarry Smith 1438d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1439d763cef2SBarry Smith 1440d763cef2SBarry Smith .seealso: TSDefaultMonitor(), TSClearMonitor() 1441d763cef2SBarry Smith @*/ 144263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetMonitor(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void*)) 1443d763cef2SBarry Smith { 1444d763cef2SBarry Smith PetscFunctionBegin; 14454482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1446d763cef2SBarry Smith if (ts->numbermonitors >= MAXTSMONITORS) { 144729bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many monitors set"); 1448d763cef2SBarry Smith } 1449d763cef2SBarry Smith ts->monitor[ts->numbermonitors] = monitor; 1450329f5518SBarry Smith ts->mdestroy[ts->numbermonitors] = mdestroy; 1451d763cef2SBarry Smith ts->monitorcontext[ts->numbermonitors++] = (void*)mctx; 1452d763cef2SBarry Smith PetscFunctionReturn(0); 1453d763cef2SBarry Smith } 1454d763cef2SBarry Smith 14554a2ae208SSatish Balay #undef __FUNCT__ 14564a2ae208SSatish Balay #define __FUNCT__ "TSClearMonitor" 1457d763cef2SBarry Smith /*@C 1458d763cef2SBarry Smith TSClearMonitor - Clears all the monitors that have been set on a time-step object. 1459d763cef2SBarry Smith 1460d763cef2SBarry Smith Collective on TS 1461d763cef2SBarry Smith 1462d763cef2SBarry Smith Input Parameters: 1463d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1464d763cef2SBarry Smith 1465d763cef2SBarry Smith Notes: 1466d763cef2SBarry Smith There is no way to remove a single, specific monitor. 1467d763cef2SBarry Smith 1468d763cef2SBarry Smith Level: intermediate 1469d763cef2SBarry Smith 1470d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1471d763cef2SBarry Smith 1472d763cef2SBarry Smith .seealso: TSDefaultMonitor(), TSSetMonitor() 1473d763cef2SBarry Smith @*/ 147463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSClearMonitor(TS ts) 1475d763cef2SBarry Smith { 1476d763cef2SBarry Smith PetscFunctionBegin; 14774482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1478d763cef2SBarry Smith ts->numbermonitors = 0; 1479d763cef2SBarry Smith PetscFunctionReturn(0); 1480d763cef2SBarry Smith } 1481d763cef2SBarry Smith 14824a2ae208SSatish Balay #undef __FUNCT__ 14834a2ae208SSatish Balay #define __FUNCT__ "TSDefaultMonitor" 1484a7cc72afSBarry Smith PetscErrorCode TSDefaultMonitor(TS ts,PetscInt step,PetscReal ptime,Vec v,void *ctx) 1485d763cef2SBarry Smith { 1486dfbe8321SBarry Smith PetscErrorCode ierr; 1487d132466eSBarry Smith 1488d763cef2SBarry Smith PetscFunctionBegin; 148977431f27SBarry Smith ierr = PetscPrintf(ts->comm,"timestep %D dt %g time %g\n",step,ts->time_step,ptime);CHKERRQ(ierr); 1490d763cef2SBarry Smith PetscFunctionReturn(0); 1491d763cef2SBarry Smith } 1492d763cef2SBarry Smith 14934a2ae208SSatish Balay #undef __FUNCT__ 14944a2ae208SSatish Balay #define __FUNCT__ "TSStep" 1495d763cef2SBarry Smith /*@ 1496d763cef2SBarry Smith TSStep - Steps the requested number of timesteps. 1497d763cef2SBarry Smith 1498d763cef2SBarry Smith Collective on TS 1499d763cef2SBarry Smith 1500d763cef2SBarry Smith Input Parameter: 1501d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1502d763cef2SBarry Smith 1503d763cef2SBarry Smith Output Parameters: 1504d763cef2SBarry Smith + steps - number of iterations until termination 1505142b95e3SSatish Balay - ptime - time until termination 1506d763cef2SBarry Smith 1507d763cef2SBarry Smith Level: beginner 1508d763cef2SBarry Smith 1509d763cef2SBarry Smith .keywords: TS, timestep, solve 1510d763cef2SBarry Smith 1511d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSDestroy() 1512d763cef2SBarry Smith @*/ 151363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS ts,PetscInt *steps,PetscReal *ptime) 1514d763cef2SBarry Smith { 1515dfbe8321SBarry Smith PetscErrorCode ierr; 1516d763cef2SBarry Smith 1517d763cef2SBarry Smith PetscFunctionBegin; 15184482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1519d405a339SMatthew Knepley if (!ts->setupcalled) { 1520d405a339SMatthew Knepley ierr = TSSetUp(ts);CHKERRQ(ierr); 1521d405a339SMatthew Knepley } 1522d405a339SMatthew Knepley 1523d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1524d405a339SMatthew Knepley ierr = (*ts->ops->prestep)(ts);CHKERRQ(ierr); 1525000e7ae3SMatthew Knepley ierr = (*ts->ops->step)(ts, steps, ptime);CHKERRQ(ierr); 1526d405a339SMatthew Knepley ierr = (*ts->ops->poststep)(ts);CHKERRQ(ierr); 1527d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1528d405a339SMatthew Knepley 15294bb05414SBarry Smith if (!PetscPreLoadingOn) { 15304bb05414SBarry Smith ierr = TSViewFromOptions(ts,ts->name);CHKERRQ(ierr); 1531d405a339SMatthew Knepley } 1532d763cef2SBarry Smith PetscFunctionReturn(0); 1533d763cef2SBarry Smith } 1534d763cef2SBarry Smith 15354a2ae208SSatish Balay #undef __FUNCT__ 15364a2ae208SSatish Balay #define __FUNCT__ "TSMonitor" 1537d763cef2SBarry Smith /* 1538d763cef2SBarry Smith Runs the user provided monitor routines, if they exists. 1539d763cef2SBarry Smith */ 1540a7cc72afSBarry Smith PetscErrorCode TSMonitor(TS ts,PetscInt step,PetscReal ptime,Vec x) 1541d763cef2SBarry Smith { 15426849ba73SBarry Smith PetscErrorCode ierr; 1543a7cc72afSBarry Smith PetscInt i,n = ts->numbermonitors; 1544d763cef2SBarry Smith 1545d763cef2SBarry Smith PetscFunctionBegin; 1546d763cef2SBarry Smith for (i=0; i<n; i++) { 1547142b95e3SSatish Balay ierr = (*ts->monitor[i])(ts,step,ptime,x,ts->monitorcontext[i]);CHKERRQ(ierr); 1548d763cef2SBarry Smith } 1549d763cef2SBarry Smith PetscFunctionReturn(0); 1550d763cef2SBarry Smith } 1551d763cef2SBarry Smith 1552d763cef2SBarry Smith /* ------------------------------------------------------------------------*/ 1553d763cef2SBarry Smith 15544a2ae208SSatish Balay #undef __FUNCT__ 15554a2ae208SSatish Balay #define __FUNCT__ "TSLGMonitorCreate" 1556d763cef2SBarry Smith /*@C 1557d763cef2SBarry Smith TSLGMonitorCreate - Creates a line graph context for use with 1558d763cef2SBarry Smith TS to monitor convergence of preconditioned residual norms. 1559d763cef2SBarry Smith 1560d763cef2SBarry Smith Collective on TS 1561d763cef2SBarry Smith 1562d763cef2SBarry Smith Input Parameters: 1563d763cef2SBarry Smith + host - the X display to open, or null for the local machine 1564d763cef2SBarry Smith . label - the title to put in the title bar 15657c922b88SBarry Smith . x, y - the screen coordinates of the upper left coordinate of the window 1566d763cef2SBarry Smith - m, n - the screen width and height in pixels 1567d763cef2SBarry Smith 1568d763cef2SBarry Smith Output Parameter: 1569d763cef2SBarry Smith . draw - the drawing context 1570d763cef2SBarry Smith 1571d763cef2SBarry Smith Options Database Key: 1572d763cef2SBarry Smith . -ts_xmonitor - automatically sets line graph monitor 1573d763cef2SBarry Smith 1574d763cef2SBarry Smith Notes: 1575b0a32e0cSBarry Smith Use TSLGMonitorDestroy() to destroy this line graph, not PetscDrawLGDestroy(). 1576d763cef2SBarry Smith 1577d763cef2SBarry Smith Level: intermediate 1578d763cef2SBarry Smith 15797c922b88SBarry Smith .keywords: TS, monitor, line graph, residual, seealso 1580d763cef2SBarry Smith 1581d763cef2SBarry Smith .seealso: TSLGMonitorDestroy(), TSSetMonitor() 15827c922b88SBarry Smith 1583d763cef2SBarry Smith @*/ 158463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSLGMonitorCreate(const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *draw) 1585d763cef2SBarry Smith { 1586b0a32e0cSBarry Smith PetscDraw win; 1587dfbe8321SBarry Smith PetscErrorCode ierr; 1588d763cef2SBarry Smith 1589d763cef2SBarry Smith PetscFunctionBegin; 1590b0a32e0cSBarry Smith ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr); 1591b0a32e0cSBarry Smith ierr = PetscDrawSetType(win,PETSC_DRAW_X);CHKERRQ(ierr); 1592b0a32e0cSBarry Smith ierr = PetscDrawLGCreate(win,1,draw);CHKERRQ(ierr); 1593b0a32e0cSBarry Smith ierr = PetscDrawLGIndicateDataPoints(*draw);CHKERRQ(ierr); 1594d763cef2SBarry Smith 159552e6d16bSBarry Smith ierr = PetscLogObjectParent(*draw,win);CHKERRQ(ierr); 1596d763cef2SBarry Smith PetscFunctionReturn(0); 1597d763cef2SBarry Smith } 1598d763cef2SBarry Smith 15994a2ae208SSatish Balay #undef __FUNCT__ 16004a2ae208SSatish Balay #define __FUNCT__ "TSLGMonitor" 1601a7cc72afSBarry Smith PetscErrorCode TSLGMonitor(TS ts,PetscInt n,PetscReal ptime,Vec v,void *monctx) 1602d763cef2SBarry Smith { 1603b0a32e0cSBarry Smith PetscDrawLG lg = (PetscDrawLG) monctx; 160487828ca2SBarry Smith PetscReal x,y = ptime; 1605dfbe8321SBarry Smith PetscErrorCode ierr; 1606d763cef2SBarry Smith 1607d763cef2SBarry Smith PetscFunctionBegin; 16087c922b88SBarry Smith if (!monctx) { 16097c922b88SBarry Smith MPI_Comm comm; 1610b0a32e0cSBarry Smith PetscViewer viewer; 16117c922b88SBarry Smith 16127c922b88SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 1613b0a32e0cSBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 1614b0a32e0cSBarry Smith ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr); 16157c922b88SBarry Smith } 16167c922b88SBarry Smith 1617b0a32e0cSBarry Smith if (!n) {ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);} 161887828ca2SBarry Smith x = (PetscReal)n; 1619b0a32e0cSBarry Smith ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr); 1620d763cef2SBarry Smith if (n < 20 || (n % 5)) { 1621b0a32e0cSBarry Smith ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr); 1622d763cef2SBarry Smith } 1623d763cef2SBarry Smith PetscFunctionReturn(0); 1624d763cef2SBarry Smith } 1625d763cef2SBarry Smith 16264a2ae208SSatish Balay #undef __FUNCT__ 16274a2ae208SSatish Balay #define __FUNCT__ "TSLGMonitorDestroy" 1628d763cef2SBarry Smith /*@C 1629d763cef2SBarry Smith TSLGMonitorDestroy - Destroys a line graph context that was created 1630d763cef2SBarry Smith with TSLGMonitorCreate(). 1631d763cef2SBarry Smith 1632b0a32e0cSBarry Smith Collective on PetscDrawLG 1633d763cef2SBarry Smith 1634d763cef2SBarry Smith Input Parameter: 1635d763cef2SBarry Smith . draw - the drawing context 1636d763cef2SBarry Smith 1637d763cef2SBarry Smith Level: intermediate 1638d763cef2SBarry Smith 1639d763cef2SBarry Smith .keywords: TS, monitor, line graph, destroy 1640d763cef2SBarry Smith 1641d763cef2SBarry Smith .seealso: TSLGMonitorCreate(), TSSetMonitor(), TSLGMonitor(); 1642d763cef2SBarry Smith @*/ 164363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSLGMonitorDestroy(PetscDrawLG drawlg) 1644d763cef2SBarry Smith { 1645b0a32e0cSBarry Smith PetscDraw draw; 1646dfbe8321SBarry Smith PetscErrorCode ierr; 1647d763cef2SBarry Smith 1648d763cef2SBarry Smith PetscFunctionBegin; 1649b0a32e0cSBarry Smith ierr = PetscDrawLGGetDraw(drawlg,&draw);CHKERRQ(ierr); 1650b0a32e0cSBarry Smith ierr = PetscDrawDestroy(draw);CHKERRQ(ierr); 1651b0a32e0cSBarry Smith ierr = PetscDrawLGDestroy(drawlg);CHKERRQ(ierr); 1652d763cef2SBarry Smith PetscFunctionReturn(0); 1653d763cef2SBarry Smith } 1654d763cef2SBarry Smith 16554a2ae208SSatish Balay #undef __FUNCT__ 16564a2ae208SSatish Balay #define __FUNCT__ "TSGetTime" 1657d763cef2SBarry Smith /*@ 1658d763cef2SBarry Smith TSGetTime - Gets the current time. 1659d763cef2SBarry Smith 1660d763cef2SBarry Smith Not Collective 1661d763cef2SBarry Smith 1662d763cef2SBarry Smith Input Parameter: 1663d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1664d763cef2SBarry Smith 1665d763cef2SBarry Smith Output Parameter: 1666d763cef2SBarry Smith . t - the current time 1667d763cef2SBarry Smith 1668d763cef2SBarry Smith Contributed by: Matthew Knepley 1669d763cef2SBarry Smith 1670d763cef2SBarry Smith Level: beginner 1671d763cef2SBarry Smith 1672d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1673d763cef2SBarry Smith 1674d763cef2SBarry Smith .keywords: TS, get, time 1675d763cef2SBarry Smith @*/ 167663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS ts,PetscReal* t) 1677d763cef2SBarry Smith { 1678d763cef2SBarry Smith PetscFunctionBegin; 16794482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 16804482741eSBarry Smith PetscValidDoublePointer(t,2); 1681d763cef2SBarry Smith *t = ts->ptime; 1682d763cef2SBarry Smith PetscFunctionReturn(0); 1683d763cef2SBarry Smith } 1684d763cef2SBarry Smith 16854a2ae208SSatish Balay #undef __FUNCT__ 16864a2ae208SSatish Balay #define __FUNCT__ "TSSetOptionsPrefix" 1687d763cef2SBarry Smith /*@C 1688d763cef2SBarry Smith TSSetOptionsPrefix - Sets the prefix used for searching for all 1689d763cef2SBarry Smith TS options in the database. 1690d763cef2SBarry Smith 1691d763cef2SBarry Smith Collective on TS 1692d763cef2SBarry Smith 1693d763cef2SBarry Smith Input Parameter: 1694d763cef2SBarry Smith + ts - The TS context 1695d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1696d763cef2SBarry Smith 1697d763cef2SBarry Smith Notes: 1698d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1699d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1700d763cef2SBarry Smith hyphen. 1701d763cef2SBarry Smith 1702d763cef2SBarry Smith Contributed by: Matthew Knepley 1703d763cef2SBarry Smith 1704d763cef2SBarry Smith Level: advanced 1705d763cef2SBarry Smith 1706d763cef2SBarry Smith .keywords: TS, set, options, prefix, database 1707d763cef2SBarry Smith 1708d763cef2SBarry Smith .seealso: TSSetFromOptions() 1709d763cef2SBarry Smith 1710d763cef2SBarry Smith @*/ 171163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS ts,const char prefix[]) 1712d763cef2SBarry Smith { 1713dfbe8321SBarry Smith PetscErrorCode ierr; 1714d763cef2SBarry Smith 1715d763cef2SBarry Smith PetscFunctionBegin; 17164482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1717d763cef2SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1718d763cef2SBarry Smith switch(ts->problem_type) { 1719d763cef2SBarry Smith case TS_NONLINEAR: 1720d763cef2SBarry Smith ierr = SNESSetOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 1721d763cef2SBarry Smith break; 1722d763cef2SBarry Smith case TS_LINEAR: 172394b7f48cSBarry Smith ierr = KSPSetOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 1724d763cef2SBarry Smith break; 1725d763cef2SBarry Smith } 1726d763cef2SBarry Smith PetscFunctionReturn(0); 1727d763cef2SBarry Smith } 1728d763cef2SBarry Smith 1729d763cef2SBarry Smith 17304a2ae208SSatish Balay #undef __FUNCT__ 17314a2ae208SSatish Balay #define __FUNCT__ "TSAppendOptionsPrefix" 1732d763cef2SBarry Smith /*@C 1733d763cef2SBarry Smith TSAppendOptionsPrefix - Appends to the prefix used for searching for all 1734d763cef2SBarry Smith TS options in the database. 1735d763cef2SBarry Smith 1736d763cef2SBarry Smith Collective on TS 1737d763cef2SBarry Smith 1738d763cef2SBarry Smith Input Parameter: 1739d763cef2SBarry Smith + ts - The TS context 1740d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1741d763cef2SBarry Smith 1742d763cef2SBarry Smith Notes: 1743d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1744d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1745d763cef2SBarry Smith hyphen. 1746d763cef2SBarry Smith 1747d763cef2SBarry Smith Contributed by: Matthew Knepley 1748d763cef2SBarry Smith 1749d763cef2SBarry Smith Level: advanced 1750d763cef2SBarry Smith 1751d763cef2SBarry Smith .keywords: TS, append, options, prefix, database 1752d763cef2SBarry Smith 1753d763cef2SBarry Smith .seealso: TSGetOptionsPrefix() 1754d763cef2SBarry Smith 1755d763cef2SBarry Smith @*/ 175663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS ts,const char prefix[]) 1757d763cef2SBarry Smith { 1758dfbe8321SBarry Smith PetscErrorCode ierr; 1759d763cef2SBarry Smith 1760d763cef2SBarry Smith PetscFunctionBegin; 17614482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1762d763cef2SBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1763d763cef2SBarry Smith switch(ts->problem_type) { 1764d763cef2SBarry Smith case TS_NONLINEAR: 1765d763cef2SBarry Smith ierr = SNESAppendOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 1766d763cef2SBarry Smith break; 1767d763cef2SBarry Smith case TS_LINEAR: 176894b7f48cSBarry Smith ierr = KSPAppendOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 1769d763cef2SBarry Smith break; 1770d763cef2SBarry Smith } 1771d763cef2SBarry Smith PetscFunctionReturn(0); 1772d763cef2SBarry Smith } 1773d763cef2SBarry Smith 17744a2ae208SSatish Balay #undef __FUNCT__ 17754a2ae208SSatish Balay #define __FUNCT__ "TSGetOptionsPrefix" 1776d763cef2SBarry Smith /*@C 1777d763cef2SBarry Smith TSGetOptionsPrefix - Sets the prefix used for searching for all 1778d763cef2SBarry Smith TS options in the database. 1779d763cef2SBarry Smith 1780d763cef2SBarry Smith Not Collective 1781d763cef2SBarry Smith 1782d763cef2SBarry Smith Input Parameter: 1783d763cef2SBarry Smith . ts - The TS context 1784d763cef2SBarry Smith 1785d763cef2SBarry Smith Output Parameter: 1786d763cef2SBarry Smith . prefix - A pointer to the prefix string used 1787d763cef2SBarry Smith 1788d763cef2SBarry Smith Contributed by: Matthew Knepley 1789d763cef2SBarry Smith 1790d763cef2SBarry Smith Notes: On the fortran side, the user should pass in a string 'prifix' of 1791d763cef2SBarry Smith sufficient length to hold the prefix. 1792d763cef2SBarry Smith 1793d763cef2SBarry Smith Level: intermediate 1794d763cef2SBarry Smith 1795d763cef2SBarry Smith .keywords: TS, get, options, prefix, database 1796d763cef2SBarry Smith 1797d763cef2SBarry Smith .seealso: TSAppendOptionsPrefix() 1798d763cef2SBarry Smith @*/ 1799*e060cb09SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS ts,const char *prefix[]) 1800d763cef2SBarry Smith { 1801dfbe8321SBarry Smith PetscErrorCode ierr; 1802d763cef2SBarry Smith 1803d763cef2SBarry Smith PetscFunctionBegin; 18044482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 18054482741eSBarry Smith PetscValidPointer(prefix,2); 1806d763cef2SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1807d763cef2SBarry Smith PetscFunctionReturn(0); 1808d763cef2SBarry Smith } 1809d763cef2SBarry Smith 18104a2ae208SSatish Balay #undef __FUNCT__ 18114a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSMatrix" 1812d763cef2SBarry Smith /*@C 1813d763cef2SBarry Smith TSGetRHSMatrix - Returns the matrix A at the present timestep. 1814d763cef2SBarry Smith 1815d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1816d763cef2SBarry Smith 1817d763cef2SBarry Smith Input Parameter: 1818d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1819d763cef2SBarry Smith 1820d763cef2SBarry Smith Output Parameters: 1821d763cef2SBarry Smith + A - The matrix A, where U_t = A(t) U 1822d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as A 1823d763cef2SBarry Smith - ctx - User-defined context for matrix evaluation routine 1824d763cef2SBarry Smith 1825d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1826d763cef2SBarry Smith 1827d763cef2SBarry Smith Contributed by: Matthew Knepley 1828d763cef2SBarry Smith 1829d763cef2SBarry Smith Level: intermediate 1830d763cef2SBarry Smith 1831d763cef2SBarry Smith .seealso: TSGetTimeStep(), TSGetTime(), TSGetTimeStepNumber(), TSGetRHSJacobian() 1832d763cef2SBarry Smith 1833d763cef2SBarry Smith .keywords: TS, timestep, get, matrix 1834d763cef2SBarry Smith 1835d763cef2SBarry Smith @*/ 183663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSMatrix(TS ts,Mat *A,Mat *M,void **ctx) 1837d763cef2SBarry Smith { 1838d763cef2SBarry Smith PetscFunctionBegin; 18394482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1840d763cef2SBarry Smith if (A) *A = ts->A; 1841d763cef2SBarry Smith if (M) *M = ts->B; 1842d763cef2SBarry Smith if (ctx) *ctx = ts->jacP; 1843d763cef2SBarry Smith PetscFunctionReturn(0); 1844d763cef2SBarry Smith } 1845d763cef2SBarry Smith 18464a2ae208SSatish Balay #undef __FUNCT__ 18474a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSJacobian" 1848d763cef2SBarry Smith /*@C 1849d763cef2SBarry Smith TSGetRHSJacobian - Returns the Jacobian J at the present timestep. 1850d763cef2SBarry Smith 1851d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1852d763cef2SBarry Smith 1853d763cef2SBarry Smith Input Parameter: 1854d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1855d763cef2SBarry Smith 1856d763cef2SBarry Smith Output Parameters: 1857d763cef2SBarry Smith + J - The Jacobian J of F, where U_t = F(U,t) 1858d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as J 1859d763cef2SBarry Smith - ctx - User-defined context for Jacobian evaluation routine 1860d763cef2SBarry Smith 1861d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1862d763cef2SBarry Smith 1863d763cef2SBarry Smith Contributed by: Matthew Knepley 1864d763cef2SBarry Smith 1865d763cef2SBarry Smith Level: intermediate 1866d763cef2SBarry Smith 1867d763cef2SBarry Smith .seealso: TSGetTimeStep(), TSGetRHSMatrix(), TSGetTime(), TSGetTimeStepNumber() 1868d763cef2SBarry Smith 1869d763cef2SBarry Smith .keywords: TS, timestep, get, matrix, Jacobian 1870d763cef2SBarry Smith @*/ 187163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS ts,Mat *J,Mat *M,void **ctx) 1872d763cef2SBarry Smith { 1873dfbe8321SBarry Smith PetscErrorCode ierr; 1874d763cef2SBarry Smith 1875d763cef2SBarry Smith PetscFunctionBegin; 1876d763cef2SBarry Smith ierr = TSGetRHSMatrix(ts,J,M,ctx);CHKERRQ(ierr); 1877d763cef2SBarry Smith PetscFunctionReturn(0); 1878d763cef2SBarry Smith } 1879d763cef2SBarry Smith 18801713a123SBarry Smith #undef __FUNCT__ 18811713a123SBarry Smith #define __FUNCT__ "TSVecViewMonitor" 18821713a123SBarry Smith /*@C 18831713a123SBarry Smith TSVecViewMonitor - Monitors progress of the TS solvers by calling 18841713a123SBarry Smith VecView() for the solution at each timestep 18851713a123SBarry Smith 18861713a123SBarry Smith Collective on TS 18871713a123SBarry Smith 18881713a123SBarry Smith Input Parameters: 18891713a123SBarry Smith + ts - the TS context 18901713a123SBarry Smith . step - current time-step 1891142b95e3SSatish Balay . ptime - current time 18921713a123SBarry Smith - dummy - either a viewer or PETSC_NULL 18931713a123SBarry Smith 18941713a123SBarry Smith Level: intermediate 18951713a123SBarry Smith 18961713a123SBarry Smith .keywords: TS, vector, monitor, view 18971713a123SBarry Smith 18981713a123SBarry Smith .seealso: TSSetMonitor(), TSDefaultMonitor(), VecView() 18991713a123SBarry Smith @*/ 190063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSVecViewMonitor(TS ts,PetscInt step,PetscReal ptime,Vec x,void *dummy) 19011713a123SBarry Smith { 1902dfbe8321SBarry Smith PetscErrorCode ierr; 19031713a123SBarry Smith PetscViewer viewer = (PetscViewer) dummy; 19041713a123SBarry Smith 19051713a123SBarry Smith PetscFunctionBegin; 19061713a123SBarry Smith if (!viewer) { 19071713a123SBarry Smith MPI_Comm comm; 19081713a123SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 19091713a123SBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 19101713a123SBarry Smith } 19111713a123SBarry Smith ierr = VecView(x,viewer);CHKERRQ(ierr); 19121713a123SBarry Smith PetscFunctionReturn(0); 19131713a123SBarry Smith } 19141713a123SBarry Smith 19151713a123SBarry Smith 19161713a123SBarry Smith 1917