163dd3a1aSKris Buschelman #define PETSCTS_DLL 263dd3a1aSKris Buschelman 37c4f633dSBarry Smith #include "private/tsimpl.h" /*I "petscts.h" I*/ 4d763cef2SBarry Smith 5d5ba7fb7SMatthew Knepley /* Logging support */ 60700a824SBarry Smith PetscClassId PETSCTS_DLLEXPORT TS_CLASSID; 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 { 359596e0b4SJed Brown defaultType = TSEULER; 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: 594d91e141SJed Brown + -ts_type <type> - TSEULER, TSBEULER, TSSUNDIALS, TSPSEUDO, TSCN, TSRK, TSTHETA, TSGL, TSSSP 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; 810700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,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 } 1175d973c19SBarry Smith 1185d973c19SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 1195d973c19SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject)ts);CHKERRQ(ierr); 120bdad233fSMatthew Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 121bdad233fSMatthew Knepley 122bdad233fSMatthew Knepley /* Handle subobject options */ 123bdad233fSMatthew Knepley switch(ts->problem_type) { 124156fc9a6SMatthew Knepley /* Should check for implicit/explicit */ 125bdad233fSMatthew Knepley case TS_LINEAR: 126abc0a331SBarry Smith if (ts->ksp) { 1278beb423aSHong Zhang ierr = KSPSetOperators(ts->ksp,ts->Arhs,ts->B,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 12894b7f48cSBarry Smith ierr = KSPSetFromOptions(ts->ksp);CHKERRQ(ierr); 129156fc9a6SMatthew Knepley } 130bdad233fSMatthew Knepley break; 131bdad233fSMatthew Knepley case TS_NONLINEAR: 132abc0a331SBarry Smith if (ts->snes) { 1337c236d22SBarry Smith /* this is a bit of a hack, but it gets the matrix information into SNES earlier 1347c236d22SBarry Smith so that SNES and KSP have more information to pick reasonable defaults 1357c0b301bSJed Brown before they allow users to set options 1367c0b301bSJed Brown * If ts->A has been set at this point, we are probably using the implicit form 1377c0b301bSJed Brown and Arhs will never be used. */ 1387c0b301bSJed Brown ierr = SNESSetJacobian(ts->snes,ts->A?ts->A:ts->Arhs,ts->B,0,ts);CHKERRQ(ierr); 139bdad233fSMatthew Knepley ierr = SNESSetFromOptions(ts->snes);CHKERRQ(ierr); 140156fc9a6SMatthew Knepley } 141bdad233fSMatthew Knepley break; 142bdad233fSMatthew Knepley default: 143e32f2f54SBarry Smith SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Invalid problem type: %d", (int)ts->problem_type); 144bdad233fSMatthew Knepley } 145bdad233fSMatthew Knepley 146bdad233fSMatthew Knepley PetscFunctionReturn(0); 147bdad233fSMatthew Knepley } 148bdad233fSMatthew Knepley 149bdad233fSMatthew Knepley #undef __FUNCT__ 150bdad233fSMatthew Knepley #define __FUNCT__ "TSViewFromOptions" 151bdad233fSMatthew Knepley /*@ 152bdad233fSMatthew Knepley TSViewFromOptions - This function visualizes the ts based upon user options. 153bdad233fSMatthew Knepley 154bdad233fSMatthew Knepley Collective on TS 155bdad233fSMatthew Knepley 156bdad233fSMatthew Knepley Input Parameter: 157bdad233fSMatthew Knepley . ts - The ts 158bdad233fSMatthew Knepley 159bdad233fSMatthew Knepley Level: intermediate 160bdad233fSMatthew Knepley 161bdad233fSMatthew Knepley .keywords: TS, view, options, database 162bdad233fSMatthew Knepley .seealso: TSSetFromOptions(), TSView() 163bdad233fSMatthew Knepley @*/ 16463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSViewFromOptions(TS ts,const char title[]) 165bdad233fSMatthew Knepley { 166bdad233fSMatthew Knepley PetscViewer viewer; 167bdad233fSMatthew Knepley PetscDraw draw; 16890d69ab7SBarry Smith PetscTruth opt = PETSC_FALSE; 169e10c49a3SBarry Smith char fileName[PETSC_MAX_PATH_LEN]; 170dfbe8321SBarry Smith PetscErrorCode ierr; 171bdad233fSMatthew Knepley 172bdad233fSMatthew Knepley PetscFunctionBegin; 1737adad957SLisandro Dalcin ierr = PetscOptionsGetString(((PetscObject)ts)->prefix, "-ts_view", fileName, PETSC_MAX_PATH_LEN, &opt);CHKERRQ(ierr); 174eabae89aSBarry Smith if (opt && !PetscPreLoadingOn) { 1757adad957SLisandro Dalcin ierr = PetscViewerASCIIOpen(((PetscObject)ts)->comm,fileName,&viewer);CHKERRQ(ierr); 176bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 177bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 178bdad233fSMatthew Knepley } 1798e83347fSKai Germaschewski opt = PETSC_FALSE; 18090d69ab7SBarry Smith ierr = PetscOptionsGetTruth(((PetscObject)ts)->prefix, "-ts_view_draw", &opt,PETSC_NULL);CHKERRQ(ierr); 181a7cc72afSBarry Smith if (opt) { 1827adad957SLisandro Dalcin ierr = PetscViewerDrawOpen(((PetscObject)ts)->comm, 0, 0, 0, 0, 300, 300, &viewer);CHKERRQ(ierr); 183bdad233fSMatthew Knepley ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr); 184a7cc72afSBarry Smith if (title) { 1851836bdbcSSatish Balay ierr = PetscDrawSetTitle(draw, (char *)title);CHKERRQ(ierr); 186bdad233fSMatthew Knepley } else { 187bdad233fSMatthew Knepley ierr = PetscObjectName((PetscObject)ts);CHKERRQ(ierr); 1887adad957SLisandro Dalcin ierr = PetscDrawSetTitle(draw, ((PetscObject)ts)->name);CHKERRQ(ierr); 189bdad233fSMatthew Knepley } 190bdad233fSMatthew Knepley ierr = TSView(ts, viewer);CHKERRQ(ierr); 191bdad233fSMatthew Knepley ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 192bdad233fSMatthew Knepley ierr = PetscDrawPause(draw);CHKERRQ(ierr); 193bdad233fSMatthew Knepley ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); 194bdad233fSMatthew Knepley } 195bdad233fSMatthew Knepley PetscFunctionReturn(0); 196bdad233fSMatthew Knepley } 197bdad233fSMatthew Knepley 198bdad233fSMatthew Knepley #undef __FUNCT__ 1994a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSJacobian" 200a7a1495cSBarry Smith /*@ 2018c385f81SBarry Smith TSComputeRHSJacobian - Computes the Jacobian matrix that has been 202a7a1495cSBarry Smith set with TSSetRHSJacobian(). 203a7a1495cSBarry Smith 204a7a1495cSBarry Smith Collective on TS and Vec 205a7a1495cSBarry Smith 206a7a1495cSBarry Smith Input Parameters: 207316643e7SJed Brown + ts - the TS context 208a7a1495cSBarry Smith . t - current timestep 209a7a1495cSBarry Smith - x - input vector 210a7a1495cSBarry Smith 211a7a1495cSBarry Smith Output Parameters: 212a7a1495cSBarry Smith + A - Jacobian matrix 213a7a1495cSBarry Smith . B - optional preconditioning matrix 214a7a1495cSBarry Smith - flag - flag indicating matrix structure 215a7a1495cSBarry Smith 216a7a1495cSBarry Smith Notes: 217a7a1495cSBarry Smith Most users should not need to explicitly call this routine, as it 218a7a1495cSBarry Smith is used internally within the nonlinear solvers. 219a7a1495cSBarry Smith 22094b7f48cSBarry Smith See KSPSetOperators() for important information about setting the 221a7a1495cSBarry Smith flag parameter. 222a7a1495cSBarry Smith 223a7a1495cSBarry Smith TSComputeJacobian() is valid only for TS_NONLINEAR 224a7a1495cSBarry Smith 225a7a1495cSBarry Smith Level: developer 226a7a1495cSBarry Smith 227a7a1495cSBarry Smith .keywords: SNES, compute, Jacobian, matrix 228a7a1495cSBarry Smith 22994b7f48cSBarry Smith .seealso: TSSetRHSJacobian(), KSPSetOperators() 230a7a1495cSBarry Smith @*/ 23163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS ts,PetscReal t,Vec X,Mat *A,Mat *B,MatStructure *flg) 232a7a1495cSBarry Smith { 233dfbe8321SBarry Smith PetscErrorCode ierr; 234a7a1495cSBarry Smith 235a7a1495cSBarry Smith PetscFunctionBegin; 2360700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 2370700a824SBarry Smith PetscValidHeaderSpecific(X,VEC_CLASSID,3); 238c9780b6fSBarry Smith PetscCheckSameComm(ts,1,X,3); 23917186662SBarry Smith if (ts->problem_type != TS_NONLINEAR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"For TS_NONLINEAR only"); 240000e7ae3SMatthew Knepley if (ts->ops->rhsjacobian) { 241d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 242a7a1495cSBarry Smith *flg = DIFFERENT_NONZERO_PATTERN; 243a7a1495cSBarry Smith PetscStackPush("TS user Jacobian function"); 244000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr); 245a7a1495cSBarry Smith PetscStackPop; 246d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 247a7a1495cSBarry Smith /* make sure user returned a correct Jacobian and preconditioner */ 2480700a824SBarry Smith PetscValidHeaderSpecific(*A,MAT_CLASSID,4); 2490700a824SBarry Smith PetscValidHeaderSpecific(*B,MAT_CLASSID,5); 250ef66eb69SBarry Smith } else { 251ef66eb69SBarry Smith ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 252ef66eb69SBarry Smith ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 253ef66eb69SBarry Smith if (*A != *B) { 254ef66eb69SBarry Smith ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 255ef66eb69SBarry Smith ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 256ef66eb69SBarry Smith } 257ef66eb69SBarry Smith } 258a7a1495cSBarry Smith PetscFunctionReturn(0); 259a7a1495cSBarry Smith } 260a7a1495cSBarry Smith 2614a2ae208SSatish Balay #undef __FUNCT__ 2624a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSFunction" 263316643e7SJed Brown /*@ 264d763cef2SBarry Smith TSComputeRHSFunction - Evaluates the right-hand-side function. 265d763cef2SBarry Smith 266316643e7SJed Brown Collective on TS and Vec 267316643e7SJed Brown 268316643e7SJed Brown Input Parameters: 269316643e7SJed Brown + ts - the TS context 270316643e7SJed Brown . t - current time 271316643e7SJed Brown - x - state vector 272316643e7SJed Brown 273316643e7SJed Brown Output Parameter: 274316643e7SJed Brown . y - right hand side 275316643e7SJed Brown 276316643e7SJed Brown Note: 277316643e7SJed Brown Most users should not need to explicitly call this routine, as it 278316643e7SJed Brown is used internally within the nonlinear solvers. 279316643e7SJed Brown 280316643e7SJed Brown If the user did not provide a function but merely a matrix, 281d763cef2SBarry Smith this routine applies the matrix. 282316643e7SJed Brown 283316643e7SJed Brown Level: developer 284316643e7SJed Brown 285316643e7SJed Brown .keywords: TS, compute 286316643e7SJed Brown 287316643e7SJed Brown .seealso: TSSetRHSFunction(), TSComputeIFunction() 288316643e7SJed Brown @*/ 289dfbe8321SBarry Smith PetscErrorCode TSComputeRHSFunction(TS ts,PetscReal t,Vec x,Vec y) 290d763cef2SBarry Smith { 291dfbe8321SBarry Smith PetscErrorCode ierr; 292d763cef2SBarry Smith 293d763cef2SBarry Smith PetscFunctionBegin; 2940700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 2950700a824SBarry Smith PetscValidHeaderSpecific(x,VEC_CLASSID,3); 2960700a824SBarry Smith PetscValidHeaderSpecific(y,VEC_CLASSID,4); 297d763cef2SBarry Smith 298d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 299000e7ae3SMatthew Knepley if (ts->ops->rhsfunction) { 300d763cef2SBarry Smith PetscStackPush("TS user right-hand-side function"); 301000e7ae3SMatthew Knepley ierr = (*ts->ops->rhsfunction)(ts,t,x,y,ts->funP);CHKERRQ(ierr); 302d763cef2SBarry Smith PetscStackPop; 3037c922b88SBarry Smith } else { 304000e7ae3SMatthew Knepley if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */ 305d763cef2SBarry Smith MatStructure flg; 306d763cef2SBarry Smith PetscStackPush("TS user right-hand-side matrix function"); 3078beb423aSHong Zhang ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->Arhs,&ts->B,&flg,ts->jacP);CHKERRQ(ierr); 308d763cef2SBarry Smith PetscStackPop; 309d763cef2SBarry Smith } 3108beb423aSHong Zhang ierr = MatMult(ts->Arhs,x,y);CHKERRQ(ierr); 3117c922b88SBarry Smith } 312d763cef2SBarry Smith 313d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr); 314d763cef2SBarry Smith 315d763cef2SBarry Smith PetscFunctionReturn(0); 316d763cef2SBarry Smith } 317d763cef2SBarry Smith 3184a2ae208SSatish Balay #undef __FUNCT__ 319316643e7SJed Brown #define __FUNCT__ "TSComputeIFunction" 320316643e7SJed Brown /*@ 321316643e7SJed Brown TSComputeIFunction - Evaluates the DAE residual written in implicit form F(t,X,Xdot)=0 322316643e7SJed Brown 323316643e7SJed Brown Collective on TS and Vec 324316643e7SJed Brown 325316643e7SJed Brown Input Parameters: 326316643e7SJed Brown + ts - the TS context 327316643e7SJed Brown . t - current time 328316643e7SJed Brown . X - state vector 329316643e7SJed Brown - Xdot - time derivative of state vector 330316643e7SJed Brown 331316643e7SJed Brown Output Parameter: 332316643e7SJed Brown . Y - right hand side 333316643e7SJed Brown 334316643e7SJed Brown Note: 335316643e7SJed Brown Most users should not need to explicitly call this routine, as it 336316643e7SJed Brown is used internally within the nonlinear solvers. 337316643e7SJed Brown 338316643e7SJed Brown If the user did did not write their equations in implicit form, this 339316643e7SJed Brown function recasts them in implicit form. 340316643e7SJed Brown 341316643e7SJed Brown Level: developer 342316643e7SJed Brown 343316643e7SJed Brown .keywords: TS, compute 344316643e7SJed Brown 345316643e7SJed Brown .seealso: TSSetIFunction(), TSComputeRHSFunction() 346316643e7SJed Brown @*/ 347316643e7SJed Brown PetscErrorCode TSComputeIFunction(TS ts,PetscReal t,Vec X,Vec Xdot,Vec Y) 348316643e7SJed Brown { 349316643e7SJed Brown PetscErrorCode ierr; 350316643e7SJed Brown 351316643e7SJed Brown PetscFunctionBegin; 3520700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 3530700a824SBarry Smith PetscValidHeaderSpecific(X,VEC_CLASSID,3); 3540700a824SBarry Smith PetscValidHeaderSpecific(Xdot,VEC_CLASSID,4); 3550700a824SBarry Smith PetscValidHeaderSpecific(Y,VEC_CLASSID,5); 356316643e7SJed Brown 357316643e7SJed Brown ierr = PetscLogEventBegin(TS_FunctionEval,ts,X,Xdot,Y);CHKERRQ(ierr); 358316643e7SJed Brown if (ts->ops->ifunction) { 359316643e7SJed Brown PetscStackPush("TS user implicit function"); 360316643e7SJed Brown ierr = (*ts->ops->ifunction)(ts,t,X,Xdot,Y,ts->funP);CHKERRQ(ierr); 361316643e7SJed Brown PetscStackPop; 362316643e7SJed Brown } else { 363316643e7SJed Brown if (ts->ops->rhsfunction) { 364316643e7SJed Brown PetscStackPush("TS user right-hand-side function"); 365316643e7SJed Brown ierr = (*ts->ops->rhsfunction)(ts,t,X,Y,ts->funP);CHKERRQ(ierr); 366316643e7SJed Brown PetscStackPop; 367316643e7SJed Brown } else { 368316643e7SJed Brown if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */ 369316643e7SJed Brown MatStructure flg; 3704a6899ffSJed Brown /* Note: flg is not being used. 3714a6899ffSJed Brown For it to be useful, we'd have to cache it and then apply it in TSComputeIJacobian. 3724a6899ffSJed Brown */ 373316643e7SJed Brown PetscStackPush("TS user right-hand-side matrix function"); 374316643e7SJed Brown ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->Arhs,&ts->B,&flg,ts->jacP);CHKERRQ(ierr); 375316643e7SJed Brown PetscStackPop; 376316643e7SJed Brown } 377316643e7SJed Brown ierr = MatMult(ts->Arhs,X,Y);CHKERRQ(ierr); 378316643e7SJed Brown } 379316643e7SJed Brown 3804a6899ffSJed Brown /* Convert to implicit form: F(X,Xdot) = Alhs * Xdot - Frhs(X) */ 3814a6899ffSJed Brown if (ts->Alhs) { 3824a6899ffSJed Brown if (ts->ops->lhsmatrix) { 3834a6899ffSJed Brown MatStructure flg; 3844a6899ffSJed Brown PetscStackPush("TS user left-hand-side matrix function"); 3854a6899ffSJed Brown ierr = (*ts->ops->lhsmatrix)(ts,t,&ts->Alhs,PETSC_NULL,&flg,ts->jacP);CHKERRQ(ierr); 3864a6899ffSJed Brown PetscStackPop; 3874a6899ffSJed Brown } 3884a6899ffSJed Brown ierr = VecScale(Y,-1.);CHKERRQ(ierr); 3894a6899ffSJed Brown ierr = MatMultAdd(ts->Alhs,Xdot,Y,Y);CHKERRQ(ierr); 3904a6899ffSJed Brown } else { 391ace68cafSJed Brown ierr = VecAYPX(Y,-1,Xdot);CHKERRQ(ierr); 392316643e7SJed Brown } 3934a6899ffSJed Brown } 394316643e7SJed Brown ierr = PetscLogEventEnd(TS_FunctionEval,ts,X,Xdot,Y);CHKERRQ(ierr); 395316643e7SJed Brown PetscFunctionReturn(0); 396316643e7SJed Brown } 397316643e7SJed Brown 398316643e7SJed Brown #undef __FUNCT__ 399316643e7SJed Brown #define __FUNCT__ "TSComputeIJacobian" 400316643e7SJed Brown /*@ 401316643e7SJed Brown TSComputeIJacobian - Evaluates the Jacobian of the DAE 402316643e7SJed Brown 403316643e7SJed Brown Collective on TS and Vec 404316643e7SJed Brown 405316643e7SJed Brown Input 406316643e7SJed Brown Input Parameters: 407316643e7SJed Brown + ts - the TS context 408316643e7SJed Brown . t - current timestep 409316643e7SJed Brown . X - state vector 410316643e7SJed Brown . Xdot - time derivative of state vector 411316643e7SJed Brown - shift - shift to apply, see note below 412316643e7SJed Brown 413316643e7SJed Brown Output Parameters: 414316643e7SJed Brown + A - Jacobian matrix 415316643e7SJed Brown . B - optional preconditioning matrix 416316643e7SJed Brown - flag - flag indicating matrix structure 417316643e7SJed Brown 418316643e7SJed Brown Notes: 419316643e7SJed Brown If F(t,X,Xdot)=0 is the DAE, the required Jacobian is 420316643e7SJed Brown 421316643e7SJed Brown dF/dX + shift*dF/dXdot 422316643e7SJed Brown 423316643e7SJed Brown Most users should not need to explicitly call this routine, as it 424316643e7SJed Brown is used internally within the nonlinear solvers. 425316643e7SJed Brown 426316643e7SJed Brown TSComputeIJacobian() is valid only for TS_NONLINEAR 427316643e7SJed Brown 428316643e7SJed Brown Level: developer 429316643e7SJed Brown 430316643e7SJed Brown .keywords: TS, compute, Jacobian, matrix 431316643e7SJed Brown 432316643e7SJed Brown .seealso: TSSetIJacobian() 43363495f91SJed Brown @*/ 434316643e7SJed Brown PetscErrorCode PETSCTS_DLLEXPORT TSComputeIJacobian(TS ts,PetscReal t,Vec X,Vec Xdot,PetscReal shift,Mat *A,Mat *B,MatStructure *flg) 435316643e7SJed Brown { 436316643e7SJed Brown PetscErrorCode ierr; 437316643e7SJed Brown 438316643e7SJed Brown PetscFunctionBegin; 4390700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 4400700a824SBarry Smith PetscValidHeaderSpecific(X,VEC_CLASSID,3); 4410700a824SBarry Smith PetscValidHeaderSpecific(Xdot,VEC_CLASSID,4); 442316643e7SJed Brown PetscValidPointer(A,6); 4430700a824SBarry Smith PetscValidHeaderSpecific(*A,MAT_CLASSID,6); 444316643e7SJed Brown PetscValidPointer(B,7); 4450700a824SBarry Smith PetscValidHeaderSpecific(*B,MAT_CLASSID,7); 446316643e7SJed Brown PetscValidPointer(flg,8); 447316643e7SJed Brown 4484a6899ffSJed Brown *flg = SAME_NONZERO_PATTERN; /* In case it we're solving a linear problem in which case it wouldn't get initialized below. */ 449316643e7SJed Brown ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 450316643e7SJed Brown if (ts->ops->ijacobian) { 451316643e7SJed Brown PetscStackPush("TS user implicit Jacobian"); 452316643e7SJed Brown ierr = (*ts->ops->ijacobian)(ts,t,X,Xdot,shift,A,B,flg,ts->jacP);CHKERRQ(ierr); 453316643e7SJed Brown PetscStackPop; 454316643e7SJed Brown } else { 455316643e7SJed Brown if (ts->ops->rhsjacobian) { 456316643e7SJed Brown PetscStackPush("TS user right-hand-side Jacobian"); 457316643e7SJed Brown ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr); 458316643e7SJed Brown PetscStackPop; 459316643e7SJed Brown } else { 460316643e7SJed Brown ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 461316643e7SJed Brown ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 462316643e7SJed Brown if (*A != *B) { 463316643e7SJed Brown ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 464316643e7SJed Brown ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 465316643e7SJed Brown } 466316643e7SJed Brown } 467316643e7SJed Brown 468316643e7SJed Brown /* Convert to implicit form */ 469316643e7SJed Brown /* inefficient because these operations will normally traverse all matrix elements twice */ 470316643e7SJed Brown ierr = MatScale(*A,-1);CHKERRQ(ierr); 4714a6899ffSJed Brown if (ts->Alhs) { 4724a6899ffSJed Brown ierr = MatAXPY(*A,shift,ts->Alhs,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 4734a6899ffSJed Brown } else { 474316643e7SJed Brown ierr = MatShift(*A,shift);CHKERRQ(ierr); 4754a6899ffSJed Brown } 476316643e7SJed Brown if (*A != *B) { 477316643e7SJed Brown ierr = MatScale(*B,-1);CHKERRQ(ierr); 478316643e7SJed Brown ierr = MatShift(*B,shift);CHKERRQ(ierr); 479316643e7SJed Brown } 480316643e7SJed Brown } 481316643e7SJed Brown ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr); 482316643e7SJed Brown PetscFunctionReturn(0); 483316643e7SJed Brown } 484316643e7SJed Brown 485316643e7SJed Brown #undef __FUNCT__ 4864a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSFunction" 487d763cef2SBarry Smith /*@C 488d763cef2SBarry Smith TSSetRHSFunction - Sets the routine for evaluating the function, 489d763cef2SBarry Smith F(t,u), where U_t = F(t,u). 490d763cef2SBarry Smith 4913f9fe445SBarry Smith Logically Collective on TS 492d763cef2SBarry Smith 493d763cef2SBarry Smith Input Parameters: 494d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 495d763cef2SBarry Smith . f - routine for evaluating the right-hand-side function 496d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 497d763cef2SBarry Smith function evaluation routine (may be PETSC_NULL) 498d763cef2SBarry Smith 499d763cef2SBarry Smith Calling sequence of func: 50087828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Vec F,void *ctx); 501d763cef2SBarry Smith 502d763cef2SBarry Smith + t - current timestep 503d763cef2SBarry Smith . u - input vector 504d763cef2SBarry Smith . F - function vector 505d763cef2SBarry Smith - ctx - [optional] user-defined function context 506d763cef2SBarry Smith 507d763cef2SBarry Smith Important: 50876f2fa84SHong Zhang The user MUST call either this routine or TSSetMatrices(). 509d763cef2SBarry Smith 510d763cef2SBarry Smith Level: beginner 511d763cef2SBarry Smith 512d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, function 513d763cef2SBarry Smith 51476f2fa84SHong Zhang .seealso: TSSetMatrices() 515d763cef2SBarry Smith @*/ 51663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS ts,PetscErrorCode (*f)(TS,PetscReal,Vec,Vec,void*),void *ctx) 517d763cef2SBarry Smith { 518d763cef2SBarry Smith PetscFunctionBegin; 519d763cef2SBarry Smith 5200700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 52117186662SBarry Smith if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Cannot set function for linear problem"); 522000e7ae3SMatthew Knepley ts->ops->rhsfunction = f; 523d763cef2SBarry Smith ts->funP = ctx; 524d763cef2SBarry Smith PetscFunctionReturn(0); 525d763cef2SBarry Smith } 526d763cef2SBarry Smith 5274a2ae208SSatish Balay #undef __FUNCT__ 52895f0b562SHong Zhang #define __FUNCT__ "TSSetMatrices" 52995f0b562SHong Zhang /*@C 53095f0b562SHong Zhang TSSetMatrices - Sets the functions to compute the matrices Alhs and Arhs, 53195f0b562SHong Zhang where Alhs(t) U_t = Arhs(t) U. 53295f0b562SHong Zhang 5333f9fe445SBarry Smith Logically Collective on TS 53495f0b562SHong Zhang 53595f0b562SHong Zhang Input Parameters: 53695f0b562SHong Zhang + ts - the TS context obtained from TSCreate() 53795f0b562SHong Zhang . Arhs - matrix 53895f0b562SHong Zhang . frhs - the matrix evaluation routine for Arhs; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 53995f0b562SHong Zhang if Arhs is not a function of t. 54095f0b562SHong Zhang . Alhs - matrix or PETSC_NULL if Alhs is an indentity matrix. 54195f0b562SHong Zhang . flhs - the matrix evaluation routine for Alhs; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran) 54295f0b562SHong Zhang if Alhs is not a function of t. 54395f0b562SHong Zhang . flag - flag indicating information about the matrix structure of Arhs and Alhs. 54495f0b562SHong Zhang The available options are 54595f0b562SHong Zhang SAME_NONZERO_PATTERN - Alhs has the same nonzero structure as Arhs 54695f0b562SHong Zhang DIFFERENT_NONZERO_PATTERN - Alhs has different nonzero structure as Arhs 54795f0b562SHong Zhang - ctx - [optional] user-defined context for private data for the 54895f0b562SHong Zhang matrix evaluation routine (may be PETSC_NULL) 54995f0b562SHong Zhang 55095f0b562SHong Zhang Calling sequence of func: 55195f0b562SHong Zhang $ func(TS ts,PetscReal t,Mat *A,Mat *B,PetscInt *flag,void *ctx); 55295f0b562SHong Zhang 55395f0b562SHong Zhang + t - current timestep 55495f0b562SHong Zhang . A - matrix A, where U_t = A(t) U 55595f0b562SHong Zhang . B - preconditioner matrix, usually the same as A 55695f0b562SHong Zhang . flag - flag indicating information about the preconditioner matrix 55795f0b562SHong Zhang structure (same as flag in KSPSetOperators()) 55895f0b562SHong Zhang - ctx - [optional] user-defined context for matrix evaluation routine 55995f0b562SHong Zhang 56095f0b562SHong Zhang Notes: 56195f0b562SHong Zhang The routine func() takes Mat* as the matrix arguments rather than Mat. 56295f0b562SHong Zhang This allows the matrix evaluation routine to replace Arhs or Alhs with a 56395f0b562SHong Zhang completely new new matrix structure (not just different matrix elements) 56495f0b562SHong Zhang when appropriate, for instance, if the nonzero structure is changing 56595f0b562SHong Zhang throughout the global iterations. 56695f0b562SHong Zhang 56795f0b562SHong Zhang Important: 56895f0b562SHong Zhang The user MUST call either this routine or TSSetRHSFunction(). 56995f0b562SHong Zhang 57095f0b562SHong Zhang Level: beginner 57195f0b562SHong Zhang 57295f0b562SHong Zhang .keywords: TS, timestep, set, matrix 57395f0b562SHong Zhang 57495f0b562SHong Zhang .seealso: TSSetRHSFunction() 57595f0b562SHong Zhang @*/ 57695f0b562SHong 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) 57795f0b562SHong Zhang { 57895f0b562SHong Zhang PetscFunctionBegin; 5790700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 58092af4f6aSHong Zhang if (Arhs){ 5810700a824SBarry Smith PetscValidHeaderSpecific(Arhs,MAT_CLASSID,2); 58295f0b562SHong Zhang PetscCheckSameComm(ts,1,Arhs,2); 58395f0b562SHong Zhang ts->Arhs = Arhs; 58492af4f6aSHong Zhang ts->ops->rhsmatrix = frhs; 58592af4f6aSHong Zhang } 58692af4f6aSHong Zhang if (Alhs){ 5870700a824SBarry Smith PetscValidHeaderSpecific(Alhs,MAT_CLASSID,4); 58892af4f6aSHong Zhang PetscCheckSameComm(ts,1,Alhs,4); 58995f0b562SHong Zhang ts->Alhs = Alhs; 59092af4f6aSHong Zhang ts->ops->lhsmatrix = flhs; 59192af4f6aSHong Zhang } 59292af4f6aSHong Zhang 59392af4f6aSHong Zhang ts->jacP = ctx; 59495f0b562SHong Zhang ts->matflg = flag; 59595f0b562SHong Zhang PetscFunctionReturn(0); 59695f0b562SHong Zhang } 597d763cef2SBarry Smith 598aa644b49SHong Zhang #undef __FUNCT__ 599cda39b92SHong Zhang #define __FUNCT__ "TSGetMatrices" 600cda39b92SHong Zhang /*@C 601cda39b92SHong Zhang TSGetMatrices - Returns the matrices Arhs and Alhs at the present timestep, 602cda39b92SHong Zhang where Alhs(t) U_t = Arhs(t) U. 603cda39b92SHong Zhang 604cda39b92SHong Zhang Not Collective, but parallel objects are returned if TS is parallel 605cda39b92SHong Zhang 606cda39b92SHong Zhang Input Parameter: 607cda39b92SHong Zhang . ts - The TS context obtained from TSCreate() 608cda39b92SHong Zhang 609cda39b92SHong Zhang Output Parameters: 610cda39b92SHong Zhang + Arhs - The right-hand side matrix 611cda39b92SHong Zhang . Alhs - The left-hand side matrix 612cda39b92SHong Zhang - ctx - User-defined context for matrix evaluation routine 613cda39b92SHong Zhang 614cda39b92SHong Zhang Notes: You can pass in PETSC_NULL for any return argument you do not need. 615cda39b92SHong Zhang 616cda39b92SHong Zhang Level: intermediate 617cda39b92SHong Zhang 618cda39b92SHong Zhang .seealso: TSSetMatrices(), TSGetTimeStep(), TSGetTime(), TSGetTimeStepNumber(), TSGetRHSJacobian() 619cda39b92SHong Zhang 620cda39b92SHong Zhang .keywords: TS, timestep, get, matrix 621cda39b92SHong Zhang 622cda39b92SHong Zhang @*/ 623cda39b92SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSGetMatrices(TS ts,Mat *Arhs,Mat *Alhs,void **ctx) 624cda39b92SHong Zhang { 625cda39b92SHong Zhang PetscFunctionBegin; 6260700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 627cda39b92SHong Zhang if (Arhs) *Arhs = ts->Arhs; 628cda39b92SHong Zhang if (Alhs) *Alhs = ts->Alhs; 629cda39b92SHong Zhang if (ctx) *ctx = ts->jacP; 630cda39b92SHong Zhang PetscFunctionReturn(0); 631cda39b92SHong Zhang } 632cda39b92SHong Zhang 633cda39b92SHong Zhang #undef __FUNCT__ 6344a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSJacobian" 635d763cef2SBarry Smith /*@C 636d763cef2SBarry Smith TSSetRHSJacobian - Sets the function to compute the Jacobian of F, 637d763cef2SBarry Smith where U_t = F(U,t), as well as the location to store the matrix. 63876f2fa84SHong Zhang Use TSSetMatrices() for linear problems. 639d763cef2SBarry Smith 6403f9fe445SBarry Smith Logically Collective on TS 641d763cef2SBarry Smith 642d763cef2SBarry Smith Input Parameters: 643d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 644d763cef2SBarry Smith . A - Jacobian matrix 645d763cef2SBarry Smith . B - preconditioner matrix (usually same as A) 646d763cef2SBarry Smith . f - the Jacobian evaluation routine 647d763cef2SBarry Smith - ctx - [optional] user-defined context for private data for the 648d763cef2SBarry Smith Jacobian evaluation routine (may be PETSC_NULL) 649d763cef2SBarry Smith 650d763cef2SBarry Smith Calling sequence of func: 65187828ca2SBarry Smith $ func (TS ts,PetscReal t,Vec u,Mat *A,Mat *B,MatStructure *flag,void *ctx); 652d763cef2SBarry Smith 653d763cef2SBarry Smith + t - current timestep 654d763cef2SBarry Smith . u - input vector 655d763cef2SBarry Smith . A - matrix A, where U_t = A(t)u 656d763cef2SBarry Smith . B - preconditioner matrix, usually the same as A 657d763cef2SBarry Smith . flag - flag indicating information about the preconditioner matrix 65894b7f48cSBarry Smith structure (same as flag in KSPSetOperators()) 659d763cef2SBarry Smith - ctx - [optional] user-defined context for matrix evaluation routine 660d763cef2SBarry Smith 661d763cef2SBarry Smith Notes: 66294b7f48cSBarry Smith See KSPSetOperators() for important information about setting the flag 663d763cef2SBarry Smith output parameter in the routine func(). Be sure to read this information! 664d763cef2SBarry Smith 665d763cef2SBarry Smith The routine func() takes Mat * as the matrix arguments rather than Mat. 666d763cef2SBarry Smith This allows the matrix evaluation routine to replace A and/or B with a 66756335db2SHong Zhang completely new matrix structure (not just different matrix elements) 668d763cef2SBarry Smith when appropriate, for instance, if the nonzero structure is changing 669d763cef2SBarry Smith throughout the global iterations. 670d763cef2SBarry Smith 671d763cef2SBarry Smith Level: beginner 672d763cef2SBarry Smith 673d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, Jacobian 674d763cef2SBarry Smith 675d763cef2SBarry Smith .seealso: TSDefaultComputeJacobianColor(), 67676f2fa84SHong Zhang SNESDefaultComputeJacobianColor(), TSSetRHSFunction(), TSSetMatrices() 677d763cef2SBarry Smith 678d763cef2SBarry Smith @*/ 67963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx) 680d763cef2SBarry Smith { 681d763cef2SBarry Smith PetscFunctionBegin; 6820700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 6830700a824SBarry Smith PetscValidHeaderSpecific(A,MAT_CLASSID,2); 6840700a824SBarry Smith PetscValidHeaderSpecific(B,MAT_CLASSID,3); 685c9780b6fSBarry Smith PetscCheckSameComm(ts,1,A,2); 686c9780b6fSBarry Smith PetscCheckSameComm(ts,1,B,3); 68717186662SBarry Smith if (ts->problem_type != TS_NONLINEAR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Not for linear problems; use TSSetMatrices()"); 688d763cef2SBarry Smith 689000e7ae3SMatthew Knepley ts->ops->rhsjacobian = f; 690d763cef2SBarry Smith ts->jacP = ctx; 6918beb423aSHong Zhang ts->Arhs = A; 692d763cef2SBarry Smith ts->B = B; 693d763cef2SBarry Smith PetscFunctionReturn(0); 694d763cef2SBarry Smith } 695d763cef2SBarry Smith 696316643e7SJed Brown 697316643e7SJed Brown #undef __FUNCT__ 698316643e7SJed Brown #define __FUNCT__ "TSSetIFunction" 699316643e7SJed Brown /*@C 700316643e7SJed Brown TSSetIFunction - Set the function to compute F(t,U,U_t) where F = 0 is the DAE to be solved. 701316643e7SJed Brown 7023f9fe445SBarry Smith Logically Collective on TS 703316643e7SJed Brown 704316643e7SJed Brown Input Parameters: 705316643e7SJed Brown + ts - the TS context obtained from TSCreate() 706316643e7SJed Brown . f - the function evaluation routine 707316643e7SJed Brown - ctx - user-defined context for private data for the function evaluation routine (may be PETSC_NULL) 708316643e7SJed Brown 709316643e7SJed Brown Calling sequence of f: 710316643e7SJed Brown $ f(TS ts,PetscReal t,Vec u,Vec u_t,Vec F,ctx); 711316643e7SJed Brown 712316643e7SJed Brown + t - time at step/stage being solved 713316643e7SJed Brown . u - state vector 714316643e7SJed Brown . u_t - time derivative of state vector 715316643e7SJed Brown . F - function vector 716316643e7SJed Brown - ctx - [optional] user-defined context for matrix evaluation routine 717316643e7SJed Brown 718316643e7SJed Brown Important: 719316643e7SJed Brown The user MUST call either this routine, TSSetRHSFunction(), or TSSetMatrices(). This routine must be used when not solving an ODE. 720316643e7SJed Brown 721316643e7SJed Brown Level: beginner 722316643e7SJed Brown 723316643e7SJed Brown .keywords: TS, timestep, set, DAE, Jacobian 724316643e7SJed Brown 725316643e7SJed Brown .seealso: TSSetMatrices(), TSSetRHSFunction(), TSSetIJacobian() 726316643e7SJed Brown @*/ 727316643e7SJed Brown PetscErrorCode PETSCTS_DLLEXPORT TSSetIFunction(TS ts,TSIFunction f,void *ctx) 728316643e7SJed Brown { 729316643e7SJed Brown 730316643e7SJed Brown PetscFunctionBegin; 7310700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 732316643e7SJed Brown ts->ops->ifunction = f; 733316643e7SJed Brown ts->funP = ctx; 734316643e7SJed Brown PetscFunctionReturn(0); 735316643e7SJed Brown } 736316643e7SJed Brown 737316643e7SJed Brown #undef __FUNCT__ 738316643e7SJed Brown #define __FUNCT__ "TSSetIJacobian" 739316643e7SJed Brown /*@C 740316643e7SJed Brown TSSetIJacobian - Set the function to compute the Jacobian of 741316643e7SJed Brown G(U) = F(t,U,U0+a*U) where F(t,U,U_t) = 0 is the DAE to be solved. 742316643e7SJed Brown 7433f9fe445SBarry Smith Logically Collective on TS 744316643e7SJed Brown 745316643e7SJed Brown Input Parameters: 746316643e7SJed Brown + ts - the TS context obtained from TSCreate() 747316643e7SJed Brown . A - Jacobian matrix 748316643e7SJed Brown . B - preconditioning matrix for A (may be same as A) 749316643e7SJed Brown . f - the Jacobian evaluation routine 750316643e7SJed Brown - ctx - user-defined context for private data for the Jacobian evaluation routine (may be PETSC_NULL) 751316643e7SJed Brown 752316643e7SJed Brown Calling sequence of f: 753316643e7SJed Brown $ f(TS ts,PetscReal t,Vec u,Vec u_t,PetscReal a,Mat *A,Mat *B,MatStructure *flag,void *ctx); 754316643e7SJed Brown 755316643e7SJed Brown + t - time at step/stage being solved 756316643e7SJed Brown . u - state vector 757316643e7SJed Brown . u_t - time derivative of state vector 758316643e7SJed Brown . a - shift 759316643e7SJed Brown . A - Jacobian of G(U) = F(t,U,U0+a*U), equivalent to dF/dU + a*dF/dU_t 760316643e7SJed Brown . B - preconditioning matrix for A, may be same as A 761316643e7SJed Brown . flag - flag indicating information about the preconditioner matrix 762316643e7SJed Brown structure (same as flag in KSPSetOperators()) 763316643e7SJed Brown - ctx - [optional] user-defined context for matrix evaluation routine 764316643e7SJed Brown 765316643e7SJed Brown Notes: 766316643e7SJed Brown The matrices A and B are exactly the matrices that are used by SNES for the nonlinear solve. 767316643e7SJed Brown 768316643e7SJed Brown Level: beginner 769316643e7SJed Brown 770316643e7SJed Brown .keywords: TS, timestep, DAE, Jacobian 771316643e7SJed Brown 772316643e7SJed Brown .seealso: TSSetIFunction(), TSSetRHSJacobian() 773316643e7SJed Brown 774316643e7SJed Brown @*/ 775316643e7SJed Brown PetscErrorCode PETSCTS_DLLEXPORT TSSetIJacobian(TS ts,Mat A,Mat B,TSIJacobian f,void *ctx) 776316643e7SJed Brown { 777316643e7SJed Brown PetscErrorCode ierr; 778316643e7SJed Brown 779316643e7SJed Brown PetscFunctionBegin; 7800700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 7810700a824SBarry Smith if (A) PetscValidHeaderSpecific(A,MAT_CLASSID,2); 7820700a824SBarry Smith if (B) PetscValidHeaderSpecific(B,MAT_CLASSID,3); 783316643e7SJed Brown if (A) PetscCheckSameComm(ts,1,A,2); 784316643e7SJed Brown if (B) PetscCheckSameComm(ts,1,B,3); 785316643e7SJed Brown if (f) ts->ops->ijacobian = f; 786316643e7SJed Brown if (ctx) ts->jacP = ctx; 787316643e7SJed Brown if (A) { 788316643e7SJed Brown ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr); 789316643e7SJed Brown if (ts->A) {ierr = MatDestroy(ts->A);CHKERRQ(ierr);} 790316643e7SJed Brown ts->A = A; 791316643e7SJed Brown } 792dc3f620dSJed Brown #if 0 793dc3f620dSJed Brown /* The sane and consistent alternative */ 794316643e7SJed Brown if (B) { 795316643e7SJed Brown ierr = PetscObjectReference((PetscObject)B);CHKERRQ(ierr); 796316643e7SJed Brown if (ts->B) {ierr = MatDestroy(ts->B);CHKERRQ(ierr);} 797316643e7SJed Brown ts->B = B; 798316643e7SJed Brown } 799dc3f620dSJed Brown #else 800dc3f620dSJed Brown /* Don't reference B because TSDestroy() doesn't destroy it. These ownership semantics are awkward and inconsistent. */ 801dc3f620dSJed Brown if (B) ts->B = B; 802dc3f620dSJed Brown #endif 803316643e7SJed Brown PetscFunctionReturn(0); 804316643e7SJed Brown } 805316643e7SJed Brown 8064a2ae208SSatish Balay #undef __FUNCT__ 8074a2ae208SSatish Balay #define __FUNCT__ "TSView" 8087e2c5f70SBarry Smith /*@C 809d763cef2SBarry Smith TSView - Prints the TS data structure. 810d763cef2SBarry Smith 8114c49b128SBarry Smith Collective on TS 812d763cef2SBarry Smith 813d763cef2SBarry Smith Input Parameters: 814d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 815d763cef2SBarry Smith - viewer - visualization context 816d763cef2SBarry Smith 817d763cef2SBarry Smith Options Database Key: 818d763cef2SBarry Smith . -ts_view - calls TSView() at end of TSStep() 819d763cef2SBarry Smith 820d763cef2SBarry Smith Notes: 821d763cef2SBarry Smith The available visualization contexts include 822b0a32e0cSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 823b0a32e0cSBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 824d763cef2SBarry Smith output where only the first processor opens 825d763cef2SBarry Smith the file. All other processors send their 826d763cef2SBarry Smith data to the first processor to print. 827d763cef2SBarry Smith 828d763cef2SBarry Smith The user can open an alternative visualization context with 829b0a32e0cSBarry Smith PetscViewerASCIIOpen() - output to a specified file. 830d763cef2SBarry Smith 831d763cef2SBarry Smith Level: beginner 832d763cef2SBarry Smith 833d763cef2SBarry Smith .keywords: TS, timestep, view 834d763cef2SBarry Smith 835b0a32e0cSBarry Smith .seealso: PetscViewerASCIIOpen() 836d763cef2SBarry Smith @*/ 83763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSView(TS ts,PetscViewer viewer) 838d763cef2SBarry Smith { 839dfbe8321SBarry Smith PetscErrorCode ierr; 840a313700dSBarry Smith const TSType type; 84132077d6dSBarry Smith PetscTruth iascii,isstring; 842d763cef2SBarry Smith 843d763cef2SBarry Smith PetscFunctionBegin; 8440700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 8453050cee2SBarry Smith if (!viewer) { 8467adad957SLisandro Dalcin ierr = PetscViewerASCIIGetStdout(((PetscObject)ts)->comm,&viewer);CHKERRQ(ierr); 8473050cee2SBarry Smith } 8480700a824SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 849c9780b6fSBarry Smith PetscCheckSameComm(ts,1,viewer,2); 850fd16b177SBarry Smith 8512692d6eeSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 8522692d6eeSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr); 85332077d6dSBarry Smith if (iascii) { 854b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"TS Object:\n");CHKERRQ(ierr); 855a313700dSBarry Smith ierr = TSGetType(ts,&type);CHKERRQ(ierr); 856454a90a3SBarry Smith if (type) { 857b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: %s\n",type);CHKERRQ(ierr); 858184914b5SBarry Smith } else { 859b0a32e0cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," type: not yet set\n");CHKERRQ(ierr); 860184914b5SBarry Smith } 861000e7ae3SMatthew Knepley if (ts->ops->view) { 862b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 863000e7ae3SMatthew Knepley ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr); 864b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 865d763cef2SBarry Smith } 86677431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum steps=%D\n",ts->max_steps);CHKERRQ(ierr); 867a83599f4SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," maximum time=%G\n",ts->max_time);CHKERRQ(ierr); 868d763cef2SBarry Smith if (ts->problem_type == TS_NONLINEAR) { 86977431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of nonlinear solver iterations=%D\n",ts->nonlinear_its);CHKERRQ(ierr); 870d763cef2SBarry Smith } 87177431f27SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," total number of linear solver iterations=%D\n",ts->linear_its);CHKERRQ(ierr); 8720f5bd95cSBarry Smith } else if (isstring) { 873a313700dSBarry Smith ierr = TSGetType(ts,&type);CHKERRQ(ierr); 874b0a32e0cSBarry Smith ierr = PetscViewerStringSPrintf(viewer," %-7.7s",type);CHKERRQ(ierr); 875d763cef2SBarry Smith } 876b0a32e0cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 87794b7f48cSBarry Smith if (ts->ksp) {ierr = KSPView(ts->ksp,viewer);CHKERRQ(ierr);} 878d763cef2SBarry Smith if (ts->snes) {ierr = SNESView(ts->snes,viewer);CHKERRQ(ierr);} 879b0a32e0cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 880d763cef2SBarry Smith PetscFunctionReturn(0); 881d763cef2SBarry Smith } 882d763cef2SBarry Smith 883d763cef2SBarry Smith 8844a2ae208SSatish Balay #undef __FUNCT__ 8854a2ae208SSatish Balay #define __FUNCT__ "TSSetApplicationContext" 886d763cef2SBarry Smith /*@C 887d763cef2SBarry Smith TSSetApplicationContext - Sets an optional user-defined context for 888d763cef2SBarry Smith the timesteppers. 889d763cef2SBarry Smith 8903f9fe445SBarry Smith Logically Collective on TS 891d763cef2SBarry Smith 892d763cef2SBarry Smith Input Parameters: 893d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 894d763cef2SBarry Smith - usrP - optional user context 895d763cef2SBarry Smith 896d763cef2SBarry Smith Level: intermediate 897d763cef2SBarry Smith 898d763cef2SBarry Smith .keywords: TS, timestep, set, application, context 899d763cef2SBarry Smith 900d763cef2SBarry Smith .seealso: TSGetApplicationContext() 901d763cef2SBarry Smith @*/ 90263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS ts,void *usrP) 903d763cef2SBarry Smith { 904d763cef2SBarry Smith PetscFunctionBegin; 9050700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 906d763cef2SBarry Smith ts->user = usrP; 907d763cef2SBarry Smith PetscFunctionReturn(0); 908d763cef2SBarry Smith } 909d763cef2SBarry Smith 9104a2ae208SSatish Balay #undef __FUNCT__ 9114a2ae208SSatish Balay #define __FUNCT__ "TSGetApplicationContext" 912d763cef2SBarry Smith /*@C 913d763cef2SBarry Smith TSGetApplicationContext - Gets the user-defined context for the 914d763cef2SBarry Smith timestepper. 915d763cef2SBarry Smith 916d763cef2SBarry Smith Not Collective 917d763cef2SBarry Smith 918d763cef2SBarry Smith Input Parameter: 919d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 920d763cef2SBarry Smith 921d763cef2SBarry Smith Output Parameter: 922d763cef2SBarry Smith . usrP - user context 923d763cef2SBarry Smith 924d763cef2SBarry Smith Level: intermediate 925d763cef2SBarry Smith 926d763cef2SBarry Smith .keywords: TS, timestep, get, application, context 927d763cef2SBarry Smith 928d763cef2SBarry Smith .seealso: TSSetApplicationContext() 929d763cef2SBarry Smith @*/ 93063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS ts,void **usrP) 931d763cef2SBarry Smith { 932d763cef2SBarry Smith PetscFunctionBegin; 9330700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 934d763cef2SBarry Smith *usrP = ts->user; 935d763cef2SBarry Smith PetscFunctionReturn(0); 936d763cef2SBarry Smith } 937d763cef2SBarry Smith 9384a2ae208SSatish Balay #undef __FUNCT__ 9394a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStepNumber" 940d763cef2SBarry Smith /*@ 941d763cef2SBarry Smith TSGetTimeStepNumber - Gets the current number of timesteps. 942d763cef2SBarry Smith 943d763cef2SBarry Smith Not Collective 944d763cef2SBarry Smith 945d763cef2SBarry Smith Input Parameter: 946d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 947d763cef2SBarry Smith 948d763cef2SBarry Smith Output Parameter: 949d763cef2SBarry Smith . iter - number steps so far 950d763cef2SBarry Smith 951d763cef2SBarry Smith Level: intermediate 952d763cef2SBarry Smith 953d763cef2SBarry Smith .keywords: TS, timestep, get, iteration, number 954d763cef2SBarry Smith @*/ 95563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS ts,PetscInt* iter) 956d763cef2SBarry Smith { 957d763cef2SBarry Smith PetscFunctionBegin; 9580700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 9594482741eSBarry Smith PetscValidIntPointer(iter,2); 960d763cef2SBarry Smith *iter = ts->steps; 961d763cef2SBarry Smith PetscFunctionReturn(0); 962d763cef2SBarry Smith } 963d763cef2SBarry Smith 9644a2ae208SSatish Balay #undef __FUNCT__ 9654a2ae208SSatish Balay #define __FUNCT__ "TSSetInitialTimeStep" 966d763cef2SBarry Smith /*@ 967d763cef2SBarry Smith TSSetInitialTimeStep - Sets the initial timestep to be used, 968d763cef2SBarry Smith as well as the initial time. 969d763cef2SBarry Smith 9703f9fe445SBarry Smith Logically Collective on TS 971d763cef2SBarry Smith 972d763cef2SBarry Smith Input Parameters: 973d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 974d763cef2SBarry Smith . initial_time - the initial time 975d763cef2SBarry Smith - time_step - the size of the timestep 976d763cef2SBarry Smith 977d763cef2SBarry Smith Level: intermediate 978d763cef2SBarry Smith 979d763cef2SBarry Smith .seealso: TSSetTimeStep(), TSGetTimeStep() 980d763cef2SBarry Smith 981d763cef2SBarry Smith .keywords: TS, set, initial, timestep 982d763cef2SBarry Smith @*/ 98363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS ts,PetscReal initial_time,PetscReal time_step) 984d763cef2SBarry Smith { 985d763cef2SBarry Smith PetscFunctionBegin; 9860700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 987d763cef2SBarry Smith ts->time_step = time_step; 988d763cef2SBarry Smith ts->initial_time_step = time_step; 989d763cef2SBarry Smith ts->ptime = initial_time; 990d763cef2SBarry Smith PetscFunctionReturn(0); 991d763cef2SBarry Smith } 992d763cef2SBarry Smith 9934a2ae208SSatish Balay #undef __FUNCT__ 9944a2ae208SSatish Balay #define __FUNCT__ "TSSetTimeStep" 995d763cef2SBarry Smith /*@ 996d763cef2SBarry Smith TSSetTimeStep - Allows one to reset the timestep at any time, 997d763cef2SBarry Smith useful for simple pseudo-timestepping codes. 998d763cef2SBarry Smith 9993f9fe445SBarry Smith Logically Collective on TS 1000d763cef2SBarry Smith 1001d763cef2SBarry Smith Input Parameters: 1002d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1003d763cef2SBarry Smith - time_step - the size of the timestep 1004d763cef2SBarry Smith 1005d763cef2SBarry Smith Level: intermediate 1006d763cef2SBarry Smith 1007d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1008d763cef2SBarry Smith 1009d763cef2SBarry Smith .keywords: TS, set, timestep 1010d763cef2SBarry Smith @*/ 101163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS ts,PetscReal time_step) 1012d763cef2SBarry Smith { 1013d763cef2SBarry Smith PetscFunctionBegin; 10140700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1015*c5eb9154SBarry Smith PetscValidLogicalCollectiveReal(ts,time_step,2); 1016d763cef2SBarry Smith ts->time_step = time_step; 1017d763cef2SBarry Smith PetscFunctionReturn(0); 1018d763cef2SBarry Smith } 1019d763cef2SBarry Smith 10204a2ae208SSatish Balay #undef __FUNCT__ 10214a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStep" 1022d763cef2SBarry Smith /*@ 1023d763cef2SBarry Smith TSGetTimeStep - Gets the current timestep size. 1024d763cef2SBarry Smith 1025d763cef2SBarry Smith Not Collective 1026d763cef2SBarry Smith 1027d763cef2SBarry Smith Input Parameter: 1028d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1029d763cef2SBarry Smith 1030d763cef2SBarry Smith Output Parameter: 1031d763cef2SBarry Smith . dt - the current timestep size 1032d763cef2SBarry Smith 1033d763cef2SBarry Smith Level: intermediate 1034d763cef2SBarry Smith 1035d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1036d763cef2SBarry Smith 1037d763cef2SBarry Smith .keywords: TS, get, timestep 1038d763cef2SBarry Smith @*/ 103963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS ts,PetscReal* dt) 1040d763cef2SBarry Smith { 1041d763cef2SBarry Smith PetscFunctionBegin; 10420700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 10434482741eSBarry Smith PetscValidDoublePointer(dt,2); 1044d763cef2SBarry Smith *dt = ts->time_step; 1045d763cef2SBarry Smith PetscFunctionReturn(0); 1046d763cef2SBarry Smith } 1047d763cef2SBarry Smith 10484a2ae208SSatish Balay #undef __FUNCT__ 10494a2ae208SSatish Balay #define __FUNCT__ "TSGetSolution" 1050d8e5e3e6SSatish Balay /*@ 1051d763cef2SBarry Smith TSGetSolution - Returns the solution at the present timestep. It 1052d763cef2SBarry Smith is valid to call this routine inside the function that you are evaluating 1053d763cef2SBarry Smith in order to move to the new timestep. This vector not changed until 1054d763cef2SBarry Smith the solution at the next timestep has been calculated. 1055d763cef2SBarry Smith 1056d763cef2SBarry Smith Not Collective, but Vec returned is parallel if TS is parallel 1057d763cef2SBarry Smith 1058d763cef2SBarry Smith Input Parameter: 1059d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1060d763cef2SBarry Smith 1061d763cef2SBarry Smith Output Parameter: 1062d763cef2SBarry Smith . v - the vector containing the solution 1063d763cef2SBarry Smith 1064d763cef2SBarry Smith Level: intermediate 1065d763cef2SBarry Smith 1066d763cef2SBarry Smith .seealso: TSGetTimeStep() 1067d763cef2SBarry Smith 1068d763cef2SBarry Smith .keywords: TS, timestep, get, solution 1069d763cef2SBarry Smith @*/ 107063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS ts,Vec *v) 1071d763cef2SBarry Smith { 1072d763cef2SBarry Smith PetscFunctionBegin; 10730700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 10744482741eSBarry Smith PetscValidPointer(v,2); 1075d763cef2SBarry Smith *v = ts->vec_sol_always; 1076d763cef2SBarry Smith PetscFunctionReturn(0); 1077d763cef2SBarry Smith } 1078d763cef2SBarry Smith 1079bdad233fSMatthew Knepley /* ----- Routines to initialize and destroy a timestepper ---- */ 10804a2ae208SSatish Balay #undef __FUNCT__ 1081bdad233fSMatthew Knepley #define __FUNCT__ "TSSetProblemType" 1082d8e5e3e6SSatish Balay /*@ 1083bdad233fSMatthew Knepley TSSetProblemType - Sets the type of problem to be solved. 1084d763cef2SBarry Smith 1085bdad233fSMatthew Knepley Not collective 1086d763cef2SBarry Smith 1087bdad233fSMatthew Knepley Input Parameters: 1088bdad233fSMatthew Knepley + ts - The TS 1089bdad233fSMatthew Knepley - type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 1090d763cef2SBarry Smith .vb 1091d763cef2SBarry Smith U_t = A U 1092d763cef2SBarry Smith U_t = A(t) U 1093d763cef2SBarry Smith U_t = F(t,U) 1094d763cef2SBarry Smith .ve 1095d763cef2SBarry Smith 1096d763cef2SBarry Smith Level: beginner 1097d763cef2SBarry Smith 1098bdad233fSMatthew Knepley .keywords: TS, problem type 1099bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 1100d763cef2SBarry Smith @*/ 110163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS ts, TSProblemType type) 1102a7cc72afSBarry Smith { 1103d763cef2SBarry Smith PetscFunctionBegin; 11040700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,1); 1105bdad233fSMatthew Knepley ts->problem_type = type; 1106d763cef2SBarry Smith PetscFunctionReturn(0); 1107d763cef2SBarry Smith } 1108d763cef2SBarry Smith 1109bdad233fSMatthew Knepley #undef __FUNCT__ 1110bdad233fSMatthew Knepley #define __FUNCT__ "TSGetProblemType" 1111bdad233fSMatthew Knepley /*@C 1112bdad233fSMatthew Knepley TSGetProblemType - Gets the type of problem to be solved. 1113bdad233fSMatthew Knepley 1114bdad233fSMatthew Knepley Not collective 1115bdad233fSMatthew Knepley 1116bdad233fSMatthew Knepley Input Parameter: 1117bdad233fSMatthew Knepley . ts - The TS 1118bdad233fSMatthew Knepley 1119bdad233fSMatthew Knepley Output Parameter: 1120bdad233fSMatthew Knepley . type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms 1121bdad233fSMatthew Knepley .vb 1122bdad233fSMatthew Knepley U_t = A U 1123bdad233fSMatthew Knepley U_t = A(t) U 1124bdad233fSMatthew Knepley U_t = F(t,U) 1125bdad233fSMatthew Knepley .ve 1126bdad233fSMatthew Knepley 1127bdad233fSMatthew Knepley Level: beginner 1128bdad233fSMatthew Knepley 1129bdad233fSMatthew Knepley .keywords: TS, problem type 1130bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS 1131bdad233fSMatthew Knepley @*/ 113263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS ts, TSProblemType *type) 1133a7cc72afSBarry Smith { 1134bdad233fSMatthew Knepley PetscFunctionBegin; 11350700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,1); 11364482741eSBarry Smith PetscValidIntPointer(type,2); 1137bdad233fSMatthew Knepley *type = ts->problem_type; 1138bdad233fSMatthew Knepley PetscFunctionReturn(0); 1139bdad233fSMatthew Knepley } 1140d763cef2SBarry Smith 11414a2ae208SSatish Balay #undef __FUNCT__ 11424a2ae208SSatish Balay #define __FUNCT__ "TSSetUp" 1143d763cef2SBarry Smith /*@ 1144d763cef2SBarry Smith TSSetUp - Sets up the internal data structures for the later use 1145d763cef2SBarry Smith of a timestepper. 1146d763cef2SBarry Smith 1147d763cef2SBarry Smith Collective on TS 1148d763cef2SBarry Smith 1149d763cef2SBarry Smith Input Parameter: 1150d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1151d763cef2SBarry Smith 1152d763cef2SBarry Smith Notes: 1153d763cef2SBarry Smith For basic use of the TS solvers the user need not explicitly call 1154d763cef2SBarry Smith TSSetUp(), since these actions will automatically occur during 1155d763cef2SBarry Smith the call to TSStep(). However, if one wishes to control this 1156d763cef2SBarry Smith phase separately, TSSetUp() should be called after TSCreate() 1157d763cef2SBarry Smith and optional routines of the form TSSetXXX(), but before TSStep(). 1158d763cef2SBarry Smith 1159d763cef2SBarry Smith Level: advanced 1160d763cef2SBarry Smith 1161d763cef2SBarry Smith .keywords: TS, timestep, setup 1162d763cef2SBarry Smith 1163d763cef2SBarry Smith .seealso: TSCreate(), TSStep(), TSDestroy() 1164d763cef2SBarry Smith @*/ 116563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS ts) 1166d763cef2SBarry Smith { 1167dfbe8321SBarry Smith PetscErrorCode ierr; 1168d763cef2SBarry Smith 1169d763cef2SBarry Smith PetscFunctionBegin; 11700700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1171e32f2f54SBarry Smith if (!ts->vec_sol) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Must call TSSetSolution() first"); 11727adad957SLisandro Dalcin if (!((PetscObject)ts)->type_name) { 11739596e0b4SJed Brown ierr = TSSetType(ts,TSEULER);CHKERRQ(ierr); 1174d763cef2SBarry Smith } 1175000e7ae3SMatthew Knepley ierr = (*ts->ops->setup)(ts);CHKERRQ(ierr); 1176d763cef2SBarry Smith ts->setupcalled = 1; 1177d763cef2SBarry Smith PetscFunctionReturn(0); 1178d763cef2SBarry Smith } 1179d763cef2SBarry Smith 11804a2ae208SSatish Balay #undef __FUNCT__ 11814a2ae208SSatish Balay #define __FUNCT__ "TSDestroy" 1182d8e5e3e6SSatish Balay /*@ 1183d763cef2SBarry Smith TSDestroy - Destroys the timestepper context that was created 1184d763cef2SBarry Smith with TSCreate(). 1185d763cef2SBarry Smith 1186d763cef2SBarry Smith Collective on TS 1187d763cef2SBarry Smith 1188d763cef2SBarry Smith Input Parameter: 1189d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1190d763cef2SBarry Smith 1191d763cef2SBarry Smith Level: beginner 1192d763cef2SBarry Smith 1193d763cef2SBarry Smith .keywords: TS, timestepper, destroy 1194d763cef2SBarry Smith 1195d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve() 1196d763cef2SBarry Smith @*/ 119763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS ts) 1198d763cef2SBarry Smith { 11996849ba73SBarry Smith PetscErrorCode ierr; 1200d763cef2SBarry Smith 1201d763cef2SBarry Smith PetscFunctionBegin; 12020700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 12037adad957SLisandro Dalcin if (--((PetscObject)ts)->refct > 0) PetscFunctionReturn(0); 1204d763cef2SBarry Smith 1205be0abb6dSBarry Smith /* if memory was published with AMS then destroy it */ 12060f5bd95cSBarry Smith ierr = PetscObjectDepublish(ts);CHKERRQ(ierr); 12076c699258SBarry Smith 12086c699258SBarry Smith if (ts->dm) {ierr = DMDestroy(ts->dm);CHKERRQ(ierr);} 1209cb9801acSJed Brown if (ts->A) {ierr = MatDestroy(ts->A);CHKERRQ(ierr);} 121094b7f48cSBarry Smith if (ts->ksp) {ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);} 1211d763cef2SBarry Smith if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);} 12121e3347e8SBarry Smith if (ts->ops->destroy) {ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);} 1213a6570f20SBarry Smith ierr = TSMonitorCancel(ts);CHKERRQ(ierr); 1214a79aaaedSSatish Balay ierr = PetscHeaderDestroy(ts);CHKERRQ(ierr); 1215d763cef2SBarry Smith PetscFunctionReturn(0); 1216d763cef2SBarry Smith } 1217d763cef2SBarry Smith 12184a2ae208SSatish Balay #undef __FUNCT__ 12194a2ae208SSatish Balay #define __FUNCT__ "TSGetSNES" 1220d8e5e3e6SSatish Balay /*@ 1221d763cef2SBarry Smith TSGetSNES - Returns the SNES (nonlinear solver) associated with 1222d763cef2SBarry Smith a TS (timestepper) context. Valid only for nonlinear problems. 1223d763cef2SBarry Smith 1224d763cef2SBarry Smith Not Collective, but SNES is parallel if TS is parallel 1225d763cef2SBarry Smith 1226d763cef2SBarry Smith Input Parameter: 1227d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1228d763cef2SBarry Smith 1229d763cef2SBarry Smith Output Parameter: 1230d763cef2SBarry Smith . snes - the nonlinear solver context 1231d763cef2SBarry Smith 1232d763cef2SBarry Smith Notes: 1233d763cef2SBarry Smith The user can then directly manipulate the SNES context to set various 1234d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 123594b7f48cSBarry Smith KSP, KSP, and PC contexts as well. 1236d763cef2SBarry Smith 1237d763cef2SBarry Smith TSGetSNES() does not work for integrators that do not use SNES; in 1238d763cef2SBarry Smith this case TSGetSNES() returns PETSC_NULL in snes. 1239d763cef2SBarry Smith 1240d763cef2SBarry Smith Level: beginner 1241d763cef2SBarry Smith 1242d763cef2SBarry Smith .keywords: timestep, get, SNES 1243d763cef2SBarry Smith @*/ 124463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS ts,SNES *snes) 1245d763cef2SBarry Smith { 1246d763cef2SBarry Smith PetscFunctionBegin; 12470700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 12484482741eSBarry Smith PetscValidPointer(snes,2); 124917186662SBarry Smith if (!((PetscObject)ts)->type_name) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"SNES is not created yet. Call TSSetType() first"); 1250e32f2f54SBarry Smith if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Nonlinear only; use TSGetKSP()"); 1251d763cef2SBarry Smith *snes = ts->snes; 1252d763cef2SBarry Smith PetscFunctionReturn(0); 1253d763cef2SBarry Smith } 1254d763cef2SBarry Smith 12554a2ae208SSatish Balay #undef __FUNCT__ 125694b7f48cSBarry Smith #define __FUNCT__ "TSGetKSP" 1257d8e5e3e6SSatish Balay /*@ 125894b7f48cSBarry Smith TSGetKSP - Returns the KSP (linear solver) associated with 1259d763cef2SBarry Smith a TS (timestepper) context. 1260d763cef2SBarry Smith 126194b7f48cSBarry Smith Not Collective, but KSP is parallel if TS is parallel 1262d763cef2SBarry Smith 1263d763cef2SBarry Smith Input Parameter: 1264d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1265d763cef2SBarry Smith 1266d763cef2SBarry Smith Output Parameter: 126794b7f48cSBarry Smith . ksp - the nonlinear solver context 1268d763cef2SBarry Smith 1269d763cef2SBarry Smith Notes: 127094b7f48cSBarry Smith The user can then directly manipulate the KSP context to set various 1271d763cef2SBarry Smith options, etc. Likewise, the user can then extract and manipulate the 1272d763cef2SBarry Smith KSP and PC contexts as well. 1273d763cef2SBarry Smith 127494b7f48cSBarry Smith TSGetKSP() does not work for integrators that do not use KSP; 127594b7f48cSBarry Smith in this case TSGetKSP() returns PETSC_NULL in ksp. 1276d763cef2SBarry Smith 1277d763cef2SBarry Smith Level: beginner 1278d763cef2SBarry Smith 127994b7f48cSBarry Smith .keywords: timestep, get, KSP 1280d763cef2SBarry Smith @*/ 128163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS ts,KSP *ksp) 1282d763cef2SBarry Smith { 1283d763cef2SBarry Smith PetscFunctionBegin; 12840700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 12854482741eSBarry Smith PetscValidPointer(ksp,2); 128617186662SBarry Smith if (!((PetscObject)ts)->type_name) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"KSP is not created yet. Call TSSetType() first"); 1287e32f2f54SBarry Smith if (ts->problem_type != TS_LINEAR) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Linear only; use TSGetSNES()"); 128894b7f48cSBarry Smith *ksp = ts->ksp; 1289d763cef2SBarry Smith PetscFunctionReturn(0); 1290d763cef2SBarry Smith } 1291d763cef2SBarry Smith 1292d763cef2SBarry Smith /* ----------- Routines to set solver parameters ---------- */ 1293d763cef2SBarry Smith 12944a2ae208SSatish Balay #undef __FUNCT__ 1295adb62b0dSMatthew Knepley #define __FUNCT__ "TSGetDuration" 1296adb62b0dSMatthew Knepley /*@ 1297adb62b0dSMatthew Knepley TSGetDuration - Gets the maximum number of timesteps to use and 1298adb62b0dSMatthew Knepley maximum time for iteration. 1299adb62b0dSMatthew Knepley 13003f9fe445SBarry Smith Not Collective 1301adb62b0dSMatthew Knepley 1302adb62b0dSMatthew Knepley Input Parameters: 1303adb62b0dSMatthew Knepley + ts - the TS context obtained from TSCreate() 1304adb62b0dSMatthew Knepley . maxsteps - maximum number of iterations to use, or PETSC_NULL 1305adb62b0dSMatthew Knepley - maxtime - final time to iterate to, or PETSC_NULL 1306adb62b0dSMatthew Knepley 1307adb62b0dSMatthew Knepley Level: intermediate 1308adb62b0dSMatthew Knepley 1309adb62b0dSMatthew Knepley .keywords: TS, timestep, get, maximum, iterations, time 1310adb62b0dSMatthew Knepley @*/ 131163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS ts, PetscInt *maxsteps, PetscReal *maxtime) 1312adb62b0dSMatthew Knepley { 1313adb62b0dSMatthew Knepley PetscFunctionBegin; 13140700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,1); 1315abc0a331SBarry Smith if (maxsteps) { 13164482741eSBarry Smith PetscValidIntPointer(maxsteps,2); 1317adb62b0dSMatthew Knepley *maxsteps = ts->max_steps; 1318adb62b0dSMatthew Knepley } 1319abc0a331SBarry Smith if (maxtime ) { 13204482741eSBarry Smith PetscValidScalarPointer(maxtime,3); 1321adb62b0dSMatthew Knepley *maxtime = ts->max_time; 1322adb62b0dSMatthew Knepley } 1323adb62b0dSMatthew Knepley PetscFunctionReturn(0); 1324adb62b0dSMatthew Knepley } 1325adb62b0dSMatthew Knepley 1326adb62b0dSMatthew Knepley #undef __FUNCT__ 13274a2ae208SSatish Balay #define __FUNCT__ "TSSetDuration" 1328d763cef2SBarry Smith /*@ 1329d763cef2SBarry Smith TSSetDuration - Sets the maximum number of timesteps to use and 1330d763cef2SBarry Smith maximum time for iteration. 1331d763cef2SBarry Smith 13323f9fe445SBarry Smith Logically Collective on TS 1333d763cef2SBarry Smith 1334d763cef2SBarry Smith Input Parameters: 1335d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1336d763cef2SBarry Smith . maxsteps - maximum number of iterations to use 1337d763cef2SBarry Smith - maxtime - final time to iterate to 1338d763cef2SBarry Smith 1339d763cef2SBarry Smith Options Database Keys: 1340d763cef2SBarry Smith . -ts_max_steps <maxsteps> - Sets maxsteps 1341d763cef2SBarry Smith . -ts_max_time <maxtime> - Sets maxtime 1342d763cef2SBarry Smith 1343d763cef2SBarry Smith Notes: 1344d763cef2SBarry Smith The default maximum number of iterations is 5000. Default time is 5.0 1345d763cef2SBarry Smith 1346d763cef2SBarry Smith Level: intermediate 1347d763cef2SBarry Smith 1348d763cef2SBarry Smith .keywords: TS, timestep, set, maximum, iterations 1349d763cef2SBarry Smith @*/ 135063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS ts,PetscInt maxsteps,PetscReal maxtime) 1351d763cef2SBarry Smith { 1352d763cef2SBarry Smith PetscFunctionBegin; 13530700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1354*c5eb9154SBarry Smith PetscValidLogicalCollectiveInt(ts,maxsteps,2); 1355*c5eb9154SBarry Smith PetscValidLogicalCollectiveReal(ts,maxtime,2); 1356d763cef2SBarry Smith ts->max_steps = maxsteps; 1357d763cef2SBarry Smith ts->max_time = maxtime; 1358d763cef2SBarry Smith PetscFunctionReturn(0); 1359d763cef2SBarry Smith } 1360d763cef2SBarry Smith 13614a2ae208SSatish Balay #undef __FUNCT__ 13624a2ae208SSatish Balay #define __FUNCT__ "TSSetSolution" 1363d763cef2SBarry Smith /*@ 1364d763cef2SBarry Smith TSSetSolution - Sets the initial solution vector 1365d763cef2SBarry Smith for use by the TS routines. 1366d763cef2SBarry Smith 13673f9fe445SBarry Smith Logically Collective on TS and Vec 1368d763cef2SBarry Smith 1369d763cef2SBarry Smith Input Parameters: 1370d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1371d763cef2SBarry Smith - x - the solution vector 1372d763cef2SBarry Smith 1373d763cef2SBarry Smith Level: beginner 1374d763cef2SBarry Smith 1375d763cef2SBarry Smith .keywords: TS, timestep, set, solution, initial conditions 1376d763cef2SBarry Smith @*/ 137763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS ts,Vec x) 1378d763cef2SBarry Smith { 1379d763cef2SBarry Smith PetscFunctionBegin; 13800700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 13810700a824SBarry Smith PetscValidHeaderSpecific(x,VEC_CLASSID,2); 1382d763cef2SBarry Smith ts->vec_sol = ts->vec_sol_always = x; 1383d763cef2SBarry Smith PetscFunctionReturn(0); 1384d763cef2SBarry Smith } 1385d763cef2SBarry Smith 1386e74ef692SMatthew Knepley #undef __FUNCT__ 1387e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPreStep" 1388ac226902SBarry Smith /*@C 1389000e7ae3SMatthew Knepley TSSetPreStep - Sets the general-purpose function 13903f2090d5SJed Brown called once at the beginning of each time step. 1391000e7ae3SMatthew Knepley 13923f9fe445SBarry Smith Logically Collective on TS 1393000e7ae3SMatthew Knepley 1394000e7ae3SMatthew Knepley Input Parameters: 1395000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1396000e7ae3SMatthew Knepley - func - The function 1397000e7ae3SMatthew Knepley 1398000e7ae3SMatthew Knepley Calling sequence of func: 1399000e7ae3SMatthew Knepley . func (TS ts); 1400000e7ae3SMatthew Knepley 1401000e7ae3SMatthew Knepley Level: intermediate 1402000e7ae3SMatthew Knepley 1403000e7ae3SMatthew Knepley .keywords: TS, timestep 1404000e7ae3SMatthew Knepley @*/ 140563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS ts, PetscErrorCode (*func)(TS)) 1406000e7ae3SMatthew Knepley { 1407000e7ae3SMatthew Knepley PetscFunctionBegin; 14080700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,1); 1409000e7ae3SMatthew Knepley ts->ops->prestep = func; 1410000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1411000e7ae3SMatthew Knepley } 1412000e7ae3SMatthew Knepley 1413e74ef692SMatthew Knepley #undef __FUNCT__ 14143f2090d5SJed Brown #define __FUNCT__ "TSPreStep" 14153f2090d5SJed Brown /*@C 14163f2090d5SJed Brown TSPreStep - Runs the user-defined pre-step function. 14173f2090d5SJed Brown 14183f2090d5SJed Brown Collective on TS 14193f2090d5SJed Brown 14203f2090d5SJed Brown Input Parameters: 14213f2090d5SJed Brown . ts - The TS context obtained from TSCreate() 14223f2090d5SJed Brown 14233f2090d5SJed Brown Notes: 14243f2090d5SJed Brown TSPreStep() is typically used within time stepping implementations, 14253f2090d5SJed Brown so most users would not generally call this routine themselves. 14263f2090d5SJed Brown 14273f2090d5SJed Brown Level: developer 14283f2090d5SJed Brown 14293f2090d5SJed Brown .keywords: TS, timestep 14303f2090d5SJed Brown @*/ 14313f2090d5SJed Brown PetscErrorCode PETSCTS_DLLEXPORT TSPreStep(TS ts) 14323f2090d5SJed Brown { 14333f2090d5SJed Brown PetscErrorCode ierr; 14343f2090d5SJed Brown 14353f2090d5SJed Brown PetscFunctionBegin; 14360700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 143772ac3e02SJed Brown if (ts->ops->prestep) { 14383f2090d5SJed Brown PetscStackPush("TS PreStep function"); 14393f2090d5SJed Brown CHKMEMQ; 14403f2090d5SJed Brown ierr = (*ts->ops->prestep)(ts);CHKERRQ(ierr); 14413f2090d5SJed Brown CHKMEMQ; 14423f2090d5SJed Brown PetscStackPop; 1443312ce896SJed Brown } 14443f2090d5SJed Brown PetscFunctionReturn(0); 14453f2090d5SJed Brown } 14463f2090d5SJed Brown 14473f2090d5SJed Brown #undef __FUNCT__ 1448e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPreStep" 1449000e7ae3SMatthew Knepley /*@ 1450000e7ae3SMatthew Knepley TSDefaultPreStep - The default pre-stepping function which does nothing. 1451000e7ae3SMatthew Knepley 1452000e7ae3SMatthew Knepley Collective on TS 1453000e7ae3SMatthew Knepley 1454000e7ae3SMatthew Knepley Input Parameters: 1455000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1456000e7ae3SMatthew Knepley 1457000e7ae3SMatthew Knepley Level: developer 1458000e7ae3SMatthew Knepley 1459000e7ae3SMatthew Knepley .keywords: TS, timestep 1460000e7ae3SMatthew Knepley @*/ 146163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS ts) 1462000e7ae3SMatthew Knepley { 1463000e7ae3SMatthew Knepley PetscFunctionBegin; 1464000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1465000e7ae3SMatthew Knepley } 1466000e7ae3SMatthew Knepley 1467e74ef692SMatthew Knepley #undef __FUNCT__ 1468e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPostStep" 1469ac226902SBarry Smith /*@C 1470000e7ae3SMatthew Knepley TSSetPostStep - Sets the general-purpose function 14713f2090d5SJed Brown called once at the end of each time step. 1472000e7ae3SMatthew Knepley 14733f9fe445SBarry Smith Logically Collective on TS 1474000e7ae3SMatthew Knepley 1475000e7ae3SMatthew Knepley Input Parameters: 1476000e7ae3SMatthew Knepley + ts - The TS context obtained from TSCreate() 1477000e7ae3SMatthew Knepley - func - The function 1478000e7ae3SMatthew Knepley 1479000e7ae3SMatthew Knepley Calling sequence of func: 1480000e7ae3SMatthew Knepley . func (TS ts); 1481000e7ae3SMatthew Knepley 1482000e7ae3SMatthew Knepley Level: intermediate 1483000e7ae3SMatthew Knepley 1484000e7ae3SMatthew Knepley .keywords: TS, timestep 1485000e7ae3SMatthew Knepley @*/ 148663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS ts, PetscErrorCode (*func)(TS)) 1487000e7ae3SMatthew Knepley { 1488000e7ae3SMatthew Knepley PetscFunctionBegin; 14890700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,1); 1490000e7ae3SMatthew Knepley ts->ops->poststep = func; 1491000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1492000e7ae3SMatthew Knepley } 1493000e7ae3SMatthew Knepley 1494e74ef692SMatthew Knepley #undef __FUNCT__ 14953f2090d5SJed Brown #define __FUNCT__ "TSPostStep" 14963f2090d5SJed Brown /*@C 14973f2090d5SJed Brown TSPostStep - Runs the user-defined post-step function. 14983f2090d5SJed Brown 14993f2090d5SJed Brown Collective on TS 15003f2090d5SJed Brown 15013f2090d5SJed Brown Input Parameters: 15023f2090d5SJed Brown . ts - The TS context obtained from TSCreate() 15033f2090d5SJed Brown 15043f2090d5SJed Brown Notes: 15053f2090d5SJed Brown TSPostStep() is typically used within time stepping implementations, 15063f2090d5SJed Brown so most users would not generally call this routine themselves. 15073f2090d5SJed Brown 15083f2090d5SJed Brown Level: developer 15093f2090d5SJed Brown 15103f2090d5SJed Brown .keywords: TS, timestep 15113f2090d5SJed Brown @*/ 15123f2090d5SJed Brown PetscErrorCode PETSCTS_DLLEXPORT TSPostStep(TS ts) 15133f2090d5SJed Brown { 15143f2090d5SJed Brown PetscErrorCode ierr; 15153f2090d5SJed Brown 15163f2090d5SJed Brown PetscFunctionBegin; 15170700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 151872ac3e02SJed Brown if (ts->ops->poststep) { 15193f2090d5SJed Brown PetscStackPush("TS PostStep function"); 15203f2090d5SJed Brown CHKMEMQ; 15213f2090d5SJed Brown ierr = (*ts->ops->poststep)(ts);CHKERRQ(ierr); 15223f2090d5SJed Brown CHKMEMQ; 15233f2090d5SJed Brown PetscStackPop; 152472ac3e02SJed Brown } 15253f2090d5SJed Brown PetscFunctionReturn(0); 15263f2090d5SJed Brown } 15273f2090d5SJed Brown 15283f2090d5SJed Brown #undef __FUNCT__ 1529e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPostStep" 1530000e7ae3SMatthew Knepley /*@ 1531000e7ae3SMatthew Knepley TSDefaultPostStep - The default post-stepping function which does nothing. 1532000e7ae3SMatthew Knepley 1533000e7ae3SMatthew Knepley Collective on TS 1534000e7ae3SMatthew Knepley 1535000e7ae3SMatthew Knepley Input Parameters: 1536000e7ae3SMatthew Knepley . ts - The TS context obtained from TSCreate() 1537000e7ae3SMatthew Knepley 1538000e7ae3SMatthew Knepley Level: developer 1539000e7ae3SMatthew Knepley 1540000e7ae3SMatthew Knepley .keywords: TS, timestep 1541000e7ae3SMatthew Knepley @*/ 154263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS ts) 1543000e7ae3SMatthew Knepley { 1544000e7ae3SMatthew Knepley PetscFunctionBegin; 1545000e7ae3SMatthew Knepley PetscFunctionReturn(0); 1546000e7ae3SMatthew Knepley } 1547000e7ae3SMatthew Knepley 1548d763cef2SBarry Smith /* ------------ Routines to set performance monitoring options ----------- */ 1549d763cef2SBarry Smith 15504a2ae208SSatish Balay #undef __FUNCT__ 1551a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSet" 1552d763cef2SBarry Smith /*@C 1553a6570f20SBarry Smith TSMonitorSet - Sets an ADDITIONAL function that is to be used at every 1554d763cef2SBarry Smith timestep to display the iteration's progress. 1555d763cef2SBarry Smith 15563f9fe445SBarry Smith Logically Collective on TS 1557d763cef2SBarry Smith 1558d763cef2SBarry Smith Input Parameters: 1559d763cef2SBarry Smith + ts - the TS context obtained from TSCreate() 1560d763cef2SBarry Smith . func - monitoring routine 1561329f5518SBarry Smith . mctx - [optional] user-defined context for private data for the 1562b3006f0bSLois Curfman McInnes monitor routine (use PETSC_NULL if no context is desired) 1563b3006f0bSLois Curfman McInnes - monitordestroy - [optional] routine that frees monitor context 1564b3006f0bSLois Curfman McInnes (may be PETSC_NULL) 1565d763cef2SBarry Smith 1566d763cef2SBarry Smith Calling sequence of func: 1567a7cc72afSBarry Smith $ int func(TS ts,PetscInt steps,PetscReal time,Vec x,void *mctx) 1568d763cef2SBarry Smith 1569d763cef2SBarry Smith + ts - the TS context 1570d763cef2SBarry Smith . steps - iteration number 15711f06c33eSBarry Smith . time - current time 1572d763cef2SBarry Smith . x - current iterate 1573d763cef2SBarry Smith - mctx - [optional] monitoring context 1574d763cef2SBarry Smith 1575d763cef2SBarry Smith Notes: 1576d763cef2SBarry Smith This routine adds an additional monitor to the list of monitors that 1577d763cef2SBarry Smith already has been loaded. 1578d763cef2SBarry Smith 1579025f1a04SBarry Smith Fortran notes: Only a single monitor function can be set for each TS object 1580025f1a04SBarry Smith 1581d763cef2SBarry Smith Level: intermediate 1582d763cef2SBarry Smith 1583d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1584d763cef2SBarry Smith 1585a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorCancel() 1586d763cef2SBarry Smith @*/ 1587a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSet(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void*)) 1588d763cef2SBarry Smith { 1589d763cef2SBarry Smith PetscFunctionBegin; 15900700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 159117186662SBarry Smith if (ts->numbermonitors >= MAXTSMONITORS) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many monitors set"); 1592d763cef2SBarry Smith ts->monitor[ts->numbermonitors] = monitor; 1593329f5518SBarry Smith ts->mdestroy[ts->numbermonitors] = mdestroy; 1594d763cef2SBarry Smith ts->monitorcontext[ts->numbermonitors++] = (void*)mctx; 1595d763cef2SBarry Smith PetscFunctionReturn(0); 1596d763cef2SBarry Smith } 1597d763cef2SBarry Smith 15984a2ae208SSatish Balay #undef __FUNCT__ 1599a6570f20SBarry Smith #define __FUNCT__ "TSMonitorCancel" 1600d763cef2SBarry Smith /*@C 1601a6570f20SBarry Smith TSMonitorCancel - Clears all the monitors that have been set on a time-step object. 1602d763cef2SBarry Smith 16033f9fe445SBarry Smith Logically Collective on TS 1604d763cef2SBarry Smith 1605d763cef2SBarry Smith Input Parameters: 1606d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1607d763cef2SBarry Smith 1608d763cef2SBarry Smith Notes: 1609d763cef2SBarry Smith There is no way to remove a single, specific monitor. 1610d763cef2SBarry Smith 1611d763cef2SBarry Smith Level: intermediate 1612d763cef2SBarry Smith 1613d763cef2SBarry Smith .keywords: TS, timestep, set, monitor 1614d763cef2SBarry Smith 1615a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorSet() 1616d763cef2SBarry Smith @*/ 1617a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorCancel(TS ts) 1618d763cef2SBarry Smith { 1619d952e501SBarry Smith PetscErrorCode ierr; 1620d952e501SBarry Smith PetscInt i; 1621d952e501SBarry Smith 1622d763cef2SBarry Smith PetscFunctionBegin; 16230700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1624d952e501SBarry Smith for (i=0; i<ts->numbermonitors; i++) { 1625d952e501SBarry Smith if (ts->mdestroy[i]) { 1626d952e501SBarry Smith ierr = (*ts->mdestroy[i])(ts->monitorcontext[i]);CHKERRQ(ierr); 1627d952e501SBarry Smith } 1628d952e501SBarry Smith } 1629d763cef2SBarry Smith ts->numbermonitors = 0; 1630d763cef2SBarry Smith PetscFunctionReturn(0); 1631d763cef2SBarry Smith } 1632d763cef2SBarry Smith 16334a2ae208SSatish Balay #undef __FUNCT__ 1634a6570f20SBarry Smith #define __FUNCT__ "TSMonitorDefault" 1635d8e5e3e6SSatish Balay /*@ 1636a6570f20SBarry Smith TSMonitorDefault - Sets the Default monitor 16375516499fSSatish Balay 16385516499fSSatish Balay Level: intermediate 163941251cbbSSatish Balay 16405516499fSSatish Balay .keywords: TS, set, monitor 16415516499fSSatish Balay 164241251cbbSSatish Balay .seealso: TSMonitorDefault(), TSMonitorSet() 164341251cbbSSatish Balay @*/ 1644a6570f20SBarry Smith PetscErrorCode TSMonitorDefault(TS ts,PetscInt step,PetscReal ptime,Vec v,void *ctx) 1645d763cef2SBarry Smith { 1646dfbe8321SBarry Smith PetscErrorCode ierr; 1647a34d58ebSBarry Smith PetscViewerASCIIMonitor viewer = (PetscViewerASCIIMonitor)ctx; 1648d132466eSBarry Smith 1649d763cef2SBarry Smith PetscFunctionBegin; 1650a34d58ebSBarry Smith if (!ctx) { 16517adad957SLisandro Dalcin ierr = PetscViewerASCIIMonitorCreate(((PetscObject)ts)->comm,"stdout",0,&viewer);CHKERRQ(ierr); 1652a34d58ebSBarry Smith } 1653f22f69f0SBarry Smith ierr = PetscViewerASCIIMonitorPrintf(viewer,"%D TS dt %G time %G\n",step,ts->time_step,ptime);CHKERRQ(ierr); 1654a34d58ebSBarry Smith if (!ctx) { 1655a34d58ebSBarry Smith ierr = PetscViewerASCIIMonitorDestroy(viewer);CHKERRQ(ierr); 1656a34d58ebSBarry Smith } 1657d763cef2SBarry Smith PetscFunctionReturn(0); 1658d763cef2SBarry Smith } 1659d763cef2SBarry Smith 16604a2ae208SSatish Balay #undef __FUNCT__ 16614a2ae208SSatish Balay #define __FUNCT__ "TSStep" 1662d763cef2SBarry Smith /*@ 1663d763cef2SBarry Smith TSStep - Steps the requested number of timesteps. 1664d763cef2SBarry Smith 1665d763cef2SBarry Smith Collective on TS 1666d763cef2SBarry Smith 1667d763cef2SBarry Smith Input Parameter: 1668d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1669d763cef2SBarry Smith 1670d763cef2SBarry Smith Output Parameters: 1671d763cef2SBarry Smith + steps - number of iterations until termination 1672142b95e3SSatish Balay - ptime - time until termination 1673d763cef2SBarry Smith 1674d763cef2SBarry Smith Level: beginner 1675d763cef2SBarry Smith 1676d763cef2SBarry Smith .keywords: TS, timestep, solve 1677d763cef2SBarry Smith 1678d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSDestroy() 1679d763cef2SBarry Smith @*/ 168063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS ts,PetscInt *steps,PetscReal *ptime) 1681d763cef2SBarry Smith { 1682dfbe8321SBarry Smith PetscErrorCode ierr; 1683d763cef2SBarry Smith 1684d763cef2SBarry Smith PetscFunctionBegin; 16850700a824SBarry Smith PetscValidHeaderSpecific(ts, TS_CLASSID,1); 1686d405a339SMatthew Knepley if (!ts->setupcalled) { 1687d405a339SMatthew Knepley ierr = TSSetUp(ts);CHKERRQ(ierr); 1688d405a339SMatthew Knepley } 1689d405a339SMatthew Knepley 1690d5ba7fb7SMatthew Knepley ierr = PetscLogEventBegin(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1691000e7ae3SMatthew Knepley ierr = (*ts->ops->step)(ts, steps, ptime);CHKERRQ(ierr); 1692d5ba7fb7SMatthew Knepley ierr = PetscLogEventEnd(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr); 1693d405a339SMatthew Knepley 16944bb05414SBarry Smith if (!PetscPreLoadingOn) { 16957adad957SLisandro Dalcin ierr = TSViewFromOptions(ts,((PetscObject)ts)->name);CHKERRQ(ierr); 1696d405a339SMatthew Knepley } 1697d763cef2SBarry Smith PetscFunctionReturn(0); 1698d763cef2SBarry Smith } 1699d763cef2SBarry Smith 17004a2ae208SSatish Balay #undef __FUNCT__ 17016a4d4014SLisandro Dalcin #define __FUNCT__ "TSSolve" 17026a4d4014SLisandro Dalcin /*@ 17036a4d4014SLisandro Dalcin TSSolve - Steps the requested number of timesteps. 17046a4d4014SLisandro Dalcin 17056a4d4014SLisandro Dalcin Collective on TS 17066a4d4014SLisandro Dalcin 17076a4d4014SLisandro Dalcin Input Parameter: 17086a4d4014SLisandro Dalcin + ts - the TS context obtained from TSCreate() 17096a4d4014SLisandro Dalcin - x - the solution vector, or PETSC_NULL if it was set with TSSetSolution() 17106a4d4014SLisandro Dalcin 17116a4d4014SLisandro Dalcin Level: beginner 17126a4d4014SLisandro Dalcin 17136a4d4014SLisandro Dalcin .keywords: TS, timestep, solve 17146a4d4014SLisandro Dalcin 17156a4d4014SLisandro Dalcin .seealso: TSCreate(), TSSetSolution(), TSStep() 17166a4d4014SLisandro Dalcin @*/ 17176a4d4014SLisandro Dalcin PetscErrorCode PETSCTS_DLLEXPORT TSSolve(TS ts, Vec x) 17186a4d4014SLisandro Dalcin { 17196a4d4014SLisandro Dalcin PetscInt steps; 17206a4d4014SLisandro Dalcin PetscReal ptime; 17216a4d4014SLisandro Dalcin PetscErrorCode ierr; 1722f22f69f0SBarry Smith 17236a4d4014SLisandro Dalcin PetscFunctionBegin; 17240700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 17256a4d4014SLisandro Dalcin /* set solution vector if provided */ 17266a4d4014SLisandro Dalcin if (x) { ierr = TSSetSolution(ts, x); CHKERRQ(ierr); } 17276a4d4014SLisandro Dalcin /* reset time step and iteration counters */ 17286a4d4014SLisandro Dalcin ts->steps = 0; ts->linear_its = 0; ts->nonlinear_its = 0; 17296a4d4014SLisandro Dalcin /* steps the requested number of timesteps. */ 17306a4d4014SLisandro Dalcin ierr = TSStep(ts, &steps, &ptime);CHKERRQ(ierr); 17316a4d4014SLisandro Dalcin PetscFunctionReturn(0); 17326a4d4014SLisandro Dalcin } 17336a4d4014SLisandro Dalcin 17346a4d4014SLisandro Dalcin #undef __FUNCT__ 17354a2ae208SSatish Balay #define __FUNCT__ "TSMonitor" 1736d763cef2SBarry Smith /* 1737d763cef2SBarry Smith Runs the user provided monitor routines, if they exists. 1738d763cef2SBarry Smith */ 1739a7cc72afSBarry Smith PetscErrorCode TSMonitor(TS ts,PetscInt step,PetscReal ptime,Vec x) 1740d763cef2SBarry Smith { 17416849ba73SBarry Smith PetscErrorCode ierr; 1742a7cc72afSBarry Smith PetscInt i,n = ts->numbermonitors; 1743d763cef2SBarry Smith 1744d763cef2SBarry Smith PetscFunctionBegin; 1745d763cef2SBarry Smith for (i=0; i<n; i++) { 1746142b95e3SSatish Balay ierr = (*ts->monitor[i])(ts,step,ptime,x,ts->monitorcontext[i]);CHKERRQ(ierr); 1747d763cef2SBarry Smith } 1748d763cef2SBarry Smith PetscFunctionReturn(0); 1749d763cef2SBarry Smith } 1750d763cef2SBarry Smith 1751d763cef2SBarry Smith /* ------------------------------------------------------------------------*/ 1752d763cef2SBarry Smith 17534a2ae208SSatish Balay #undef __FUNCT__ 1754a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGCreate" 1755d763cef2SBarry Smith /*@C 1756a6570f20SBarry Smith TSMonitorLGCreate - Creates a line graph context for use with 1757d763cef2SBarry Smith TS to monitor convergence of preconditioned residual norms. 1758d763cef2SBarry Smith 1759d763cef2SBarry Smith Collective on TS 1760d763cef2SBarry Smith 1761d763cef2SBarry Smith Input Parameters: 1762d763cef2SBarry Smith + host - the X display to open, or null for the local machine 1763d763cef2SBarry Smith . label - the title to put in the title bar 17647c922b88SBarry Smith . x, y - the screen coordinates of the upper left coordinate of the window 1765d763cef2SBarry Smith - m, n - the screen width and height in pixels 1766d763cef2SBarry Smith 1767d763cef2SBarry Smith Output Parameter: 1768d763cef2SBarry Smith . draw - the drawing context 1769d763cef2SBarry Smith 1770d763cef2SBarry Smith Options Database Key: 1771a6570f20SBarry Smith . -ts_monitor_draw - automatically sets line graph monitor 1772d763cef2SBarry Smith 1773d763cef2SBarry Smith Notes: 1774a6570f20SBarry Smith Use TSMonitorLGDestroy() to destroy this line graph, not PetscDrawLGDestroy(). 1775d763cef2SBarry Smith 1776d763cef2SBarry Smith Level: intermediate 1777d763cef2SBarry Smith 17787c922b88SBarry Smith .keywords: TS, monitor, line graph, residual, seealso 1779d763cef2SBarry Smith 1780a6570f20SBarry Smith .seealso: TSMonitorLGDestroy(), TSMonitorSet() 17817c922b88SBarry Smith 1782d763cef2SBarry Smith @*/ 1783a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGCreate(const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *draw) 1784d763cef2SBarry Smith { 1785b0a32e0cSBarry Smith PetscDraw win; 1786dfbe8321SBarry Smith PetscErrorCode ierr; 1787d763cef2SBarry Smith 1788d763cef2SBarry Smith PetscFunctionBegin; 1789b0a32e0cSBarry Smith ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr); 1790b0a32e0cSBarry Smith ierr = PetscDrawSetType(win,PETSC_DRAW_X);CHKERRQ(ierr); 1791b0a32e0cSBarry Smith ierr = PetscDrawLGCreate(win,1,draw);CHKERRQ(ierr); 1792b0a32e0cSBarry Smith ierr = PetscDrawLGIndicateDataPoints(*draw);CHKERRQ(ierr); 1793d763cef2SBarry Smith 179452e6d16bSBarry Smith ierr = PetscLogObjectParent(*draw,win);CHKERRQ(ierr); 1795d763cef2SBarry Smith PetscFunctionReturn(0); 1796d763cef2SBarry Smith } 1797d763cef2SBarry Smith 17984a2ae208SSatish Balay #undef __FUNCT__ 1799a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLG" 1800a6570f20SBarry Smith PetscErrorCode TSMonitorLG(TS ts,PetscInt n,PetscReal ptime,Vec v,void *monctx) 1801d763cef2SBarry Smith { 1802b0a32e0cSBarry Smith PetscDrawLG lg = (PetscDrawLG) monctx; 180387828ca2SBarry Smith PetscReal x,y = ptime; 1804dfbe8321SBarry Smith PetscErrorCode ierr; 1805d763cef2SBarry Smith 1806d763cef2SBarry Smith PetscFunctionBegin; 18077c922b88SBarry Smith if (!monctx) { 18087c922b88SBarry Smith MPI_Comm comm; 1809b0a32e0cSBarry Smith PetscViewer viewer; 18107c922b88SBarry Smith 18117c922b88SBarry Smith ierr = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr); 1812b0a32e0cSBarry Smith viewer = PETSC_VIEWER_DRAW_(comm); 1813b0a32e0cSBarry Smith ierr = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr); 18147c922b88SBarry Smith } 18157c922b88SBarry Smith 1816b0a32e0cSBarry Smith if (!n) {ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);} 181787828ca2SBarry Smith x = (PetscReal)n; 1818b0a32e0cSBarry Smith ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr); 1819d763cef2SBarry Smith if (n < 20 || (n % 5)) { 1820b0a32e0cSBarry Smith ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr); 1821d763cef2SBarry Smith } 1822d763cef2SBarry Smith PetscFunctionReturn(0); 1823d763cef2SBarry Smith } 1824d763cef2SBarry Smith 18254a2ae208SSatish Balay #undef __FUNCT__ 1826a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGDestroy" 1827d763cef2SBarry Smith /*@C 1828a6570f20SBarry Smith TSMonitorLGDestroy - Destroys a line graph context that was created 1829a6570f20SBarry Smith with TSMonitorLGCreate(). 1830d763cef2SBarry Smith 1831b0a32e0cSBarry Smith Collective on PetscDrawLG 1832d763cef2SBarry Smith 1833d763cef2SBarry Smith Input Parameter: 1834d763cef2SBarry Smith . draw - the drawing context 1835d763cef2SBarry Smith 1836d763cef2SBarry Smith Level: intermediate 1837d763cef2SBarry Smith 1838d763cef2SBarry Smith .keywords: TS, monitor, line graph, destroy 1839d763cef2SBarry Smith 1840a6570f20SBarry Smith .seealso: TSMonitorLGCreate(), TSMonitorSet(), TSMonitorLG(); 1841d763cef2SBarry Smith @*/ 1842a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGDestroy(PetscDrawLG drawlg) 1843d763cef2SBarry Smith { 1844b0a32e0cSBarry Smith PetscDraw draw; 1845dfbe8321SBarry Smith PetscErrorCode ierr; 1846d763cef2SBarry Smith 1847d763cef2SBarry Smith PetscFunctionBegin; 1848b0a32e0cSBarry Smith ierr = PetscDrawLGGetDraw(drawlg,&draw);CHKERRQ(ierr); 1849b0a32e0cSBarry Smith ierr = PetscDrawDestroy(draw);CHKERRQ(ierr); 1850b0a32e0cSBarry Smith ierr = PetscDrawLGDestroy(drawlg);CHKERRQ(ierr); 1851d763cef2SBarry Smith PetscFunctionReturn(0); 1852d763cef2SBarry Smith } 1853d763cef2SBarry Smith 18544a2ae208SSatish Balay #undef __FUNCT__ 18554a2ae208SSatish Balay #define __FUNCT__ "TSGetTime" 1856d763cef2SBarry Smith /*@ 1857d763cef2SBarry Smith TSGetTime - Gets the current time. 1858d763cef2SBarry Smith 1859d763cef2SBarry Smith Not Collective 1860d763cef2SBarry Smith 1861d763cef2SBarry Smith Input Parameter: 1862d763cef2SBarry Smith . ts - the TS context obtained from TSCreate() 1863d763cef2SBarry Smith 1864d763cef2SBarry Smith Output Parameter: 1865d763cef2SBarry Smith . t - the current time 1866d763cef2SBarry Smith 1867d763cef2SBarry Smith Level: beginner 1868d763cef2SBarry Smith 1869d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep() 1870d763cef2SBarry Smith 1871d763cef2SBarry Smith .keywords: TS, get, time 1872d763cef2SBarry Smith @*/ 187363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS ts,PetscReal* t) 1874d763cef2SBarry Smith { 1875d763cef2SBarry Smith PetscFunctionBegin; 18760700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 18774482741eSBarry Smith PetscValidDoublePointer(t,2); 1878d763cef2SBarry Smith *t = ts->ptime; 1879d763cef2SBarry Smith PetscFunctionReturn(0); 1880d763cef2SBarry Smith } 1881d763cef2SBarry Smith 18824a2ae208SSatish Balay #undef __FUNCT__ 18836a4d4014SLisandro Dalcin #define __FUNCT__ "TSSetTime" 18846a4d4014SLisandro Dalcin /*@ 18856a4d4014SLisandro Dalcin TSSetTime - Allows one to reset the time. 18866a4d4014SLisandro Dalcin 18873f9fe445SBarry Smith Logically Collective on TS 18886a4d4014SLisandro Dalcin 18896a4d4014SLisandro Dalcin Input Parameters: 18906a4d4014SLisandro Dalcin + ts - the TS context obtained from TSCreate() 18916a4d4014SLisandro Dalcin - time - the time 18926a4d4014SLisandro Dalcin 18936a4d4014SLisandro Dalcin Level: intermediate 18946a4d4014SLisandro Dalcin 18956a4d4014SLisandro Dalcin .seealso: TSGetTime(), TSSetDuration() 18966a4d4014SLisandro Dalcin 18976a4d4014SLisandro Dalcin .keywords: TS, set, time 18986a4d4014SLisandro Dalcin @*/ 18996a4d4014SLisandro Dalcin PetscErrorCode PETSCTS_DLLEXPORT TSSetTime(TS ts, PetscReal t) 19006a4d4014SLisandro Dalcin { 19016a4d4014SLisandro Dalcin PetscFunctionBegin; 19020700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1903*c5eb9154SBarry Smith PetscValidLogicalCollectiveReal(ts,t,2); 19046a4d4014SLisandro Dalcin ts->ptime = t; 19056a4d4014SLisandro Dalcin PetscFunctionReturn(0); 19066a4d4014SLisandro Dalcin } 19076a4d4014SLisandro Dalcin 19086a4d4014SLisandro Dalcin #undef __FUNCT__ 19094a2ae208SSatish Balay #define __FUNCT__ "TSSetOptionsPrefix" 1910d763cef2SBarry Smith /*@C 1911d763cef2SBarry Smith TSSetOptionsPrefix - Sets the prefix used for searching for all 1912d763cef2SBarry Smith TS options in the database. 1913d763cef2SBarry Smith 19143f9fe445SBarry Smith Logically Collective on TS 1915d763cef2SBarry Smith 1916d763cef2SBarry Smith Input Parameter: 1917d763cef2SBarry Smith + ts - The TS context 1918d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1919d763cef2SBarry Smith 1920d763cef2SBarry Smith Notes: 1921d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1922d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1923d763cef2SBarry Smith hyphen. 1924d763cef2SBarry Smith 1925d763cef2SBarry Smith Level: advanced 1926d763cef2SBarry Smith 1927d763cef2SBarry Smith .keywords: TS, set, options, prefix, database 1928d763cef2SBarry Smith 1929d763cef2SBarry Smith .seealso: TSSetFromOptions() 1930d763cef2SBarry Smith 1931d763cef2SBarry Smith @*/ 193263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS ts,const char prefix[]) 1933d763cef2SBarry Smith { 1934dfbe8321SBarry Smith PetscErrorCode ierr; 1935d763cef2SBarry Smith 1936d763cef2SBarry Smith PetscFunctionBegin; 19370700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1938d763cef2SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1939d763cef2SBarry Smith switch(ts->problem_type) { 1940d763cef2SBarry Smith case TS_NONLINEAR: 194159580b9cSBarry Smith if (ts->snes) { 1942d763cef2SBarry Smith ierr = SNESSetOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 194359580b9cSBarry Smith } 1944d763cef2SBarry Smith break; 1945d763cef2SBarry Smith case TS_LINEAR: 194659580b9cSBarry Smith if (ts->ksp) { 194794b7f48cSBarry Smith ierr = KSPSetOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 194859580b9cSBarry Smith } 1949d763cef2SBarry Smith break; 1950d763cef2SBarry Smith } 1951d763cef2SBarry Smith PetscFunctionReturn(0); 1952d763cef2SBarry Smith } 1953d763cef2SBarry Smith 1954d763cef2SBarry Smith 19554a2ae208SSatish Balay #undef __FUNCT__ 19564a2ae208SSatish Balay #define __FUNCT__ "TSAppendOptionsPrefix" 1957d763cef2SBarry Smith /*@C 1958d763cef2SBarry Smith TSAppendOptionsPrefix - Appends to the prefix used for searching for all 1959d763cef2SBarry Smith TS options in the database. 1960d763cef2SBarry Smith 19613f9fe445SBarry Smith Logically Collective on TS 1962d763cef2SBarry Smith 1963d763cef2SBarry Smith Input Parameter: 1964d763cef2SBarry Smith + ts - The TS context 1965d763cef2SBarry Smith - prefix - The prefix to prepend to all option names 1966d763cef2SBarry Smith 1967d763cef2SBarry Smith Notes: 1968d763cef2SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1969d763cef2SBarry Smith The first character of all runtime options is AUTOMATICALLY the 1970d763cef2SBarry Smith hyphen. 1971d763cef2SBarry Smith 1972d763cef2SBarry Smith Level: advanced 1973d763cef2SBarry Smith 1974d763cef2SBarry Smith .keywords: TS, append, options, prefix, database 1975d763cef2SBarry Smith 1976d763cef2SBarry Smith .seealso: TSGetOptionsPrefix() 1977d763cef2SBarry Smith 1978d763cef2SBarry Smith @*/ 197963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS ts,const char prefix[]) 1980d763cef2SBarry Smith { 1981dfbe8321SBarry Smith PetscErrorCode ierr; 1982d763cef2SBarry Smith 1983d763cef2SBarry Smith PetscFunctionBegin; 19840700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 1985d763cef2SBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 1986d763cef2SBarry Smith switch(ts->problem_type) { 1987d763cef2SBarry Smith case TS_NONLINEAR: 19881ac94b3bSBarry Smith if (ts->snes) { 1989d763cef2SBarry Smith ierr = SNESAppendOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr); 19901ac94b3bSBarry Smith } 1991d763cef2SBarry Smith break; 1992d763cef2SBarry Smith case TS_LINEAR: 19931ac94b3bSBarry Smith if (ts->ksp) { 199494b7f48cSBarry Smith ierr = KSPAppendOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr); 19951ac94b3bSBarry Smith } 1996d763cef2SBarry Smith break; 1997d763cef2SBarry Smith } 1998d763cef2SBarry Smith PetscFunctionReturn(0); 1999d763cef2SBarry Smith } 2000d763cef2SBarry Smith 20014a2ae208SSatish Balay #undef __FUNCT__ 20024a2ae208SSatish Balay #define __FUNCT__ "TSGetOptionsPrefix" 2003d763cef2SBarry Smith /*@C 2004d763cef2SBarry Smith TSGetOptionsPrefix - Sets the prefix used for searching for all 2005d763cef2SBarry Smith TS options in the database. 2006d763cef2SBarry Smith 2007d763cef2SBarry Smith Not Collective 2008d763cef2SBarry Smith 2009d763cef2SBarry Smith Input Parameter: 2010d763cef2SBarry Smith . ts - The TS context 2011d763cef2SBarry Smith 2012d763cef2SBarry Smith Output Parameter: 2013d763cef2SBarry Smith . prefix - A pointer to the prefix string used 2014d763cef2SBarry Smith 2015d763cef2SBarry Smith Notes: On the fortran side, the user should pass in a string 'prifix' of 2016d763cef2SBarry Smith sufficient length to hold the prefix. 2017d763cef2SBarry Smith 2018d763cef2SBarry Smith Level: intermediate 2019d763cef2SBarry Smith 2020d763cef2SBarry Smith .keywords: TS, get, options, prefix, database 2021d763cef2SBarry Smith 2022d763cef2SBarry Smith .seealso: TSAppendOptionsPrefix() 2023d763cef2SBarry Smith @*/ 2024e060cb09SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS ts,const char *prefix[]) 2025d763cef2SBarry Smith { 2026dfbe8321SBarry Smith PetscErrorCode ierr; 2027d763cef2SBarry Smith 2028d763cef2SBarry Smith PetscFunctionBegin; 20290700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 20304482741eSBarry Smith PetscValidPointer(prefix,2); 2031d763cef2SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr); 2032d763cef2SBarry Smith PetscFunctionReturn(0); 2033d763cef2SBarry Smith } 2034d763cef2SBarry Smith 20354a2ae208SSatish Balay #undef __FUNCT__ 20364a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSJacobian" 2037d763cef2SBarry Smith /*@C 2038d763cef2SBarry Smith TSGetRHSJacobian - Returns the Jacobian J at the present timestep. 2039d763cef2SBarry Smith 2040d763cef2SBarry Smith Not Collective, but parallel objects are returned if TS is parallel 2041d763cef2SBarry Smith 2042d763cef2SBarry Smith Input Parameter: 2043d763cef2SBarry Smith . ts - The TS context obtained from TSCreate() 2044d763cef2SBarry Smith 2045d763cef2SBarry Smith Output Parameters: 2046d763cef2SBarry Smith + J - The Jacobian J of F, where U_t = F(U,t) 2047d763cef2SBarry Smith . M - The preconditioner matrix, usually the same as J 2048d763cef2SBarry Smith - ctx - User-defined context for Jacobian evaluation routine 2049d763cef2SBarry Smith 2050d763cef2SBarry Smith Notes: You can pass in PETSC_NULL for any return argument you do not need. 2051d763cef2SBarry Smith 2052d763cef2SBarry Smith Level: intermediate 2053d763cef2SBarry Smith 205426d46c62SHong Zhang .seealso: TSGetTimeStep(), TSGetMatrices(), TSGetTime(), TSGetTimeStepNumber() 2055d763cef2SBarry Smith 2056d763cef2SBarry Smith .keywords: TS, timestep, get, matrix, Jacobian 2057d763cef2SBarry Smith @*/ 205863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS ts,Mat *J,Mat *M,void **ctx) 2059d763cef2SBarry Smith { 2060d763cef2SBarry Smith PetscFunctionBegin; 206126d46c62SHong Zhang if (J) *J = ts->Arhs; 206226d46c62SHong Zhang if (M) *M = ts->B; 206326d46c62SHong Zhang if (ctx) *ctx = ts->jacP; 2064d763cef2SBarry Smith PetscFunctionReturn(0); 2065d763cef2SBarry Smith } 2066d763cef2SBarry Smith 20671713a123SBarry Smith #undef __FUNCT__ 20682eca1d9cSJed Brown #define __FUNCT__ "TSGetIJacobian" 20692eca1d9cSJed Brown /*@C 20702eca1d9cSJed Brown TSGetIJacobian - Returns the implicit Jacobian at the present timestep. 20712eca1d9cSJed Brown 20722eca1d9cSJed Brown Not Collective, but parallel objects are returned if TS is parallel 20732eca1d9cSJed Brown 20742eca1d9cSJed Brown Input Parameter: 20752eca1d9cSJed Brown . ts - The TS context obtained from TSCreate() 20762eca1d9cSJed Brown 20772eca1d9cSJed Brown Output Parameters: 20782eca1d9cSJed Brown + A - The Jacobian of F(t,U,U_t) 20792eca1d9cSJed Brown . B - The preconditioner matrix, often the same as A 20802eca1d9cSJed Brown . f - The function to compute the matrices 20812eca1d9cSJed Brown - ctx - User-defined context for Jacobian evaluation routine 20822eca1d9cSJed Brown 20832eca1d9cSJed Brown Notes: You can pass in PETSC_NULL for any return argument you do not need. 20842eca1d9cSJed Brown 20852eca1d9cSJed Brown Level: advanced 20862eca1d9cSJed Brown 20872eca1d9cSJed Brown .seealso: TSGetTimeStep(), TSGetRHSJacobian(), TSGetMatrices(), TSGetTime(), TSGetTimeStepNumber() 20882eca1d9cSJed Brown 20892eca1d9cSJed Brown .keywords: TS, timestep, get, matrix, Jacobian 20902eca1d9cSJed Brown @*/ 20912eca1d9cSJed Brown PetscErrorCode PETSCTS_DLLEXPORT TSGetIJacobian(TS ts,Mat *A,Mat *B,TSIJacobian *f,void **ctx) 20922eca1d9cSJed Brown { 20932eca1d9cSJed Brown PetscFunctionBegin; 20942eca1d9cSJed Brown if (A) *A = ts->A; 20952eca1d9cSJed Brown if (B) *B = ts->B; 20962eca1d9cSJed Brown if (f) *f = ts->ops->ijacobian; 20972eca1d9cSJed Brown if (ctx) *ctx = ts->jacP; 20982eca1d9cSJed Brown PetscFunctionReturn(0); 20992eca1d9cSJed Brown } 21002eca1d9cSJed Brown 21012eca1d9cSJed Brown #undef __FUNCT__ 2102a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSolution" 21031713a123SBarry Smith /*@C 2104a6570f20SBarry Smith TSMonitorSolution - Monitors progress of the TS solvers by calling 21051713a123SBarry Smith VecView() for the solution at each timestep 21061713a123SBarry Smith 21071713a123SBarry Smith Collective on TS 21081713a123SBarry Smith 21091713a123SBarry Smith Input Parameters: 21101713a123SBarry Smith + ts - the TS context 21111713a123SBarry Smith . step - current time-step 2112142b95e3SSatish Balay . ptime - current time 21131713a123SBarry Smith - dummy - either a viewer or PETSC_NULL 21141713a123SBarry Smith 21151713a123SBarry Smith Level: intermediate 21161713a123SBarry Smith 21171713a123SBarry Smith .keywords: TS, vector, monitor, view 21181713a123SBarry Smith 2119a6570f20SBarry Smith .seealso: TSMonitorSet(), TSMonitorDefault(), VecView() 21201713a123SBarry Smith @*/ 2121a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSolution(TS ts,PetscInt step,PetscReal ptime,Vec x,void *dummy) 21221713a123SBarry Smith { 2123dfbe8321SBarry Smith PetscErrorCode ierr; 21241713a123SBarry Smith PetscViewer viewer = (PetscViewer) dummy; 21251713a123SBarry Smith 21261713a123SBarry Smith PetscFunctionBegin; 2127a34d58ebSBarry Smith if (!dummy) { 21287adad957SLisandro Dalcin viewer = PETSC_VIEWER_DRAW_(((PetscObject)ts)->comm); 21291713a123SBarry Smith } 21301713a123SBarry Smith ierr = VecView(x,viewer);CHKERRQ(ierr); 21311713a123SBarry Smith PetscFunctionReturn(0); 21321713a123SBarry Smith } 21331713a123SBarry Smith 21341713a123SBarry Smith 21356c699258SBarry Smith #undef __FUNCT__ 21366c699258SBarry Smith #define __FUNCT__ "TSSetDM" 21376c699258SBarry Smith /*@ 21386c699258SBarry Smith TSSetDM - Sets the DM that may be used by some preconditioners 21396c699258SBarry Smith 21403f9fe445SBarry Smith Logically Collective on TS and DM 21416c699258SBarry Smith 21426c699258SBarry Smith Input Parameters: 21436c699258SBarry Smith + ts - the preconditioner context 21446c699258SBarry Smith - dm - the dm 21456c699258SBarry Smith 21466c699258SBarry Smith Level: intermediate 21476c699258SBarry Smith 21486c699258SBarry Smith 21496c699258SBarry Smith .seealso: TSGetDM(), SNESSetDM(), SNESGetDM() 21506c699258SBarry Smith @*/ 21516c699258SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSSetDM(TS ts,DM dm) 21526c699258SBarry Smith { 21536c699258SBarry Smith PetscErrorCode ierr; 21546c699258SBarry Smith 21556c699258SBarry Smith PetscFunctionBegin; 21560700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 215770663e4aSLisandro Dalcin ierr = PetscObjectReference((PetscObject)dm);CHKERRQ(ierr); 21586c699258SBarry Smith if (ts->dm) {ierr = DMDestroy(ts->dm);CHKERRQ(ierr);} 21596c699258SBarry Smith ts->dm = dm; 216070663e4aSLisandro Dalcin if (ts->snes) { 216170663e4aSLisandro Dalcin ierr = SNESSetDM(ts->snes,dm);CHKERRQ(ierr); 216270663e4aSLisandro Dalcin } 216370663e4aSLisandro Dalcin if (ts->ksp) { 216470663e4aSLisandro Dalcin ierr = KSPSetDM(ts->ksp,dm);CHKERRQ(ierr); 216570663e4aSLisandro Dalcin ierr = KSPSetDMActive(ts->ksp,PETSC_FALSE);CHKERRQ(ierr); 216670663e4aSLisandro Dalcin } 21676c699258SBarry Smith PetscFunctionReturn(0); 21686c699258SBarry Smith } 21696c699258SBarry Smith 21706c699258SBarry Smith #undef __FUNCT__ 21716c699258SBarry Smith #define __FUNCT__ "TSGetDM" 21726c699258SBarry Smith /*@ 21736c699258SBarry Smith TSGetDM - Gets the DM that may be used by some preconditioners 21746c699258SBarry Smith 21753f9fe445SBarry Smith Not Collective 21766c699258SBarry Smith 21776c699258SBarry Smith Input Parameter: 21786c699258SBarry Smith . ts - the preconditioner context 21796c699258SBarry Smith 21806c699258SBarry Smith Output Parameter: 21816c699258SBarry Smith . dm - the dm 21826c699258SBarry Smith 21836c699258SBarry Smith Level: intermediate 21846c699258SBarry Smith 21856c699258SBarry Smith 21866c699258SBarry Smith .seealso: TSSetDM(), SNESSetDM(), SNESGetDM() 21876c699258SBarry Smith @*/ 21886c699258SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetDM(TS ts,DM *dm) 21896c699258SBarry Smith { 21906c699258SBarry Smith PetscFunctionBegin; 21910700a824SBarry Smith PetscValidHeaderSpecific(ts,TS_CLASSID,1); 21926c699258SBarry Smith *dm = ts->dm; 21936c699258SBarry Smith PetscFunctionReturn(0); 21946c699258SBarry Smith } 21951713a123SBarry Smith 21960f5c6efeSJed Brown #undef __FUNCT__ 21970f5c6efeSJed Brown #define __FUNCT__ "SNESTSFormFunction" 21980f5c6efeSJed Brown /*@ 21990f5c6efeSJed Brown SNESTSFormFunction - Function to evaluate nonlinear residual 22000f5c6efeSJed Brown 22013f9fe445SBarry Smith Logically Collective on SNES 22020f5c6efeSJed Brown 22030f5c6efeSJed Brown Input Parameter: 2204d42a1c89SJed Brown + snes - nonlinear solver 22050f5c6efeSJed Brown . X - the current state at which to evaluate the residual 2206d42a1c89SJed Brown - ctx - user context, must be a TS 22070f5c6efeSJed Brown 22080f5c6efeSJed Brown Output Parameter: 22090f5c6efeSJed Brown . F - the nonlinear residual 22100f5c6efeSJed Brown 22110f5c6efeSJed Brown Notes: 22120f5c6efeSJed Brown This function is not normally called by users and is automatically registered with the SNES used by TS. 22130f5c6efeSJed Brown It is most frequently passed to MatFDColoringSetFunction(). 22140f5c6efeSJed Brown 22150f5c6efeSJed Brown Level: advanced 22160f5c6efeSJed Brown 22170f5c6efeSJed Brown .seealso: SNESSetFunction(), MatFDColoringSetFunction() 22180f5c6efeSJed Brown @*/ 22190f5c6efeSJed Brown PetscErrorCode PETSCTS_DLLEXPORT SNESTSFormFunction(SNES snes,Vec X,Vec F,void *ctx) 22200f5c6efeSJed Brown { 22210f5c6efeSJed Brown TS ts = (TS)ctx; 22220f5c6efeSJed Brown PetscErrorCode ierr; 22230f5c6efeSJed Brown 22240f5c6efeSJed Brown PetscFunctionBegin; 22250f5c6efeSJed Brown PetscValidHeaderSpecific(snes,SNES_CLASSID,1); 22260f5c6efeSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 22270f5c6efeSJed Brown PetscValidHeaderSpecific(F,VEC_CLASSID,3); 22280f5c6efeSJed Brown PetscValidHeaderSpecific(ts,TS_CLASSID,4); 22290f5c6efeSJed Brown ierr = (ts->ops->snesfunction)(snes,X,F,ts);CHKERRQ(ierr); 22300f5c6efeSJed Brown PetscFunctionReturn(0); 22310f5c6efeSJed Brown } 22320f5c6efeSJed Brown 22330f5c6efeSJed Brown #undef __FUNCT__ 22340f5c6efeSJed Brown #define __FUNCT__ "SNESTSFormJacobian" 22350f5c6efeSJed Brown /*@ 22360f5c6efeSJed Brown SNESTSFormJacobian - Function to evaluate the Jacobian 22370f5c6efeSJed Brown 22380f5c6efeSJed Brown Collective on SNES 22390f5c6efeSJed Brown 22400f5c6efeSJed Brown Input Parameter: 22410f5c6efeSJed Brown + snes - nonlinear solver 22420f5c6efeSJed Brown . X - the current state at which to evaluate the residual 22430f5c6efeSJed Brown - ctx - user context, must be a TS 22440f5c6efeSJed Brown 22450f5c6efeSJed Brown Output Parameter: 22460f5c6efeSJed Brown + A - the Jacobian 22470f5c6efeSJed Brown . B - the preconditioning matrix (may be the same as A) 22480f5c6efeSJed Brown - flag - indicates any structure change in the matrix 22490f5c6efeSJed Brown 22500f5c6efeSJed Brown Notes: 22510f5c6efeSJed Brown This function is not normally called by users and is automatically registered with the SNES used by TS. 22520f5c6efeSJed Brown 22530f5c6efeSJed Brown Level: developer 22540f5c6efeSJed Brown 22550f5c6efeSJed Brown .seealso: SNESSetJacobian() 22560f5c6efeSJed Brown @*/ 22570f5c6efeSJed Brown PetscErrorCode PETSCTS_DLLEXPORT SNESTSFormJacobian(SNES snes,Vec X,Mat *A,Mat *B,MatStructure *flag,void *ctx) 22580f5c6efeSJed Brown { 22590f5c6efeSJed Brown TS ts = (TS)ctx; 22600f5c6efeSJed Brown PetscErrorCode ierr; 22610f5c6efeSJed Brown 22620f5c6efeSJed Brown PetscFunctionBegin; 22630f5c6efeSJed Brown PetscValidHeaderSpecific(snes,SNES_CLASSID,1); 22640f5c6efeSJed Brown PetscValidHeaderSpecific(X,VEC_CLASSID,2); 22650f5c6efeSJed Brown PetscValidPointer(A,3); 22660f5c6efeSJed Brown PetscValidHeaderSpecific(*A,MAT_CLASSID,3); 22670f5c6efeSJed Brown PetscValidPointer(B,4); 22680f5c6efeSJed Brown PetscValidHeaderSpecific(*B,MAT_CLASSID,4); 22690f5c6efeSJed Brown PetscValidPointer(flag,5); 22700f5c6efeSJed Brown PetscValidHeaderSpecific(ts,TS_CLASSID,6); 22710f5c6efeSJed Brown ierr = (ts->ops->snesjacobian)(snes,X,A,B,flag,ts);CHKERRQ(ierr); 22720f5c6efeSJed Brown PetscFunctionReturn(0); 22730f5c6efeSJed Brown } 2274