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: 610f3b3ca1SHong Zhang + -ts_type <type> - TS_EULER, TS_BEULER, TS_SUNDIALS, 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 66*a6570f20SBarry Smith - -ts_monitor_draw - 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; 77eabae89aSBarry Smith PetscTruth opt,flg; 78dfbe8321SBarry Smith PetscErrorCode ierr; 79eabae89aSBarry Smith PetscViewer monviewer; 80eabae89aSBarry Smith char monfilename[PETSC_MAX_PATH_LEN]; 81bdad233fSMatthew Knepley 82bdad233fSMatthew Knepley PetscFunctionBegin; 834482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 84bdad233fSMatthew Knepley ierr = PetscOptionsBegin(ts->comm, ts->prefix, "Time step options", "TS");CHKERRQ(ierr); 85bdad233fSMatthew Knepley 86bdad233fSMatthew Knepley /* Handle generic TS options */ 87bdad233fSMatthew Knepley ierr = PetscOptionsInt("-ts_max_steps","Maximum number of time steps","TSSetDuration",ts->max_steps,&ts->max_steps,PETSC_NULL);CHKERRQ(ierr); 88bdad233fSMatthew Knepley ierr = PetscOptionsReal("-ts_max_time","Time to run to","TSSetDuration",ts->max_time,&ts->max_time,PETSC_NULL);CHKERRQ(ierr); 89bdad233fSMatthew Knepley ierr = PetscOptionsReal("-ts_init_time","Initial time","TSSetInitialTime", ts->ptime, &ts->ptime, PETSC_NULL);CHKERRQ(ierr); 90bdad233fSMatthew Knepley ierr = PetscOptionsReal("-ts_dt","Initial time step","TSSetInitialTimeStep",ts->initial_time_step,&dt,&opt);CHKERRQ(ierr); 91a7cc72afSBarry Smith if (opt) { 92bdad233fSMatthew Knepley ts->initial_time_step = ts->time_step = dt; 93bdad233fSMatthew Knepley } 94bdad233fSMatthew Knepley 95bdad233fSMatthew Knepley /* Monitor options */ 96*a6570f20SBarry Smith ierr = PetscOptionsString("-ts_monitor","Monitor timestep size","TSMonitorDefault","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); 97eabae89aSBarry Smith if (flg) { 98eabae89aSBarry Smith ierr = PetscViewerASCIIOpen(ts->comm,monfilename,&monviewer);CHKERRQ(ierr); 99*a6570f20SBarry Smith ierr = TSMonitorSet(ts,TSMonitorDefault,monviewer,(PetscErrorCode (*)(void*))PetscViewerDestroy);CHKERRQ(ierr); 100bdad233fSMatthew Knepley } 101*a6570f20SBarry Smith ierr = PetscOptionsName("-ts_monitor_draw","Monitor timestep size graphically","TSMonitorLG",&opt);CHKERRQ(ierr); 102a7cc72afSBarry Smith if (opt) { 103*a6570f20SBarry Smith ierr = TSMonitorSet(ts,TSMonitorLG,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 104bdad233fSMatthew Knepley } 105*a6570f20SBarry Smith ierr = PetscOptionsName("-ts_monitor_solution","Monitor solution graphically","TSMonitorSolution",&opt);CHKERRQ(ierr); 106a7cc72afSBarry Smith if (opt) { 107*a6570f20SBarry Smith ierr = TSMonitorSet(ts,TSMonitorSolution,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 108bdad233fSMatthew Knepley } 109bdad233fSMatthew Knepley 110bdad233fSMatthew Knepley /* Handle TS type options */ 111bdad233fSMatthew Knepley ierr = TSSetTypeFromOptions(ts);CHKERRQ(ierr); 112bdad233fSMatthew Knepley 113bdad233fSMatthew Knepley /* Handle specific TS options */ 114abc0a331SBarry Smith if (ts->ops->setfromoptions) { 115bdad233fSMatthew Knepley ierr = (*ts->ops->setfromoptions)(ts);CHKERRQ(ierr); 116bdad233fSMatthew Knepley } 117bdad233fSMatthew Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 118bdad233fSMatthew Knepley 119bdad233fSMatthew Knepley /* Handle subobject options */ 120bdad233fSMatthew Knepley switch(ts->problem_type) { 121156fc9a6SMatthew Knepley /* Should check for implicit/explicit */ 122bdad233fSMatthew Knepley case TS_LINEAR: 123abc0a331SBarry Smith if (ts->ksp) { 1247c236d22SBarry Smith ierr = KSPSetOperators(ts->ksp,ts->A,ts->B,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 12594b7f48cSBarry Smith ierr = KSPSetFromOptions(ts->ksp);CHKERRQ(ierr); 126156fc9a6SMatthew Knepley } 127bdad233fSMatthew Knepley break; 128bdad233fSMatthew Knepley case TS_NONLINEAR: 129abc0a331SBarry Smith if (ts->snes) { 1307c236d22SBarry Smith /* this is a bit of a hack, but it gets the matrix information into SNES earlier 1317c236d22SBarry Smith so that SNES and KSP have more information to pick reasonable defaults 1327c236d22SBarry Smith before they allow users to set options */ 1337c236d22SBarry Smith ierr = SNESSetJacobian(ts->snes,ts->A,ts->B,0,ts);CHKERRQ(ierr); 134bdad233fSMatthew Knepley ierr = SNESSetFromOptions(ts->snes);CHKERRQ(ierr); 135156fc9a6SMatthew Knepley } 136bdad233fSMatthew Knepley break; 137bdad233fSMatthew Knepley default: 13877431f27SBarry Smith SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid problem type: %d", (int)ts->problem_type); 139bdad233fSMatthew Knepley } 140bdad233fSMatthew Knepley 141bdad233fSMatthew Knepley PetscFunctionReturn(0); 142bdad233fSMatthew Knepley } 143bdad233fSMatthew Knepley 144bdad233fSMatthew Knepley #undef __FUNCT__ 145bdad233fSMatthew Knepley #define __FUNCT__ "TSViewFromOptions" 146bdad233fSMatthew Knepley /*@ 147bdad233fSMatthew Knepley TSViewFromOptions - This function visualizes the ts based upon user options. 148bdad233fSMatthew Knepley 149bdad233fSMatthew Knepley Collective on TS 150bdad233fSMatthew Knepley 151bdad233fSMatthew Knepley Input Parameter: 152bdad233fSMatthew Knepley . ts - The ts 153bdad233fSMatthew Knepley 154bdad233fSMatthew Knepley Level: intermediate 155bdad233fSMatthew Knepley 156bdad233fSMatthew Knepley .keywords: TS, view, options, database 157bdad233fSMatthew Knepley .seealso: TSSetFromOptions(), TSView() 158bdad233fSMatthew Knepley @*/ 15963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSViewFromOptions(TS ts,const char title[]) 160bdad233fSMatthew Knepley { 161bdad233fSMatthew Knepley PetscViewer viewer; 162bdad233fSMatthew Knepley PetscDraw draw; 163bdad233fSMatthew Knepley PetscTruth opt; 164e10c49a3SBarry Smith char fileName[PETSC_MAX_PATH_LEN]; 165dfbe8321SBarry Smith PetscErrorCode ierr; 166bdad233fSMatthew Knepley 167bdad233fSMatthew Knepley PetscFunctionBegin; 168eabae89aSBarry Smith ierr = PetscOptionsGetString(ts->prefix, "-ts_view", fileName, PETSC_MAX_PATH_LEN, &opt);CHKERRQ(ierr); 169eabae89aSBarry Smith if (opt && !PetscPreLoadingOn) { 170eabae89aSBarry Smith ierr = PetscViewerASCIIOpen(ts->comm,fileName,&viewer);CHKERRQ(ierr); 171bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 172bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 173bdad233fSMatthew Knepley } 174bdad233fSMatthew Knepley ierr = PetscOptionsHasName(ts->prefix, "-ts_view_draw", &opt);CHKERRQ(ierr); 175a7cc72afSBarry Smith if (opt) { 176bdad233fSMatthew Knepley ierr = PetscViewerDrawOpen(ts->comm, 0, 0, 0, 0, 300, 300, &viewer);CHKERRQ(ierr); 177bdad233fSMatthew Knepley ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr); 178a7cc72afSBarry Smith if (title) { 1791836bdbcSSatish Balay ierr = PetscDrawSetTitle(draw, (char *)title);CHKERRQ(ierr); 180bdad233fSMatthew Knepley } else { 181bdad233fSMatthew Knepley ierr = PetscObjectName((PetscObject) ts);CHKERRQ(ierr); 1821836bdbcSSatish Balay ierr = PetscDrawSetTitle(draw, ts->name);CHKERRQ(ierr); 183bdad233fSMatthew Knepley } 184bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 185bdad233fSMatthew Knepley ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 186bdad233fSMatthew Knepley ierr = PetscDrawPause(draw);CHKERRQ(ierr); 187bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 188bdad233fSMatthew Knepley } 189bdad233fSMatthew Knepley PetscFunctionReturn(0); 190bdad233fSMatthew Knepley } 191bdad233fSMatthew Knepley 192bdad233fSMatthew Knepley #undef __FUNCT__ 1934a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSJacobian" 194a7a1495cSBarry Smith /*@ 1958c385f81SBarry Smith TSComputeRHSJacobian - Computes the Jacobian matrix that has been 196a7a1495cSBarry Smith set with TSSetRHSJacobian(). 197a7a1495cSBarry Smith 198a7a1495cSBarry Smith Collective on TS and Vec 199a7a1495cSBarry Smith 200a7a1495cSBarry Smith Input Parameters: 201a7a1495cSBarry Smith + ts - the SNES context 202a7a1495cSBarry Smith . t - current timestep 203a7a1495cSBarry Smith - x - input vector 204a7a1495cSBarry Smith 205a7a1495cSBarry Smith Output Parameters: 206a7a1495cSBarry Smith + A - Jacobian matrix 207a7a1495cSBarry Smith . B - optional preconditioning matrix 208a7a1495cSBarry Smith - flag - flag indicating matrix structure 209a7a1495cSBarry Smith 210a7a1495cSBarry Smith Notes: 211a7a1495cSBarry Smith Most users should not need to explicitly call this routine, as it 212a7a1495cSBarry Smith is used internally within the nonlinear solvers. 213a7a1495cSBarry Smith 21494b7f48cSBarry Smith See KSPSetOperators() for important information about setting the 215a7a1495cSBarry Smith flag parameter. 216a7a1495cSBarry Smith 217a7a1495cSBarry Smith TSComputeJacobian() is valid only for TS_NONLINEAR 218a7a1495cSBarry Smith 219a7a1495cSBarry Smith Level: developer 220a7a1495cSBarry Smith 221a7a1495cSBarry Smith .keywords: SNES, compute, Jacobian, matrix 222a7a1495cSBarry Smith 22394b7f48cSBarry Smith .seealso: TSSetRHSJacobian(), KSPSetOperators() 224a7a1495cSBarry Smith @*/ 22563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS ts,PetscReal t,Vec X,Mat *A,Mat *B,MatStructure *flg) 226a7a1495cSBarry Smith { 227dfbe8321SBarry Smith PetscErrorCode ierr; 228a7a1495cSBarry Smith 229a7a1495cSBarry Smith PetscFunctionBegin; 2304482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 2314482741eSBarry Smith PetscValidHeaderSpecific(X,VEC_COOKIE,3); 232c9780b6fSBarry Smith PetscCheckSameComm(ts,1,X,3); 233a7a1495cSBarry Smith if (ts->problem_type != TS_NONLINEAR) { 23429bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"For TS_NONLINEAR only"); 235a7a1495cSBarry Smith } 236000e7ae3SMatthew Knepley if (ts->ops->rhsjacobian) { 237d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 238a7a1495cSBarry Smith *flg = DIFFERENT_NONZERO_PATTERN; 239a7a1495cSBarry Smith PetscStackPush("TS user Jacobian function"); 240000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr); 241a7a1495cSBarry Smith PetscStackPop; 242d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 243a7a1495cSBarry Smith /* make sure user returned a correct Jacobian and preconditioner */ 2444482741eSBarry Smith PetscValidHeaderSpecific(*A,MAT_COOKIE,4); 2454482741eSBarry Smith PetscValidHeaderSpecific(*B,MAT_COOKIE,5); 246ef66eb69SBarry Smith } else { 247ef66eb69SBarry Smith ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 248ef66eb69SBarry Smith ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 249ef66eb69SBarry Smith if (*A != *B) { 250ef66eb69SBarry Smith ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 251ef66eb69SBarry Smith ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 252ef66eb69SBarry Smith } 253ef66eb69SBarry Smith } 254a7a1495cSBarry Smith PetscFunctionReturn(0); 255a7a1495cSBarry Smith } 256a7a1495cSBarry Smith 2574a2ae208SSatish Balay #undef __FUNCT__ 2584a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSFunction" 259d763cef2SBarry Smith /* 260d763cef2SBarry Smith TSComputeRHSFunction - Evaluates the right-hand-side function. 261d763cef2SBarry Smith 262d763cef2SBarry Smith Note: If the user did not provide a function but merely a matrix, 263d763cef2SBarry Smith this routine applies the matrix. 264d763cef2SBarry Smith */ 265dfbe8321SBarry Smith PetscErrorCode TSComputeRHSFunction(TS ts,PetscReal t,Vec x,Vec y) 266d763cef2SBarry Smith { 267dfbe8321SBarry Smith PetscErrorCode ierr; 268d763cef2SBarry Smith 269d763cef2SBarry Smith PetscFunctionBegin; 2704482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 2714482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,2); 2724482741eSBarry Smith PetscValidHeaderSpecific(y,VEC_COOKIE,3); 273d763cef2SBarry Smith 274d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 275000e7ae3SMatthew Knepley if (ts->ops->rhsfunction) { 276d763cef2SBarry Smith PetscStackPush("TS user right-hand-side function"); 277000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsfunction)(ts,t,x,y,ts->funP);CHKERRQ(ierr); 278d763cef2SBarry Smith PetscStackPop; 2797c922b88SBarry Smith } else { 280000e7ae3SMatthew Knepley if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */ 281d763cef2SBarry Smith MatStructure flg; 282d763cef2SBarry Smith PetscStackPush("TS user right-hand-side matrix function"); 283000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->A,&ts->B,&flg,ts->jacP);CHKERRQ(ierr); 284d763cef2SBarry Smith PetscStackPop; 285d763cef2SBarry Smith } 286d763cef2SBarry Smith ierr = MatMult(ts->A,x,y);CHKERRQ(ierr); 2877c922b88SBarry Smith } 288d763cef2SBarry Smith 289d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 290d763cef2SBarry Smith 291d763cef2SBarry Smith PetscFunctionReturn(0); 292d763cef2SBarry Smith } 293d763cef2SBarry Smith 2944a2ae208SSatish Balay #undef __FUNCT__ 2954a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSFunction" 296d763cef2SBarry Smith /*@C 297d763cef2SBarry Smith TSSetRHSFunction - Sets the routine for evaluating the function, 298d763cef2SBarry Smith F(t,u), where U_t = F(t,u). 299d763cef2SBarry Smith 300d763cef2SBarry Smith Collective on TS 301d763cef2SBarry Smith 302d763cef2SBarry Smith Input Parameters: 303d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 304d763cef2SBarry Smith . f - routine for evaluating the right-hand-side function 305d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 306d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 307d763cef2SBarry Smith 308d763cef2SBarry Smith Calling sequence of func: 30987828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Vec F,void *ctx); 310d763cef2SBarry Smith 311d763cef2SBarry Smith + t - current timestep 312d763cef2SBarry Smith . u - input vector 313d763cef2SBarry Smith . F - function vector 314d763cef2SBarry Smith - ctx - [optional] user-defined function context 315d763cef2SBarry Smith 316d763cef2SBarry Smith Important: 317d763cef2SBarry Smith The user MUST call either this routine or TSSetRHSMatrix(). 318d763cef2SBarry Smith 319d763cef2SBarry Smith Level: beginner 320d763cef2SBarry Smith 321d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, function 322d763cef2SBarry Smith 323d763cef2SBarry Smith .seealso: TSSetRHSMatrix() 324d763cef2SBarry Smith @*/ 32563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS ts,PetscErrorCode (*f)(TS,PetscReal,Vec,Vec,void*),void *ctx) 326d763cef2SBarry Smith { 327d763cef2SBarry Smith PetscFunctionBegin; 328d763cef2SBarry Smith 3294482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 330d763cef2SBarry Smith if (ts->problem_type == TS_LINEAR) { 33129bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Cannot set function for linear problem"); 332d763cef2SBarry Smith } 333000e7ae3SMatthew Knepley ts->ops->rhsfunction = f; 334d763cef2SBarry Smith ts->funP = ctx; 335d763cef2SBarry Smith PetscFunctionReturn(0); 336d763cef2SBarry Smith } 337d763cef2SBarry Smith 3384a2ae208SSatish Balay #undef __FUNCT__ 3394a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSMatrix" 340d763cef2SBarry Smith /*@C 341d763cef2SBarry Smith TSSetRHSMatrix - Sets the function to compute the matrix A, where U_t = A(t) U. 342d763cef2SBarry Smith Also sets the location to store A. 343d763cef2SBarry Smith 344d763cef2SBarry Smith Collective on TS 345d763cef2SBarry Smith 346d763cef2SBarry Smith Input Parameters: 347d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 348d763cef2SBarry Smith . A - matrix 349d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 350d763cef2SBarry Smith . f - the matrix evaluation routine; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 351d763cef2SBarry Smith if A is not a function of t. 352d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 353d763cef2SBarry Smith matrix evaluation routine (may be PETSC_NULL) 354d763cef2SBarry Smith 355d763cef2SBarry Smith Calling sequence of func: 356a7cc72afSBarry Smith $ func (TS ts,PetscReal t,Mat *A,Mat *B,PetscInt *flag,void *ctx); 357d763cef2SBarry Smith 358d763cef2SBarry Smith + t - current timestep 359d763cef2SBarry Smith . A - matrix A, where U_t = A(t) U 360d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 361d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 36294b7f48cSBarry Smith structure (same as flag in KSPSetOperators()) 363d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 364d763cef2SBarry Smith 365d763cef2SBarry Smith Notes: 36694b7f48cSBarry Smith See KSPSetOperators() for important information about setting the flag 367d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 368d763cef2SBarry Smith 369d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 370d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 371d763cef2SBarry Smith completely new new matrix structure (not just different matrix elements) 372d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 373d763cef2SBarry Smith throughout the global iterations. 374d763cef2SBarry Smith 375d763cef2SBarry Smith Important: 376d763cef2SBarry Smith The user MUST call either this routine or TSSetRHSFunction(). 377d763cef2SBarry Smith 378d763cef2SBarry Smith Level: beginner 379d763cef2SBarry Smith 380d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, matrix 381d763cef2SBarry Smith 382d763cef2SBarry Smith .seealso: TSSetRHSFunction() 383d763cef2SBarry Smith @*/ 38463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSMatrix(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void *ctx) 385d763cef2SBarry Smith { 386d763cef2SBarry Smith PetscFunctionBegin; 3874482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 3884482741eSBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE,2); 3894482741eSBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE,3); 390c9780b6fSBarry Smith PetscCheckSameComm(ts,1,A,2); 391c9780b6fSBarry Smith PetscCheckSameComm(ts,1,B,3); 392d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 39329bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not for nonlinear problems; use TSSetRHSJacobian()"); 394d763cef2SBarry Smith } 395d763cef2SBarry Smith 396000e7ae3SMatthew Knepley ts->ops->rhsmatrix = f; 397d763cef2SBarry Smith ts->jacP = ctx; 398d763cef2SBarry Smith ts->A = A; 399d763cef2SBarry Smith ts->B = B; 400d763cef2SBarry Smith 401d763cef2SBarry Smith PetscFunctionReturn(0); 402d763cef2SBarry Smith } 403d763cef2SBarry Smith 4044a2ae208SSatish Balay #undef __FUNCT__ 405aa644b49SHong Zhang #define __FUNCT__ "TSSetLHSMatrix" 406aa644b49SHong Zhang /*@C 407aa644b49SHong Zhang TSSetLHSMatrix - Sets the function to compute the matrix A, where A U_t = F(U). 408aa644b49SHong Zhang Also sets the location to store A. 409aa644b49SHong Zhang 410aa644b49SHong Zhang Collective on TS 411aa644b49SHong Zhang 412aa644b49SHong Zhang Input Parameters: 413aa644b49SHong Zhang + ts - the TS context obtained from TSCreate() 414aa644b49SHong Zhang . A - matrix 415aa644b49SHong Zhang . B - preconditioner matrix (usually same as A) 416aa644b49SHong Zhang . f - the matrix evaluation routine; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 417aa644b49SHong Zhang if A is not a function of t. 418aa644b49SHong Zhang - ctx - [optional] user-defined context for private data for the 419aa644b49SHong Zhang matrix evaluation routine (may be PETSC_NULL) 420aa644b49SHong Zhang 421aa644b49SHong Zhang Calling sequence of func: 422aa644b49SHong Zhang $ func (TS ts,PetscReal t,Mat *A,Mat *B,PetscInt *flag,void *ctx); 423aa644b49SHong Zhang 424aa644b49SHong Zhang + t - current timestep 425aa644b49SHong Zhang . A - matrix A, where A U_t = F(U) 426aa644b49SHong Zhang . B - preconditioner matrix, usually the same as A 427aa644b49SHong Zhang . flag - flag indicating information about the preconditioner matrix 428aa644b49SHong Zhang structure (same as flag in KSPSetOperators()) 429aa644b49SHong Zhang - ctx - [optional] user-defined context for matrix evaluation routine 430aa644b49SHong Zhang 431aa644b49SHong Zhang Notes: 432aa644b49SHong Zhang See KSPSetOperators() for important information about setting the flag 433aa644b49SHong Zhang output parameter in the routine func(). Be sure to read this information! 434aa644b49SHong Zhang 435aa644b49SHong Zhang The routine func() takes Mat * as the matrix arguments rather than Mat. 436aa644b49SHong Zhang This allows the matrix evaluation routine to replace A and/or B with a 437aa644b49SHong Zhang completely new new matrix structure (not just different matrix elements) 438aa644b49SHong Zhang when appropriate, for instance, if the nonzero structure is changing 439aa644b49SHong Zhang throughout the global iterations. 440aa644b49SHong Zhang 441aa644b49SHong Zhang Notes: 442aa644b49SHong Zhang Currently, TSSetLHSMatrix() only supports the TS_BEULER type. 443aa644b49SHong Zhang 444aa644b49SHong Zhang Level: beginner 445aa644b49SHong Zhang 446aa644b49SHong Zhang .keywords: TS, timestep, set, left-hand-side, matrix 447aa644b49SHong Zhang 448aa644b49SHong Zhang .seealso: TSSetRHSMatrix() 449aa644b49SHong Zhang @*/ 450aa644b49SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSetLHSMatrix(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),void *ctx) 451aa644b49SHong Zhang { 452aa644b49SHong Zhang PetscTruth sametype; 453aa644b49SHong Zhang PetscErrorCode ierr; 454aa644b49SHong Zhang 455aa644b49SHong Zhang PetscFunctionBegin; 456aa644b49SHong Zhang PetscValidHeaderSpecific(ts,TS_COOKIE,1); 457aa644b49SHong Zhang PetscValidHeaderSpecific(A,MAT_COOKIE,2); 458aa644b49SHong Zhang PetscValidHeaderSpecific(B,MAT_COOKIE,3); 459aa644b49SHong Zhang PetscCheckSameComm(ts,1,A,2); 460aa644b49SHong Zhang PetscCheckSameComm(ts,1,B,3); 461aa644b49SHong Zhang 462aa644b49SHong Zhang if (!ts->type_name) SETERRQ(PETSC_ERR_ARG_NULL,"TS type must be set before calling TSSetLHSMatrix()"); 463aa644b49SHong Zhang ierr = PetscTypeCompare((PetscObject)ts,"beuler",&sametype);CHKERRQ(ierr); 464aa644b49SHong Zhang if (!sametype) 465aa644b49SHong Zhang SETERRQ1(PETSC_ERR_SUP,"TS type %s not supported for LHSMatrix",ts->type_name); 466aa644b49SHong Zhang if (ts->problem_type == TS_NONLINEAR) { 467aa644b49SHong Zhang SETERRQ(PETSC_ERR_ARG_WRONG,"Not for nonlinear problems yet"); 468aa644b49SHong Zhang } 469aa644b49SHong Zhang 470aa644b49SHong Zhang ts->ops->lhsmatrix = f; 471aa644b49SHong Zhang ts->jacPlhs = ctx; 472aa644b49SHong Zhang ts->Alhs = A; 473aa644b49SHong Zhang ts->Blhs = B; 474aa644b49SHong Zhang PetscFunctionReturn(0); 475aa644b49SHong Zhang } 476aa644b49SHong Zhang 477aa644b49SHong Zhang #undef __FUNCT__ 4784a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSJacobian" 479d763cef2SBarry Smith /*@C 480d763cef2SBarry Smith TSSetRHSJacobian - Sets the function to compute the Jacobian of F, 481d763cef2SBarry Smith where U_t = F(U,t), as well as the location to store the matrix. 4823c94ec11SBarry Smith Use TSSetRHSMatrix() for linear problems. 483d763cef2SBarry Smith 484d763cef2SBarry Smith Collective on TS 485d763cef2SBarry Smith 486d763cef2SBarry Smith Input Parameters: 487d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 488d763cef2SBarry Smith . A - Jacobian matrix 489d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 490d763cef2SBarry Smith . f - the Jacobian evaluation routine 491d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 492d763cef2SBarry Smith Jacobian evaluation routine (may be PETSC_NULL) 493d763cef2SBarry Smith 494d763cef2SBarry Smith Calling sequence of func: 49587828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Mat *A,Mat *B,MatStructure *flag,void *ctx); 496d763cef2SBarry Smith 497d763cef2SBarry Smith + t - current timestep 498d763cef2SBarry Smith . u - input vector 499d763cef2SBarry Smith . A - matrix A, where U_t = A(t)u 500d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 501d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 50294b7f48cSBarry Smith structure (same as flag in KSPSetOperators()) 503d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 504d763cef2SBarry Smith 505d763cef2SBarry Smith Notes: 50694b7f48cSBarry Smith See KSPSetOperators() for important information about setting the flag 507d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 508d763cef2SBarry Smith 509d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 510d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 511d763cef2SBarry Smith completely new new matrix structure (not just different matrix elements) 512d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 513d763cef2SBarry Smith throughout the global iterations. 514d763cef2SBarry Smith 515d763cef2SBarry Smith Level: beginner 516d763cef2SBarry Smith 517d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, Jacobian 518d763cef2SBarry Smith 519d763cef2SBarry Smith .seealso: TSDefaultComputeJacobianColor(), 5203c94ec11SBarry Smith SNESDefaultComputeJacobianColor(), TSSetRHSFunction(), TSSetRHSMatrix() 521d763cef2SBarry Smith 522d763cef2SBarry Smith @*/ 52363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx) 524d763cef2SBarry Smith { 525d763cef2SBarry Smith PetscFunctionBegin; 5264482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 5274482741eSBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE,2); 5284482741eSBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE,3); 529c9780b6fSBarry Smith PetscCheckSameComm(ts,1,A,2); 530c9780b6fSBarry Smith PetscCheckSameComm(ts,1,B,3); 531d763cef2SBarry Smith if (ts->problem_type != TS_NONLINEAR) { 53229bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Not for linear problems; use TSSetRHSMatrix()"); 533d763cef2SBarry Smith } 534d763cef2SBarry Smith 535000e7ae3SMatthew Knepley ts->ops->rhsjacobian = f; 536d763cef2SBarry Smith ts->jacP = ctx; 537d763cef2SBarry Smith ts->A = A; 538d763cef2SBarry Smith ts->B = B; 539d763cef2SBarry Smith PetscFunctionReturn(0); 540d763cef2SBarry Smith } 541d763cef2SBarry Smith 5424a2ae208SSatish Balay #undef __FUNCT__ 5434a2ae208SSatish Balay #define __FUNCT__ "TSView" 5447e2c5f70SBarry Smith /*@C 545d763cef2SBarry Smith TSView - Prints the TS data structure. 546d763cef2SBarry Smith 5474c49b128SBarry Smith Collective on TS 548d763cef2SBarry Smith 549d763cef2SBarry Smith Input Parameters: 550d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 551d763cef2SBarry Smith - viewer - visualization context 552d763cef2SBarry Smith 553d763cef2SBarry Smith Options Database Key: 554d763cef2SBarry Smith . -ts_view - calls TSView() at end of TSStep() 555d763cef2SBarry Smith 556d763cef2SBarry Smith Notes: 557d763cef2SBarry Smith The available visualization contexts include 558b0a32e0cSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 559b0a32e0cSBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 560d763cef2SBarry Smith output where only the first processor opens 561d763cef2SBarry Smith the file. All other processors send their 562d763cef2SBarry Smith data to the first processor to print. 563d763cef2SBarry Smith 564d763cef2SBarry Smith The user can open an alternative visualization context with 565b0a32e0cSBarry Smith PetscViewerASCIIOpen() - output to a specified file. 566d763cef2SBarry Smith 567d763cef2SBarry Smith Level: beginner 568d763cef2SBarry Smith 569d763cef2SBarry Smith .keywords: TS, timestep, view 570d763cef2SBarry Smith 571b0a32e0cSBarry Smith .seealso: PetscViewerASCIIOpen() 572d763cef2SBarry Smith @*/ 57363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSView(TS ts,PetscViewer viewer) 574d763cef2SBarry Smith { 575dfbe8321SBarry Smith PetscErrorCode ierr; 576454a90a3SBarry Smith char *type; 57732077d6dSBarry Smith PetscTruth iascii,isstring; 578d763cef2SBarry Smith 579d763cef2SBarry Smith PetscFunctionBegin; 5804482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 581b0a32e0cSBarry Smith if (!viewer) viewer = PETSC_VIEWER_STDOUT_(ts->comm); 5824482741eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2); 583c9780b6fSBarry Smith PetscCheckSameComm(ts,1,viewer,2); 584fd16b177SBarry Smith 58532077d6dSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 586b0a32e0cSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr); 58732077d6dSBarry Smith if (iascii) { 588b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"TS Object:\n");CHKERRQ(ierr); 589454a90a3SBarry Smith ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr); 590454a90a3SBarry Smith if (type) { 591b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: %s\n",type);CHKERRQ(ierr); 592184914b5SBarry Smith } else { 593b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: not yet set\n");CHKERRQ(ierr); 594184914b5SBarry Smith } 595000e7ae3SMatthew Knepley if (ts->ops->view) { 596b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 597000e7ae3SMatthew Knepley ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr); 598b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 599d763cef2SBarry Smith } 60077431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum steps=%D\n",ts->max_steps);CHKERRQ(ierr); 601a83599f4SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum time=%G\n",ts->max_time);CHKERRQ(ierr); 602d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 60377431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of nonlinear solver iterations=%D\n",ts->nonlinear_its);CHKERRQ(ierr); 604d763cef2SBarry Smith } 60577431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of linear solver iterations=%D\n",ts->linear_its);CHKERRQ(ierr); 6060f5bd95cSBarry Smith } else if (isstring) { 607454a90a3SBarry Smith ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr); 608b0a32e0cSBarry Smith ierr = PetscViewerStringSPrintf(viewer," %-7.7s",type);CHKERRQ(ierr); 609d763cef2SBarry Smith } 610b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 61194b7f48cSBarry Smith if (ts->ksp) {ierr = KSPView(ts->ksp,viewer);CHKERRQ(ierr);} 612d763cef2SBarry Smith if (ts->snes) {ierr = SNESView(ts->snes,viewer);CHKERRQ(ierr);} 613b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 614d763cef2SBarry Smith PetscFunctionReturn(0); 615d763cef2SBarry Smith } 616d763cef2SBarry Smith 617d763cef2SBarry Smith 6184a2ae208SSatish Balay #undef __FUNCT__ 6194a2ae208SSatish Balay #define __FUNCT__ "TSSetApplicationContext" 620d763cef2SBarry Smith /*@C 621d763cef2SBarry Smith TSSetApplicationContext - Sets an optional user-defined context for 622d763cef2SBarry Smith the timesteppers. 623d763cef2SBarry Smith 624d763cef2SBarry Smith Collective on TS 625d763cef2SBarry Smith 626d763cef2SBarry Smith Input Parameters: 627d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 628d763cef2SBarry Smith - usrP - optional user context 629d763cef2SBarry Smith 630d763cef2SBarry Smith Level: intermediate 631d763cef2SBarry Smith 632d763cef2SBarry Smith .keywords: TS, timestep, set, application, context 633d763cef2SBarry Smith 634d763cef2SBarry Smith .seealso: TSGetApplicationContext() 635d763cef2SBarry Smith @*/ 63663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS ts,void *usrP) 637d763cef2SBarry Smith { 638d763cef2SBarry Smith PetscFunctionBegin; 6394482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 640d763cef2SBarry Smith ts->user = usrP; 641d763cef2SBarry Smith PetscFunctionReturn(0); 642d763cef2SBarry Smith } 643d763cef2SBarry Smith 6444a2ae208SSatish Balay #undef __FUNCT__ 6454a2ae208SSatish Balay #define __FUNCT__ "TSGetApplicationContext" 646d763cef2SBarry Smith /*@C 647d763cef2SBarry Smith TSGetApplicationContext - Gets the user-defined context for the 648d763cef2SBarry Smith timestepper. 649d763cef2SBarry Smith 650d763cef2SBarry Smith Not Collective 651d763cef2SBarry Smith 652d763cef2SBarry Smith Input Parameter: 653d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 654d763cef2SBarry Smith 655d763cef2SBarry Smith Output Parameter: 656d763cef2SBarry Smith . usrP - user context 657d763cef2SBarry Smith 658d763cef2SBarry Smith Level: intermediate 659d763cef2SBarry Smith 660d763cef2SBarry Smith .keywords: TS, timestep, get, application, context 661d763cef2SBarry Smith 662d763cef2SBarry Smith .seealso: TSSetApplicationContext() 663d763cef2SBarry Smith @*/ 66463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS ts,void **usrP) 665d763cef2SBarry Smith { 666d763cef2SBarry Smith PetscFunctionBegin; 6674482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 668d763cef2SBarry Smith *usrP = ts->user; 669d763cef2SBarry Smith PetscFunctionReturn(0); 670d763cef2SBarry Smith } 671d763cef2SBarry Smith 6724a2ae208SSatish Balay #undef __FUNCT__ 6734a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStepNumber" 674d763cef2SBarry Smith /*@ 675d763cef2SBarry Smith TSGetTimeStepNumber - Gets the current number of timesteps. 676d763cef2SBarry Smith 677d763cef2SBarry Smith Not Collective 678d763cef2SBarry Smith 679d763cef2SBarry Smith Input Parameter: 680d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 681d763cef2SBarry Smith 682d763cef2SBarry Smith Output Parameter: 683d763cef2SBarry Smith . iter - number steps so far 684d763cef2SBarry Smith 685d763cef2SBarry Smith Level: intermediate 686d763cef2SBarry Smith 687d763cef2SBarry Smith .keywords: TS, timestep, get, iteration, number 688d763cef2SBarry Smith @*/ 68963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS ts,PetscInt* iter) 690d763cef2SBarry Smith { 691d763cef2SBarry Smith PetscFunctionBegin; 6924482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 6934482741eSBarry Smith PetscValidIntPointer(iter,2); 694d763cef2SBarry Smith *iter = ts->steps; 695d763cef2SBarry Smith PetscFunctionReturn(0); 696d763cef2SBarry Smith } 697d763cef2SBarry Smith 6984a2ae208SSatish Balay #undef __FUNCT__ 6994a2ae208SSatish Balay #define __FUNCT__ "TSSetInitialTimeStep" 700d763cef2SBarry Smith /*@ 701d763cef2SBarry Smith TSSetInitialTimeStep - Sets the initial timestep to be used, 702d763cef2SBarry Smith as well as the initial time. 703d763cef2SBarry Smith 704d763cef2SBarry Smith Collective on TS 705d763cef2SBarry Smith 706d763cef2SBarry Smith Input Parameters: 707d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 708d763cef2SBarry Smith . initial_time - the initial time 709d763cef2SBarry Smith - time_step - the size of the timestep 710d763cef2SBarry Smith 711d763cef2SBarry Smith Level: intermediate 712d763cef2SBarry Smith 713d763cef2SBarry Smith .seealso: TSSetTimeStep(), TSGetTimeStep() 714d763cef2SBarry Smith 715d763cef2SBarry Smith .keywords: TS, set, initial, timestep 716d763cef2SBarry Smith @*/ 71763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS ts,PetscReal initial_time,PetscReal time_step) 718d763cef2SBarry Smith { 719d763cef2SBarry Smith PetscFunctionBegin; 7204482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 721d763cef2SBarry Smith ts->time_step = time_step; 722d763cef2SBarry Smith ts->initial_time_step = time_step; 723d763cef2SBarry Smith ts->ptime = initial_time; 724d763cef2SBarry Smith PetscFunctionReturn(0); 725d763cef2SBarry Smith } 726d763cef2SBarry Smith 7274a2ae208SSatish Balay #undef __FUNCT__ 7284a2ae208SSatish Balay #define __FUNCT__ "TSSetTimeStep" 729d763cef2SBarry Smith /*@ 730d763cef2SBarry Smith TSSetTimeStep - Allows one to reset the timestep at any time, 731d763cef2SBarry Smith useful for simple pseudo-timestepping codes. 732d763cef2SBarry Smith 733d763cef2SBarry Smith Collective on TS 734d763cef2SBarry Smith 735d763cef2SBarry Smith Input Parameters: 736d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 737d763cef2SBarry Smith - time_step - the size of the timestep 738d763cef2SBarry Smith 739d763cef2SBarry Smith Level: intermediate 740d763cef2SBarry Smith 741d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 742d763cef2SBarry Smith 743d763cef2SBarry Smith .keywords: TS, set, timestep 744d763cef2SBarry Smith @*/ 74563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS ts,PetscReal time_step) 746d763cef2SBarry Smith { 747d763cef2SBarry Smith PetscFunctionBegin; 7484482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 749d763cef2SBarry Smith ts->time_step = time_step; 750d763cef2SBarry Smith PetscFunctionReturn(0); 751d763cef2SBarry Smith } 752d763cef2SBarry Smith 7534a2ae208SSatish Balay #undef __FUNCT__ 7544a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStep" 755d763cef2SBarry Smith /*@ 756d763cef2SBarry Smith TSGetTimeStep - Gets the current timestep size. 757d763cef2SBarry Smith 758d763cef2SBarry Smith Not Collective 759d763cef2SBarry Smith 760d763cef2SBarry Smith Input Parameter: 761d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 762d763cef2SBarry Smith 763d763cef2SBarry Smith Output Parameter: 764d763cef2SBarry Smith . dt - the current timestep size 765d763cef2SBarry Smith 766d763cef2SBarry Smith Level: intermediate 767d763cef2SBarry Smith 768d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 769d763cef2SBarry Smith 770d763cef2SBarry Smith .keywords: TS, get, timestep 771d763cef2SBarry Smith @*/ 77263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS ts,PetscReal* dt) 773d763cef2SBarry Smith { 774d763cef2SBarry Smith PetscFunctionBegin; 7754482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 7764482741eSBarry Smith PetscValidDoublePointer(dt,2); 777d763cef2SBarry Smith *dt = ts->time_step; 778d763cef2SBarry Smith PetscFunctionReturn(0); 779d763cef2SBarry Smith } 780d763cef2SBarry Smith 7814a2ae208SSatish Balay #undef __FUNCT__ 7824a2ae208SSatish Balay #define __FUNCT__ "TSGetSolution" 783d8e5e3e6SSatish Balay /*@ 784d763cef2SBarry Smith TSGetSolution - Returns the solution at the present timestep. It 785d763cef2SBarry Smith is valid to call this routine inside the function that you are evaluating 786d763cef2SBarry Smith in order to move to the new timestep. This vector not changed until 787d763cef2SBarry Smith the solution at the next timestep has been calculated. 788d763cef2SBarry Smith 789d763cef2SBarry Smith Not Collective, but Vec returned is parallel if TS is parallel 790d763cef2SBarry Smith 791d763cef2SBarry Smith Input Parameter: 792d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 793d763cef2SBarry Smith 794d763cef2SBarry Smith Output Parameter: 795d763cef2SBarry Smith . v - the vector containing the solution 796d763cef2SBarry Smith 797d763cef2SBarry Smith Level: intermediate 798d763cef2SBarry Smith 799d763cef2SBarry Smith .seealso: TSGetTimeStep() 800d763cef2SBarry Smith 801d763cef2SBarry Smith .keywords: TS, timestep, get, solution 802d763cef2SBarry Smith @*/ 80363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS ts,Vec *v) 804d763cef2SBarry Smith { 805d763cef2SBarry Smith PetscFunctionBegin; 8064482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 8074482741eSBarry Smith PetscValidPointer(v,2); 808d763cef2SBarry Smith *v = ts->vec_sol_always; 809d763cef2SBarry Smith PetscFunctionReturn(0); 810d763cef2SBarry Smith } 811d763cef2SBarry Smith 812bdad233fSMatthew Knepley /* ----- Routines to initialize and destroy a timestepper ---- */ 8134a2ae208SSatish Balay #undef __FUNCT__ 814bdad233fSMatthew Knepley #define __FUNCT__ "TSSetProblemType" 815d8e5e3e6SSatish Balay /*@ 816bdad233fSMatthew Knepley TSSetProblemType - Sets the type of problem to be solved. 817d763cef2SBarry Smith 818bdad233fSMatthew Knepley Not collective 819d763cef2SBarry Smith 820bdad233fSMatthew Knepley Input Parameters: 821bdad233fSMatthew Knepley + ts - The TS 822bdad233fSMatthew Knepley - type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 823d763cef2SBarry Smith .vb 824d763cef2SBarry Smith U_t = A U 825d763cef2SBarry Smith U_t = A(t) U 826d763cef2SBarry Smith U_t = F(t,U) 827d763cef2SBarry Smith .ve 828d763cef2SBarry Smith 829d763cef2SBarry Smith Level: beginner 830d763cef2SBarry Smith 831bdad233fSMatthew Knepley .keywords: TS, problem type 832bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 833d763cef2SBarry Smith @*/ 83463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS ts, TSProblemType type) 835a7cc72afSBarry Smith { 836d763cef2SBarry Smith PetscFunctionBegin; 8374482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 838bdad233fSMatthew Knepley ts->problem_type = type; 839d763cef2SBarry Smith PetscFunctionReturn(0); 840d763cef2SBarry Smith } 841d763cef2SBarry Smith 842bdad233fSMatthew Knepley #undef __FUNCT__ 843bdad233fSMatthew Knepley #define __FUNCT__ "TSGetProblemType" 844bdad233fSMatthew Knepley /*@C 845bdad233fSMatthew Knepley TSGetProblemType - Gets the type of problem to be solved. 846bdad233fSMatthew Knepley 847bdad233fSMatthew Knepley Not collective 848bdad233fSMatthew Knepley 849bdad233fSMatthew Knepley Input Parameter: 850bdad233fSMatthew Knepley . ts - The TS 851bdad233fSMatthew Knepley 852bdad233fSMatthew Knepley Output Parameter: 853bdad233fSMatthew Knepley . type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 854bdad233fSMatthew Knepley .vb 855bdad233fSMatthew Knepley U_t = A U 856bdad233fSMatthew Knepley U_t = A(t) U 857bdad233fSMatthew Knepley U_t = F(t,U) 858bdad233fSMatthew Knepley .ve 859bdad233fSMatthew Knepley 860bdad233fSMatthew Knepley Level: beginner 861bdad233fSMatthew Knepley 862bdad233fSMatthew Knepley .keywords: TS, problem type 863bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 864bdad233fSMatthew Knepley @*/ 86563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS ts, TSProblemType *type) 866a7cc72afSBarry Smith { 867bdad233fSMatthew Knepley PetscFunctionBegin; 8684482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 8694482741eSBarry Smith PetscValidIntPointer(type,2); 870bdad233fSMatthew Knepley *type = ts->problem_type; 871bdad233fSMatthew Knepley PetscFunctionReturn(0); 872bdad233fSMatthew Knepley } 873d763cef2SBarry Smith 8744a2ae208SSatish Balay #undef __FUNCT__ 8754a2ae208SSatish Balay #define __FUNCT__ "TSSetUp" 876d763cef2SBarry Smith /*@ 877d763cef2SBarry Smith TSSetUp - Sets up the internal data structures for the later use 878d763cef2SBarry Smith of a timestepper. 879d763cef2SBarry Smith 880d763cef2SBarry Smith Collective on TS 881d763cef2SBarry Smith 882d763cef2SBarry Smith Input Parameter: 883d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 884d763cef2SBarry Smith 885d763cef2SBarry Smith Notes: 886d763cef2SBarry Smith For basic use of the TS solvers the user need not explicitly call 887d763cef2SBarry Smith TSSetUp(), since these actions will automatically occur during 888d763cef2SBarry Smith the call to TSStep(). However, if one wishes to control this 889d763cef2SBarry Smith phase separately, TSSetUp() should be called after TSCreate() 890d763cef2SBarry Smith and optional routines of the form TSSetXXX(), but before TSStep(). 891d763cef2SBarry Smith 892d763cef2SBarry Smith Level: advanced 893d763cef2SBarry Smith 894d763cef2SBarry Smith .keywords: TS, timestep, setup 895d763cef2SBarry Smith 896d763cef2SBarry Smith .seealso: TSCreate(), TSStep(), TSDestroy() 897d763cef2SBarry Smith @*/ 89863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS ts) 899d763cef2SBarry Smith { 900dfbe8321SBarry Smith PetscErrorCode ierr; 901d763cef2SBarry Smith 902d763cef2SBarry Smith PetscFunctionBegin; 9034482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 90429bbc08cSBarry Smith if (!ts->vec_sol) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call TSSetSolution() first"); 905d763cef2SBarry Smith if (!ts->type_name) { 906d763cef2SBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 907d763cef2SBarry Smith } 908000e7ae3SMatthew Knepley ierr = (*ts->ops->setup)(ts);CHKERRQ(ierr); 909d763cef2SBarry Smith ts->setupcalled = 1; 910d763cef2SBarry Smith PetscFunctionReturn(0); 911d763cef2SBarry Smith } 912d763cef2SBarry Smith 9134a2ae208SSatish Balay #undef __FUNCT__ 9144a2ae208SSatish Balay #define __FUNCT__ "TSDestroy" 915d8e5e3e6SSatish Balay /*@ 916d763cef2SBarry Smith TSDestroy - Destroys the timestepper context that was created 917d763cef2SBarry Smith with TSCreate(). 918d763cef2SBarry Smith 919d763cef2SBarry Smith Collective on TS 920d763cef2SBarry Smith 921d763cef2SBarry Smith Input Parameter: 922d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 923d763cef2SBarry Smith 924d763cef2SBarry Smith Level: beginner 925d763cef2SBarry Smith 926d763cef2SBarry Smith .keywords: TS, timestepper, destroy 927d763cef2SBarry Smith 928d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve() 929d763cef2SBarry Smith @*/ 93063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS ts) 931d763cef2SBarry Smith { 9326849ba73SBarry Smith PetscErrorCode ierr; 933d763cef2SBarry Smith 934d763cef2SBarry Smith PetscFunctionBegin; 9354482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 936d763cef2SBarry Smith if (--ts->refct > 0) PetscFunctionReturn(0); 937d763cef2SBarry Smith 938be0abb6dSBarry Smith /* if memory was published with AMS then destroy it */ 9390f5bd95cSBarry Smith ierr = PetscObjectDepublish(ts);CHKERRQ(ierr); 940be0abb6dSBarry Smith 94194b7f48cSBarry Smith if (ts->ksp) {ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);} 942d763cef2SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 9431e3347e8SBarry Smith if (ts->ops->destroy) {ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);} 944*a6570f20SBarry Smith ierr = TSMonitorCancel(ts);CHKERRQ(ierr); 945a79aaaedSSatish Balay ierr = PetscHeaderDestroy(ts);CHKERRQ(ierr); 946d763cef2SBarry Smith PetscFunctionReturn(0); 947d763cef2SBarry Smith } 948d763cef2SBarry Smith 9494a2ae208SSatish Balay #undef __FUNCT__ 9504a2ae208SSatish Balay #define __FUNCT__ "TSGetSNES" 951d8e5e3e6SSatish Balay /*@ 952d763cef2SBarry Smith TSGetSNES - Returns the SNES (nonlinear solver) associated with 953d763cef2SBarry Smith a TS (timestepper) context. Valid only for nonlinear problems. 954d763cef2SBarry Smith 955d763cef2SBarry Smith Not Collective, but SNES is parallel if TS is parallel 956d763cef2SBarry Smith 957d763cef2SBarry Smith Input Parameter: 958d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 959d763cef2SBarry Smith 960d763cef2SBarry Smith Output Parameter: 961d763cef2SBarry Smith . snes - the nonlinear solver context 962d763cef2SBarry Smith 963d763cef2SBarry Smith Notes: 964d763cef2SBarry Smith The user can then directly manipulate the SNES context to set various 965d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 96694b7f48cSBarry Smith KSP, KSP, and PC contexts as well. 967d763cef2SBarry Smith 968d763cef2SBarry Smith TSGetSNES() does not work for integrators that do not use SNES; in 969d763cef2SBarry Smith this case TSGetSNES() returns PETSC_NULL in snes. 970d763cef2SBarry Smith 971d763cef2SBarry Smith Level: beginner 972d763cef2SBarry Smith 973d763cef2SBarry Smith .keywords: timestep, get, SNES 974d763cef2SBarry Smith @*/ 97563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS ts,SNES *snes) 976d763cef2SBarry Smith { 977d763cef2SBarry Smith PetscFunctionBegin; 9784482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 9794482741eSBarry Smith PetscValidPointer(snes,2); 98094b7f48cSBarry Smith if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Nonlinear only; use TSGetKSP()"); 981d763cef2SBarry Smith *snes = ts->snes; 982d763cef2SBarry Smith PetscFunctionReturn(0); 983d763cef2SBarry Smith } 984d763cef2SBarry Smith 9854a2ae208SSatish Balay #undef __FUNCT__ 98694b7f48cSBarry Smith #define __FUNCT__ "TSGetKSP" 987d8e5e3e6SSatish Balay /*@ 98894b7f48cSBarry Smith TSGetKSP - Returns the KSP (linear solver) associated with 989d763cef2SBarry Smith a TS (timestepper) context. 990d763cef2SBarry Smith 99194b7f48cSBarry Smith Not Collective, but KSP is parallel if TS is parallel 992d763cef2SBarry Smith 993d763cef2SBarry Smith Input Parameter: 994d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 995d763cef2SBarry Smith 996d763cef2SBarry Smith Output Parameter: 99794b7f48cSBarry Smith . ksp - the nonlinear solver context 998d763cef2SBarry Smith 999d763cef2SBarry Smith Notes: 100094b7f48cSBarry Smith The user can then directly manipulate the KSP context to set various 1001d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 1002d763cef2SBarry Smith KSP and PC contexts as well. 1003d763cef2SBarry Smith 100494b7f48cSBarry Smith TSGetKSP() does not work for integrators that do not use KSP; 100594b7f48cSBarry Smith in this case TSGetKSP() returns PETSC_NULL in ksp. 1006d763cef2SBarry Smith 1007d763cef2SBarry Smith Level: beginner 1008d763cef2SBarry Smith 100994b7f48cSBarry Smith .keywords: timestep, get, KSP 1010d763cef2SBarry Smith @*/ 101163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS ts,KSP *ksp) 1012d763cef2SBarry Smith { 1013d763cef2SBarry Smith PetscFunctionBegin; 10144482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 10154482741eSBarry Smith PetscValidPointer(ksp,2); 101629bbc08cSBarry Smith if (ts->problem_type != TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Linear only; use TSGetSNES()"); 101794b7f48cSBarry Smith *ksp = ts->ksp; 1018d763cef2SBarry Smith PetscFunctionReturn(0); 1019d763cef2SBarry Smith } 1020d763cef2SBarry Smith 1021d763cef2SBarry Smith /* ----------- Routines to set solver parameters ---------- */ 1022d763cef2SBarry Smith 10234a2ae208SSatish Balay #undef __FUNCT__ 1024adb62b0dSMatthew Knepley #define __FUNCT__ "TSGetDuration" 1025adb62b0dSMatthew Knepley /*@ 1026adb62b0dSMatthew Knepley TSGetDuration - Gets the maximum number of timesteps to use and 1027adb62b0dSMatthew Knepley maximum time for iteration. 1028adb62b0dSMatthew Knepley 1029adb62b0dSMatthew Knepley Collective on TS 1030adb62b0dSMatthew Knepley 1031adb62b0dSMatthew Knepley Input Parameters: 1032adb62b0dSMatthew Knepley + ts - the TS context obtained from TSCreate() 1033adb62b0dSMatthew Knepley . maxsteps - maximum number of iterations to use, or PETSC_NULL 1034adb62b0dSMatthew Knepley - maxtime - final time to iterate to, or PETSC_NULL 1035adb62b0dSMatthew Knepley 1036adb62b0dSMatthew Knepley Level: intermediate 1037adb62b0dSMatthew Knepley 1038adb62b0dSMatthew Knepley .keywords: TS, timestep, get, maximum, iterations, time 1039adb62b0dSMatthew Knepley @*/ 104063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS ts, PetscInt *maxsteps, PetscReal *maxtime) 1041adb62b0dSMatthew Knepley { 1042adb62b0dSMatthew Knepley PetscFunctionBegin; 10434482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1044abc0a331SBarry Smith if (maxsteps) { 10454482741eSBarry Smith PetscValidIntPointer(maxsteps,2); 1046adb62b0dSMatthew Knepley *maxsteps = ts->max_steps; 1047adb62b0dSMatthew Knepley } 1048abc0a331SBarry Smith if (maxtime ) { 10494482741eSBarry Smith PetscValidScalarPointer(maxtime,3); 1050adb62b0dSMatthew Knepley *maxtime = ts->max_time; 1051adb62b0dSMatthew Knepley } 1052adb62b0dSMatthew Knepley PetscFunctionReturn(0); 1053adb62b0dSMatthew Knepley } 1054adb62b0dSMatthew Knepley 1055adb62b0dSMatthew Knepley #undef __FUNCT__ 10564a2ae208SSatish Balay #define __FUNCT__ "TSSetDuration" 1057d763cef2SBarry Smith /*@ 1058d763cef2SBarry Smith TSSetDuration - Sets the maximum number of timesteps to use and 1059d763cef2SBarry Smith maximum time for iteration. 1060d763cef2SBarry Smith 1061d763cef2SBarry Smith Collective on TS 1062d763cef2SBarry Smith 1063d763cef2SBarry Smith Input Parameters: 1064d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1065d763cef2SBarry Smith . maxsteps - maximum number of iterations to use 1066d763cef2SBarry Smith - maxtime - final time to iterate to 1067d763cef2SBarry Smith 1068d763cef2SBarry Smith Options Database Keys: 1069d763cef2SBarry Smith . -ts_max_steps <maxsteps> - Sets maxsteps 1070d763cef2SBarry Smith . -ts_max_time <maxtime> - Sets maxtime 1071d763cef2SBarry Smith 1072d763cef2SBarry Smith Notes: 1073d763cef2SBarry Smith The default maximum number of iterations is 5000. Default time is 5.0 1074d763cef2SBarry Smith 1075d763cef2SBarry Smith Level: intermediate 1076d763cef2SBarry Smith 1077d763cef2SBarry Smith .keywords: TS, timestep, set, maximum, iterations 1078d763cef2SBarry Smith @*/ 107963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS ts,PetscInt maxsteps,PetscReal maxtime) 1080d763cef2SBarry Smith { 1081d763cef2SBarry Smith PetscFunctionBegin; 10824482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1083d763cef2SBarry Smith ts->max_steps = maxsteps; 1084d763cef2SBarry Smith ts->max_time = maxtime; 1085d763cef2SBarry Smith PetscFunctionReturn(0); 1086d763cef2SBarry Smith } 1087d763cef2SBarry Smith 10884a2ae208SSatish Balay #undef __FUNCT__ 10894a2ae208SSatish Balay #define __FUNCT__ "TSSetSolution" 1090d763cef2SBarry Smith /*@ 1091d763cef2SBarry Smith TSSetSolution - Sets the initial solution vector 1092d763cef2SBarry Smith for use by the TS routines. 1093d763cef2SBarry Smith 1094d763cef2SBarry Smith Collective on TS and Vec 1095d763cef2SBarry Smith 1096d763cef2SBarry Smith Input Parameters: 1097d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1098d763cef2SBarry Smith - x - the solution vector 1099d763cef2SBarry Smith 1100d763cef2SBarry Smith Level: beginner 1101d763cef2SBarry Smith 1102d763cef2SBarry Smith .keywords: TS, timestep, set, solution, initial conditions 1103d763cef2SBarry Smith @*/ 110463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS ts,Vec x) 1105d763cef2SBarry Smith { 1106d763cef2SBarry Smith PetscFunctionBegin; 11074482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 11084482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,2); 1109d763cef2SBarry Smith ts->vec_sol = ts->vec_sol_always = x; 1110d763cef2SBarry Smith PetscFunctionReturn(0); 1111d763cef2SBarry Smith } 1112d763cef2SBarry Smith 1113e74ef692SMatthew Knepley #undef __FUNCT__ 1114e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPreStep" 1115ac226902SBarry Smith /*@C 1116000e7ae3SMatthew Knepley TSSetPreStep - Sets the general-purpose function 1117000e7ae3SMatthew Knepley called once at the beginning of time stepping. 1118000e7ae3SMatthew Knepley 1119000e7ae3SMatthew Knepley Collective on TS 1120000e7ae3SMatthew Knepley 1121000e7ae3SMatthew Knepley Input Parameters: 1122000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1123000e7ae3SMatthew Knepley - func - The function 1124000e7ae3SMatthew Knepley 1125000e7ae3SMatthew Knepley Calling sequence of func: 1126000e7ae3SMatthew Knepley . func (TS ts); 1127000e7ae3SMatthew Knepley 1128000e7ae3SMatthew Knepley Level: intermediate 1129000e7ae3SMatthew Knepley 1130000e7ae3SMatthew Knepley .keywords: TS, timestep 1131000e7ae3SMatthew Knepley @*/ 113263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS ts, PetscErrorCode (*func)(TS)) 1133000e7ae3SMatthew Knepley { 1134000e7ae3SMatthew Knepley PetscFunctionBegin; 11354482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1136000e7ae3SMatthew Knepley ts->ops->prestep = func; 1137000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1138000e7ae3SMatthew Knepley } 1139000e7ae3SMatthew Knepley 1140e74ef692SMatthew Knepley #undef __FUNCT__ 1141e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPreStep" 1142000e7ae3SMatthew Knepley /*@ 1143000e7ae3SMatthew Knepley TSDefaultPreStep - The default pre-stepping function which does nothing. 1144000e7ae3SMatthew Knepley 1145000e7ae3SMatthew Knepley Collective on TS 1146000e7ae3SMatthew Knepley 1147000e7ae3SMatthew Knepley Input Parameters: 1148000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1149000e7ae3SMatthew Knepley 1150000e7ae3SMatthew Knepley Level: developer 1151000e7ae3SMatthew Knepley 1152000e7ae3SMatthew Knepley .keywords: TS, timestep 1153000e7ae3SMatthew Knepley @*/ 115463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS ts) 1155000e7ae3SMatthew Knepley { 1156000e7ae3SMatthew Knepley PetscFunctionBegin; 1157000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1158000e7ae3SMatthew Knepley } 1159000e7ae3SMatthew Knepley 1160e74ef692SMatthew Knepley #undef __FUNCT__ 1161e74ef692SMatthew Knepley #define __FUNCT__ "TSSetUpdate" 1162ac226902SBarry Smith /*@C 1163000e7ae3SMatthew Knepley TSSetUpdate - Sets the general-purpose update function called 1164000e7ae3SMatthew Knepley at the beginning of every time step. This function can change 1165000e7ae3SMatthew Knepley the time step. 1166000e7ae3SMatthew Knepley 1167000e7ae3SMatthew Knepley Collective on TS 1168000e7ae3SMatthew Knepley 1169000e7ae3SMatthew Knepley Input Parameters: 1170000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1171000e7ae3SMatthew Knepley - func - The function 1172000e7ae3SMatthew Knepley 1173000e7ae3SMatthew Knepley Calling sequence of func: 1174000e7ae3SMatthew Knepley . func (TS ts, double t, double *dt); 1175000e7ae3SMatthew Knepley 1176000e7ae3SMatthew Knepley + t - The current time 1177000e7ae3SMatthew Knepley - dt - The current time step 1178000e7ae3SMatthew Knepley 1179000e7ae3SMatthew Knepley Level: intermediate 1180000e7ae3SMatthew Knepley 1181000e7ae3SMatthew Knepley .keywords: TS, update, timestep 1182000e7ae3SMatthew Knepley @*/ 118363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUpdate(TS ts, PetscErrorCode (*func)(TS, PetscReal, PetscReal *)) 1184000e7ae3SMatthew Knepley { 1185000e7ae3SMatthew Knepley PetscFunctionBegin; 11864482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1187000e7ae3SMatthew Knepley ts->ops->update = func; 1188000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1189000e7ae3SMatthew Knepley } 1190000e7ae3SMatthew Knepley 1191e74ef692SMatthew Knepley #undef __FUNCT__ 1192e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultUpdate" 1193000e7ae3SMatthew Knepley /*@ 1194000e7ae3SMatthew Knepley TSDefaultUpdate - The default update function which does nothing. 1195000e7ae3SMatthew Knepley 1196000e7ae3SMatthew Knepley Collective on TS 1197000e7ae3SMatthew Knepley 1198000e7ae3SMatthew Knepley Input Parameters: 1199000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1200000e7ae3SMatthew Knepley - t - The current time 1201000e7ae3SMatthew Knepley 1202000e7ae3SMatthew Knepley Output Parameters: 1203000e7ae3SMatthew Knepley . dt - The current time step 1204000e7ae3SMatthew Knepley 1205000e7ae3SMatthew Knepley Level: developer 1206000e7ae3SMatthew Knepley 1207000e7ae3SMatthew Knepley .keywords: TS, update, timestep 1208000e7ae3SMatthew Knepley @*/ 120963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultUpdate(TS ts, PetscReal t, PetscReal *dt) 1210000e7ae3SMatthew Knepley { 1211000e7ae3SMatthew Knepley PetscFunctionBegin; 1212000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1213000e7ae3SMatthew Knepley } 1214000e7ae3SMatthew Knepley 1215e74ef692SMatthew Knepley #undef __FUNCT__ 1216e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPostStep" 1217ac226902SBarry Smith /*@C 1218000e7ae3SMatthew Knepley TSSetPostStep - Sets the general-purpose function 1219000e7ae3SMatthew Knepley called once at the end of time stepping. 1220000e7ae3SMatthew Knepley 1221000e7ae3SMatthew Knepley Collective on TS 1222000e7ae3SMatthew Knepley 1223000e7ae3SMatthew Knepley Input Parameters: 1224000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1225000e7ae3SMatthew Knepley - func - The function 1226000e7ae3SMatthew Knepley 1227000e7ae3SMatthew Knepley Calling sequence of func: 1228000e7ae3SMatthew Knepley . func (TS ts); 1229000e7ae3SMatthew Knepley 1230000e7ae3SMatthew Knepley Level: intermediate 1231000e7ae3SMatthew Knepley 1232000e7ae3SMatthew Knepley .keywords: TS, timestep 1233000e7ae3SMatthew Knepley @*/ 123463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS ts, PetscErrorCode (*func)(TS)) 1235000e7ae3SMatthew Knepley { 1236000e7ae3SMatthew Knepley PetscFunctionBegin; 12374482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1238000e7ae3SMatthew Knepley ts->ops->poststep = func; 1239000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1240000e7ae3SMatthew Knepley } 1241000e7ae3SMatthew Knepley 1242e74ef692SMatthew Knepley #undef __FUNCT__ 1243e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPostStep" 1244000e7ae3SMatthew Knepley /*@ 1245000e7ae3SMatthew Knepley TSDefaultPostStep - The default post-stepping function which does nothing. 1246000e7ae3SMatthew Knepley 1247000e7ae3SMatthew Knepley Collective on TS 1248000e7ae3SMatthew Knepley 1249000e7ae3SMatthew Knepley Input Parameters: 1250000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1251000e7ae3SMatthew Knepley 1252000e7ae3SMatthew Knepley Level: developer 1253000e7ae3SMatthew Knepley 1254000e7ae3SMatthew Knepley .keywords: TS, timestep 1255000e7ae3SMatthew Knepley @*/ 125663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS ts) 1257000e7ae3SMatthew Knepley { 1258000e7ae3SMatthew Knepley PetscFunctionBegin; 1259000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1260000e7ae3SMatthew Knepley } 1261000e7ae3SMatthew Knepley 1262d763cef2SBarry Smith /* ------------ Routines to set performance monitoring options ----------- */ 1263d763cef2SBarry Smith 12644a2ae208SSatish Balay #undef __FUNCT__ 1265*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSet" 1266d763cef2SBarry Smith /*@C 1267*a6570f20SBarry Smith TSMonitorSet - Sets an ADDITIONAL function that is to be used at every 1268d763cef2SBarry Smith timestep to display the iteration's progress. 1269d763cef2SBarry Smith 1270d763cef2SBarry Smith Collective on TS 1271d763cef2SBarry Smith 1272d763cef2SBarry Smith Input Parameters: 1273d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1274d763cef2SBarry Smith . func - monitoring routine 1275329f5518SBarry Smith . mctx - [optional] user-defined context for private data for the 1276b3006f0bSLois Curfman McInnes monitor routine (use PETSC_NULL if no context is desired) 1277b3006f0bSLois Curfman McInnes - monitordestroy - [optional] routine that frees monitor context 1278b3006f0bSLois Curfman McInnes (may be PETSC_NULL) 1279d763cef2SBarry Smith 1280d763cef2SBarry Smith Calling sequence of func: 1281a7cc72afSBarry Smith $ int func(TS ts,PetscInt steps,PetscReal time,Vec x,void *mctx) 1282d763cef2SBarry Smith 1283d763cef2SBarry Smith + ts - the TS context 1284d763cef2SBarry Smith . steps - iteration number 12851f06c33eSBarry Smith . time - current time 1286d763cef2SBarry Smith . x - current iterate 1287d763cef2SBarry Smith - mctx - [optional] monitoring context 1288d763cef2SBarry Smith 1289d763cef2SBarry Smith Notes: 1290d763cef2SBarry Smith This routine adds an additional monitor to the list of monitors that 1291d763cef2SBarry Smith already has been loaded. 1292d763cef2SBarry Smith 1293d763cef2SBarry Smith Level: intermediate 1294d763cef2SBarry Smith 1295d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1296d763cef2SBarry Smith 1297*a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorCancel() 1298d763cef2SBarry Smith @*/ 1299*a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSet(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void*)) 1300d763cef2SBarry Smith { 1301d763cef2SBarry Smith PetscFunctionBegin; 13024482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1303d763cef2SBarry Smith if (ts->numbermonitors >= MAXTSMONITORS) { 130429bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many monitors set"); 1305d763cef2SBarry Smith } 1306d763cef2SBarry Smith ts->monitor[ts->numbermonitors] = monitor; 1307329f5518SBarry Smith ts->mdestroy[ts->numbermonitors] = mdestroy; 1308d763cef2SBarry Smith ts->monitorcontext[ts->numbermonitors++] = (void*)mctx; 1309d763cef2SBarry Smith PetscFunctionReturn(0); 1310d763cef2SBarry Smith } 1311d763cef2SBarry Smith 13124a2ae208SSatish Balay #undef __FUNCT__ 1313*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorCancel" 1314d763cef2SBarry Smith /*@C 1315*a6570f20SBarry Smith TSMonitorCancel - Clears all the monitors that have been set on a time-step object. 1316d763cef2SBarry Smith 1317d763cef2SBarry Smith Collective on TS 1318d763cef2SBarry Smith 1319d763cef2SBarry Smith Input Parameters: 1320d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1321d763cef2SBarry Smith 1322d763cef2SBarry Smith Notes: 1323d763cef2SBarry Smith There is no way to remove a single, specific monitor. 1324d763cef2SBarry Smith 1325d763cef2SBarry Smith Level: intermediate 1326d763cef2SBarry Smith 1327d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1328d763cef2SBarry Smith 1329*a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorSet() 1330d763cef2SBarry Smith @*/ 1331*a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorCancel(TS ts) 1332d763cef2SBarry Smith { 1333d952e501SBarry Smith PetscErrorCode ierr; 1334d952e501SBarry Smith PetscInt i; 1335d952e501SBarry Smith 1336d763cef2SBarry Smith PetscFunctionBegin; 13374482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1338d952e501SBarry Smith for (i=0; i<ts->numbermonitors; i++) { 1339d952e501SBarry Smith if (ts->mdestroy[i]) { 1340d952e501SBarry Smith ierr = (*ts->mdestroy[i])(ts->monitorcontext[i]);CHKERRQ(ierr); 1341d952e501SBarry Smith } 1342d952e501SBarry Smith } 1343d763cef2SBarry Smith ts->numbermonitors = 0; 1344d763cef2SBarry Smith PetscFunctionReturn(0); 1345d763cef2SBarry Smith } 1346d763cef2SBarry Smith 13474a2ae208SSatish Balay #undef __FUNCT__ 1348*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorDefault" 1349d8e5e3e6SSatish Balay /*@ 1350*a6570f20SBarry Smith TSMonitorDefault - Sets the Default monitor 1351d8e5e3e6SSatish Balay @*/ 1352*a6570f20SBarry Smith PetscErrorCode TSMonitorDefault(TS ts,PetscInt step,PetscReal ptime,Vec v,void *ctx) 1353d763cef2SBarry Smith { 1354dfbe8321SBarry Smith PetscErrorCode ierr; 1355eabae89aSBarry Smith PetscViewer viewer = (PetscViewer)ctx; 1356d132466eSBarry Smith 1357d763cef2SBarry Smith PetscFunctionBegin; 1358eabae89aSBarry Smith if (!viewer) viewer = PETSC_VIEWER_STDOUT_(ts->comm); 1359a83599f4SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"timestep %D dt %G time %G\n",step,ts->time_step,ptime);CHKERRQ(ierr); 1360d763cef2SBarry Smith PetscFunctionReturn(0); 1361d763cef2SBarry Smith } 1362d763cef2SBarry Smith 13634a2ae208SSatish Balay #undef __FUNCT__ 13644a2ae208SSatish Balay #define __FUNCT__ "TSStep" 1365d763cef2SBarry Smith /*@ 1366d763cef2SBarry Smith TSStep - Steps the requested number of timesteps. 1367d763cef2SBarry Smith 1368d763cef2SBarry Smith Collective on TS 1369d763cef2SBarry Smith 1370d763cef2SBarry Smith Input Parameter: 1371d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1372d763cef2SBarry Smith 1373d763cef2SBarry Smith Output Parameters: 1374d763cef2SBarry Smith + steps - number of iterations until termination 1375142b95e3SSatish Balay - ptime - time until termination 1376d763cef2SBarry Smith 1377d763cef2SBarry Smith Level: beginner 1378d763cef2SBarry Smith 1379d763cef2SBarry Smith .keywords: TS, timestep, solve 1380d763cef2SBarry Smith 1381d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSDestroy() 1382d763cef2SBarry Smith @*/ 138363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS ts,PetscInt *steps,PetscReal *ptime) 1384d763cef2SBarry Smith { 1385dfbe8321SBarry Smith PetscErrorCode ierr; 1386d763cef2SBarry Smith 1387d763cef2SBarry Smith PetscFunctionBegin; 13884482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1389d405a339SMatthew Knepley if (!ts->setupcalled) { 1390d405a339SMatthew Knepley ierr = TSSetUp(ts);CHKERRQ(ierr); 1391d405a339SMatthew Knepley } 1392d405a339SMatthew Knepley 1393d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1394d405a339SMatthew Knepley ierr = (*ts->ops->prestep)(ts);CHKERRQ(ierr); 1395000e7ae3SMatthew Knepley ierr = (*ts->ops->step)(ts, steps, ptime);CHKERRQ(ierr); 1396d405a339SMatthew Knepley ierr = (*ts->ops->poststep)(ts);CHKERRQ(ierr); 1397d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1398d405a339SMatthew Knepley 13994bb05414SBarry Smith if (!PetscPreLoadingOn) { 14004bb05414SBarry Smith ierr = TSViewFromOptions(ts,ts->name);CHKERRQ(ierr); 1401d405a339SMatthew Knepley } 1402d763cef2SBarry Smith PetscFunctionReturn(0); 1403d763cef2SBarry Smith } 1404d763cef2SBarry Smith 14054a2ae208SSatish Balay #undef __FUNCT__ 14064a2ae208SSatish Balay #define __FUNCT__ "TSMonitor" 1407d763cef2SBarry Smith /* 1408d763cef2SBarry Smith Runs the user provided monitor routines, if they exists. 1409d763cef2SBarry Smith */ 1410a7cc72afSBarry Smith PetscErrorCode TSMonitor(TS ts,PetscInt step,PetscReal ptime,Vec x) 1411d763cef2SBarry Smith { 14126849ba73SBarry Smith PetscErrorCode ierr; 1413a7cc72afSBarry Smith PetscInt i,n = ts->numbermonitors; 1414d763cef2SBarry Smith 1415d763cef2SBarry Smith PetscFunctionBegin; 1416d763cef2SBarry Smith for (i=0; i<n; i++) { 1417142b95e3SSatish Balay ierr = (*ts->monitor[i])(ts,step,ptime,x,ts->monitorcontext[i]);CHKERRQ(ierr); 1418d763cef2SBarry Smith } 1419d763cef2SBarry Smith PetscFunctionReturn(0); 1420d763cef2SBarry Smith } 1421d763cef2SBarry Smith 1422d763cef2SBarry Smith /* ------------------------------------------------------------------------*/ 1423d763cef2SBarry Smith 14244a2ae208SSatish Balay #undef __FUNCT__ 1425*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGCreate" 1426d763cef2SBarry Smith /*@C 1427*a6570f20SBarry Smith TSMonitorLGCreate - Creates a line graph context for use with 1428d763cef2SBarry Smith TS to monitor convergence of preconditioned residual norms. 1429d763cef2SBarry Smith 1430d763cef2SBarry Smith Collective on TS 1431d763cef2SBarry Smith 1432d763cef2SBarry Smith Input Parameters: 1433d763cef2SBarry Smith + host - the X display to open, or null for the local machine 1434d763cef2SBarry Smith . label - the title to put in the title bar 14357c922b88SBarry Smith . x, y - the screen coordinates of the upper left coordinate of the window 1436d763cef2SBarry Smith - m, n - the screen width and height in pixels 1437d763cef2SBarry Smith 1438d763cef2SBarry Smith Output Parameter: 1439d763cef2SBarry Smith . draw - the drawing context 1440d763cef2SBarry Smith 1441d763cef2SBarry Smith Options Database Key: 1442*a6570f20SBarry Smith . -ts_monitor_draw - automatically sets line graph monitor 1443d763cef2SBarry Smith 1444d763cef2SBarry Smith Notes: 1445*a6570f20SBarry Smith Use TSMonitorLGDestroy() to destroy this line graph, not PetscDrawLGDestroy(). 1446d763cef2SBarry Smith 1447d763cef2SBarry Smith Level: intermediate 1448d763cef2SBarry Smith 14497c922b88SBarry Smith .keywords: TS, monitor, line graph, residual, seealso 1450d763cef2SBarry Smith 1451*a6570f20SBarry Smith .seealso: TSMonitorLGDestroy(), TSMonitorSet() 14527c922b88SBarry Smith 1453d763cef2SBarry Smith @*/ 1454*a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGCreate(const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *draw) 1455d763cef2SBarry Smith { 1456b0a32e0cSBarry Smith PetscDraw win; 1457dfbe8321SBarry Smith PetscErrorCode ierr; 1458d763cef2SBarry Smith 1459d763cef2SBarry Smith PetscFunctionBegin; 1460b0a32e0cSBarry Smith ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr); 1461b0a32e0cSBarry Smith ierr = PetscDrawSetType(win,PETSC_DRAW_X);CHKERRQ(ierr); 1462b0a32e0cSBarry Smith ierr = PetscDrawLGCreate(win,1,draw);CHKERRQ(ierr); 1463b0a32e0cSBarry Smith ierr = PetscDrawLGIndicateDataPoints(*draw);CHKERRQ(ierr); 1464d763cef2SBarry Smith 146552e6d16bSBarry Smith ierr = PetscLogObjectParent(*draw,win);CHKERRQ(ierr); 1466d763cef2SBarry Smith PetscFunctionReturn(0); 1467d763cef2SBarry Smith } 1468d763cef2SBarry Smith 14694a2ae208SSatish Balay #undef __FUNCT__ 1470*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLG" 1471*a6570f20SBarry Smith PetscErrorCode TSMonitorLG(TS ts,PetscInt n,PetscReal ptime,Vec v,void *monctx) 1472d763cef2SBarry Smith { 1473b0a32e0cSBarry Smith PetscDrawLG lg = (PetscDrawLG) monctx; 147487828ca2SBarry Smith PetscReal x,y = ptime; 1475dfbe8321SBarry Smith PetscErrorCode ierr; 1476d763cef2SBarry Smith 1477d763cef2SBarry Smith PetscFunctionBegin; 14787c922b88SBarry Smith if (!monctx) { 14797c922b88SBarry Smith MPI_Comm comm; 1480b0a32e0cSBarry Smith PetscViewer viewer; 14817c922b88SBarry Smith 14827c922b88SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 1483b0a32e0cSBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 1484b0a32e0cSBarry Smith ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr); 14857c922b88SBarry Smith } 14867c922b88SBarry Smith 1487b0a32e0cSBarry Smith if (!n) {ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);} 148887828ca2SBarry Smith x = (PetscReal)n; 1489b0a32e0cSBarry Smith ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr); 1490d763cef2SBarry Smith if (n < 20 || (n % 5)) { 1491b0a32e0cSBarry Smith ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr); 1492d763cef2SBarry Smith } 1493d763cef2SBarry Smith PetscFunctionReturn(0); 1494d763cef2SBarry Smith } 1495d763cef2SBarry Smith 14964a2ae208SSatish Balay #undef __FUNCT__ 1497*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGDestroy" 1498d763cef2SBarry Smith /*@C 1499*a6570f20SBarry Smith TSMonitorLGDestroy - Destroys a line graph context that was created 1500*a6570f20SBarry Smith with TSMonitorLGCreate(). 1501d763cef2SBarry Smith 1502b0a32e0cSBarry Smith Collective on PetscDrawLG 1503d763cef2SBarry Smith 1504d763cef2SBarry Smith Input Parameter: 1505d763cef2SBarry Smith . draw - the drawing context 1506d763cef2SBarry Smith 1507d763cef2SBarry Smith Level: intermediate 1508d763cef2SBarry Smith 1509d763cef2SBarry Smith .keywords: TS, monitor, line graph, destroy 1510d763cef2SBarry Smith 1511*a6570f20SBarry Smith .seealso: TSMonitorLGCreate(), TSMonitorSet(), TSMonitorLG(); 1512d763cef2SBarry Smith @*/ 1513*a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGDestroy(PetscDrawLG drawlg) 1514d763cef2SBarry Smith { 1515b0a32e0cSBarry Smith PetscDraw draw; 1516dfbe8321SBarry Smith PetscErrorCode ierr; 1517d763cef2SBarry Smith 1518d763cef2SBarry Smith PetscFunctionBegin; 1519b0a32e0cSBarry Smith ierr = PetscDrawLGGetDraw(drawlg,&draw);CHKERRQ(ierr); 1520b0a32e0cSBarry Smith ierr = PetscDrawDestroy(draw);CHKERRQ(ierr); 1521b0a32e0cSBarry Smith ierr = PetscDrawLGDestroy(drawlg);CHKERRQ(ierr); 1522d763cef2SBarry Smith PetscFunctionReturn(0); 1523d763cef2SBarry Smith } 1524d763cef2SBarry Smith 15254a2ae208SSatish Balay #undef __FUNCT__ 15264a2ae208SSatish Balay #define __FUNCT__ "TSGetTime" 1527d763cef2SBarry Smith /*@ 1528d763cef2SBarry Smith TSGetTime - Gets the current time. 1529d763cef2SBarry Smith 1530d763cef2SBarry Smith Not Collective 1531d763cef2SBarry Smith 1532d763cef2SBarry Smith Input Parameter: 1533d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1534d763cef2SBarry Smith 1535d763cef2SBarry Smith Output Parameter: 1536d763cef2SBarry Smith . t - the current time 1537d763cef2SBarry Smith 1538d763cef2SBarry Smith Contributed by: Matthew Knepley 1539d763cef2SBarry Smith 1540d763cef2SBarry Smith Level: beginner 1541d763cef2SBarry Smith 1542d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1543d763cef2SBarry Smith 1544d763cef2SBarry Smith .keywords: TS, get, time 1545d763cef2SBarry Smith @*/ 154663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS ts,PetscReal* t) 1547d763cef2SBarry Smith { 1548d763cef2SBarry Smith PetscFunctionBegin; 15494482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 15504482741eSBarry Smith PetscValidDoublePointer(t,2); 1551d763cef2SBarry Smith *t = ts->ptime; 1552d763cef2SBarry Smith PetscFunctionReturn(0); 1553d763cef2SBarry Smith } 1554d763cef2SBarry Smith 15554a2ae208SSatish Balay #undef __FUNCT__ 15564a2ae208SSatish Balay #define __FUNCT__ "TSSetOptionsPrefix" 1557d763cef2SBarry Smith /*@C 1558d763cef2SBarry Smith TSSetOptionsPrefix - Sets the prefix used for searching for all 1559d763cef2SBarry Smith TS options in the database. 1560d763cef2SBarry Smith 1561d763cef2SBarry Smith Collective on TS 1562d763cef2SBarry Smith 1563d763cef2SBarry Smith Input Parameter: 1564d763cef2SBarry Smith + ts - The TS context 1565d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1566d763cef2SBarry Smith 1567d763cef2SBarry Smith Notes: 1568d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1569d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1570d763cef2SBarry Smith hyphen. 1571d763cef2SBarry Smith 1572d763cef2SBarry Smith Contributed by: Matthew Knepley 1573d763cef2SBarry Smith 1574d763cef2SBarry Smith Level: advanced 1575d763cef2SBarry Smith 1576d763cef2SBarry Smith .keywords: TS, set, options, prefix, database 1577d763cef2SBarry Smith 1578d763cef2SBarry Smith .seealso: TSSetFromOptions() 1579d763cef2SBarry Smith 1580d763cef2SBarry Smith @*/ 158163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS ts,const char prefix[]) 1582d763cef2SBarry Smith { 1583dfbe8321SBarry Smith PetscErrorCode ierr; 1584d763cef2SBarry Smith 1585d763cef2SBarry Smith PetscFunctionBegin; 15864482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1587d763cef2SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1588d763cef2SBarry Smith switch(ts->problem_type) { 1589d763cef2SBarry Smith case TS_NONLINEAR: 1590d763cef2SBarry Smith ierr = SNESSetOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 1591d763cef2SBarry Smith break; 1592d763cef2SBarry Smith case TS_LINEAR: 159394b7f48cSBarry Smith ierr = KSPSetOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 1594d763cef2SBarry Smith break; 1595d763cef2SBarry Smith } 1596d763cef2SBarry Smith PetscFunctionReturn(0); 1597d763cef2SBarry Smith } 1598d763cef2SBarry Smith 1599d763cef2SBarry Smith 16004a2ae208SSatish Balay #undef __FUNCT__ 16014a2ae208SSatish Balay #define __FUNCT__ "TSAppendOptionsPrefix" 1602d763cef2SBarry Smith /*@C 1603d763cef2SBarry Smith TSAppendOptionsPrefix - Appends to the prefix used for searching for all 1604d763cef2SBarry Smith TS options in the database. 1605d763cef2SBarry Smith 1606d763cef2SBarry Smith Collective on TS 1607d763cef2SBarry Smith 1608d763cef2SBarry Smith Input Parameter: 1609d763cef2SBarry Smith + ts - The TS context 1610d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1611d763cef2SBarry Smith 1612d763cef2SBarry Smith Notes: 1613d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1614d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1615d763cef2SBarry Smith hyphen. 1616d763cef2SBarry Smith 1617d763cef2SBarry Smith Contributed by: Matthew Knepley 1618d763cef2SBarry Smith 1619d763cef2SBarry Smith Level: advanced 1620d763cef2SBarry Smith 1621d763cef2SBarry Smith .keywords: TS, append, options, prefix, database 1622d763cef2SBarry Smith 1623d763cef2SBarry Smith .seealso: TSGetOptionsPrefix() 1624d763cef2SBarry Smith 1625d763cef2SBarry Smith @*/ 162663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS ts,const char prefix[]) 1627d763cef2SBarry Smith { 1628dfbe8321SBarry Smith PetscErrorCode ierr; 1629d763cef2SBarry Smith 1630d763cef2SBarry Smith PetscFunctionBegin; 16314482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1632d763cef2SBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1633d763cef2SBarry Smith switch(ts->problem_type) { 1634d763cef2SBarry Smith case TS_NONLINEAR: 1635d763cef2SBarry Smith ierr = SNESAppendOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 1636d763cef2SBarry Smith break; 1637d763cef2SBarry Smith case TS_LINEAR: 163894b7f48cSBarry Smith ierr = KSPAppendOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 1639d763cef2SBarry Smith break; 1640d763cef2SBarry Smith } 1641d763cef2SBarry Smith PetscFunctionReturn(0); 1642d763cef2SBarry Smith } 1643d763cef2SBarry Smith 16444a2ae208SSatish Balay #undef __FUNCT__ 16454a2ae208SSatish Balay #define __FUNCT__ "TSGetOptionsPrefix" 1646d763cef2SBarry Smith /*@C 1647d763cef2SBarry Smith TSGetOptionsPrefix - Sets the prefix used for searching for all 1648d763cef2SBarry Smith TS options in the database. 1649d763cef2SBarry Smith 1650d763cef2SBarry Smith Not Collective 1651d763cef2SBarry Smith 1652d763cef2SBarry Smith Input Parameter: 1653d763cef2SBarry Smith . ts - The TS context 1654d763cef2SBarry Smith 1655d763cef2SBarry Smith Output Parameter: 1656d763cef2SBarry Smith . prefix - A pointer to the prefix string used 1657d763cef2SBarry Smith 1658d763cef2SBarry Smith Contributed by: Matthew Knepley 1659d763cef2SBarry Smith 1660d763cef2SBarry Smith Notes: On the fortran side, the user should pass in a string 'prifix' of 1661d763cef2SBarry Smith sufficient length to hold the prefix. 1662d763cef2SBarry Smith 1663d763cef2SBarry Smith Level: intermediate 1664d763cef2SBarry Smith 1665d763cef2SBarry Smith .keywords: TS, get, options, prefix, database 1666d763cef2SBarry Smith 1667d763cef2SBarry Smith .seealso: TSAppendOptionsPrefix() 1668d763cef2SBarry Smith @*/ 1669e060cb09SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS ts,const char *prefix[]) 1670d763cef2SBarry Smith { 1671dfbe8321SBarry Smith PetscErrorCode ierr; 1672d763cef2SBarry Smith 1673d763cef2SBarry Smith PetscFunctionBegin; 16744482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 16754482741eSBarry Smith PetscValidPointer(prefix,2); 1676d763cef2SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1677d763cef2SBarry Smith PetscFunctionReturn(0); 1678d763cef2SBarry Smith } 1679d763cef2SBarry Smith 16804a2ae208SSatish Balay #undef __FUNCT__ 16814a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSMatrix" 1682d763cef2SBarry Smith /*@C 1683d763cef2SBarry Smith TSGetRHSMatrix - Returns the matrix A at the present timestep. 1684d763cef2SBarry Smith 1685d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1686d763cef2SBarry Smith 1687d763cef2SBarry Smith Input Parameter: 1688d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1689d763cef2SBarry Smith 1690d763cef2SBarry Smith Output Parameters: 1691d763cef2SBarry Smith + A - The matrix A, where U_t = A(t) U 1692d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as A 1693d763cef2SBarry Smith - ctx - User-defined context for matrix evaluation routine 1694d763cef2SBarry Smith 1695d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1696d763cef2SBarry Smith 1697d763cef2SBarry Smith Contributed by: Matthew Knepley 1698d763cef2SBarry Smith 1699d763cef2SBarry Smith Level: intermediate 1700d763cef2SBarry Smith 1701d763cef2SBarry Smith .seealso: TSGetTimeStep(), TSGetTime(), TSGetTimeStepNumber(), TSGetRHSJacobian() 1702d763cef2SBarry Smith 1703d763cef2SBarry Smith .keywords: TS, timestep, get, matrix 1704d763cef2SBarry Smith 1705d763cef2SBarry Smith @*/ 170663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSMatrix(TS ts,Mat *A,Mat *M,void **ctx) 1707d763cef2SBarry Smith { 1708d763cef2SBarry Smith PetscFunctionBegin; 17094482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1710d763cef2SBarry Smith if (A) *A = ts->A; 1711d763cef2SBarry Smith if (M) *M = ts->B; 1712d763cef2SBarry Smith if (ctx) *ctx = ts->jacP; 1713d763cef2SBarry Smith PetscFunctionReturn(0); 1714d763cef2SBarry Smith } 1715d763cef2SBarry Smith 17164a2ae208SSatish Balay #undef __FUNCT__ 17174a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSJacobian" 1718d763cef2SBarry Smith /*@C 1719d763cef2SBarry Smith TSGetRHSJacobian - Returns the Jacobian J at the present timestep. 1720d763cef2SBarry Smith 1721d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1722d763cef2SBarry Smith 1723d763cef2SBarry Smith Input Parameter: 1724d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1725d763cef2SBarry Smith 1726d763cef2SBarry Smith Output Parameters: 1727d763cef2SBarry Smith + J - The Jacobian J of F, where U_t = F(U,t) 1728d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as J 1729d763cef2SBarry Smith - ctx - User-defined context for Jacobian evaluation routine 1730d763cef2SBarry Smith 1731d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1732d763cef2SBarry Smith 1733d763cef2SBarry Smith Contributed by: Matthew Knepley 1734d763cef2SBarry Smith 1735d763cef2SBarry Smith Level: intermediate 1736d763cef2SBarry Smith 1737d763cef2SBarry Smith .seealso: TSGetTimeStep(), TSGetRHSMatrix(), TSGetTime(), TSGetTimeStepNumber() 1738d763cef2SBarry Smith 1739d763cef2SBarry Smith .keywords: TS, timestep, get, matrix, Jacobian 1740d763cef2SBarry Smith @*/ 174163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS ts,Mat *J,Mat *M,void **ctx) 1742d763cef2SBarry Smith { 1743dfbe8321SBarry Smith PetscErrorCode ierr; 1744d763cef2SBarry Smith 1745d763cef2SBarry Smith PetscFunctionBegin; 1746d763cef2SBarry Smith ierr = TSGetRHSMatrix(ts,J,M,ctx);CHKERRQ(ierr); 1747d763cef2SBarry Smith PetscFunctionReturn(0); 1748d763cef2SBarry Smith } 1749d763cef2SBarry Smith 17501713a123SBarry Smith #undef __FUNCT__ 1751*a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSolution" 17521713a123SBarry Smith /*@C 1753*a6570f20SBarry Smith TSMonitorSolution - Monitors progress of the TS solvers by calling 17541713a123SBarry Smith VecView() for the solution at each timestep 17551713a123SBarry Smith 17561713a123SBarry Smith Collective on TS 17571713a123SBarry Smith 17581713a123SBarry Smith Input Parameters: 17591713a123SBarry Smith + ts - the TS context 17601713a123SBarry Smith . step - current time-step 1761142b95e3SSatish Balay . ptime - current time 17621713a123SBarry Smith - dummy - either a viewer or PETSC_NULL 17631713a123SBarry Smith 17641713a123SBarry Smith Level: intermediate 17651713a123SBarry Smith 17661713a123SBarry Smith .keywords: TS, vector, monitor, view 17671713a123SBarry Smith 1768*a6570f20SBarry Smith .seealso: TSMonitorSet(), TSMonitorDefault(), VecView() 17691713a123SBarry Smith @*/ 1770*a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSolution(TS ts,PetscInt step,PetscReal ptime,Vec x,void *dummy) 17711713a123SBarry Smith { 1772dfbe8321SBarry Smith PetscErrorCode ierr; 17731713a123SBarry Smith PetscViewer viewer = (PetscViewer) dummy; 17741713a123SBarry Smith 17751713a123SBarry Smith PetscFunctionBegin; 17761713a123SBarry Smith if (!viewer) { 17771713a123SBarry Smith MPI_Comm comm; 17781713a123SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 17791713a123SBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 17801713a123SBarry Smith } 17811713a123SBarry Smith ierr = VecView(x,viewer);CHKERRQ(ierr); 17821713a123SBarry Smith PetscFunctionReturn(0); 17831713a123SBarry Smith } 17841713a123SBarry Smith 17851713a123SBarry Smith 17861713a123SBarry Smith 1787