163dd3a1aSKris Buschelman #define PETSCTS_DLL 263dd3a1aSKris Buschelman 37c4f633dSBarry Smith #include "private/tsimpl.h" /*I "petscts.h" I*/ 4d763cef2SBarry Smith 5d5ba7fb7SMatthew Knepley /* Logging support */ 6166c7f25SBarry Smith PetscCookie PETSCTS_DLLEXPORT TS_COOKIE; 7166c7f25SBarry Smith PetscLogEvent TS_Step, TS_PseudoComputeTimeStep, TS_FunctionEval, TS_JacobianEval; 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; 327adad957SLisandro Dalcin if (((PetscObject)ts)->type_name) { 337adad957SLisandro Dalcin defaultType = ((PetscObject)ts)->type_name; 34bdad233fSMatthew Knepley } else { 35bdad233fSMatthew Knepley defaultType = TS_EULER; 36bdad233fSMatthew Knepley } 37bdad233fSMatthew Knepley 38cce0b1b2SLisandro Dalcin if (!TSRegisterAllCalled) {ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 39bdad233fSMatthew Knepley ierr = PetscOptionsList("-ts_type", "TS method"," TSSetType", TSList, defaultType, typeName, 256, &opt);CHKERRQ(ierr); 40a7cc72afSBarry Smith if (opt) { 41bdad233fSMatthew Knepley ierr = TSSetType(ts, typeName);CHKERRQ(ierr); 42bdad233fSMatthew Knepley } else { 43bdad233fSMatthew Knepley ierr = TSSetType(ts, defaultType);CHKERRQ(ierr); 44bdad233fSMatthew Knepley } 45bdad233fSMatthew Knepley PetscFunctionReturn(0); 46bdad233fSMatthew Knepley } 47bdad233fSMatthew Knepley 48bdad233fSMatthew Knepley #undef __FUNCT__ 49bdad233fSMatthew Knepley #define __FUNCT__ "TSSetFromOptions" 50bdad233fSMatthew Knepley /*@ 51bdad233fSMatthew Knepley TSSetFromOptions - Sets various TS parameters from user options. 52bdad233fSMatthew Knepley 53bdad233fSMatthew Knepley Collective on TS 54bdad233fSMatthew Knepley 55bdad233fSMatthew Knepley Input Parameter: 56bdad233fSMatthew Knepley . ts - the TS context obtained from TSCreate() 57bdad233fSMatthew Knepley 58bdad233fSMatthew Knepley Options Database Keys: 590f3b3ca1SHong Zhang + -ts_type <type> - TS_EULER, TS_BEULER, TS_SUNDIALS, TS_PSEUDO, TS_CRANK_NICHOLSON 60bdad233fSMatthew Knepley . -ts_max_steps maxsteps - maximum number of time-steps to take 61bdad233fSMatthew Knepley . -ts_max_time time - maximum time to compute to 62bdad233fSMatthew Knepley . -ts_dt dt - initial time step 63bdad233fSMatthew Knepley . -ts_monitor - print information at each timestep 64a6570f20SBarry Smith - -ts_monitor_draw - plot information at each timestep 65bdad233fSMatthew Knepley 66bdad233fSMatthew Knepley Level: beginner 67bdad233fSMatthew Knepley 68bdad233fSMatthew Knepley .keywords: TS, timestep, set, options, database 69bdad233fSMatthew Knepley 70a313700dSBarry Smith .seealso: TSGetType() 71bdad233fSMatthew Knepley @*/ 7263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetFromOptions(TS ts) 73bdad233fSMatthew Knepley { 74bdad233fSMatthew Knepley PetscReal dt; 75eabae89aSBarry Smith PetscTruth opt,flg; 76dfbe8321SBarry Smith PetscErrorCode ierr; 77a34d58ebSBarry Smith PetscViewerASCIIMonitor monviewer; 78eabae89aSBarry Smith char monfilename[PETSC_MAX_PATH_LEN]; 79bdad233fSMatthew Knepley 80bdad233fSMatthew Knepley PetscFunctionBegin; 814482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 827adad957SLisandro Dalcin ierr = PetscOptionsBegin(((PetscObject)ts)->comm, ((PetscObject)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 */ 94a6570f20SBarry Smith ierr = PetscOptionsString("-ts_monitor","Monitor timestep size","TSMonitorDefault","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); 95eabae89aSBarry Smith if (flg) { 96050a712dSBarry Smith ierr = PetscViewerASCIIMonitorCreate(((PetscObject)ts)->comm,monfilename,((PetscObject)ts)->tablevel,&monviewer);CHKERRQ(ierr); 97a34d58ebSBarry Smith ierr = TSMonitorSet(ts,TSMonitorDefault,monviewer,(PetscErrorCode (*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr); 98bdad233fSMatthew Knepley } 9990d69ab7SBarry Smith opt = PETSC_FALSE; 10090d69ab7SBarry Smith ierr = PetscOptionsTruth("-ts_monitor_draw","Monitor timestep size graphically","TSMonitorLG",opt,&opt,PETSC_NULL);CHKERRQ(ierr); 101a7cc72afSBarry Smith if (opt) { 102a6570f20SBarry Smith ierr = TSMonitorSet(ts,TSMonitorLG,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); 103bdad233fSMatthew Knepley } 10490d69ab7SBarry Smith opt = PETSC_FALSE; 10590d69ab7SBarry Smith ierr = PetscOptionsTruth("-ts_monitor_solution","Monitor solution graphically","TSMonitorSolution",opt,&opt,PETSC_NULL);CHKERRQ(ierr); 106a7cc72afSBarry Smith if (opt) { 107a6570f20SBarry 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) { 1248beb423aSHong Zhang ierr = KSPSetOperators(ts->ksp,ts->Arhs,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 */ 1338beb423aSHong Zhang ierr = SNESSetJacobian(ts->snes,ts->Arhs,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; 16390d69ab7SBarry Smith PetscTruth opt = PETSC_FALSE; 164e10c49a3SBarry Smith char fileName[PETSC_MAX_PATH_LEN]; 165dfbe8321SBarry Smith PetscErrorCode ierr; 166bdad233fSMatthew Knepley 167bdad233fSMatthew Knepley PetscFunctionBegin; 1687adad957SLisandro Dalcin ierr = PetscOptionsGetString(((PetscObject)ts)->prefix, "-ts_view", fileName, PETSC_MAX_PATH_LEN, &opt);CHKERRQ(ierr); 169eabae89aSBarry Smith if (opt && !PetscPreLoadingOn) { 1707adad957SLisandro Dalcin ierr = PetscViewerASCIIOpen(((PetscObject)ts)->comm,fileName,&viewer);CHKERRQ(ierr); 171bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 172bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 173bdad233fSMatthew Knepley } 174*8e83347fSKai Germaschewski opt = PETSC_FALSE; 17590d69ab7SBarry Smith ierr = PetscOptionsGetTruth(((PetscObject)ts)->prefix, "-ts_view_draw", &opt,PETSC_NULL);CHKERRQ(ierr); 176a7cc72afSBarry Smith if (opt) { 1777adad957SLisandro Dalcin ierr = PetscViewerDrawOpen(((PetscObject)ts)->comm, 0, 0, 0, 0, 300, 300, &viewer);CHKERRQ(ierr); 178bdad233fSMatthew Knepley ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr); 179a7cc72afSBarry Smith if (title) { 1801836bdbcSSatish Balay ierr = PetscDrawSetTitle(draw, (char *)title);CHKERRQ(ierr); 181bdad233fSMatthew Knepley } else { 182bdad233fSMatthew Knepley ierr = PetscObjectName((PetscObject)ts);CHKERRQ(ierr); 1837adad957SLisandro Dalcin ierr = PetscDrawSetTitle(draw, ((PetscObject)ts)->name);CHKERRQ(ierr); 184bdad233fSMatthew Knepley } 185bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 186bdad233fSMatthew Knepley ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 187bdad233fSMatthew Knepley ierr = PetscDrawPause(draw);CHKERRQ(ierr); 188bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 189bdad233fSMatthew Knepley } 190bdad233fSMatthew Knepley PetscFunctionReturn(0); 191bdad233fSMatthew Knepley } 192bdad233fSMatthew Knepley 193bdad233fSMatthew Knepley #undef __FUNCT__ 1944a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSJacobian" 195a7a1495cSBarry Smith /*@ 1968c385f81SBarry Smith TSComputeRHSJacobian - Computes the Jacobian matrix that has been 197a7a1495cSBarry Smith set with TSSetRHSJacobian(). 198a7a1495cSBarry Smith 199a7a1495cSBarry Smith Collective on TS and Vec 200a7a1495cSBarry Smith 201a7a1495cSBarry Smith Input Parameters: 202a7a1495cSBarry Smith + ts - the SNES context 203a7a1495cSBarry Smith . t - current timestep 204a7a1495cSBarry Smith - x - input vector 205a7a1495cSBarry Smith 206a7a1495cSBarry Smith Output Parameters: 207a7a1495cSBarry Smith + A - Jacobian matrix 208a7a1495cSBarry Smith . B - optional preconditioning matrix 209a7a1495cSBarry Smith - flag - flag indicating matrix structure 210a7a1495cSBarry Smith 211a7a1495cSBarry Smith Notes: 212a7a1495cSBarry Smith Most users should not need to explicitly call this routine, as it 213a7a1495cSBarry Smith is used internally within the nonlinear solvers. 214a7a1495cSBarry Smith 21594b7f48cSBarry Smith See KSPSetOperators() for important information about setting the 216a7a1495cSBarry Smith flag parameter. 217a7a1495cSBarry Smith 218a7a1495cSBarry Smith TSComputeJacobian() is valid only for TS_NONLINEAR 219a7a1495cSBarry Smith 220a7a1495cSBarry Smith Level: developer 221a7a1495cSBarry Smith 222a7a1495cSBarry Smith .keywords: SNES, compute, Jacobian, matrix 223a7a1495cSBarry Smith 22494b7f48cSBarry Smith .seealso: TSSetRHSJacobian(), KSPSetOperators() 225a7a1495cSBarry Smith @*/ 22663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS ts,PetscReal t,Vec X,Mat *A,Mat *B,MatStructure *flg) 227a7a1495cSBarry Smith { 228dfbe8321SBarry Smith PetscErrorCode ierr; 229a7a1495cSBarry Smith 230a7a1495cSBarry Smith PetscFunctionBegin; 2314482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 2324482741eSBarry Smith PetscValidHeaderSpecific(X,VEC_COOKIE,3); 233c9780b6fSBarry Smith PetscCheckSameComm(ts,1,X,3); 234a7a1495cSBarry Smith if (ts->problem_type != TS_NONLINEAR) { 23529bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"For TS_NONLINEAR only"); 236a7a1495cSBarry Smith } 237000e7ae3SMatthew Knepley if (ts->ops->rhsjacobian) { 238d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 239a7a1495cSBarry Smith *flg = DIFFERENT_NONZERO_PATTERN; 240a7a1495cSBarry Smith PetscStackPush("TS user Jacobian function"); 241000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr); 242a7a1495cSBarry Smith PetscStackPop; 243d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 244a7a1495cSBarry Smith /* make sure user returned a correct Jacobian and preconditioner */ 2454482741eSBarry Smith PetscValidHeaderSpecific(*A,MAT_COOKIE,4); 2464482741eSBarry Smith PetscValidHeaderSpecific(*B,MAT_COOKIE,5); 247ef66eb69SBarry Smith } else { 248ef66eb69SBarry Smith ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 249ef66eb69SBarry Smith ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 250ef66eb69SBarry Smith if (*A != *B) { 251ef66eb69SBarry Smith ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 252ef66eb69SBarry Smith ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 253ef66eb69SBarry Smith } 254ef66eb69SBarry Smith } 255a7a1495cSBarry Smith PetscFunctionReturn(0); 256a7a1495cSBarry Smith } 257a7a1495cSBarry Smith 2584a2ae208SSatish Balay #undef __FUNCT__ 2594a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSFunction" 260d763cef2SBarry Smith /* 261d763cef2SBarry Smith TSComputeRHSFunction - Evaluates the right-hand-side function. 262d763cef2SBarry Smith 263d763cef2SBarry Smith Note: If the user did not provide a function but merely a matrix, 264d763cef2SBarry Smith this routine applies the matrix. 265d763cef2SBarry Smith */ 266dfbe8321SBarry Smith PetscErrorCode TSComputeRHSFunction(TS ts,PetscReal t,Vec x,Vec y) 267d763cef2SBarry Smith { 268dfbe8321SBarry Smith PetscErrorCode ierr; 269d763cef2SBarry Smith 270d763cef2SBarry Smith PetscFunctionBegin; 2714482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 2724482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,2); 2734482741eSBarry Smith PetscValidHeaderSpecific(y,VEC_COOKIE,3); 274d763cef2SBarry Smith 275d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 276000e7ae3SMatthew Knepley if (ts->ops->rhsfunction) { 277d763cef2SBarry Smith PetscStackPush("TS user right-hand-side function"); 278000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsfunction)(ts,t,x,y,ts->funP);CHKERRQ(ierr); 279d763cef2SBarry Smith PetscStackPop; 2807c922b88SBarry Smith } else { 281000e7ae3SMatthew Knepley if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */ 282d763cef2SBarry Smith MatStructure flg; 283d763cef2SBarry Smith PetscStackPush("TS user right-hand-side matrix function"); 2848beb423aSHong Zhang ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->Arhs,&ts->B,&flg,ts->jacP);CHKERRQ(ierr); 285d763cef2SBarry Smith PetscStackPop; 286d763cef2SBarry Smith } 2878beb423aSHong Zhang ierr = MatMult(ts->Arhs,x,y);CHKERRQ(ierr); 2887c922b88SBarry Smith } 289d763cef2SBarry Smith 290d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 291d763cef2SBarry Smith 292d763cef2SBarry Smith PetscFunctionReturn(0); 293d763cef2SBarry Smith } 294d763cef2SBarry Smith 2954a2ae208SSatish Balay #undef __FUNCT__ 2964a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSFunction" 297d763cef2SBarry Smith /*@C 298d763cef2SBarry Smith TSSetRHSFunction - Sets the routine for evaluating the function, 299d763cef2SBarry Smith F(t,u), where U_t = F(t,u). 300d763cef2SBarry Smith 301d763cef2SBarry Smith Collective on TS 302d763cef2SBarry Smith 303d763cef2SBarry Smith Input Parameters: 304d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 305d763cef2SBarry Smith . f - routine for evaluating the right-hand-side function 306d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 307d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 308d763cef2SBarry Smith 309d763cef2SBarry Smith Calling sequence of func: 31087828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Vec F,void *ctx); 311d763cef2SBarry Smith 312d763cef2SBarry Smith + t - current timestep 313d763cef2SBarry Smith . u - input vector 314d763cef2SBarry Smith . F - function vector 315d763cef2SBarry Smith - ctx - [optional] user-defined function context 316d763cef2SBarry Smith 317d763cef2SBarry Smith Important: 31876f2fa84SHong Zhang The user MUST call either this routine or TSSetMatrices(). 319d763cef2SBarry Smith 320d763cef2SBarry Smith Level: beginner 321d763cef2SBarry Smith 322d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, function 323d763cef2SBarry Smith 32476f2fa84SHong Zhang .seealso: TSSetMatrices() 325d763cef2SBarry Smith @*/ 32663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS ts,PetscErrorCode (*f)(TS,PetscReal,Vec,Vec,void*),void *ctx) 327d763cef2SBarry Smith { 328d763cef2SBarry Smith PetscFunctionBegin; 329d763cef2SBarry Smith 3304482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 331d763cef2SBarry Smith if (ts->problem_type == TS_LINEAR) { 33229bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_WRONG,"Cannot set function for linear problem"); 333d763cef2SBarry Smith } 334000e7ae3SMatthew Knepley ts->ops->rhsfunction = f; 335d763cef2SBarry Smith ts->funP = ctx; 336d763cef2SBarry Smith PetscFunctionReturn(0); 337d763cef2SBarry Smith } 338d763cef2SBarry Smith 3394a2ae208SSatish Balay #undef __FUNCT__ 34095f0b562SHong Zhang #define __FUNCT__ "TSSetMatrices" 34195f0b562SHong Zhang /*@C 34295f0b562SHong Zhang TSSetMatrices - Sets the functions to compute the matrices Alhs and Arhs, 34395f0b562SHong Zhang where Alhs(t) U_t = Arhs(t) U. 34495f0b562SHong Zhang 34595f0b562SHong Zhang Collective on TS 34695f0b562SHong Zhang 34795f0b562SHong Zhang Input Parameters: 34895f0b562SHong Zhang + ts - the TS context obtained from TSCreate() 34995f0b562SHong Zhang . Arhs - matrix 35095f0b562SHong Zhang . frhs - the matrix evaluation routine for Arhs; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 35195f0b562SHong Zhang if Arhs is not a function of t. 35295f0b562SHong Zhang . Alhs - matrix or PETSC_NULL if Alhs is an indentity matrix. 35395f0b562SHong Zhang . flhs - the matrix evaluation routine for Alhs; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 35495f0b562SHong Zhang if Alhs is not a function of t. 35595f0b562SHong Zhang . flag - flag indicating information about the matrix structure of Arhs and Alhs. 35695f0b562SHong Zhang The available options are 35795f0b562SHong Zhang SAME_NONZERO_PATTERN - Alhs has the same nonzero structure as Arhs 35895f0b562SHong Zhang DIFFERENT_NONZERO_PATTERN - Alhs has different nonzero structure as Arhs 35995f0b562SHong Zhang - ctx - [optional] user-defined context for private data for the 36095f0b562SHong Zhang matrix evaluation routine (may be PETSC_NULL) 36195f0b562SHong Zhang 36295f0b562SHong Zhang Calling sequence of func: 36395f0b562SHong Zhang $ func(TS ts,PetscReal t,Mat *A,Mat *B,PetscInt *flag,void *ctx); 36495f0b562SHong Zhang 36595f0b562SHong Zhang + t - current timestep 36695f0b562SHong Zhang . A - matrix A, where U_t = A(t) U 36795f0b562SHong Zhang . B - preconditioner matrix, usually the same as A 36895f0b562SHong Zhang . flag - flag indicating information about the preconditioner matrix 36995f0b562SHong Zhang structure (same as flag in KSPSetOperators()) 37095f0b562SHong Zhang - ctx - [optional] user-defined context for matrix evaluation routine 37195f0b562SHong Zhang 37295f0b562SHong Zhang Notes: 37395f0b562SHong Zhang The routine func() takes Mat* as the matrix arguments rather than Mat. 37495f0b562SHong Zhang This allows the matrix evaluation routine to replace Arhs or Alhs with a 37595f0b562SHong Zhang completely new new matrix structure (not just different matrix elements) 37695f0b562SHong Zhang when appropriate, for instance, if the nonzero structure is changing 37795f0b562SHong Zhang throughout the global iterations. 37895f0b562SHong Zhang 37995f0b562SHong Zhang Important: 38095f0b562SHong Zhang The user MUST call either this routine or TSSetRHSFunction(). 38195f0b562SHong Zhang 38295f0b562SHong Zhang Level: beginner 38395f0b562SHong Zhang 38495f0b562SHong Zhang .keywords: TS, timestep, set, matrix 38595f0b562SHong Zhang 38695f0b562SHong Zhang .seealso: TSSetRHSFunction() 38795f0b562SHong Zhang @*/ 38895f0b562SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSetMatrices(TS ts,Mat Arhs,PetscErrorCode (*frhs)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),Mat Alhs,PetscErrorCode (*flhs)(TS,PetscReal,Mat*,Mat*,MatStructure*,void*),MatStructure flag,void *ctx) 38995f0b562SHong Zhang { 39095f0b562SHong Zhang PetscFunctionBegin; 39195f0b562SHong Zhang PetscValidHeaderSpecific(ts,TS_COOKIE,1); 39292af4f6aSHong Zhang if (Arhs){ 39395f0b562SHong Zhang PetscValidHeaderSpecific(Arhs,MAT_COOKIE,2); 39495f0b562SHong Zhang PetscCheckSameComm(ts,1,Arhs,2); 39595f0b562SHong Zhang ts->Arhs = Arhs; 39692af4f6aSHong Zhang ts->ops->rhsmatrix = frhs; 39792af4f6aSHong Zhang } 39892af4f6aSHong Zhang if (Alhs){ 39992af4f6aSHong Zhang PetscValidHeaderSpecific(Alhs,MAT_COOKIE,4); 40092af4f6aSHong Zhang PetscCheckSameComm(ts,1,Alhs,4); 40195f0b562SHong Zhang ts->Alhs = Alhs; 40292af4f6aSHong Zhang ts->ops->lhsmatrix = flhs; 40392af4f6aSHong Zhang } 40492af4f6aSHong Zhang 40592af4f6aSHong Zhang ts->jacP = ctx; 40695f0b562SHong Zhang ts->matflg = flag; 40795f0b562SHong Zhang PetscFunctionReturn(0); 40895f0b562SHong Zhang } 409d763cef2SBarry Smith 410aa644b49SHong Zhang #undef __FUNCT__ 411cda39b92SHong Zhang #define __FUNCT__ "TSGetMatrices" 412cda39b92SHong Zhang /*@C 413cda39b92SHong Zhang TSGetMatrices - Returns the matrices Arhs and Alhs at the present timestep, 414cda39b92SHong Zhang where Alhs(t) U_t = Arhs(t) U. 415cda39b92SHong Zhang 416cda39b92SHong Zhang Not Collective, but parallel objects are returned if TS is parallel 417cda39b92SHong Zhang 418cda39b92SHong Zhang Input Parameter: 419cda39b92SHong Zhang . ts - The TS context obtained from TSCreate() 420cda39b92SHong Zhang 421cda39b92SHong Zhang Output Parameters: 422cda39b92SHong Zhang + Arhs - The right-hand side matrix 423cda39b92SHong Zhang . Alhs - The left-hand side matrix 424cda39b92SHong Zhang - ctx - User-defined context for matrix evaluation routine 425cda39b92SHong Zhang 426cda39b92SHong Zhang Notes: You can pass in PETSC_NULL for any return argument you do not need. 427cda39b92SHong Zhang 428cda39b92SHong Zhang Level: intermediate 429cda39b92SHong Zhang 430cda39b92SHong Zhang .seealso: TSSetMatrices(), TSGetTimeStep(), TSGetTime(), TSGetTimeStepNumber(), TSGetRHSJacobian() 431cda39b92SHong Zhang 432cda39b92SHong Zhang .keywords: TS, timestep, get, matrix 433cda39b92SHong Zhang 434cda39b92SHong Zhang @*/ 435cda39b92SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSGetMatrices(TS ts,Mat *Arhs,Mat *Alhs,void **ctx) 436cda39b92SHong Zhang { 437cda39b92SHong Zhang PetscFunctionBegin; 438cda39b92SHong Zhang PetscValidHeaderSpecific(ts,TS_COOKIE,1); 439cda39b92SHong Zhang if (Arhs) *Arhs = ts->Arhs; 440cda39b92SHong Zhang if (Alhs) *Alhs = ts->Alhs; 441cda39b92SHong Zhang if (ctx) *ctx = ts->jacP; 442cda39b92SHong Zhang PetscFunctionReturn(0); 443cda39b92SHong Zhang } 444cda39b92SHong Zhang 445cda39b92SHong Zhang #undef __FUNCT__ 4464a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSJacobian" 447d763cef2SBarry Smith /*@C 448d763cef2SBarry Smith TSSetRHSJacobian - Sets the function to compute the Jacobian of F, 449d763cef2SBarry Smith where U_t = F(U,t), as well as the location to store the matrix. 45076f2fa84SHong Zhang Use TSSetMatrices() for linear problems. 451d763cef2SBarry Smith 452d763cef2SBarry Smith Collective on TS 453d763cef2SBarry Smith 454d763cef2SBarry Smith Input Parameters: 455d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 456d763cef2SBarry Smith . A - Jacobian matrix 457d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 458d763cef2SBarry Smith . f - the Jacobian evaluation routine 459d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 460d763cef2SBarry Smith Jacobian evaluation routine (may be PETSC_NULL) 461d763cef2SBarry Smith 462d763cef2SBarry Smith Calling sequence of func: 46387828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Mat *A,Mat *B,MatStructure *flag,void *ctx); 464d763cef2SBarry Smith 465d763cef2SBarry Smith + t - current timestep 466d763cef2SBarry Smith . u - input vector 467d763cef2SBarry Smith . A - matrix A, where U_t = A(t)u 468d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 469d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 47094b7f48cSBarry Smith structure (same as flag in KSPSetOperators()) 471d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 472d763cef2SBarry Smith 473d763cef2SBarry Smith Notes: 47494b7f48cSBarry Smith See KSPSetOperators() for important information about setting the flag 475d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 476d763cef2SBarry Smith 477d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 478d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 47956335db2SHong Zhang completely new matrix structure (not just different matrix elements) 480d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 481d763cef2SBarry Smith throughout the global iterations. 482d763cef2SBarry Smith 483d763cef2SBarry Smith Level: beginner 484d763cef2SBarry Smith 485d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, Jacobian 486d763cef2SBarry Smith 487d763cef2SBarry Smith .seealso: TSDefaultComputeJacobianColor(), 48876f2fa84SHong Zhang SNESDefaultComputeJacobianColor(), TSSetRHSFunction(), TSSetMatrices() 489d763cef2SBarry Smith 490d763cef2SBarry Smith @*/ 49163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx) 492d763cef2SBarry Smith { 493d763cef2SBarry Smith PetscFunctionBegin; 4944482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 4954482741eSBarry Smith PetscValidHeaderSpecific(A,MAT_COOKIE,2); 4964482741eSBarry Smith PetscValidHeaderSpecific(B,MAT_COOKIE,3); 497c9780b6fSBarry Smith PetscCheckSameComm(ts,1,A,2); 498c9780b6fSBarry Smith PetscCheckSameComm(ts,1,B,3); 499d763cef2SBarry Smith if (ts->problem_type != TS_NONLINEAR) { 50076f2fa84SHong Zhang SETERRQ(PETSC_ERR_ARG_WRONG,"Not for linear problems; use TSSetMatrices()"); 501d763cef2SBarry Smith } 502d763cef2SBarry Smith 503000e7ae3SMatthew Knepley ts->ops->rhsjacobian = f; 504d763cef2SBarry Smith ts->jacP = ctx; 5058beb423aSHong Zhang ts->Arhs = A; 506d763cef2SBarry Smith ts->B = B; 507d763cef2SBarry Smith PetscFunctionReturn(0); 508d763cef2SBarry Smith } 509d763cef2SBarry Smith 5104a2ae208SSatish Balay #undef __FUNCT__ 5114a2ae208SSatish Balay #define __FUNCT__ "TSView" 5127e2c5f70SBarry Smith /*@C 513d763cef2SBarry Smith TSView - Prints the TS data structure. 514d763cef2SBarry Smith 5154c49b128SBarry Smith Collective on TS 516d763cef2SBarry Smith 517d763cef2SBarry Smith Input Parameters: 518d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 519d763cef2SBarry Smith - viewer - visualization context 520d763cef2SBarry Smith 521d763cef2SBarry Smith Options Database Key: 522d763cef2SBarry Smith . -ts_view - calls TSView() at end of TSStep() 523d763cef2SBarry Smith 524d763cef2SBarry Smith Notes: 525d763cef2SBarry Smith The available visualization contexts include 526b0a32e0cSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 527b0a32e0cSBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 528d763cef2SBarry Smith output where only the first processor opens 529d763cef2SBarry Smith the file. All other processors send their 530d763cef2SBarry Smith data to the first processor to print. 531d763cef2SBarry Smith 532d763cef2SBarry Smith The user can open an alternative visualization context with 533b0a32e0cSBarry Smith PetscViewerASCIIOpen() - output to a specified file. 534d763cef2SBarry Smith 535d763cef2SBarry Smith Level: beginner 536d763cef2SBarry Smith 537d763cef2SBarry Smith .keywords: TS, timestep, view 538d763cef2SBarry Smith 539b0a32e0cSBarry Smith .seealso: PetscViewerASCIIOpen() 540d763cef2SBarry Smith @*/ 54163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSView(TS ts,PetscViewer viewer) 542d763cef2SBarry Smith { 543dfbe8321SBarry Smith PetscErrorCode ierr; 544a313700dSBarry Smith const TSType type; 54532077d6dSBarry Smith PetscTruth iascii,isstring; 546d763cef2SBarry Smith 547d763cef2SBarry Smith PetscFunctionBegin; 5484482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 5493050cee2SBarry Smith if (!viewer) { 5507adad957SLisandro Dalcin ierr = PetscViewerASCIIGetStdout(((PetscObject)ts)->comm,&viewer);CHKERRQ(ierr); 5513050cee2SBarry Smith } 5524482741eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2); 553c9780b6fSBarry Smith PetscCheckSameComm(ts,1,viewer,2); 554fd16b177SBarry Smith 55532077d6dSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 556b0a32e0cSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr); 55732077d6dSBarry Smith if (iascii) { 558b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"TS Object:\n");CHKERRQ(ierr); 559a313700dSBarry Smith ierr = TSGetType(ts,&type);CHKERRQ(ierr); 560454a90a3SBarry Smith if (type) { 561b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: %s\n",type);CHKERRQ(ierr); 562184914b5SBarry Smith } else { 563b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: not yet set\n");CHKERRQ(ierr); 564184914b5SBarry Smith } 565000e7ae3SMatthew Knepley if (ts->ops->view) { 566b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 567000e7ae3SMatthew Knepley ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr); 568b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 569d763cef2SBarry Smith } 57077431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum steps=%D\n",ts->max_steps);CHKERRQ(ierr); 571a83599f4SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum time=%G\n",ts->max_time);CHKERRQ(ierr); 572d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 57377431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of nonlinear solver iterations=%D\n",ts->nonlinear_its);CHKERRQ(ierr); 574d763cef2SBarry Smith } 57577431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of linear solver iterations=%D\n",ts->linear_its);CHKERRQ(ierr); 5760f5bd95cSBarry Smith } else if (isstring) { 577a313700dSBarry Smith ierr = TSGetType(ts,&type);CHKERRQ(ierr); 578b0a32e0cSBarry Smith ierr = PetscViewerStringSPrintf(viewer," %-7.7s",type);CHKERRQ(ierr); 579d763cef2SBarry Smith } 580b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 58194b7f48cSBarry Smith if (ts->ksp) {ierr = KSPView(ts->ksp,viewer);CHKERRQ(ierr);} 582d763cef2SBarry Smith if (ts->snes) {ierr = SNESView(ts->snes,viewer);CHKERRQ(ierr);} 583b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 584d763cef2SBarry Smith PetscFunctionReturn(0); 585d763cef2SBarry Smith } 586d763cef2SBarry Smith 587d763cef2SBarry Smith 5884a2ae208SSatish Balay #undef __FUNCT__ 5894a2ae208SSatish Balay #define __FUNCT__ "TSSetApplicationContext" 590d763cef2SBarry Smith /*@C 591d763cef2SBarry Smith TSSetApplicationContext - Sets an optional user-defined context for 592d763cef2SBarry Smith the timesteppers. 593d763cef2SBarry Smith 594d763cef2SBarry Smith Collective on TS 595d763cef2SBarry Smith 596d763cef2SBarry Smith Input Parameters: 597d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 598d763cef2SBarry Smith - usrP - optional user context 599d763cef2SBarry Smith 600d763cef2SBarry Smith Level: intermediate 601d763cef2SBarry Smith 602d763cef2SBarry Smith .keywords: TS, timestep, set, application, context 603d763cef2SBarry Smith 604d763cef2SBarry Smith .seealso: TSGetApplicationContext() 605d763cef2SBarry Smith @*/ 60663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS ts,void *usrP) 607d763cef2SBarry Smith { 608d763cef2SBarry Smith PetscFunctionBegin; 6094482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 610d763cef2SBarry Smith ts->user = usrP; 611d763cef2SBarry Smith PetscFunctionReturn(0); 612d763cef2SBarry Smith } 613d763cef2SBarry Smith 6144a2ae208SSatish Balay #undef __FUNCT__ 6154a2ae208SSatish Balay #define __FUNCT__ "TSGetApplicationContext" 616d763cef2SBarry Smith /*@C 617d763cef2SBarry Smith TSGetApplicationContext - Gets the user-defined context for the 618d763cef2SBarry Smith timestepper. 619d763cef2SBarry Smith 620d763cef2SBarry Smith Not Collective 621d763cef2SBarry Smith 622d763cef2SBarry Smith Input Parameter: 623d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 624d763cef2SBarry Smith 625d763cef2SBarry Smith Output Parameter: 626d763cef2SBarry Smith . usrP - user context 627d763cef2SBarry Smith 628d763cef2SBarry Smith Level: intermediate 629d763cef2SBarry Smith 630d763cef2SBarry Smith .keywords: TS, timestep, get, application, context 631d763cef2SBarry Smith 632d763cef2SBarry Smith .seealso: TSSetApplicationContext() 633d763cef2SBarry Smith @*/ 63463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS ts,void **usrP) 635d763cef2SBarry Smith { 636d763cef2SBarry Smith PetscFunctionBegin; 6374482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 638d763cef2SBarry Smith *usrP = ts->user; 639d763cef2SBarry Smith PetscFunctionReturn(0); 640d763cef2SBarry Smith } 641d763cef2SBarry Smith 6424a2ae208SSatish Balay #undef __FUNCT__ 6434a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStepNumber" 644d763cef2SBarry Smith /*@ 645d763cef2SBarry Smith TSGetTimeStepNumber - Gets the current number of timesteps. 646d763cef2SBarry Smith 647d763cef2SBarry Smith Not Collective 648d763cef2SBarry Smith 649d763cef2SBarry Smith Input Parameter: 650d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 651d763cef2SBarry Smith 652d763cef2SBarry Smith Output Parameter: 653d763cef2SBarry Smith . iter - number steps so far 654d763cef2SBarry Smith 655d763cef2SBarry Smith Level: intermediate 656d763cef2SBarry Smith 657d763cef2SBarry Smith .keywords: TS, timestep, get, iteration, number 658d763cef2SBarry Smith @*/ 65963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS ts,PetscInt* iter) 660d763cef2SBarry Smith { 661d763cef2SBarry Smith PetscFunctionBegin; 6624482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 6634482741eSBarry Smith PetscValidIntPointer(iter,2); 664d763cef2SBarry Smith *iter = ts->steps; 665d763cef2SBarry Smith PetscFunctionReturn(0); 666d763cef2SBarry Smith } 667d763cef2SBarry Smith 6684a2ae208SSatish Balay #undef __FUNCT__ 6694a2ae208SSatish Balay #define __FUNCT__ "TSSetInitialTimeStep" 670d763cef2SBarry Smith /*@ 671d763cef2SBarry Smith TSSetInitialTimeStep - Sets the initial timestep to be used, 672d763cef2SBarry Smith as well as the initial time. 673d763cef2SBarry Smith 674d763cef2SBarry Smith Collective on TS 675d763cef2SBarry Smith 676d763cef2SBarry Smith Input Parameters: 677d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 678d763cef2SBarry Smith . initial_time - the initial time 679d763cef2SBarry Smith - time_step - the size of the timestep 680d763cef2SBarry Smith 681d763cef2SBarry Smith Level: intermediate 682d763cef2SBarry Smith 683d763cef2SBarry Smith .seealso: TSSetTimeStep(), TSGetTimeStep() 684d763cef2SBarry Smith 685d763cef2SBarry Smith .keywords: TS, set, initial, timestep 686d763cef2SBarry Smith @*/ 68763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS ts,PetscReal initial_time,PetscReal time_step) 688d763cef2SBarry Smith { 689d763cef2SBarry Smith PetscFunctionBegin; 6904482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 691d763cef2SBarry Smith ts->time_step = time_step; 692d763cef2SBarry Smith ts->initial_time_step = time_step; 693d763cef2SBarry Smith ts->ptime = initial_time; 694d763cef2SBarry Smith PetscFunctionReturn(0); 695d763cef2SBarry Smith } 696d763cef2SBarry Smith 6974a2ae208SSatish Balay #undef __FUNCT__ 6984a2ae208SSatish Balay #define __FUNCT__ "TSSetTimeStep" 699d763cef2SBarry Smith /*@ 700d763cef2SBarry Smith TSSetTimeStep - Allows one to reset the timestep at any time, 701d763cef2SBarry Smith useful for simple pseudo-timestepping codes. 702d763cef2SBarry Smith 703d763cef2SBarry Smith Collective on TS 704d763cef2SBarry Smith 705d763cef2SBarry Smith Input Parameters: 706d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 707d763cef2SBarry Smith - time_step - the size of the timestep 708d763cef2SBarry Smith 709d763cef2SBarry Smith Level: intermediate 710d763cef2SBarry Smith 711d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 712d763cef2SBarry Smith 713d763cef2SBarry Smith .keywords: TS, set, timestep 714d763cef2SBarry Smith @*/ 71563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS ts,PetscReal time_step) 716d763cef2SBarry Smith { 717d763cef2SBarry Smith PetscFunctionBegin; 7184482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 719d763cef2SBarry Smith ts->time_step = time_step; 720d763cef2SBarry Smith PetscFunctionReturn(0); 721d763cef2SBarry Smith } 722d763cef2SBarry Smith 7234a2ae208SSatish Balay #undef __FUNCT__ 7244a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStep" 725d763cef2SBarry Smith /*@ 726d763cef2SBarry Smith TSGetTimeStep - Gets the current timestep size. 727d763cef2SBarry Smith 728d763cef2SBarry Smith Not Collective 729d763cef2SBarry Smith 730d763cef2SBarry Smith Input Parameter: 731d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 732d763cef2SBarry Smith 733d763cef2SBarry Smith Output Parameter: 734d763cef2SBarry Smith . dt - the current timestep size 735d763cef2SBarry Smith 736d763cef2SBarry Smith Level: intermediate 737d763cef2SBarry Smith 738d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 739d763cef2SBarry Smith 740d763cef2SBarry Smith .keywords: TS, get, timestep 741d763cef2SBarry Smith @*/ 74263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS ts,PetscReal* dt) 743d763cef2SBarry Smith { 744d763cef2SBarry Smith PetscFunctionBegin; 7454482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 7464482741eSBarry Smith PetscValidDoublePointer(dt,2); 747d763cef2SBarry Smith *dt = ts->time_step; 748d763cef2SBarry Smith PetscFunctionReturn(0); 749d763cef2SBarry Smith } 750d763cef2SBarry Smith 7514a2ae208SSatish Balay #undef __FUNCT__ 7524a2ae208SSatish Balay #define __FUNCT__ "TSGetSolution" 753d8e5e3e6SSatish Balay /*@ 754d763cef2SBarry Smith TSGetSolution - Returns the solution at the present timestep. It 755d763cef2SBarry Smith is valid to call this routine inside the function that you are evaluating 756d763cef2SBarry Smith in order to move to the new timestep. This vector not changed until 757d763cef2SBarry Smith the solution at the next timestep has been calculated. 758d763cef2SBarry Smith 759d763cef2SBarry Smith Not Collective, but Vec returned is parallel if TS is parallel 760d763cef2SBarry Smith 761d763cef2SBarry Smith Input Parameter: 762d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 763d763cef2SBarry Smith 764d763cef2SBarry Smith Output Parameter: 765d763cef2SBarry Smith . v - the vector containing the solution 766d763cef2SBarry Smith 767d763cef2SBarry Smith Level: intermediate 768d763cef2SBarry Smith 769d763cef2SBarry Smith .seealso: TSGetTimeStep() 770d763cef2SBarry Smith 771d763cef2SBarry Smith .keywords: TS, timestep, get, solution 772d763cef2SBarry Smith @*/ 77363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS ts,Vec *v) 774d763cef2SBarry Smith { 775d763cef2SBarry Smith PetscFunctionBegin; 7764482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 7774482741eSBarry Smith PetscValidPointer(v,2); 778d763cef2SBarry Smith *v = ts->vec_sol_always; 779d763cef2SBarry Smith PetscFunctionReturn(0); 780d763cef2SBarry Smith } 781d763cef2SBarry Smith 782bdad233fSMatthew Knepley /* ----- Routines to initialize and destroy a timestepper ---- */ 7834a2ae208SSatish Balay #undef __FUNCT__ 784bdad233fSMatthew Knepley #define __FUNCT__ "TSSetProblemType" 785d8e5e3e6SSatish Balay /*@ 786bdad233fSMatthew Knepley TSSetProblemType - Sets the type of problem to be solved. 787d763cef2SBarry Smith 788bdad233fSMatthew Knepley Not collective 789d763cef2SBarry Smith 790bdad233fSMatthew Knepley Input Parameters: 791bdad233fSMatthew Knepley + ts - The TS 792bdad233fSMatthew Knepley - type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 793d763cef2SBarry Smith .vb 794d763cef2SBarry Smith U_t = A U 795d763cef2SBarry Smith U_t = A(t) U 796d763cef2SBarry Smith U_t = F(t,U) 797d763cef2SBarry Smith .ve 798d763cef2SBarry Smith 799d763cef2SBarry Smith Level: beginner 800d763cef2SBarry Smith 801bdad233fSMatthew Knepley .keywords: TS, problem type 802bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 803d763cef2SBarry Smith @*/ 80463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS ts, TSProblemType type) 805a7cc72afSBarry Smith { 806d763cef2SBarry Smith PetscFunctionBegin; 8074482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 808bdad233fSMatthew Knepley ts->problem_type = type; 809d763cef2SBarry Smith PetscFunctionReturn(0); 810d763cef2SBarry Smith } 811d763cef2SBarry Smith 812bdad233fSMatthew Knepley #undef __FUNCT__ 813bdad233fSMatthew Knepley #define __FUNCT__ "TSGetProblemType" 814bdad233fSMatthew Knepley /*@C 815bdad233fSMatthew Knepley TSGetProblemType - Gets the type of problem to be solved. 816bdad233fSMatthew Knepley 817bdad233fSMatthew Knepley Not collective 818bdad233fSMatthew Knepley 819bdad233fSMatthew Knepley Input Parameter: 820bdad233fSMatthew Knepley . ts - The TS 821bdad233fSMatthew Knepley 822bdad233fSMatthew Knepley Output Parameter: 823bdad233fSMatthew Knepley . type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 824bdad233fSMatthew Knepley .vb 825bdad233fSMatthew Knepley U_t = A U 826bdad233fSMatthew Knepley U_t = A(t) U 827bdad233fSMatthew Knepley U_t = F(t,U) 828bdad233fSMatthew Knepley .ve 829bdad233fSMatthew Knepley 830bdad233fSMatthew Knepley Level: beginner 831bdad233fSMatthew Knepley 832bdad233fSMatthew Knepley .keywords: TS, problem type 833bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 834bdad233fSMatthew Knepley @*/ 83563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS ts, TSProblemType *type) 836a7cc72afSBarry Smith { 837bdad233fSMatthew Knepley PetscFunctionBegin; 8384482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 8394482741eSBarry Smith PetscValidIntPointer(type,2); 840bdad233fSMatthew Knepley *type = ts->problem_type; 841bdad233fSMatthew Knepley PetscFunctionReturn(0); 842bdad233fSMatthew Knepley } 843d763cef2SBarry Smith 8444a2ae208SSatish Balay #undef __FUNCT__ 8454a2ae208SSatish Balay #define __FUNCT__ "TSSetUp" 846d763cef2SBarry Smith /*@ 847d763cef2SBarry Smith TSSetUp - Sets up the internal data structures for the later use 848d763cef2SBarry Smith of a timestepper. 849d763cef2SBarry Smith 850d763cef2SBarry Smith Collective on TS 851d763cef2SBarry Smith 852d763cef2SBarry Smith Input Parameter: 853d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 854d763cef2SBarry Smith 855d763cef2SBarry Smith Notes: 856d763cef2SBarry Smith For basic use of the TS solvers the user need not explicitly call 857d763cef2SBarry Smith TSSetUp(), since these actions will automatically occur during 858d763cef2SBarry Smith the call to TSStep(). However, if one wishes to control this 859d763cef2SBarry Smith phase separately, TSSetUp() should be called after TSCreate() 860d763cef2SBarry Smith and optional routines of the form TSSetXXX(), but before TSStep(). 861d763cef2SBarry Smith 862d763cef2SBarry Smith Level: advanced 863d763cef2SBarry Smith 864d763cef2SBarry Smith .keywords: TS, timestep, setup 865d763cef2SBarry Smith 866d763cef2SBarry Smith .seealso: TSCreate(), TSStep(), TSDestroy() 867d763cef2SBarry Smith @*/ 86863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS ts) 869d763cef2SBarry Smith { 870dfbe8321SBarry Smith PetscErrorCode ierr; 871d763cef2SBarry Smith 872d763cef2SBarry Smith PetscFunctionBegin; 8734482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 87429bbc08cSBarry Smith if (!ts->vec_sol) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call TSSetSolution() first"); 8757adad957SLisandro Dalcin if (!((PetscObject)ts)->type_name) { 876d763cef2SBarry Smith ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr); 877d763cef2SBarry Smith } 878000e7ae3SMatthew Knepley ierr = (*ts->ops->setup)(ts);CHKERRQ(ierr); 879d763cef2SBarry Smith ts->setupcalled = 1; 880d763cef2SBarry Smith PetscFunctionReturn(0); 881d763cef2SBarry Smith } 882d763cef2SBarry Smith 8834a2ae208SSatish Balay #undef __FUNCT__ 8844a2ae208SSatish Balay #define __FUNCT__ "TSDestroy" 885d8e5e3e6SSatish Balay /*@ 886d763cef2SBarry Smith TSDestroy - Destroys the timestepper context that was created 887d763cef2SBarry Smith with TSCreate(). 888d763cef2SBarry Smith 889d763cef2SBarry Smith Collective on TS 890d763cef2SBarry Smith 891d763cef2SBarry Smith Input Parameter: 892d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 893d763cef2SBarry Smith 894d763cef2SBarry Smith Level: beginner 895d763cef2SBarry Smith 896d763cef2SBarry Smith .keywords: TS, timestepper, destroy 897d763cef2SBarry Smith 898d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve() 899d763cef2SBarry Smith @*/ 90063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS ts) 901d763cef2SBarry Smith { 9026849ba73SBarry Smith PetscErrorCode ierr; 903d763cef2SBarry Smith 904d763cef2SBarry Smith PetscFunctionBegin; 9054482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 9067adad957SLisandro Dalcin if (--((PetscObject)ts)->refct > 0) PetscFunctionReturn(0); 907d763cef2SBarry Smith 908be0abb6dSBarry Smith /* if memory was published with AMS then destroy it */ 9090f5bd95cSBarry Smith ierr = PetscObjectDepublish(ts);CHKERRQ(ierr); 9108beb423aSHong Zhang if (ts->A) {ierr = MatDestroy(ts->A);CHKERRQ(ierr)} 91194b7f48cSBarry Smith if (ts->ksp) {ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);} 912d763cef2SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 9131e3347e8SBarry Smith if (ts->ops->destroy) {ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);} 914a6570f20SBarry Smith ierr = TSMonitorCancel(ts);CHKERRQ(ierr); 915a79aaaedSSatish Balay ierr = PetscHeaderDestroy(ts);CHKERRQ(ierr); 916d763cef2SBarry Smith PetscFunctionReturn(0); 917d763cef2SBarry Smith } 918d763cef2SBarry Smith 9194a2ae208SSatish Balay #undef __FUNCT__ 9204a2ae208SSatish Balay #define __FUNCT__ "TSGetSNES" 921d8e5e3e6SSatish Balay /*@ 922d763cef2SBarry Smith TSGetSNES - Returns the SNES (nonlinear solver) associated with 923d763cef2SBarry Smith a TS (timestepper) context. Valid only for nonlinear problems. 924d763cef2SBarry Smith 925d763cef2SBarry Smith Not Collective, but SNES is parallel if TS is parallel 926d763cef2SBarry Smith 927d763cef2SBarry Smith Input Parameter: 928d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 929d763cef2SBarry Smith 930d763cef2SBarry Smith Output Parameter: 931d763cef2SBarry Smith . snes - the nonlinear solver context 932d763cef2SBarry Smith 933d763cef2SBarry Smith Notes: 934d763cef2SBarry Smith The user can then directly manipulate the SNES context to set various 935d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 93694b7f48cSBarry Smith KSP, KSP, and PC contexts as well. 937d763cef2SBarry Smith 938d763cef2SBarry Smith TSGetSNES() does not work for integrators that do not use SNES; in 939d763cef2SBarry Smith this case TSGetSNES() returns PETSC_NULL in snes. 940d763cef2SBarry Smith 941d763cef2SBarry Smith Level: beginner 942d763cef2SBarry Smith 943d763cef2SBarry Smith .keywords: timestep, get, SNES 944d763cef2SBarry Smith @*/ 94563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS ts,SNES *snes) 946d763cef2SBarry Smith { 947d763cef2SBarry Smith PetscFunctionBegin; 9484482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 9494482741eSBarry Smith PetscValidPointer(snes,2); 950447600ffSHong Zhang if (((PetscObject)ts)->type_name == PETSC_NULL) 951447600ffSHong Zhang SETERRQ(PETSC_ERR_ARG_NULL,"SNES is not created yet. Call TSSetType() first"); 95294b7f48cSBarry Smith if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Nonlinear only; use TSGetKSP()"); 953d763cef2SBarry Smith *snes = ts->snes; 954d763cef2SBarry Smith PetscFunctionReturn(0); 955d763cef2SBarry Smith } 956d763cef2SBarry Smith 9574a2ae208SSatish Balay #undef __FUNCT__ 95894b7f48cSBarry Smith #define __FUNCT__ "TSGetKSP" 959d8e5e3e6SSatish Balay /*@ 96094b7f48cSBarry Smith TSGetKSP - Returns the KSP (linear solver) associated with 961d763cef2SBarry Smith a TS (timestepper) context. 962d763cef2SBarry Smith 96394b7f48cSBarry Smith Not Collective, but KSP is parallel if TS is parallel 964d763cef2SBarry Smith 965d763cef2SBarry Smith Input Parameter: 966d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 967d763cef2SBarry Smith 968d763cef2SBarry Smith Output Parameter: 96994b7f48cSBarry Smith . ksp - the nonlinear solver context 970d763cef2SBarry Smith 971d763cef2SBarry Smith Notes: 97294b7f48cSBarry Smith The user can then directly manipulate the KSP context to set various 973d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 974d763cef2SBarry Smith KSP and PC contexts as well. 975d763cef2SBarry Smith 97694b7f48cSBarry Smith TSGetKSP() does not work for integrators that do not use KSP; 97794b7f48cSBarry Smith in this case TSGetKSP() returns PETSC_NULL in ksp. 978d763cef2SBarry Smith 979d763cef2SBarry Smith Level: beginner 980d763cef2SBarry Smith 98194b7f48cSBarry Smith .keywords: timestep, get, KSP 982d763cef2SBarry Smith @*/ 98363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS ts,KSP *ksp) 984d763cef2SBarry Smith { 985d763cef2SBarry Smith PetscFunctionBegin; 9864482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 9874482741eSBarry Smith PetscValidPointer(ksp,2); 988988402f6SHong Zhang if (((PetscObject)ts)->type_name == PETSC_NULL) 989988402f6SHong Zhang SETERRQ(PETSC_ERR_ARG_NULL,"KSP is not created yet. Call TSSetType() first"); 99029bbc08cSBarry Smith if (ts->problem_type != TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Linear only; use TSGetSNES()"); 99194b7f48cSBarry Smith *ksp = ts->ksp; 992d763cef2SBarry Smith PetscFunctionReturn(0); 993d763cef2SBarry Smith } 994d763cef2SBarry Smith 995d763cef2SBarry Smith /* ----------- Routines to set solver parameters ---------- */ 996d763cef2SBarry Smith 9974a2ae208SSatish Balay #undef __FUNCT__ 998adb62b0dSMatthew Knepley #define __FUNCT__ "TSGetDuration" 999adb62b0dSMatthew Knepley /*@ 1000adb62b0dSMatthew Knepley TSGetDuration - Gets the maximum number of timesteps to use and 1001adb62b0dSMatthew Knepley maximum time for iteration. 1002adb62b0dSMatthew Knepley 1003adb62b0dSMatthew Knepley Collective on TS 1004adb62b0dSMatthew Knepley 1005adb62b0dSMatthew Knepley Input Parameters: 1006adb62b0dSMatthew Knepley + ts - the TS context obtained from TSCreate() 1007adb62b0dSMatthew Knepley . maxsteps - maximum number of iterations to use, or PETSC_NULL 1008adb62b0dSMatthew Knepley - maxtime - final time to iterate to, or PETSC_NULL 1009adb62b0dSMatthew Knepley 1010adb62b0dSMatthew Knepley Level: intermediate 1011adb62b0dSMatthew Knepley 1012adb62b0dSMatthew Knepley .keywords: TS, timestep, get, maximum, iterations, time 1013adb62b0dSMatthew Knepley @*/ 101463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS ts, PetscInt *maxsteps, PetscReal *maxtime) 1015adb62b0dSMatthew Knepley { 1016adb62b0dSMatthew Knepley PetscFunctionBegin; 10174482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1018abc0a331SBarry Smith if (maxsteps) { 10194482741eSBarry Smith PetscValidIntPointer(maxsteps,2); 1020adb62b0dSMatthew Knepley *maxsteps = ts->max_steps; 1021adb62b0dSMatthew Knepley } 1022abc0a331SBarry Smith if (maxtime ) { 10234482741eSBarry Smith PetscValidScalarPointer(maxtime,3); 1024adb62b0dSMatthew Knepley *maxtime = ts->max_time; 1025adb62b0dSMatthew Knepley } 1026adb62b0dSMatthew Knepley PetscFunctionReturn(0); 1027adb62b0dSMatthew Knepley } 1028adb62b0dSMatthew Knepley 1029adb62b0dSMatthew Knepley #undef __FUNCT__ 10304a2ae208SSatish Balay #define __FUNCT__ "TSSetDuration" 1031d763cef2SBarry Smith /*@ 1032d763cef2SBarry Smith TSSetDuration - Sets the maximum number of timesteps to use and 1033d763cef2SBarry Smith maximum time for iteration. 1034d763cef2SBarry Smith 1035d763cef2SBarry Smith Collective on TS 1036d763cef2SBarry Smith 1037d763cef2SBarry Smith Input Parameters: 1038d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1039d763cef2SBarry Smith . maxsteps - maximum number of iterations to use 1040d763cef2SBarry Smith - maxtime - final time to iterate to 1041d763cef2SBarry Smith 1042d763cef2SBarry Smith Options Database Keys: 1043d763cef2SBarry Smith . -ts_max_steps <maxsteps> - Sets maxsteps 1044d763cef2SBarry Smith . -ts_max_time <maxtime> - Sets maxtime 1045d763cef2SBarry Smith 1046d763cef2SBarry Smith Notes: 1047d763cef2SBarry Smith The default maximum number of iterations is 5000. Default time is 5.0 1048d763cef2SBarry Smith 1049d763cef2SBarry Smith Level: intermediate 1050d763cef2SBarry Smith 1051d763cef2SBarry Smith .keywords: TS, timestep, set, maximum, iterations 1052d763cef2SBarry Smith @*/ 105363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS ts,PetscInt maxsteps,PetscReal maxtime) 1054d763cef2SBarry Smith { 1055d763cef2SBarry Smith PetscFunctionBegin; 10564482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1057d763cef2SBarry Smith ts->max_steps = maxsteps; 1058d763cef2SBarry Smith ts->max_time = maxtime; 1059d763cef2SBarry Smith PetscFunctionReturn(0); 1060d763cef2SBarry Smith } 1061d763cef2SBarry Smith 10624a2ae208SSatish Balay #undef __FUNCT__ 10634a2ae208SSatish Balay #define __FUNCT__ "TSSetSolution" 1064d763cef2SBarry Smith /*@ 1065d763cef2SBarry Smith TSSetSolution - Sets the initial solution vector 1066d763cef2SBarry Smith for use by the TS routines. 1067d763cef2SBarry Smith 1068d763cef2SBarry Smith Collective on TS and Vec 1069d763cef2SBarry Smith 1070d763cef2SBarry Smith Input Parameters: 1071d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1072d763cef2SBarry Smith - x - the solution vector 1073d763cef2SBarry Smith 1074d763cef2SBarry Smith Level: beginner 1075d763cef2SBarry Smith 1076d763cef2SBarry Smith .keywords: TS, timestep, set, solution, initial conditions 1077d763cef2SBarry Smith @*/ 107863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS ts,Vec x) 1079d763cef2SBarry Smith { 1080d763cef2SBarry Smith PetscFunctionBegin; 10814482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 10824482741eSBarry Smith PetscValidHeaderSpecific(x,VEC_COOKIE,2); 1083d763cef2SBarry Smith ts->vec_sol = ts->vec_sol_always = x; 1084d763cef2SBarry Smith PetscFunctionReturn(0); 1085d763cef2SBarry Smith } 1086d763cef2SBarry Smith 1087e74ef692SMatthew Knepley #undef __FUNCT__ 1088e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPreStep" 1089ac226902SBarry Smith /*@C 1090000e7ae3SMatthew Knepley TSSetPreStep - Sets the general-purpose function 1091000e7ae3SMatthew Knepley called once at the beginning of time stepping. 1092000e7ae3SMatthew Knepley 1093000e7ae3SMatthew Knepley Collective on TS 1094000e7ae3SMatthew Knepley 1095000e7ae3SMatthew Knepley Input Parameters: 1096000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1097000e7ae3SMatthew Knepley - func - The function 1098000e7ae3SMatthew Knepley 1099000e7ae3SMatthew Knepley Calling sequence of func: 1100000e7ae3SMatthew Knepley . func (TS ts); 1101000e7ae3SMatthew Knepley 1102000e7ae3SMatthew Knepley Level: intermediate 1103000e7ae3SMatthew Knepley 1104000e7ae3SMatthew Knepley .keywords: TS, timestep 1105000e7ae3SMatthew Knepley @*/ 110663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS ts, PetscErrorCode (*func)(TS)) 1107000e7ae3SMatthew Knepley { 1108000e7ae3SMatthew Knepley PetscFunctionBegin; 11094482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1110000e7ae3SMatthew Knepley ts->ops->prestep = func; 1111000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1112000e7ae3SMatthew Knepley } 1113000e7ae3SMatthew Knepley 1114e74ef692SMatthew Knepley #undef __FUNCT__ 1115e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPreStep" 1116000e7ae3SMatthew Knepley /*@ 1117000e7ae3SMatthew Knepley TSDefaultPreStep - The default pre-stepping function which does nothing. 1118000e7ae3SMatthew Knepley 1119000e7ae3SMatthew Knepley Collective on TS 1120000e7ae3SMatthew Knepley 1121000e7ae3SMatthew Knepley Input Parameters: 1122000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1123000e7ae3SMatthew Knepley 1124000e7ae3SMatthew Knepley Level: developer 1125000e7ae3SMatthew Knepley 1126000e7ae3SMatthew Knepley .keywords: TS, timestep 1127000e7ae3SMatthew Knepley @*/ 112863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS ts) 1129000e7ae3SMatthew Knepley { 1130000e7ae3SMatthew Knepley PetscFunctionBegin; 1131000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1132000e7ae3SMatthew Knepley } 1133000e7ae3SMatthew Knepley 1134e74ef692SMatthew Knepley #undef __FUNCT__ 1135e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPostStep" 1136ac226902SBarry Smith /*@C 1137000e7ae3SMatthew Knepley TSSetPostStep - Sets the general-purpose function 1138000e7ae3SMatthew Knepley called once at the end of time stepping. 1139000e7ae3SMatthew Knepley 1140000e7ae3SMatthew Knepley Collective on TS 1141000e7ae3SMatthew Knepley 1142000e7ae3SMatthew Knepley Input Parameters: 1143000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1144000e7ae3SMatthew Knepley - func - The function 1145000e7ae3SMatthew Knepley 1146000e7ae3SMatthew Knepley Calling sequence of func: 1147000e7ae3SMatthew Knepley . func (TS ts); 1148000e7ae3SMatthew Knepley 1149000e7ae3SMatthew Knepley Level: intermediate 1150000e7ae3SMatthew Knepley 1151000e7ae3SMatthew Knepley .keywords: TS, timestep 1152000e7ae3SMatthew Knepley @*/ 115363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS ts, PetscErrorCode (*func)(TS)) 1154000e7ae3SMatthew Knepley { 1155000e7ae3SMatthew Knepley PetscFunctionBegin; 11564482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1157000e7ae3SMatthew Knepley ts->ops->poststep = func; 1158000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1159000e7ae3SMatthew Knepley } 1160000e7ae3SMatthew Knepley 1161e74ef692SMatthew Knepley #undef __FUNCT__ 1162e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPostStep" 1163000e7ae3SMatthew Knepley /*@ 1164000e7ae3SMatthew Knepley TSDefaultPostStep - The default post-stepping function which does nothing. 1165000e7ae3SMatthew Knepley 1166000e7ae3SMatthew Knepley Collective on TS 1167000e7ae3SMatthew Knepley 1168000e7ae3SMatthew Knepley Input Parameters: 1169000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1170000e7ae3SMatthew Knepley 1171000e7ae3SMatthew Knepley Level: developer 1172000e7ae3SMatthew Knepley 1173000e7ae3SMatthew Knepley .keywords: TS, timestep 1174000e7ae3SMatthew Knepley @*/ 117563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS ts) 1176000e7ae3SMatthew Knepley { 1177000e7ae3SMatthew Knepley PetscFunctionBegin; 1178000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1179000e7ae3SMatthew Knepley } 1180000e7ae3SMatthew Knepley 1181d763cef2SBarry Smith /* ------------ Routines to set performance monitoring options ----------- */ 1182d763cef2SBarry Smith 11834a2ae208SSatish Balay #undef __FUNCT__ 1184a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSet" 1185d763cef2SBarry Smith /*@C 1186a6570f20SBarry Smith TSMonitorSet - Sets an ADDITIONAL function that is to be used at every 1187d763cef2SBarry Smith timestep to display the iteration's progress. 1188d763cef2SBarry Smith 1189d763cef2SBarry Smith Collective on TS 1190d763cef2SBarry Smith 1191d763cef2SBarry Smith Input Parameters: 1192d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1193d763cef2SBarry Smith . func - monitoring routine 1194329f5518SBarry Smith . mctx - [optional] user-defined context for private data for the 1195b3006f0bSLois Curfman McInnes monitor routine (use PETSC_NULL if no context is desired) 1196b3006f0bSLois Curfman McInnes - monitordestroy - [optional] routine that frees monitor context 1197b3006f0bSLois Curfman McInnes (may be PETSC_NULL) 1198d763cef2SBarry Smith 1199d763cef2SBarry Smith Calling sequence of func: 1200a7cc72afSBarry Smith $ int func(TS ts,PetscInt steps,PetscReal time,Vec x,void *mctx) 1201d763cef2SBarry Smith 1202d763cef2SBarry Smith + ts - the TS context 1203d763cef2SBarry Smith . steps - iteration number 12041f06c33eSBarry Smith . time - current time 1205d763cef2SBarry Smith . x - current iterate 1206d763cef2SBarry Smith - mctx - [optional] monitoring context 1207d763cef2SBarry Smith 1208d763cef2SBarry Smith Notes: 1209d763cef2SBarry Smith This routine adds an additional monitor to the list of monitors that 1210d763cef2SBarry Smith already has been loaded. 1211d763cef2SBarry Smith 1212025f1a04SBarry Smith Fortran notes: Only a single monitor function can be set for each TS object 1213025f1a04SBarry Smith 1214d763cef2SBarry Smith Level: intermediate 1215d763cef2SBarry Smith 1216d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1217d763cef2SBarry Smith 1218a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorCancel() 1219d763cef2SBarry Smith @*/ 1220a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSet(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void*)) 1221d763cef2SBarry Smith { 1222d763cef2SBarry Smith PetscFunctionBegin; 12234482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1224d763cef2SBarry Smith if (ts->numbermonitors >= MAXTSMONITORS) { 122529bbc08cSBarry Smith SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many monitors set"); 1226d763cef2SBarry Smith } 1227d763cef2SBarry Smith ts->monitor[ts->numbermonitors] = monitor; 1228329f5518SBarry Smith ts->mdestroy[ts->numbermonitors] = mdestroy; 1229d763cef2SBarry Smith ts->monitorcontext[ts->numbermonitors++] = (void*)mctx; 1230d763cef2SBarry Smith PetscFunctionReturn(0); 1231d763cef2SBarry Smith } 1232d763cef2SBarry Smith 12334a2ae208SSatish Balay #undef __FUNCT__ 1234a6570f20SBarry Smith #define __FUNCT__ "TSMonitorCancel" 1235d763cef2SBarry Smith /*@C 1236a6570f20SBarry Smith TSMonitorCancel - Clears all the monitors that have been set on a time-step object. 1237d763cef2SBarry Smith 1238d763cef2SBarry Smith Collective on TS 1239d763cef2SBarry Smith 1240d763cef2SBarry Smith Input Parameters: 1241d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1242d763cef2SBarry Smith 1243d763cef2SBarry Smith Notes: 1244d763cef2SBarry Smith There is no way to remove a single, specific monitor. 1245d763cef2SBarry Smith 1246d763cef2SBarry Smith Level: intermediate 1247d763cef2SBarry Smith 1248d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1249d763cef2SBarry Smith 1250a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorSet() 1251d763cef2SBarry Smith @*/ 1252a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorCancel(TS ts) 1253d763cef2SBarry Smith { 1254d952e501SBarry Smith PetscErrorCode ierr; 1255d952e501SBarry Smith PetscInt i; 1256d952e501SBarry Smith 1257d763cef2SBarry Smith PetscFunctionBegin; 12584482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1259d952e501SBarry Smith for (i=0; i<ts->numbermonitors; i++) { 1260d952e501SBarry Smith if (ts->mdestroy[i]) { 1261d952e501SBarry Smith ierr = (*ts->mdestroy[i])(ts->monitorcontext[i]);CHKERRQ(ierr); 1262d952e501SBarry Smith } 1263d952e501SBarry Smith } 1264d763cef2SBarry Smith ts->numbermonitors = 0; 1265d763cef2SBarry Smith PetscFunctionReturn(0); 1266d763cef2SBarry Smith } 1267d763cef2SBarry Smith 12684a2ae208SSatish Balay #undef __FUNCT__ 1269a6570f20SBarry Smith #define __FUNCT__ "TSMonitorDefault" 1270d8e5e3e6SSatish Balay /*@ 1271a6570f20SBarry Smith TSMonitorDefault - Sets the Default monitor 12725516499fSSatish Balay 12735516499fSSatish Balay Level: intermediate 127441251cbbSSatish Balay 12755516499fSSatish Balay .keywords: TS, set, monitor 12765516499fSSatish Balay 127741251cbbSSatish Balay .seealso: TSMonitorDefault(), TSMonitorSet() 127841251cbbSSatish Balay @*/ 1279a6570f20SBarry Smith PetscErrorCode TSMonitorDefault(TS ts,PetscInt step,PetscReal ptime,Vec v,void *ctx) 1280d763cef2SBarry Smith { 1281dfbe8321SBarry Smith PetscErrorCode ierr; 1282a34d58ebSBarry Smith PetscViewerASCIIMonitor viewer = (PetscViewerASCIIMonitor)ctx; 1283d132466eSBarry Smith 1284d763cef2SBarry Smith PetscFunctionBegin; 1285a34d58ebSBarry Smith if (!ctx) { 12867adad957SLisandro Dalcin ierr = PetscViewerASCIIMonitorCreate(((PetscObject)ts)->comm,"stdout",0,&viewer);CHKERRQ(ierr); 1287a34d58ebSBarry Smith } 1288a34d58ebSBarry Smith ierr = PetscViewerASCIIMonitorPrintf(viewer,"timestep %D dt %G time %G\n",step,ts->time_step,ptime);CHKERRQ(ierr); 1289a34d58ebSBarry Smith if (!ctx) { 1290a34d58ebSBarry Smith ierr = PetscViewerASCIIMonitorDestroy(viewer);CHKERRQ(ierr); 1291a34d58ebSBarry Smith } 1292d763cef2SBarry Smith PetscFunctionReturn(0); 1293d763cef2SBarry Smith } 1294d763cef2SBarry Smith 12954a2ae208SSatish Balay #undef __FUNCT__ 12964a2ae208SSatish Balay #define __FUNCT__ "TSStep" 1297d763cef2SBarry Smith /*@ 1298d763cef2SBarry Smith TSStep - Steps the requested number of timesteps. 1299d763cef2SBarry Smith 1300d763cef2SBarry Smith Collective on TS 1301d763cef2SBarry Smith 1302d763cef2SBarry Smith Input Parameter: 1303d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1304d763cef2SBarry Smith 1305d763cef2SBarry Smith Output Parameters: 1306d763cef2SBarry Smith + steps - number of iterations until termination 1307142b95e3SSatish Balay - ptime - time until termination 1308d763cef2SBarry Smith 1309d763cef2SBarry Smith Level: beginner 1310d763cef2SBarry Smith 1311d763cef2SBarry Smith .keywords: TS, timestep, solve 1312d763cef2SBarry Smith 1313d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSDestroy() 1314d763cef2SBarry Smith @*/ 131563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS ts,PetscInt *steps,PetscReal *ptime) 1316d763cef2SBarry Smith { 1317dfbe8321SBarry Smith PetscErrorCode ierr; 1318d763cef2SBarry Smith 1319d763cef2SBarry Smith PetscFunctionBegin; 13204482741eSBarry Smith PetscValidHeaderSpecific(ts, TS_COOKIE,1); 1321d405a339SMatthew Knepley if (!ts->setupcalled) { 1322d405a339SMatthew Knepley ierr = TSSetUp(ts);CHKERRQ(ierr); 1323d405a339SMatthew Knepley } 1324d405a339SMatthew Knepley 1325d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1326d405a339SMatthew Knepley ierr = (*ts->ops->prestep)(ts);CHKERRQ(ierr); 1327000e7ae3SMatthew Knepley ierr = (*ts->ops->step)(ts, steps, ptime);CHKERRQ(ierr); 1328d405a339SMatthew Knepley ierr = (*ts->ops->poststep)(ts);CHKERRQ(ierr); 1329d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1330d405a339SMatthew Knepley 13314bb05414SBarry Smith if (!PetscPreLoadingOn) { 13327adad957SLisandro Dalcin ierr = TSViewFromOptions(ts,((PetscObject)ts)->name);CHKERRQ(ierr); 1333d405a339SMatthew Knepley } 1334d763cef2SBarry Smith PetscFunctionReturn(0); 1335d763cef2SBarry Smith } 1336d763cef2SBarry Smith 13374a2ae208SSatish Balay #undef __FUNCT__ 13386a4d4014SLisandro Dalcin #define __FUNCT__ "TSSolve" 13396a4d4014SLisandro Dalcin /*@ 13406a4d4014SLisandro Dalcin TSSolve - Steps the requested number of timesteps. 13416a4d4014SLisandro Dalcin 13426a4d4014SLisandro Dalcin Collective on TS 13436a4d4014SLisandro Dalcin 13446a4d4014SLisandro Dalcin Input Parameter: 13456a4d4014SLisandro Dalcin + ts - the TS context obtained from TSCreate() 13466a4d4014SLisandro Dalcin - x - the solution vector, or PETSC_NULL if it was set with TSSetSolution() 13476a4d4014SLisandro Dalcin 13486a4d4014SLisandro Dalcin Level: beginner 13496a4d4014SLisandro Dalcin 13506a4d4014SLisandro Dalcin .keywords: TS, timestep, solve 13516a4d4014SLisandro Dalcin 13526a4d4014SLisandro Dalcin .seealso: TSCreate(), TSSetSolution(), TSStep() 13536a4d4014SLisandro Dalcin @*/ 13546a4d4014SLisandro Dalcin PetscErrorCode PETSCTS_DLLEXPORT TSSolve(TS ts, Vec x) 13556a4d4014SLisandro Dalcin { 13566a4d4014SLisandro Dalcin PetscInt steps; 13576a4d4014SLisandro Dalcin PetscReal ptime; 13586a4d4014SLisandro Dalcin PetscErrorCode ierr; 13596a4d4014SLisandro Dalcin PetscFunctionBegin; 13606a4d4014SLisandro Dalcin PetscValidHeaderSpecific(ts,TS_COOKIE,1); 13616a4d4014SLisandro Dalcin /* set solution vector if provided */ 13626a4d4014SLisandro Dalcin if (x) { ierr = TSSetSolution(ts, x); CHKERRQ(ierr); } 13636a4d4014SLisandro Dalcin /* reset time step and iteration counters */ 13646a4d4014SLisandro Dalcin ts->steps = 0; ts->linear_its = 0; ts->nonlinear_its = 0; 13656a4d4014SLisandro Dalcin /* steps the requested number of timesteps. */ 13666a4d4014SLisandro Dalcin ierr = TSStep(ts, &steps, &ptime);CHKERRQ(ierr); 13676a4d4014SLisandro Dalcin PetscFunctionReturn(0); 13686a4d4014SLisandro Dalcin } 13696a4d4014SLisandro Dalcin 13706a4d4014SLisandro Dalcin #undef __FUNCT__ 13714a2ae208SSatish Balay #define __FUNCT__ "TSMonitor" 1372d763cef2SBarry Smith /* 1373d763cef2SBarry Smith Runs the user provided monitor routines, if they exists. 1374d763cef2SBarry Smith */ 1375a7cc72afSBarry Smith PetscErrorCode TSMonitor(TS ts,PetscInt step,PetscReal ptime,Vec x) 1376d763cef2SBarry Smith { 13776849ba73SBarry Smith PetscErrorCode ierr; 1378a7cc72afSBarry Smith PetscInt i,n = ts->numbermonitors; 1379d763cef2SBarry Smith 1380d763cef2SBarry Smith PetscFunctionBegin; 1381d763cef2SBarry Smith for (i=0; i<n; i++) { 1382142b95e3SSatish Balay ierr = (*ts->monitor[i])(ts,step,ptime,x,ts->monitorcontext[i]);CHKERRQ(ierr); 1383d763cef2SBarry Smith } 1384d763cef2SBarry Smith PetscFunctionReturn(0); 1385d763cef2SBarry Smith } 1386d763cef2SBarry Smith 1387d763cef2SBarry Smith /* ------------------------------------------------------------------------*/ 1388d763cef2SBarry Smith 13894a2ae208SSatish Balay #undef __FUNCT__ 1390a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGCreate" 1391d763cef2SBarry Smith /*@C 1392a6570f20SBarry Smith TSMonitorLGCreate - Creates a line graph context for use with 1393d763cef2SBarry Smith TS to monitor convergence of preconditioned residual norms. 1394d763cef2SBarry Smith 1395d763cef2SBarry Smith Collective on TS 1396d763cef2SBarry Smith 1397d763cef2SBarry Smith Input Parameters: 1398d763cef2SBarry Smith + host - the X display to open, or null for the local machine 1399d763cef2SBarry Smith . label - the title to put in the title bar 14007c922b88SBarry Smith . x, y - the screen coordinates of the upper left coordinate of the window 1401d763cef2SBarry Smith - m, n - the screen width and height in pixels 1402d763cef2SBarry Smith 1403d763cef2SBarry Smith Output Parameter: 1404d763cef2SBarry Smith . draw - the drawing context 1405d763cef2SBarry Smith 1406d763cef2SBarry Smith Options Database Key: 1407a6570f20SBarry Smith . -ts_monitor_draw - automatically sets line graph monitor 1408d763cef2SBarry Smith 1409d763cef2SBarry Smith Notes: 1410a6570f20SBarry Smith Use TSMonitorLGDestroy() to destroy this line graph, not PetscDrawLGDestroy(). 1411d763cef2SBarry Smith 1412d763cef2SBarry Smith Level: intermediate 1413d763cef2SBarry Smith 14147c922b88SBarry Smith .keywords: TS, monitor, line graph, residual, seealso 1415d763cef2SBarry Smith 1416a6570f20SBarry Smith .seealso: TSMonitorLGDestroy(), TSMonitorSet() 14177c922b88SBarry Smith 1418d763cef2SBarry Smith @*/ 1419a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGCreate(const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *draw) 1420d763cef2SBarry Smith { 1421b0a32e0cSBarry Smith PetscDraw win; 1422dfbe8321SBarry Smith PetscErrorCode ierr; 1423d763cef2SBarry Smith 1424d763cef2SBarry Smith PetscFunctionBegin; 1425b0a32e0cSBarry Smith ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr); 1426b0a32e0cSBarry Smith ierr = PetscDrawSetType(win,PETSC_DRAW_X);CHKERRQ(ierr); 1427b0a32e0cSBarry Smith ierr = PetscDrawLGCreate(win,1,draw);CHKERRQ(ierr); 1428b0a32e0cSBarry Smith ierr = PetscDrawLGIndicateDataPoints(*draw);CHKERRQ(ierr); 1429d763cef2SBarry Smith 143052e6d16bSBarry Smith ierr = PetscLogObjectParent(*draw,win);CHKERRQ(ierr); 1431d763cef2SBarry Smith PetscFunctionReturn(0); 1432d763cef2SBarry Smith } 1433d763cef2SBarry Smith 14344a2ae208SSatish Balay #undef __FUNCT__ 1435a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLG" 1436a6570f20SBarry Smith PetscErrorCode TSMonitorLG(TS ts,PetscInt n,PetscReal ptime,Vec v,void *monctx) 1437d763cef2SBarry Smith { 1438b0a32e0cSBarry Smith PetscDrawLG lg = (PetscDrawLG) monctx; 143987828ca2SBarry Smith PetscReal x,y = ptime; 1440dfbe8321SBarry Smith PetscErrorCode ierr; 1441d763cef2SBarry Smith 1442d763cef2SBarry Smith PetscFunctionBegin; 14437c922b88SBarry Smith if (!monctx) { 14447c922b88SBarry Smith MPI_Comm comm; 1445b0a32e0cSBarry Smith PetscViewer viewer; 14467c922b88SBarry Smith 14477c922b88SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 1448b0a32e0cSBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 1449b0a32e0cSBarry Smith ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr); 14507c922b88SBarry Smith } 14517c922b88SBarry Smith 1452b0a32e0cSBarry Smith if (!n) {ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);} 145387828ca2SBarry Smith x = (PetscReal)n; 1454b0a32e0cSBarry Smith ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr); 1455d763cef2SBarry Smith if (n < 20 || (n % 5)) { 1456b0a32e0cSBarry Smith ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr); 1457d763cef2SBarry Smith } 1458d763cef2SBarry Smith PetscFunctionReturn(0); 1459d763cef2SBarry Smith } 1460d763cef2SBarry Smith 14614a2ae208SSatish Balay #undef __FUNCT__ 1462a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGDestroy" 1463d763cef2SBarry Smith /*@C 1464a6570f20SBarry Smith TSMonitorLGDestroy - Destroys a line graph context that was created 1465a6570f20SBarry Smith with TSMonitorLGCreate(). 1466d763cef2SBarry Smith 1467b0a32e0cSBarry Smith Collective on PetscDrawLG 1468d763cef2SBarry Smith 1469d763cef2SBarry Smith Input Parameter: 1470d763cef2SBarry Smith . draw - the drawing context 1471d763cef2SBarry Smith 1472d763cef2SBarry Smith Level: intermediate 1473d763cef2SBarry Smith 1474d763cef2SBarry Smith .keywords: TS, monitor, line graph, destroy 1475d763cef2SBarry Smith 1476a6570f20SBarry Smith .seealso: TSMonitorLGCreate(), TSMonitorSet(), TSMonitorLG(); 1477d763cef2SBarry Smith @*/ 1478a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGDestroy(PetscDrawLG drawlg) 1479d763cef2SBarry Smith { 1480b0a32e0cSBarry Smith PetscDraw draw; 1481dfbe8321SBarry Smith PetscErrorCode ierr; 1482d763cef2SBarry Smith 1483d763cef2SBarry Smith PetscFunctionBegin; 1484b0a32e0cSBarry Smith ierr = PetscDrawLGGetDraw(drawlg,&draw);CHKERRQ(ierr); 1485b0a32e0cSBarry Smith ierr = PetscDrawDestroy(draw);CHKERRQ(ierr); 1486b0a32e0cSBarry Smith ierr = PetscDrawLGDestroy(drawlg);CHKERRQ(ierr); 1487d763cef2SBarry Smith PetscFunctionReturn(0); 1488d763cef2SBarry Smith } 1489d763cef2SBarry Smith 14904a2ae208SSatish Balay #undef __FUNCT__ 14914a2ae208SSatish Balay #define __FUNCT__ "TSGetTime" 1492d763cef2SBarry Smith /*@ 1493d763cef2SBarry Smith TSGetTime - Gets the current time. 1494d763cef2SBarry Smith 1495d763cef2SBarry Smith Not Collective 1496d763cef2SBarry Smith 1497d763cef2SBarry Smith Input Parameter: 1498d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1499d763cef2SBarry Smith 1500d763cef2SBarry Smith Output Parameter: 1501d763cef2SBarry Smith . t - the current time 1502d763cef2SBarry Smith 1503d763cef2SBarry Smith Contributed by: Matthew Knepley 1504d763cef2SBarry Smith 1505d763cef2SBarry Smith Level: beginner 1506d763cef2SBarry Smith 1507d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1508d763cef2SBarry Smith 1509d763cef2SBarry Smith .keywords: TS, get, time 1510d763cef2SBarry Smith @*/ 151163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS ts,PetscReal* t) 1512d763cef2SBarry Smith { 1513d763cef2SBarry Smith PetscFunctionBegin; 15144482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 15154482741eSBarry Smith PetscValidDoublePointer(t,2); 1516d763cef2SBarry Smith *t = ts->ptime; 1517d763cef2SBarry Smith PetscFunctionReturn(0); 1518d763cef2SBarry Smith } 1519d763cef2SBarry Smith 15204a2ae208SSatish Balay #undef __FUNCT__ 15216a4d4014SLisandro Dalcin #define __FUNCT__ "TSSetTime" 15226a4d4014SLisandro Dalcin /*@ 15236a4d4014SLisandro Dalcin TSSetTime - Allows one to reset the time. 15246a4d4014SLisandro Dalcin 15256a4d4014SLisandro Dalcin Collective on TS 15266a4d4014SLisandro Dalcin 15276a4d4014SLisandro Dalcin Input Parameters: 15286a4d4014SLisandro Dalcin + ts - the TS context obtained from TSCreate() 15296a4d4014SLisandro Dalcin - time - the time 15306a4d4014SLisandro Dalcin 15316a4d4014SLisandro Dalcin Level: intermediate 15326a4d4014SLisandro Dalcin 15336a4d4014SLisandro Dalcin .seealso: TSGetTime(), TSSetDuration() 15346a4d4014SLisandro Dalcin 15356a4d4014SLisandro Dalcin .keywords: TS, set, time 15366a4d4014SLisandro Dalcin @*/ 15376a4d4014SLisandro Dalcin PetscErrorCode PETSCTS_DLLEXPORT TSSetTime(TS ts, PetscReal t) 15386a4d4014SLisandro Dalcin { 15396a4d4014SLisandro Dalcin PetscFunctionBegin; 15406a4d4014SLisandro Dalcin PetscValidHeaderSpecific(ts,TS_COOKIE,1); 15416a4d4014SLisandro Dalcin ts->ptime = t; 15426a4d4014SLisandro Dalcin PetscFunctionReturn(0); 15436a4d4014SLisandro Dalcin } 15446a4d4014SLisandro Dalcin 15456a4d4014SLisandro Dalcin #undef __FUNCT__ 15464a2ae208SSatish Balay #define __FUNCT__ "TSSetOptionsPrefix" 1547d763cef2SBarry Smith /*@C 1548d763cef2SBarry Smith TSSetOptionsPrefix - Sets the prefix used for searching for all 1549d763cef2SBarry Smith TS options in the database. 1550d763cef2SBarry Smith 1551d763cef2SBarry Smith Collective on TS 1552d763cef2SBarry Smith 1553d763cef2SBarry Smith Input Parameter: 1554d763cef2SBarry Smith + ts - The TS context 1555d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1556d763cef2SBarry Smith 1557d763cef2SBarry Smith Notes: 1558d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1559d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1560d763cef2SBarry Smith hyphen. 1561d763cef2SBarry Smith 1562d763cef2SBarry Smith Contributed by: Matthew Knepley 1563d763cef2SBarry Smith 1564d763cef2SBarry Smith Level: advanced 1565d763cef2SBarry Smith 1566d763cef2SBarry Smith .keywords: TS, set, options, prefix, database 1567d763cef2SBarry Smith 1568d763cef2SBarry Smith .seealso: TSSetFromOptions() 1569d763cef2SBarry Smith 1570d763cef2SBarry Smith @*/ 157163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS ts,const char prefix[]) 1572d763cef2SBarry Smith { 1573dfbe8321SBarry Smith PetscErrorCode ierr; 1574d763cef2SBarry Smith 1575d763cef2SBarry Smith PetscFunctionBegin; 15764482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1577d763cef2SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1578d763cef2SBarry Smith switch(ts->problem_type) { 1579d763cef2SBarry Smith case TS_NONLINEAR: 158059580b9cSBarry Smith if (ts->snes) { 1581d763cef2SBarry Smith ierr = SNESSetOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 158259580b9cSBarry Smith } 1583d763cef2SBarry Smith break; 1584d763cef2SBarry Smith case TS_LINEAR: 158559580b9cSBarry Smith if (ts->ksp) { 158694b7f48cSBarry Smith ierr = KSPSetOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 158759580b9cSBarry Smith } 1588d763cef2SBarry Smith break; 1589d763cef2SBarry Smith } 1590d763cef2SBarry Smith PetscFunctionReturn(0); 1591d763cef2SBarry Smith } 1592d763cef2SBarry Smith 1593d763cef2SBarry Smith 15944a2ae208SSatish Balay #undef __FUNCT__ 15954a2ae208SSatish Balay #define __FUNCT__ "TSAppendOptionsPrefix" 1596d763cef2SBarry Smith /*@C 1597d763cef2SBarry Smith TSAppendOptionsPrefix - Appends to the prefix used for searching for all 1598d763cef2SBarry Smith TS options in the database. 1599d763cef2SBarry Smith 1600d763cef2SBarry Smith Collective on TS 1601d763cef2SBarry Smith 1602d763cef2SBarry Smith Input Parameter: 1603d763cef2SBarry Smith + ts - The TS context 1604d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1605d763cef2SBarry Smith 1606d763cef2SBarry Smith Notes: 1607d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1608d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1609d763cef2SBarry Smith hyphen. 1610d763cef2SBarry Smith 1611d763cef2SBarry Smith Contributed by: Matthew Knepley 1612d763cef2SBarry Smith 1613d763cef2SBarry Smith Level: advanced 1614d763cef2SBarry Smith 1615d763cef2SBarry Smith .keywords: TS, append, options, prefix, database 1616d763cef2SBarry Smith 1617d763cef2SBarry Smith .seealso: TSGetOptionsPrefix() 1618d763cef2SBarry Smith 1619d763cef2SBarry Smith @*/ 162063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS ts,const char prefix[]) 1621d763cef2SBarry Smith { 1622dfbe8321SBarry Smith PetscErrorCode ierr; 1623d763cef2SBarry Smith 1624d763cef2SBarry Smith PetscFunctionBegin; 16254482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 1626d763cef2SBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1627d763cef2SBarry Smith switch(ts->problem_type) { 1628d763cef2SBarry Smith case TS_NONLINEAR: 16291ac94b3bSBarry Smith if (ts->snes) { 1630d763cef2SBarry Smith ierr = SNESAppendOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 16311ac94b3bSBarry Smith } 1632d763cef2SBarry Smith break; 1633d763cef2SBarry Smith case TS_LINEAR: 16341ac94b3bSBarry Smith if (ts->ksp) { 163594b7f48cSBarry Smith ierr = KSPAppendOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 16361ac94b3bSBarry Smith } 1637d763cef2SBarry Smith break; 1638d763cef2SBarry Smith } 1639d763cef2SBarry Smith PetscFunctionReturn(0); 1640d763cef2SBarry Smith } 1641d763cef2SBarry Smith 16424a2ae208SSatish Balay #undef __FUNCT__ 16434a2ae208SSatish Balay #define __FUNCT__ "TSGetOptionsPrefix" 1644d763cef2SBarry Smith /*@C 1645d763cef2SBarry Smith TSGetOptionsPrefix - Sets the prefix used for searching for all 1646d763cef2SBarry Smith TS options in the database. 1647d763cef2SBarry Smith 1648d763cef2SBarry Smith Not Collective 1649d763cef2SBarry Smith 1650d763cef2SBarry Smith Input Parameter: 1651d763cef2SBarry Smith . ts - The TS context 1652d763cef2SBarry Smith 1653d763cef2SBarry Smith Output Parameter: 1654d763cef2SBarry Smith . prefix - A pointer to the prefix string used 1655d763cef2SBarry Smith 1656d763cef2SBarry Smith Contributed by: Matthew Knepley 1657d763cef2SBarry Smith 1658d763cef2SBarry Smith Notes: On the fortran side, the user should pass in a string 'prifix' of 1659d763cef2SBarry Smith sufficient length to hold the prefix. 1660d763cef2SBarry Smith 1661d763cef2SBarry Smith Level: intermediate 1662d763cef2SBarry Smith 1663d763cef2SBarry Smith .keywords: TS, get, options, prefix, database 1664d763cef2SBarry Smith 1665d763cef2SBarry Smith .seealso: TSAppendOptionsPrefix() 1666d763cef2SBarry Smith @*/ 1667e060cb09SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS ts,const char *prefix[]) 1668d763cef2SBarry Smith { 1669dfbe8321SBarry Smith PetscErrorCode ierr; 1670d763cef2SBarry Smith 1671d763cef2SBarry Smith PetscFunctionBegin; 16724482741eSBarry Smith PetscValidHeaderSpecific(ts,TS_COOKIE,1); 16734482741eSBarry Smith PetscValidPointer(prefix,2); 1674d763cef2SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1675d763cef2SBarry Smith PetscFunctionReturn(0); 1676d763cef2SBarry Smith } 1677d763cef2SBarry Smith 16784a2ae208SSatish Balay #undef __FUNCT__ 16794a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSJacobian" 1680d763cef2SBarry Smith /*@C 1681d763cef2SBarry Smith TSGetRHSJacobian - Returns the Jacobian J at the present timestep. 1682d763cef2SBarry Smith 1683d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 1684d763cef2SBarry Smith 1685d763cef2SBarry Smith Input Parameter: 1686d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 1687d763cef2SBarry Smith 1688d763cef2SBarry Smith Output Parameters: 1689d763cef2SBarry Smith + J - The Jacobian J of F, where U_t = F(U,t) 1690d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as J 1691d763cef2SBarry Smith - ctx - User-defined context for Jacobian evaluation routine 1692d763cef2SBarry Smith 1693d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 1694d763cef2SBarry Smith 1695d763cef2SBarry Smith Level: intermediate 1696d763cef2SBarry Smith 169726d46c62SHong Zhang .seealso: TSGetTimeStep(), TSGetMatrices(), TSGetTime(), TSGetTimeStepNumber() 1698d763cef2SBarry Smith 1699d763cef2SBarry Smith .keywords: TS, timestep, get, matrix, Jacobian 1700d763cef2SBarry Smith @*/ 170163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS ts,Mat *J,Mat *M,void **ctx) 1702d763cef2SBarry Smith { 1703d763cef2SBarry Smith PetscFunctionBegin; 170426d46c62SHong Zhang if (J) *J = ts->Arhs; 170526d46c62SHong Zhang if (M) *M = ts->B; 170626d46c62SHong Zhang if (ctx) *ctx = ts->jacP; 1707d763cef2SBarry Smith PetscFunctionReturn(0); 1708d763cef2SBarry Smith } 1709d763cef2SBarry Smith 17101713a123SBarry Smith #undef __FUNCT__ 1711a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSolution" 17121713a123SBarry Smith /*@C 1713a6570f20SBarry Smith TSMonitorSolution - Monitors progress of the TS solvers by calling 17141713a123SBarry Smith VecView() for the solution at each timestep 17151713a123SBarry Smith 17161713a123SBarry Smith Collective on TS 17171713a123SBarry Smith 17181713a123SBarry Smith Input Parameters: 17191713a123SBarry Smith + ts - the TS context 17201713a123SBarry Smith . step - current time-step 1721142b95e3SSatish Balay . ptime - current time 17221713a123SBarry Smith - dummy - either a viewer or PETSC_NULL 17231713a123SBarry Smith 17241713a123SBarry Smith Level: intermediate 17251713a123SBarry Smith 17261713a123SBarry Smith .keywords: TS, vector, monitor, view 17271713a123SBarry Smith 1728a6570f20SBarry Smith .seealso: TSMonitorSet(), TSMonitorDefault(), VecView() 17291713a123SBarry Smith @*/ 1730a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSolution(TS ts,PetscInt step,PetscReal ptime,Vec x,void *dummy) 17311713a123SBarry Smith { 1732dfbe8321SBarry Smith PetscErrorCode ierr; 17331713a123SBarry Smith PetscViewer viewer = (PetscViewer) dummy; 17341713a123SBarry Smith 17351713a123SBarry Smith PetscFunctionBegin; 1736a34d58ebSBarry Smith if (!dummy) { 17377adad957SLisandro Dalcin viewer = PETSC_VIEWER_DRAW_(((PetscObject)ts)->comm); 17381713a123SBarry Smith } 17391713a123SBarry Smith ierr = VecView(x,viewer);CHKERRQ(ierr); 17401713a123SBarry Smith PetscFunctionReturn(0); 17411713a123SBarry Smith } 17421713a123SBarry Smith 17431713a123SBarry Smith 17441713a123SBarry Smith 1745