xref: /petsc/src/ts/interface/ts.c (revision 025f1a0480dcff154a24a80c8d03877a2ba7e925)
163dd3a1aSKris Buschelman #define PETSCTS_DLL
263dd3a1aSKris Buschelman 
3b9147fbbSdalcinl #include "include/private/tsimpl.h"        /*I "petscts.h"  I*/
4d763cef2SBarry Smith 
5d5ba7fb7SMatthew Knepley /* Logging support */
663dd3a1aSKris Buschelman PetscCookie PETSCTS_DLLEXPORT TS_COOKIE = 0;
76849ba73SBarry Smith PetscEvent  TS_Step = 0, TS_PseudoComputeTimeStep = 0, TS_FunctionEval = 0, TS_JacobianEval = 0;
8d405a339SMatthew Knepley 
94a2ae208SSatish Balay #undef __FUNCT__
10bdad233fSMatthew Knepley #define __FUNCT__ "TSSetTypeFromOptions"
11bdad233fSMatthew Knepley /*
12bdad233fSMatthew Knepley   TSSetTypeFromOptions - Sets the type of ts from user options.
13bdad233fSMatthew Knepley 
14bdad233fSMatthew Knepley   Collective on TS
15bdad233fSMatthew Knepley 
16bdad233fSMatthew Knepley   Input Parameter:
17bdad233fSMatthew Knepley . ts - The ts
18bdad233fSMatthew Knepley 
19bdad233fSMatthew Knepley   Level: intermediate
20bdad233fSMatthew Knepley 
21bdad233fSMatthew Knepley .keywords: TS, set, options, database, type
22bdad233fSMatthew Knepley .seealso: TSSetFromOptions(), TSSetType()
23bdad233fSMatthew Knepley */
246849ba73SBarry Smith static PetscErrorCode TSSetTypeFromOptions(TS ts)
25bdad233fSMatthew Knepley {
26bdad233fSMatthew Knepley   PetscTruth     opt;
272fc52814SBarry Smith   const char     *defaultType;
28bdad233fSMatthew Knepley   char           typeName[256];
29dfbe8321SBarry Smith   PetscErrorCode ierr;
30bdad233fSMatthew Knepley 
31bdad233fSMatthew Knepley   PetscFunctionBegin;
327adad957SLisandro Dalcin   if (((PetscObject)ts)->type_name) {
337adad957SLisandro Dalcin     defaultType = ((PetscObject)ts)->type_name;
34bdad233fSMatthew Knepley   } else {
35bdad233fSMatthew Knepley     defaultType = TS_EULER;
36bdad233fSMatthew Knepley   }
37bdad233fSMatthew Knepley 
38bdad233fSMatthew Knepley   if (!TSRegisterAllCalled) {
39bdad233fSMatthew Knepley     ierr = TSRegisterAll(PETSC_NULL);CHKERRQ(ierr);
40bdad233fSMatthew Knepley   }
41bdad233fSMatthew Knepley   ierr = PetscOptionsList("-ts_type", "TS method"," TSSetType", TSList, defaultType, typeName, 256, &opt);CHKERRQ(ierr);
42a7cc72afSBarry Smith   if (opt) {
43bdad233fSMatthew Knepley     ierr = TSSetType(ts, typeName);CHKERRQ(ierr);
44bdad233fSMatthew Knepley   } else {
45bdad233fSMatthew Knepley     ierr = TSSetType(ts, defaultType);CHKERRQ(ierr);
46bdad233fSMatthew Knepley   }
47bdad233fSMatthew Knepley   PetscFunctionReturn(0);
48bdad233fSMatthew Knepley }
49bdad233fSMatthew Knepley 
50bdad233fSMatthew Knepley #undef __FUNCT__
51bdad233fSMatthew Knepley #define __FUNCT__ "TSSetFromOptions"
52bdad233fSMatthew Knepley /*@
53bdad233fSMatthew Knepley    TSSetFromOptions - Sets various TS parameters from user options.
54bdad233fSMatthew Knepley 
55bdad233fSMatthew Knepley    Collective on TS
56bdad233fSMatthew Knepley 
57bdad233fSMatthew Knepley    Input Parameter:
58bdad233fSMatthew Knepley .  ts - the TS context obtained from TSCreate()
59bdad233fSMatthew Knepley 
60bdad233fSMatthew Knepley    Options Database Keys:
610f3b3ca1SHong Zhang +  -ts_type <type> - TS_EULER, TS_BEULER, TS_SUNDIALS, TS_PSEUDO, TS_CRANK_NICHOLSON
62bdad233fSMatthew Knepley .  -ts_max_steps maxsteps - maximum number of time-steps to take
63bdad233fSMatthew Knepley .  -ts_max_time time - maximum time to compute to
64bdad233fSMatthew Knepley .  -ts_dt dt - initial time step
65bdad233fSMatthew Knepley .  -ts_monitor - print information at each timestep
66a6570f20SBarry Smith -  -ts_monitor_draw - plot information at each timestep
67bdad233fSMatthew Knepley 
68bdad233fSMatthew Knepley    Level: beginner
69bdad233fSMatthew Knepley 
70bdad233fSMatthew Knepley .keywords: TS, timestep, set, options, database
71bdad233fSMatthew Knepley 
72bdad233fSMatthew Knepley .seealso: TSGetType
73bdad233fSMatthew Knepley @*/
7463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetFromOptions(TS ts)
75bdad233fSMatthew Knepley {
76bdad233fSMatthew Knepley   PetscReal               dt;
77eabae89aSBarry Smith   PetscTruth              opt,flg;
78dfbe8321SBarry Smith   PetscErrorCode          ierr;
79a34d58ebSBarry Smith   PetscViewerASCIIMonitor monviewer;
80eabae89aSBarry Smith   char                    monfilename[PETSC_MAX_PATH_LEN];
81bdad233fSMatthew Knepley 
82bdad233fSMatthew Knepley   PetscFunctionBegin;
834482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
847adad957SLisandro Dalcin   ierr = PetscOptionsBegin(((PetscObject)ts)->comm, ((PetscObject)ts)->prefix, "Time step options", "TS");CHKERRQ(ierr);
85bdad233fSMatthew Knepley 
86bdad233fSMatthew Knepley     /* Handle generic TS options */
87bdad233fSMatthew Knepley     ierr = PetscOptionsInt("-ts_max_steps","Maximum number of time steps","TSSetDuration",ts->max_steps,&ts->max_steps,PETSC_NULL);CHKERRQ(ierr);
88bdad233fSMatthew Knepley     ierr = PetscOptionsReal("-ts_max_time","Time to run to","TSSetDuration",ts->max_time,&ts->max_time,PETSC_NULL);CHKERRQ(ierr);
89bdad233fSMatthew Knepley     ierr = PetscOptionsReal("-ts_init_time","Initial time","TSSetInitialTime", ts->ptime, &ts->ptime, PETSC_NULL);CHKERRQ(ierr);
90bdad233fSMatthew Knepley     ierr = PetscOptionsReal("-ts_dt","Initial time step","TSSetInitialTimeStep",ts->initial_time_step,&dt,&opt);CHKERRQ(ierr);
91a7cc72afSBarry Smith     if (opt) {
92bdad233fSMatthew Knepley       ts->initial_time_step = ts->time_step = dt;
93bdad233fSMatthew Knepley     }
94bdad233fSMatthew Knepley 
95bdad233fSMatthew Knepley     /* Monitor options */
96a6570f20SBarry Smith     ierr = PetscOptionsString("-ts_monitor","Monitor timestep size","TSMonitorDefault","stdout",monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
97eabae89aSBarry Smith     if (flg) {
987adad957SLisandro Dalcin       ierr = PetscViewerASCIIMonitorCreate(((PetscObject)ts)->comm,monfilename,0,&monviewer);CHKERRQ(ierr);
99a34d58ebSBarry Smith       ierr = TSMonitorSet(ts,TSMonitorDefault,monviewer,(PetscErrorCode (*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr);
100bdad233fSMatthew Knepley     }
101a6570f20SBarry Smith     ierr = PetscOptionsName("-ts_monitor_draw","Monitor timestep size graphically","TSMonitorLG",&opt);CHKERRQ(ierr);
102a7cc72afSBarry Smith     if (opt) {
103a6570f20SBarry Smith       ierr = TSMonitorSet(ts,TSMonitorLG,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
104bdad233fSMatthew Knepley     }
105a6570f20SBarry Smith     ierr = PetscOptionsName("-ts_monitor_solution","Monitor solution graphically","TSMonitorSolution",&opt);CHKERRQ(ierr);
106a7cc72afSBarry Smith     if (opt) {
107a6570f20SBarry Smith       ierr = TSMonitorSet(ts,TSMonitorSolution,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
108bdad233fSMatthew Knepley     }
109bdad233fSMatthew Knepley 
110bdad233fSMatthew Knepley     /* Handle TS type options */
111bdad233fSMatthew Knepley     ierr = TSSetTypeFromOptions(ts);CHKERRQ(ierr);
112bdad233fSMatthew Knepley 
113bdad233fSMatthew Knepley     /* Handle specific TS options */
114abc0a331SBarry Smith     if (ts->ops->setfromoptions) {
115bdad233fSMatthew Knepley       ierr = (*ts->ops->setfromoptions)(ts);CHKERRQ(ierr);
116bdad233fSMatthew Knepley     }
117bdad233fSMatthew Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
118bdad233fSMatthew Knepley 
119bdad233fSMatthew Knepley   /* Handle subobject options */
120bdad233fSMatthew Knepley   switch(ts->problem_type) {
121156fc9a6SMatthew Knepley     /* Should check for implicit/explicit */
122bdad233fSMatthew Knepley   case TS_LINEAR:
123abc0a331SBarry Smith     if (ts->ksp) {
1248beb423aSHong Zhang       ierr = KSPSetOperators(ts->ksp,ts->Arhs,ts->B,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
12594b7f48cSBarry Smith       ierr = KSPSetFromOptions(ts->ksp);CHKERRQ(ierr);
126156fc9a6SMatthew Knepley     }
127bdad233fSMatthew Knepley     break;
128bdad233fSMatthew Knepley   case TS_NONLINEAR:
129abc0a331SBarry Smith     if (ts->snes) {
1307c236d22SBarry Smith       /* this is a bit of a hack, but it gets the matrix information into SNES earlier
1317c236d22SBarry Smith          so that SNES and KSP have more information to pick reasonable defaults
1327c236d22SBarry Smith          before they allow users to set options */
1338beb423aSHong Zhang       ierr = SNESSetJacobian(ts->snes,ts->Arhs,ts->B,0,ts);CHKERRQ(ierr);
134bdad233fSMatthew Knepley       ierr = SNESSetFromOptions(ts->snes);CHKERRQ(ierr);
135156fc9a6SMatthew Knepley     }
136bdad233fSMatthew Knepley     break;
137bdad233fSMatthew Knepley   default:
13877431f27SBarry Smith     SETERRQ1(PETSC_ERR_ARG_WRONG, "Invalid problem type: %d", (int)ts->problem_type);
139bdad233fSMatthew Knepley   }
140bdad233fSMatthew Knepley 
141bdad233fSMatthew Knepley   PetscFunctionReturn(0);
142bdad233fSMatthew Knepley }
143bdad233fSMatthew Knepley 
144bdad233fSMatthew Knepley #undef  __FUNCT__
145bdad233fSMatthew Knepley #define __FUNCT__ "TSViewFromOptions"
146bdad233fSMatthew Knepley /*@
147bdad233fSMatthew Knepley   TSViewFromOptions - This function visualizes the ts based upon user options.
148bdad233fSMatthew Knepley 
149bdad233fSMatthew Knepley   Collective on TS
150bdad233fSMatthew Knepley 
151bdad233fSMatthew Knepley   Input Parameter:
152bdad233fSMatthew Knepley . ts - The ts
153bdad233fSMatthew Knepley 
154bdad233fSMatthew Knepley   Level: intermediate
155bdad233fSMatthew Knepley 
156bdad233fSMatthew Knepley .keywords: TS, view, options, database
157bdad233fSMatthew Knepley .seealso: TSSetFromOptions(), TSView()
158bdad233fSMatthew Knepley @*/
15963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSViewFromOptions(TS ts,const char title[])
160bdad233fSMatthew Knepley {
161bdad233fSMatthew Knepley   PetscViewer    viewer;
162bdad233fSMatthew Knepley   PetscDraw      draw;
163bdad233fSMatthew Knepley   PetscTruth     opt;
164e10c49a3SBarry Smith   char           fileName[PETSC_MAX_PATH_LEN];
165dfbe8321SBarry Smith   PetscErrorCode ierr;
166bdad233fSMatthew Knepley 
167bdad233fSMatthew Knepley   PetscFunctionBegin;
1687adad957SLisandro Dalcin   ierr = PetscOptionsGetString(((PetscObject)ts)->prefix, "-ts_view", fileName, PETSC_MAX_PATH_LEN, &opt);CHKERRQ(ierr);
169eabae89aSBarry Smith   if (opt && !PetscPreLoadingOn) {
1707adad957SLisandro Dalcin     ierr = PetscViewerASCIIOpen(((PetscObject)ts)->comm,fileName,&viewer);CHKERRQ(ierr);
171bdad233fSMatthew Knepley     ierr = TSView(ts, viewer);CHKERRQ(ierr);
172bdad233fSMatthew Knepley     ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr);
173bdad233fSMatthew Knepley   }
1747adad957SLisandro Dalcin   ierr = PetscOptionsHasName(((PetscObject)ts)->prefix, "-ts_view_draw", &opt);CHKERRQ(ierr);
175a7cc72afSBarry Smith   if (opt) {
1767adad957SLisandro Dalcin     ierr = PetscViewerDrawOpen(((PetscObject)ts)->comm, 0, 0, 0, 0, 300, 300, &viewer);CHKERRQ(ierr);
177bdad233fSMatthew Knepley     ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);CHKERRQ(ierr);
178a7cc72afSBarry Smith     if (title) {
1791836bdbcSSatish Balay       ierr = PetscDrawSetTitle(draw, (char *)title);CHKERRQ(ierr);
180bdad233fSMatthew Knepley     } else {
181bdad233fSMatthew Knepley       ierr = PetscObjectName((PetscObject)ts);CHKERRQ(ierr);
1827adad957SLisandro Dalcin       ierr = PetscDrawSetTitle(draw, ((PetscObject)ts)->name);CHKERRQ(ierr);
183bdad233fSMatthew Knepley     }
184bdad233fSMatthew Knepley     ierr = TSView(ts, viewer);CHKERRQ(ierr);
185bdad233fSMatthew Knepley     ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
186bdad233fSMatthew Knepley     ierr = PetscDrawPause(draw);CHKERRQ(ierr);
187bdad233fSMatthew Knepley     ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr);
188bdad233fSMatthew Knepley   }
189bdad233fSMatthew Knepley   PetscFunctionReturn(0);
190bdad233fSMatthew Knepley }
191bdad233fSMatthew Knepley 
192bdad233fSMatthew Knepley #undef __FUNCT__
1934a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSJacobian"
194a7a1495cSBarry Smith /*@
1958c385f81SBarry Smith    TSComputeRHSJacobian - Computes the Jacobian matrix that has been
196a7a1495cSBarry Smith       set with TSSetRHSJacobian().
197a7a1495cSBarry Smith 
198a7a1495cSBarry Smith    Collective on TS and Vec
199a7a1495cSBarry Smith 
200a7a1495cSBarry Smith    Input Parameters:
201a7a1495cSBarry Smith +  ts - the SNES context
202a7a1495cSBarry Smith .  t - current timestep
203a7a1495cSBarry Smith -  x - input vector
204a7a1495cSBarry Smith 
205a7a1495cSBarry Smith    Output Parameters:
206a7a1495cSBarry Smith +  A - Jacobian matrix
207a7a1495cSBarry Smith .  B - optional preconditioning matrix
208a7a1495cSBarry Smith -  flag - flag indicating matrix structure
209a7a1495cSBarry Smith 
210a7a1495cSBarry Smith    Notes:
211a7a1495cSBarry Smith    Most users should not need to explicitly call this routine, as it
212a7a1495cSBarry Smith    is used internally within the nonlinear solvers.
213a7a1495cSBarry Smith 
21494b7f48cSBarry Smith    See KSPSetOperators() for important information about setting the
215a7a1495cSBarry Smith    flag parameter.
216a7a1495cSBarry Smith 
217a7a1495cSBarry Smith    TSComputeJacobian() is valid only for TS_NONLINEAR
218a7a1495cSBarry Smith 
219a7a1495cSBarry Smith    Level: developer
220a7a1495cSBarry Smith 
221a7a1495cSBarry Smith .keywords: SNES, compute, Jacobian, matrix
222a7a1495cSBarry Smith 
22394b7f48cSBarry Smith .seealso:  TSSetRHSJacobian(), KSPSetOperators()
224a7a1495cSBarry Smith @*/
22563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSComputeRHSJacobian(TS ts,PetscReal t,Vec X,Mat *A,Mat *B,MatStructure *flg)
226a7a1495cSBarry Smith {
227dfbe8321SBarry Smith   PetscErrorCode ierr;
228a7a1495cSBarry Smith 
229a7a1495cSBarry Smith   PetscFunctionBegin;
2304482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
2314482741eSBarry Smith   PetscValidHeaderSpecific(X,VEC_COOKIE,3);
232c9780b6fSBarry Smith   PetscCheckSameComm(ts,1,X,3);
233a7a1495cSBarry Smith   if (ts->problem_type != TS_NONLINEAR) {
23429bbc08cSBarry Smith     SETERRQ(PETSC_ERR_ARG_WRONG,"For TS_NONLINEAR only");
235a7a1495cSBarry Smith   }
236000e7ae3SMatthew Knepley   if (ts->ops->rhsjacobian) {
237d5ba7fb7SMatthew Knepley     ierr = PetscLogEventBegin(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr);
238a7a1495cSBarry Smith     *flg = DIFFERENT_NONZERO_PATTERN;
239a7a1495cSBarry Smith     PetscStackPush("TS user Jacobian function");
240000e7ae3SMatthew Knepley     ierr = (*ts->ops->rhsjacobian)(ts,t,X,A,B,flg,ts->jacP);CHKERRQ(ierr);
241a7a1495cSBarry Smith     PetscStackPop;
242d5ba7fb7SMatthew Knepley     ierr = PetscLogEventEnd(TS_JacobianEval,ts,X,*A,*B);CHKERRQ(ierr);
243a7a1495cSBarry Smith     /* make sure user returned a correct Jacobian and preconditioner */
2444482741eSBarry Smith     PetscValidHeaderSpecific(*A,MAT_COOKIE,4);
2454482741eSBarry Smith     PetscValidHeaderSpecific(*B,MAT_COOKIE,5);
246ef66eb69SBarry Smith   } else {
247ef66eb69SBarry Smith     ierr = MatAssemblyBegin(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
248ef66eb69SBarry Smith     ierr = MatAssemblyEnd(*A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
249ef66eb69SBarry Smith     if (*A != *B) {
250ef66eb69SBarry Smith       ierr = MatAssemblyBegin(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
251ef66eb69SBarry Smith       ierr = MatAssemblyEnd(*B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
252ef66eb69SBarry Smith     }
253ef66eb69SBarry Smith   }
254a7a1495cSBarry Smith   PetscFunctionReturn(0);
255a7a1495cSBarry Smith }
256a7a1495cSBarry Smith 
2574a2ae208SSatish Balay #undef __FUNCT__
2584a2ae208SSatish Balay #define __FUNCT__ "TSComputeRHSFunction"
259d763cef2SBarry Smith /*
260d763cef2SBarry Smith    TSComputeRHSFunction - Evaluates the right-hand-side function.
261d763cef2SBarry Smith 
262d763cef2SBarry Smith    Note: If the user did not provide a function but merely a matrix,
263d763cef2SBarry Smith    this routine applies the matrix.
264d763cef2SBarry Smith */
265dfbe8321SBarry Smith PetscErrorCode TSComputeRHSFunction(TS ts,PetscReal t,Vec x,Vec y)
266d763cef2SBarry Smith {
267dfbe8321SBarry Smith   PetscErrorCode ierr;
268d763cef2SBarry Smith 
269d763cef2SBarry Smith   PetscFunctionBegin;
2704482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
2714482741eSBarry Smith   PetscValidHeaderSpecific(x,VEC_COOKIE,2);
2724482741eSBarry Smith   PetscValidHeaderSpecific(y,VEC_COOKIE,3);
273d763cef2SBarry Smith 
274d5ba7fb7SMatthew Knepley   ierr = PetscLogEventBegin(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr);
275000e7ae3SMatthew Knepley   if (ts->ops->rhsfunction) {
276d763cef2SBarry Smith     PetscStackPush("TS user right-hand-side function");
277000e7ae3SMatthew Knepley     ierr = (*ts->ops->rhsfunction)(ts,t,x,y,ts->funP);CHKERRQ(ierr);
278d763cef2SBarry Smith     PetscStackPop;
2797c922b88SBarry Smith   } else {
280000e7ae3SMatthew Knepley     if (ts->ops->rhsmatrix) { /* assemble matrix for this timestep */
281d763cef2SBarry Smith       MatStructure flg;
282d763cef2SBarry Smith       PetscStackPush("TS user right-hand-side matrix function");
2838beb423aSHong Zhang       ierr = (*ts->ops->rhsmatrix)(ts,t,&ts->Arhs,&ts->B,&flg,ts->jacP);CHKERRQ(ierr);
284d763cef2SBarry Smith       PetscStackPop;
285d763cef2SBarry Smith     }
2868beb423aSHong Zhang     ierr = MatMult(ts->Arhs,x,y);CHKERRQ(ierr);
2877c922b88SBarry Smith   }
288d763cef2SBarry Smith 
289d5ba7fb7SMatthew Knepley   ierr = PetscLogEventEnd(TS_FunctionEval,ts,x,y,0);CHKERRQ(ierr);
290d763cef2SBarry Smith 
291d763cef2SBarry Smith   PetscFunctionReturn(0);
292d763cef2SBarry Smith }
293d763cef2SBarry Smith 
2944a2ae208SSatish Balay #undef __FUNCT__
2954a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSFunction"
296d763cef2SBarry Smith /*@C
297d763cef2SBarry Smith     TSSetRHSFunction - Sets the routine for evaluating the function,
298d763cef2SBarry Smith     F(t,u), where U_t = F(t,u).
299d763cef2SBarry Smith 
300d763cef2SBarry Smith     Collective on TS
301d763cef2SBarry Smith 
302d763cef2SBarry Smith     Input Parameters:
303d763cef2SBarry Smith +   ts - the TS context obtained from TSCreate()
304d763cef2SBarry Smith .   f - routine for evaluating the right-hand-side function
305d763cef2SBarry Smith -   ctx - [optional] user-defined context for private data for the
306d763cef2SBarry Smith           function evaluation routine (may be PETSC_NULL)
307d763cef2SBarry Smith 
308d763cef2SBarry Smith     Calling sequence of func:
30987828ca2SBarry Smith $     func (TS ts,PetscReal t,Vec u,Vec F,void *ctx);
310d763cef2SBarry Smith 
311d763cef2SBarry Smith +   t - current timestep
312d763cef2SBarry Smith .   u - input vector
313d763cef2SBarry Smith .   F - function vector
314d763cef2SBarry Smith -   ctx - [optional] user-defined function context
315d763cef2SBarry Smith 
316d763cef2SBarry Smith     Important:
31776f2fa84SHong Zhang     The user MUST call either this routine or TSSetMatrices().
318d763cef2SBarry Smith 
319d763cef2SBarry Smith     Level: beginner
320d763cef2SBarry Smith 
321d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, function
322d763cef2SBarry Smith 
32376f2fa84SHong Zhang .seealso: TSSetMatrices()
324d763cef2SBarry Smith @*/
32563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSFunction(TS ts,PetscErrorCode (*f)(TS,PetscReal,Vec,Vec,void*),void *ctx)
326d763cef2SBarry Smith {
327d763cef2SBarry Smith   PetscFunctionBegin;
328d763cef2SBarry Smith 
3294482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
330d763cef2SBarry Smith   if (ts->problem_type == TS_LINEAR) {
33129bbc08cSBarry Smith     SETERRQ(PETSC_ERR_ARG_WRONG,"Cannot set function for linear problem");
332d763cef2SBarry Smith   }
333000e7ae3SMatthew Knepley   ts->ops->rhsfunction = f;
334d763cef2SBarry Smith   ts->funP             = ctx;
335d763cef2SBarry Smith   PetscFunctionReturn(0);
336d763cef2SBarry Smith }
337d763cef2SBarry Smith 
3384a2ae208SSatish Balay #undef __FUNCT__
33995f0b562SHong Zhang #define __FUNCT__ "TSSetMatrices"
34095f0b562SHong Zhang /*@C
34195f0b562SHong Zhang    TSSetMatrices - Sets the functions to compute the matrices Alhs and Arhs,
34295f0b562SHong Zhang    where Alhs(t) U_t = Arhs(t) U.
34395f0b562SHong Zhang 
34495f0b562SHong Zhang    Collective on TS
34595f0b562SHong Zhang 
34695f0b562SHong Zhang    Input Parameters:
34795f0b562SHong Zhang +  ts   - the TS context obtained from TSCreate()
34895f0b562SHong Zhang .  Arhs - matrix
34995f0b562SHong Zhang .  frhs - the matrix evaluation routine for Arhs; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran)
35095f0b562SHong Zhang           if Arhs is not a function of t.
35195f0b562SHong Zhang .  Alhs - matrix or PETSC_NULL if Alhs is an indentity matrix.
35295f0b562SHong Zhang .  flhs - the matrix evaluation routine for Alhs; use PETSC_NULL (PETSC_NULL_FUNCTION in fortran)
35395f0b562SHong Zhang           if Alhs is not a function of t.
35495f0b562SHong Zhang .  flag - flag indicating information about the matrix structure of Arhs and Alhs.
35595f0b562SHong Zhang           The available options are
35695f0b562SHong Zhang             SAME_NONZERO_PATTERN - Alhs has the same nonzero structure as Arhs
35795f0b562SHong Zhang             DIFFERENT_NONZERO_PATTERN - Alhs has different nonzero structure as Arhs
35895f0b562SHong Zhang -  ctx  - [optional] user-defined context for private data for the
35995f0b562SHong Zhang           matrix evaluation routine (may be PETSC_NULL)
36095f0b562SHong Zhang 
36195f0b562SHong Zhang    Calling sequence of func:
36295f0b562SHong Zhang $     func(TS ts,PetscReal t,Mat *A,Mat *B,PetscInt *flag,void *ctx);
36395f0b562SHong Zhang 
36495f0b562SHong Zhang +  t - current timestep
36595f0b562SHong Zhang .  A - matrix A, where U_t = A(t) U
36695f0b562SHong Zhang .  B - preconditioner matrix, usually the same as A
36795f0b562SHong Zhang .  flag - flag indicating information about the preconditioner matrix
36895f0b562SHong Zhang           structure (same as flag in KSPSetOperators())
36995f0b562SHong Zhang -  ctx - [optional] user-defined context for matrix evaluation routine
37095f0b562SHong Zhang 
37195f0b562SHong Zhang    Notes:
37295f0b562SHong Zhang    The routine func() takes Mat* as the matrix arguments rather than Mat.
37395f0b562SHong Zhang    This allows the matrix evaluation routine to replace Arhs or Alhs with a
37495f0b562SHong Zhang    completely new new matrix structure (not just different matrix elements)
37595f0b562SHong Zhang    when appropriate, for instance, if the nonzero structure is changing
37695f0b562SHong Zhang    throughout the global iterations.
37795f0b562SHong Zhang 
37895f0b562SHong Zhang    Important:
37995f0b562SHong Zhang    The user MUST call either this routine or TSSetRHSFunction().
38095f0b562SHong Zhang 
38195f0b562SHong Zhang    Level: beginner
38295f0b562SHong Zhang 
38395f0b562SHong Zhang .keywords: TS, timestep, set, matrix
38495f0b562SHong Zhang 
38595f0b562SHong Zhang .seealso: TSSetRHSFunction()
38695f0b562SHong Zhang @*/
38795f0b562SHong 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)
38895f0b562SHong Zhang {
38995f0b562SHong Zhang   PetscFunctionBegin;
39095f0b562SHong Zhang   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
39192af4f6aSHong Zhang   if (Arhs){
39295f0b562SHong Zhang     PetscValidHeaderSpecific(Arhs,MAT_COOKIE,2);
39395f0b562SHong Zhang     PetscCheckSameComm(ts,1,Arhs,2);
39495f0b562SHong Zhang     ts->Arhs           = Arhs;
39592af4f6aSHong Zhang     ts->ops->rhsmatrix = frhs;
39692af4f6aSHong Zhang   }
39792af4f6aSHong Zhang   if (Alhs){
39892af4f6aSHong Zhang     PetscValidHeaderSpecific(Alhs,MAT_COOKIE,4);
39992af4f6aSHong Zhang     PetscCheckSameComm(ts,1,Alhs,4);
40095f0b562SHong Zhang     ts->Alhs           = Alhs;
40192af4f6aSHong Zhang     ts->ops->lhsmatrix = flhs;
40292af4f6aSHong Zhang   }
40392af4f6aSHong Zhang 
40492af4f6aSHong Zhang   ts->jacP           = ctx;
40595f0b562SHong Zhang   ts->matflg         = flag;
40695f0b562SHong Zhang   PetscFunctionReturn(0);
40795f0b562SHong Zhang }
408d763cef2SBarry Smith 
409aa644b49SHong Zhang #undef __FUNCT__
410cda39b92SHong Zhang #define __FUNCT__ "TSGetMatrices"
411cda39b92SHong Zhang /*@C
412cda39b92SHong Zhang    TSGetMatrices - Returns the matrices Arhs and Alhs at the present timestep,
413cda39b92SHong Zhang    where Alhs(t) U_t = Arhs(t) U.
414cda39b92SHong Zhang 
415cda39b92SHong Zhang    Not Collective, but parallel objects are returned if TS is parallel
416cda39b92SHong Zhang 
417cda39b92SHong Zhang    Input Parameter:
418cda39b92SHong Zhang .  ts  - The TS context obtained from TSCreate()
419cda39b92SHong Zhang 
420cda39b92SHong Zhang    Output Parameters:
421cda39b92SHong Zhang +  Arhs - The right-hand side matrix
422cda39b92SHong Zhang .  Alhs - The left-hand side matrix
423cda39b92SHong Zhang -  ctx - User-defined context for matrix evaluation routine
424cda39b92SHong Zhang 
425cda39b92SHong Zhang    Notes: You can pass in PETSC_NULL for any return argument you do not need.
426cda39b92SHong Zhang 
427cda39b92SHong Zhang    Level: intermediate
428cda39b92SHong Zhang 
429cda39b92SHong Zhang .seealso: TSSetMatrices(), TSGetTimeStep(), TSGetTime(), TSGetTimeStepNumber(), TSGetRHSJacobian()
430cda39b92SHong Zhang 
431cda39b92SHong Zhang .keywords: TS, timestep, get, matrix
432cda39b92SHong Zhang 
433cda39b92SHong Zhang @*/
434cda39b92SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSGetMatrices(TS ts,Mat *Arhs,Mat *Alhs,void **ctx)
435cda39b92SHong Zhang {
436cda39b92SHong Zhang   PetscFunctionBegin;
437cda39b92SHong Zhang   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
438cda39b92SHong Zhang   if (Arhs) *Arhs = ts->Arhs;
439cda39b92SHong Zhang   if (Alhs) *Alhs = ts->Alhs;
440cda39b92SHong Zhang   if (ctx)  *ctx = ts->jacP;
441cda39b92SHong Zhang   PetscFunctionReturn(0);
442cda39b92SHong Zhang }
443cda39b92SHong Zhang 
444cda39b92SHong Zhang #undef __FUNCT__
4454a2ae208SSatish Balay #define __FUNCT__ "TSSetRHSJacobian"
446d763cef2SBarry Smith /*@C
447d763cef2SBarry Smith    TSSetRHSJacobian - Sets the function to compute the Jacobian of F,
448d763cef2SBarry Smith    where U_t = F(U,t), as well as the location to store the matrix.
44976f2fa84SHong Zhang    Use TSSetMatrices() for linear problems.
450d763cef2SBarry Smith 
451d763cef2SBarry Smith    Collective on TS
452d763cef2SBarry Smith 
453d763cef2SBarry Smith    Input Parameters:
454d763cef2SBarry Smith +  ts  - the TS context obtained from TSCreate()
455d763cef2SBarry Smith .  A   - Jacobian matrix
456d763cef2SBarry Smith .  B   - preconditioner matrix (usually same as A)
457d763cef2SBarry Smith .  f   - the Jacobian evaluation routine
458d763cef2SBarry Smith -  ctx - [optional] user-defined context for private data for the
459d763cef2SBarry Smith          Jacobian evaluation routine (may be PETSC_NULL)
460d763cef2SBarry Smith 
461d763cef2SBarry Smith    Calling sequence of func:
46287828ca2SBarry Smith $     func (TS ts,PetscReal t,Vec u,Mat *A,Mat *B,MatStructure *flag,void *ctx);
463d763cef2SBarry Smith 
464d763cef2SBarry Smith +  t - current timestep
465d763cef2SBarry Smith .  u - input vector
466d763cef2SBarry Smith .  A - matrix A, where U_t = A(t)u
467d763cef2SBarry Smith .  B - preconditioner matrix, usually the same as A
468d763cef2SBarry Smith .  flag - flag indicating information about the preconditioner matrix
46994b7f48cSBarry Smith           structure (same as flag in KSPSetOperators())
470d763cef2SBarry Smith -  ctx - [optional] user-defined context for matrix evaluation routine
471d763cef2SBarry Smith 
472d763cef2SBarry Smith    Notes:
47394b7f48cSBarry Smith    See KSPSetOperators() for important information about setting the flag
474d763cef2SBarry Smith    output parameter in the routine func().  Be sure to read this information!
475d763cef2SBarry Smith 
476d763cef2SBarry Smith    The routine func() takes Mat * as the matrix arguments rather than Mat.
477d763cef2SBarry Smith    This allows the matrix evaluation routine to replace A and/or B with a
478d763cef2SBarry Smith    completely new new matrix structure (not just different matrix elements)
479d763cef2SBarry Smith    when appropriate, for instance, if the nonzero structure is changing
480d763cef2SBarry Smith    throughout the global iterations.
481d763cef2SBarry Smith 
482d763cef2SBarry Smith    Level: beginner
483d763cef2SBarry Smith 
484d763cef2SBarry Smith .keywords: TS, timestep, set, right-hand-side, Jacobian
485d763cef2SBarry Smith 
486d763cef2SBarry Smith .seealso: TSDefaultComputeJacobianColor(),
48776f2fa84SHong Zhang           SNESDefaultComputeJacobianColor(), TSSetRHSFunction(), TSSetMatrices()
488d763cef2SBarry Smith 
489d763cef2SBarry Smith @*/
49063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetRHSJacobian(TS ts,Mat A,Mat B,PetscErrorCode (*f)(TS,PetscReal,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
491d763cef2SBarry Smith {
492d763cef2SBarry Smith   PetscFunctionBegin;
4934482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
4944482741eSBarry Smith   PetscValidHeaderSpecific(A,MAT_COOKIE,2);
4954482741eSBarry Smith   PetscValidHeaderSpecific(B,MAT_COOKIE,3);
496c9780b6fSBarry Smith   PetscCheckSameComm(ts,1,A,2);
497c9780b6fSBarry Smith   PetscCheckSameComm(ts,1,B,3);
498d763cef2SBarry Smith   if (ts->problem_type != TS_NONLINEAR) {
49976f2fa84SHong Zhang     SETERRQ(PETSC_ERR_ARG_WRONG,"Not for linear problems; use TSSetMatrices()");
500d763cef2SBarry Smith   }
501d763cef2SBarry Smith 
502000e7ae3SMatthew Knepley   ts->ops->rhsjacobian = f;
503d763cef2SBarry Smith   ts->jacP             = ctx;
5048beb423aSHong Zhang   ts->Arhs             = A;
505d763cef2SBarry Smith   ts->B                = B;
506d763cef2SBarry Smith   PetscFunctionReturn(0);
507d763cef2SBarry Smith }
508d763cef2SBarry Smith 
5094a2ae208SSatish Balay #undef __FUNCT__
5104a2ae208SSatish Balay #define __FUNCT__ "TSView"
5117e2c5f70SBarry Smith /*@C
512d763cef2SBarry Smith     TSView - Prints the TS data structure.
513d763cef2SBarry Smith 
5144c49b128SBarry Smith     Collective on TS
515d763cef2SBarry Smith 
516d763cef2SBarry Smith     Input Parameters:
517d763cef2SBarry Smith +   ts - the TS context obtained from TSCreate()
518d763cef2SBarry Smith -   viewer - visualization context
519d763cef2SBarry Smith 
520d763cef2SBarry Smith     Options Database Key:
521d763cef2SBarry Smith .   -ts_view - calls TSView() at end of TSStep()
522d763cef2SBarry Smith 
523d763cef2SBarry Smith     Notes:
524d763cef2SBarry Smith     The available visualization contexts include
525b0a32e0cSBarry Smith +     PETSC_VIEWER_STDOUT_SELF - standard output (default)
526b0a32e0cSBarry Smith -     PETSC_VIEWER_STDOUT_WORLD - synchronized standard
527d763cef2SBarry Smith          output where only the first processor opens
528d763cef2SBarry Smith          the file.  All other processors send their
529d763cef2SBarry Smith          data to the first processor to print.
530d763cef2SBarry Smith 
531d763cef2SBarry Smith     The user can open an alternative visualization context with
532b0a32e0cSBarry Smith     PetscViewerASCIIOpen() - output to a specified file.
533d763cef2SBarry Smith 
534d763cef2SBarry Smith     Level: beginner
535d763cef2SBarry Smith 
536d763cef2SBarry Smith .keywords: TS, timestep, view
537d763cef2SBarry Smith 
538b0a32e0cSBarry Smith .seealso: PetscViewerASCIIOpen()
539d763cef2SBarry Smith @*/
54063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSView(TS ts,PetscViewer viewer)
541d763cef2SBarry Smith {
542dfbe8321SBarry Smith   PetscErrorCode ierr;
543454a90a3SBarry Smith   char           *type;
54432077d6dSBarry Smith   PetscTruth     iascii,isstring;
545d763cef2SBarry Smith 
546d763cef2SBarry Smith   PetscFunctionBegin;
5474482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
5483050cee2SBarry Smith   if (!viewer) {
5497adad957SLisandro Dalcin     ierr = PetscViewerASCIIGetStdout(((PetscObject)ts)->comm,&viewer);CHKERRQ(ierr);
5503050cee2SBarry Smith   }
5514482741eSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2);
552c9780b6fSBarry Smith   PetscCheckSameComm(ts,1,viewer,2);
553fd16b177SBarry Smith 
55432077d6dSBarry Smith   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr);
555b0a32e0cSBarry Smith   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr);
55632077d6dSBarry Smith   if (iascii) {
557b0a32e0cSBarry Smith     ierr = PetscViewerASCIIPrintf(viewer,"TS Object:\n");CHKERRQ(ierr);
558454a90a3SBarry Smith     ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr);
559454a90a3SBarry Smith     if (type) {
560b0a32e0cSBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  type: %s\n",type);CHKERRQ(ierr);
561184914b5SBarry Smith     } else {
562b0a32e0cSBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  type: not yet set\n");CHKERRQ(ierr);
563184914b5SBarry Smith     }
564000e7ae3SMatthew Knepley     if (ts->ops->view) {
565b0a32e0cSBarry Smith       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
566000e7ae3SMatthew Knepley       ierr = (*ts->ops->view)(ts,viewer);CHKERRQ(ierr);
567b0a32e0cSBarry Smith       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
568d763cef2SBarry Smith     }
56977431f27SBarry Smith     ierr = PetscViewerASCIIPrintf(viewer,"  maximum steps=%D\n",ts->max_steps);CHKERRQ(ierr);
570a83599f4SBarry Smith     ierr = PetscViewerASCIIPrintf(viewer,"  maximum time=%G\n",ts->max_time);CHKERRQ(ierr);
571d763cef2SBarry Smith     if (ts->problem_type == TS_NONLINEAR) {
57277431f27SBarry Smith       ierr = PetscViewerASCIIPrintf(viewer,"  total number of nonlinear solver iterations=%D\n",ts->nonlinear_its);CHKERRQ(ierr);
573d763cef2SBarry Smith     }
57477431f27SBarry Smith     ierr = PetscViewerASCIIPrintf(viewer,"  total number of linear solver iterations=%D\n",ts->linear_its);CHKERRQ(ierr);
5750f5bd95cSBarry Smith   } else if (isstring) {
576454a90a3SBarry Smith     ierr = TSGetType(ts,(TSType *)&type);CHKERRQ(ierr);
577b0a32e0cSBarry Smith     ierr = PetscViewerStringSPrintf(viewer," %-7.7s",type);CHKERRQ(ierr);
578d763cef2SBarry Smith   }
579b0a32e0cSBarry Smith   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
58094b7f48cSBarry Smith   if (ts->ksp) {ierr = KSPView(ts->ksp,viewer);CHKERRQ(ierr);}
581d763cef2SBarry Smith   if (ts->snes) {ierr = SNESView(ts->snes,viewer);CHKERRQ(ierr);}
582b0a32e0cSBarry Smith   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
583d763cef2SBarry Smith   PetscFunctionReturn(0);
584d763cef2SBarry Smith }
585d763cef2SBarry Smith 
586d763cef2SBarry Smith 
5874a2ae208SSatish Balay #undef __FUNCT__
5884a2ae208SSatish Balay #define __FUNCT__ "TSSetApplicationContext"
589d763cef2SBarry Smith /*@C
590d763cef2SBarry Smith    TSSetApplicationContext - Sets an optional user-defined context for
591d763cef2SBarry Smith    the timesteppers.
592d763cef2SBarry Smith 
593d763cef2SBarry Smith    Collective on TS
594d763cef2SBarry Smith 
595d763cef2SBarry Smith    Input Parameters:
596d763cef2SBarry Smith +  ts - the TS context obtained from TSCreate()
597d763cef2SBarry Smith -  usrP - optional user context
598d763cef2SBarry Smith 
599d763cef2SBarry Smith    Level: intermediate
600d763cef2SBarry Smith 
601d763cef2SBarry Smith .keywords: TS, timestep, set, application, context
602d763cef2SBarry Smith 
603d763cef2SBarry Smith .seealso: TSGetApplicationContext()
604d763cef2SBarry Smith @*/
60563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetApplicationContext(TS ts,void *usrP)
606d763cef2SBarry Smith {
607d763cef2SBarry Smith   PetscFunctionBegin;
6084482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
609d763cef2SBarry Smith   ts->user = usrP;
610d763cef2SBarry Smith   PetscFunctionReturn(0);
611d763cef2SBarry Smith }
612d763cef2SBarry Smith 
6134a2ae208SSatish Balay #undef __FUNCT__
6144a2ae208SSatish Balay #define __FUNCT__ "TSGetApplicationContext"
615d763cef2SBarry Smith /*@C
616d763cef2SBarry Smith     TSGetApplicationContext - Gets the user-defined context for the
617d763cef2SBarry Smith     timestepper.
618d763cef2SBarry Smith 
619d763cef2SBarry Smith     Not Collective
620d763cef2SBarry Smith 
621d763cef2SBarry Smith     Input Parameter:
622d763cef2SBarry Smith .   ts - the TS context obtained from TSCreate()
623d763cef2SBarry Smith 
624d763cef2SBarry Smith     Output Parameter:
625d763cef2SBarry Smith .   usrP - user context
626d763cef2SBarry Smith 
627d763cef2SBarry Smith     Level: intermediate
628d763cef2SBarry Smith 
629d763cef2SBarry Smith .keywords: TS, timestep, get, application, context
630d763cef2SBarry Smith 
631d763cef2SBarry Smith .seealso: TSSetApplicationContext()
632d763cef2SBarry Smith @*/
63363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetApplicationContext(TS ts,void **usrP)
634d763cef2SBarry Smith {
635d763cef2SBarry Smith   PetscFunctionBegin;
6364482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
637d763cef2SBarry Smith   *usrP = ts->user;
638d763cef2SBarry Smith   PetscFunctionReturn(0);
639d763cef2SBarry Smith }
640d763cef2SBarry Smith 
6414a2ae208SSatish Balay #undef __FUNCT__
6424a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStepNumber"
643d763cef2SBarry Smith /*@
644d763cef2SBarry Smith    TSGetTimeStepNumber - Gets the current number of timesteps.
645d763cef2SBarry Smith 
646d763cef2SBarry Smith    Not Collective
647d763cef2SBarry Smith 
648d763cef2SBarry Smith    Input Parameter:
649d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
650d763cef2SBarry Smith 
651d763cef2SBarry Smith    Output Parameter:
652d763cef2SBarry Smith .  iter - number steps so far
653d763cef2SBarry Smith 
654d763cef2SBarry Smith    Level: intermediate
655d763cef2SBarry Smith 
656d763cef2SBarry Smith .keywords: TS, timestep, get, iteration, number
657d763cef2SBarry Smith @*/
65863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStepNumber(TS ts,PetscInt* iter)
659d763cef2SBarry Smith {
660d763cef2SBarry Smith   PetscFunctionBegin;
6614482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
6624482741eSBarry Smith   PetscValidIntPointer(iter,2);
663d763cef2SBarry Smith   *iter = ts->steps;
664d763cef2SBarry Smith   PetscFunctionReturn(0);
665d763cef2SBarry Smith }
666d763cef2SBarry Smith 
6674a2ae208SSatish Balay #undef __FUNCT__
6684a2ae208SSatish Balay #define __FUNCT__ "TSSetInitialTimeStep"
669d763cef2SBarry Smith /*@
670d763cef2SBarry Smith    TSSetInitialTimeStep - Sets the initial timestep to be used,
671d763cef2SBarry Smith    as well as the initial time.
672d763cef2SBarry Smith 
673d763cef2SBarry Smith    Collective on TS
674d763cef2SBarry Smith 
675d763cef2SBarry Smith    Input Parameters:
676d763cef2SBarry Smith +  ts - the TS context obtained from TSCreate()
677d763cef2SBarry Smith .  initial_time - the initial time
678d763cef2SBarry Smith -  time_step - the size of the timestep
679d763cef2SBarry Smith 
680d763cef2SBarry Smith    Level: intermediate
681d763cef2SBarry Smith 
682d763cef2SBarry Smith .seealso: TSSetTimeStep(), TSGetTimeStep()
683d763cef2SBarry Smith 
684d763cef2SBarry Smith .keywords: TS, set, initial, timestep
685d763cef2SBarry Smith @*/
68663dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetInitialTimeStep(TS ts,PetscReal initial_time,PetscReal time_step)
687d763cef2SBarry Smith {
688d763cef2SBarry Smith   PetscFunctionBegin;
6894482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
690d763cef2SBarry Smith   ts->time_step         = time_step;
691d763cef2SBarry Smith   ts->initial_time_step = time_step;
692d763cef2SBarry Smith   ts->ptime             = initial_time;
693d763cef2SBarry Smith   PetscFunctionReturn(0);
694d763cef2SBarry Smith }
695d763cef2SBarry Smith 
6964a2ae208SSatish Balay #undef __FUNCT__
6974a2ae208SSatish Balay #define __FUNCT__ "TSSetTimeStep"
698d763cef2SBarry Smith /*@
699d763cef2SBarry Smith    TSSetTimeStep - Allows one to reset the timestep at any time,
700d763cef2SBarry Smith    useful for simple pseudo-timestepping codes.
701d763cef2SBarry Smith 
702d763cef2SBarry Smith    Collective on TS
703d763cef2SBarry Smith 
704d763cef2SBarry Smith    Input Parameters:
705d763cef2SBarry Smith +  ts - the TS context obtained from TSCreate()
706d763cef2SBarry Smith -  time_step - the size of the timestep
707d763cef2SBarry Smith 
708d763cef2SBarry Smith    Level: intermediate
709d763cef2SBarry Smith 
710d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep()
711d763cef2SBarry Smith 
712d763cef2SBarry Smith .keywords: TS, set, timestep
713d763cef2SBarry Smith @*/
71463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetTimeStep(TS ts,PetscReal time_step)
715d763cef2SBarry Smith {
716d763cef2SBarry Smith   PetscFunctionBegin;
7174482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
718d763cef2SBarry Smith   ts->time_step = time_step;
719d763cef2SBarry Smith   PetscFunctionReturn(0);
720d763cef2SBarry Smith }
721d763cef2SBarry Smith 
7224a2ae208SSatish Balay #undef __FUNCT__
7234a2ae208SSatish Balay #define __FUNCT__ "TSGetTimeStep"
724d763cef2SBarry Smith /*@
725d763cef2SBarry Smith    TSGetTimeStep - Gets the current timestep size.
726d763cef2SBarry Smith 
727d763cef2SBarry Smith    Not Collective
728d763cef2SBarry Smith 
729d763cef2SBarry Smith    Input Parameter:
730d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
731d763cef2SBarry Smith 
732d763cef2SBarry Smith    Output Parameter:
733d763cef2SBarry Smith .  dt - the current timestep size
734d763cef2SBarry Smith 
735d763cef2SBarry Smith    Level: intermediate
736d763cef2SBarry Smith 
737d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep()
738d763cef2SBarry Smith 
739d763cef2SBarry Smith .keywords: TS, get, timestep
740d763cef2SBarry Smith @*/
74163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTimeStep(TS ts,PetscReal* dt)
742d763cef2SBarry Smith {
743d763cef2SBarry Smith   PetscFunctionBegin;
7444482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
7454482741eSBarry Smith   PetscValidDoublePointer(dt,2);
746d763cef2SBarry Smith   *dt = ts->time_step;
747d763cef2SBarry Smith   PetscFunctionReturn(0);
748d763cef2SBarry Smith }
749d763cef2SBarry Smith 
7504a2ae208SSatish Balay #undef __FUNCT__
7514a2ae208SSatish Balay #define __FUNCT__ "TSGetSolution"
752d8e5e3e6SSatish Balay /*@
753d763cef2SBarry Smith    TSGetSolution - Returns the solution at the present timestep. It
754d763cef2SBarry Smith    is valid to call this routine inside the function that you are evaluating
755d763cef2SBarry Smith    in order to move to the new timestep. This vector not changed until
756d763cef2SBarry Smith    the solution at the next timestep has been calculated.
757d763cef2SBarry Smith 
758d763cef2SBarry Smith    Not Collective, but Vec returned is parallel if TS is parallel
759d763cef2SBarry Smith 
760d763cef2SBarry Smith    Input Parameter:
761d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
762d763cef2SBarry Smith 
763d763cef2SBarry Smith    Output Parameter:
764d763cef2SBarry Smith .  v - the vector containing the solution
765d763cef2SBarry Smith 
766d763cef2SBarry Smith    Level: intermediate
767d763cef2SBarry Smith 
768d763cef2SBarry Smith .seealso: TSGetTimeStep()
769d763cef2SBarry Smith 
770d763cef2SBarry Smith .keywords: TS, timestep, get, solution
771d763cef2SBarry Smith @*/
77263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSolution(TS ts,Vec *v)
773d763cef2SBarry Smith {
774d763cef2SBarry Smith   PetscFunctionBegin;
7754482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
7764482741eSBarry Smith   PetscValidPointer(v,2);
777d763cef2SBarry Smith   *v = ts->vec_sol_always;
778d763cef2SBarry Smith   PetscFunctionReturn(0);
779d763cef2SBarry Smith }
780d763cef2SBarry Smith 
781bdad233fSMatthew Knepley /* ----- Routines to initialize and destroy a timestepper ---- */
7824a2ae208SSatish Balay #undef __FUNCT__
783bdad233fSMatthew Knepley #define __FUNCT__ "TSSetProblemType"
784d8e5e3e6SSatish Balay /*@
785bdad233fSMatthew Knepley   TSSetProblemType - Sets the type of problem to be solved.
786d763cef2SBarry Smith 
787bdad233fSMatthew Knepley   Not collective
788d763cef2SBarry Smith 
789bdad233fSMatthew Knepley   Input Parameters:
790bdad233fSMatthew Knepley + ts   - The TS
791bdad233fSMatthew Knepley - type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms
792d763cef2SBarry Smith .vb
793d763cef2SBarry Smith          U_t = A U
794d763cef2SBarry Smith          U_t = A(t) U
795d763cef2SBarry Smith          U_t = F(t,U)
796d763cef2SBarry Smith .ve
797d763cef2SBarry Smith 
798d763cef2SBarry Smith    Level: beginner
799d763cef2SBarry Smith 
800bdad233fSMatthew Knepley .keywords: TS, problem type
801bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS
802d763cef2SBarry Smith @*/
80363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetProblemType(TS ts, TSProblemType type)
804a7cc72afSBarry Smith {
805d763cef2SBarry Smith   PetscFunctionBegin;
8064482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
807bdad233fSMatthew Knepley   ts->problem_type = type;
808d763cef2SBarry Smith   PetscFunctionReturn(0);
809d763cef2SBarry Smith }
810d763cef2SBarry Smith 
811bdad233fSMatthew Knepley #undef __FUNCT__
812bdad233fSMatthew Knepley #define __FUNCT__ "TSGetProblemType"
813bdad233fSMatthew Knepley /*@C
814bdad233fSMatthew Knepley   TSGetProblemType - Gets the type of problem to be solved.
815bdad233fSMatthew Knepley 
816bdad233fSMatthew Knepley   Not collective
817bdad233fSMatthew Knepley 
818bdad233fSMatthew Knepley   Input Parameter:
819bdad233fSMatthew Knepley . ts   - The TS
820bdad233fSMatthew Knepley 
821bdad233fSMatthew Knepley   Output Parameter:
822bdad233fSMatthew Knepley . type - One of TS_LINEAR, TS_NONLINEAR where these types refer to problems of the forms
823bdad233fSMatthew Knepley .vb
824bdad233fSMatthew Knepley          U_t = A U
825bdad233fSMatthew Knepley          U_t = A(t) U
826bdad233fSMatthew Knepley          U_t = F(t,U)
827bdad233fSMatthew Knepley .ve
828bdad233fSMatthew Knepley 
829bdad233fSMatthew Knepley    Level: beginner
830bdad233fSMatthew Knepley 
831bdad233fSMatthew Knepley .keywords: TS, problem type
832bdad233fSMatthew Knepley .seealso: TSSetUp(), TSProblemType, TS
833bdad233fSMatthew Knepley @*/
83463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetProblemType(TS ts, TSProblemType *type)
835a7cc72afSBarry Smith {
836bdad233fSMatthew Knepley   PetscFunctionBegin;
8374482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
8384482741eSBarry Smith   PetscValidIntPointer(type,2);
839bdad233fSMatthew Knepley   *type = ts->problem_type;
840bdad233fSMatthew Knepley   PetscFunctionReturn(0);
841bdad233fSMatthew Knepley }
842d763cef2SBarry Smith 
8434a2ae208SSatish Balay #undef __FUNCT__
8444a2ae208SSatish Balay #define __FUNCT__ "TSSetUp"
845d763cef2SBarry Smith /*@
846d763cef2SBarry Smith    TSSetUp - Sets up the internal data structures for the later use
847d763cef2SBarry Smith    of a timestepper.
848d763cef2SBarry Smith 
849d763cef2SBarry Smith    Collective on TS
850d763cef2SBarry Smith 
851d763cef2SBarry Smith    Input Parameter:
852d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
853d763cef2SBarry Smith 
854d763cef2SBarry Smith    Notes:
855d763cef2SBarry Smith    For basic use of the TS solvers the user need not explicitly call
856d763cef2SBarry Smith    TSSetUp(), since these actions will automatically occur during
857d763cef2SBarry Smith    the call to TSStep().  However, if one wishes to control this
858d763cef2SBarry Smith    phase separately, TSSetUp() should be called after TSCreate()
859d763cef2SBarry Smith    and optional routines of the form TSSetXXX(), but before TSStep().
860d763cef2SBarry Smith 
861d763cef2SBarry Smith    Level: advanced
862d763cef2SBarry Smith 
863d763cef2SBarry Smith .keywords: TS, timestep, setup
864d763cef2SBarry Smith 
865d763cef2SBarry Smith .seealso: TSCreate(), TSStep(), TSDestroy()
866d763cef2SBarry Smith @*/
86763dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUp(TS ts)
868d763cef2SBarry Smith {
869dfbe8321SBarry Smith   PetscErrorCode ierr;
870d763cef2SBarry Smith 
871d763cef2SBarry Smith   PetscFunctionBegin;
8724482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
87329bbc08cSBarry Smith   if (!ts->vec_sol) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call TSSetSolution() first");
8747adad957SLisandro Dalcin   if (!((PetscObject)ts)->type_name) {
875d763cef2SBarry Smith     ierr = TSSetType(ts,TS_EULER);CHKERRQ(ierr);
876d763cef2SBarry Smith   }
877000e7ae3SMatthew Knepley   ierr = (*ts->ops->setup)(ts);CHKERRQ(ierr);
878d763cef2SBarry Smith   ts->setupcalled = 1;
879d763cef2SBarry Smith   PetscFunctionReturn(0);
880d763cef2SBarry Smith }
881d763cef2SBarry Smith 
8824a2ae208SSatish Balay #undef __FUNCT__
8834a2ae208SSatish Balay #define __FUNCT__ "TSDestroy"
884d8e5e3e6SSatish Balay /*@
885d763cef2SBarry Smith    TSDestroy - Destroys the timestepper context that was created
886d763cef2SBarry Smith    with TSCreate().
887d763cef2SBarry Smith 
888d763cef2SBarry Smith    Collective on TS
889d763cef2SBarry Smith 
890d763cef2SBarry Smith    Input Parameter:
891d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
892d763cef2SBarry Smith 
893d763cef2SBarry Smith    Level: beginner
894d763cef2SBarry Smith 
895d763cef2SBarry Smith .keywords: TS, timestepper, destroy
896d763cef2SBarry Smith 
897d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSSolve()
898d763cef2SBarry Smith @*/
89963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDestroy(TS ts)
900d763cef2SBarry Smith {
9016849ba73SBarry Smith   PetscErrorCode ierr;
902d763cef2SBarry Smith 
903d763cef2SBarry Smith   PetscFunctionBegin;
9044482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
9057adad957SLisandro Dalcin   if (--((PetscObject)ts)->refct > 0) PetscFunctionReturn(0);
906d763cef2SBarry Smith 
907be0abb6dSBarry Smith   /* if memory was published with AMS then destroy it */
9080f5bd95cSBarry Smith   ierr = PetscObjectDepublish(ts);CHKERRQ(ierr);
9098beb423aSHong Zhang   if (ts->A) {ierr = MatDestroy(ts->A);CHKERRQ(ierr)}
91094b7f48cSBarry Smith   if (ts->ksp) {ierr = KSPDestroy(ts->ksp);CHKERRQ(ierr);}
911d763cef2SBarry Smith   if (ts->snes) {ierr = SNESDestroy(ts->snes);CHKERRQ(ierr);}
9121e3347e8SBarry Smith   if (ts->ops->destroy) {ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);}
913a6570f20SBarry Smith   ierr = TSMonitorCancel(ts);CHKERRQ(ierr);
914a79aaaedSSatish Balay   ierr = PetscHeaderDestroy(ts);CHKERRQ(ierr);
915d763cef2SBarry Smith   PetscFunctionReturn(0);
916d763cef2SBarry Smith }
917d763cef2SBarry Smith 
9184a2ae208SSatish Balay #undef __FUNCT__
9194a2ae208SSatish Balay #define __FUNCT__ "TSGetSNES"
920d8e5e3e6SSatish Balay /*@
921d763cef2SBarry Smith    TSGetSNES - Returns the SNES (nonlinear solver) associated with
922d763cef2SBarry Smith    a TS (timestepper) context. Valid only for nonlinear problems.
923d763cef2SBarry Smith 
924d763cef2SBarry Smith    Not Collective, but SNES is parallel if TS is parallel
925d763cef2SBarry Smith 
926d763cef2SBarry Smith    Input Parameter:
927d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
928d763cef2SBarry Smith 
929d763cef2SBarry Smith    Output Parameter:
930d763cef2SBarry Smith .  snes - the nonlinear solver context
931d763cef2SBarry Smith 
932d763cef2SBarry Smith    Notes:
933d763cef2SBarry Smith    The user can then directly manipulate the SNES context to set various
934d763cef2SBarry Smith    options, etc.  Likewise, the user can then extract and manipulate the
93594b7f48cSBarry Smith    KSP, KSP, and PC contexts as well.
936d763cef2SBarry Smith 
937d763cef2SBarry Smith    TSGetSNES() does not work for integrators that do not use SNES; in
938d763cef2SBarry Smith    this case TSGetSNES() returns PETSC_NULL in snes.
939d763cef2SBarry Smith 
940d763cef2SBarry Smith    Level: beginner
941d763cef2SBarry Smith 
942d763cef2SBarry Smith .keywords: timestep, get, SNES
943d763cef2SBarry Smith @*/
94463dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetSNES(TS ts,SNES *snes)
945d763cef2SBarry Smith {
946d763cef2SBarry Smith   PetscFunctionBegin;
9474482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
9484482741eSBarry Smith   PetscValidPointer(snes,2);
94994b7f48cSBarry Smith   if (ts->problem_type == TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Nonlinear only; use TSGetKSP()");
950d763cef2SBarry Smith   *snes = ts->snes;
951d763cef2SBarry Smith   PetscFunctionReturn(0);
952d763cef2SBarry Smith }
953d763cef2SBarry Smith 
9544a2ae208SSatish Balay #undef __FUNCT__
95594b7f48cSBarry Smith #define __FUNCT__ "TSGetKSP"
956d8e5e3e6SSatish Balay /*@
95794b7f48cSBarry Smith    TSGetKSP - Returns the KSP (linear solver) associated with
958d763cef2SBarry Smith    a TS (timestepper) context.
959d763cef2SBarry Smith 
96094b7f48cSBarry Smith    Not Collective, but KSP is parallel if TS is parallel
961d763cef2SBarry Smith 
962d763cef2SBarry Smith    Input Parameter:
963d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
964d763cef2SBarry Smith 
965d763cef2SBarry Smith    Output Parameter:
96694b7f48cSBarry Smith .  ksp - the nonlinear solver context
967d763cef2SBarry Smith 
968d763cef2SBarry Smith    Notes:
96994b7f48cSBarry Smith    The user can then directly manipulate the KSP context to set various
970d763cef2SBarry Smith    options, etc.  Likewise, the user can then extract and manipulate the
971d763cef2SBarry Smith    KSP and PC contexts as well.
972d763cef2SBarry Smith 
97394b7f48cSBarry Smith    TSGetKSP() does not work for integrators that do not use KSP;
97494b7f48cSBarry Smith    in this case TSGetKSP() returns PETSC_NULL in ksp.
975d763cef2SBarry Smith 
976d763cef2SBarry Smith    Level: beginner
977d763cef2SBarry Smith 
97894b7f48cSBarry Smith .keywords: timestep, get, KSP
979d763cef2SBarry Smith @*/
98063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetKSP(TS ts,KSP *ksp)
981d763cef2SBarry Smith {
982d763cef2SBarry Smith   PetscFunctionBegin;
9834482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
9844482741eSBarry Smith   PetscValidPointer(ksp,2);
98529bbc08cSBarry Smith   if (ts->problem_type != TS_LINEAR) SETERRQ(PETSC_ERR_ARG_WRONG,"Linear only; use TSGetSNES()");
98694b7f48cSBarry Smith   *ksp = ts->ksp;
987d763cef2SBarry Smith   PetscFunctionReturn(0);
988d763cef2SBarry Smith }
989d763cef2SBarry Smith 
990d763cef2SBarry Smith /* ----------- Routines to set solver parameters ---------- */
991d763cef2SBarry Smith 
9924a2ae208SSatish Balay #undef __FUNCT__
993adb62b0dSMatthew Knepley #define __FUNCT__ "TSGetDuration"
994adb62b0dSMatthew Knepley /*@
995adb62b0dSMatthew Knepley    TSGetDuration - Gets the maximum number of timesteps to use and
996adb62b0dSMatthew Knepley    maximum time for iteration.
997adb62b0dSMatthew Knepley 
998adb62b0dSMatthew Knepley    Collective on TS
999adb62b0dSMatthew Knepley 
1000adb62b0dSMatthew Knepley    Input Parameters:
1001adb62b0dSMatthew Knepley +  ts       - the TS context obtained from TSCreate()
1002adb62b0dSMatthew Knepley .  maxsteps - maximum number of iterations to use, or PETSC_NULL
1003adb62b0dSMatthew Knepley -  maxtime  - final time to iterate to, or PETSC_NULL
1004adb62b0dSMatthew Knepley 
1005adb62b0dSMatthew Knepley    Level: intermediate
1006adb62b0dSMatthew Knepley 
1007adb62b0dSMatthew Knepley .keywords: TS, timestep, get, maximum, iterations, time
1008adb62b0dSMatthew Knepley @*/
100963dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetDuration(TS ts, PetscInt *maxsteps, PetscReal *maxtime)
1010adb62b0dSMatthew Knepley {
1011adb62b0dSMatthew Knepley   PetscFunctionBegin;
10124482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
1013abc0a331SBarry Smith   if (maxsteps) {
10144482741eSBarry Smith     PetscValidIntPointer(maxsteps,2);
1015adb62b0dSMatthew Knepley     *maxsteps = ts->max_steps;
1016adb62b0dSMatthew Knepley   }
1017abc0a331SBarry Smith   if (maxtime ) {
10184482741eSBarry Smith     PetscValidScalarPointer(maxtime,3);
1019adb62b0dSMatthew Knepley     *maxtime  = ts->max_time;
1020adb62b0dSMatthew Knepley   }
1021adb62b0dSMatthew Knepley   PetscFunctionReturn(0);
1022adb62b0dSMatthew Knepley }
1023adb62b0dSMatthew Knepley 
1024adb62b0dSMatthew Knepley #undef __FUNCT__
10254a2ae208SSatish Balay #define __FUNCT__ "TSSetDuration"
1026d763cef2SBarry Smith /*@
1027d763cef2SBarry Smith    TSSetDuration - Sets the maximum number of timesteps to use and
1028d763cef2SBarry Smith    maximum time for iteration.
1029d763cef2SBarry Smith 
1030d763cef2SBarry Smith    Collective on TS
1031d763cef2SBarry Smith 
1032d763cef2SBarry Smith    Input Parameters:
1033d763cef2SBarry Smith +  ts - the TS context obtained from TSCreate()
1034d763cef2SBarry Smith .  maxsteps - maximum number of iterations to use
1035d763cef2SBarry Smith -  maxtime - final time to iterate to
1036d763cef2SBarry Smith 
1037d763cef2SBarry Smith    Options Database Keys:
1038d763cef2SBarry Smith .  -ts_max_steps <maxsteps> - Sets maxsteps
1039d763cef2SBarry Smith .  -ts_max_time <maxtime> - Sets maxtime
1040d763cef2SBarry Smith 
1041d763cef2SBarry Smith    Notes:
1042d763cef2SBarry Smith    The default maximum number of iterations is 5000. Default time is 5.0
1043d763cef2SBarry Smith 
1044d763cef2SBarry Smith    Level: intermediate
1045d763cef2SBarry Smith 
1046d763cef2SBarry Smith .keywords: TS, timestep, set, maximum, iterations
1047d763cef2SBarry Smith @*/
104863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetDuration(TS ts,PetscInt maxsteps,PetscReal maxtime)
1049d763cef2SBarry Smith {
1050d763cef2SBarry Smith   PetscFunctionBegin;
10514482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
1052d763cef2SBarry Smith   ts->max_steps = maxsteps;
1053d763cef2SBarry Smith   ts->max_time  = maxtime;
1054d763cef2SBarry Smith   PetscFunctionReturn(0);
1055d763cef2SBarry Smith }
1056d763cef2SBarry Smith 
10574a2ae208SSatish Balay #undef __FUNCT__
10584a2ae208SSatish Balay #define __FUNCT__ "TSSetSolution"
1059d763cef2SBarry Smith /*@
1060d763cef2SBarry Smith    TSSetSolution - Sets the initial solution vector
1061d763cef2SBarry Smith    for use by the TS routines.
1062d763cef2SBarry Smith 
1063d763cef2SBarry Smith    Collective on TS and Vec
1064d763cef2SBarry Smith 
1065d763cef2SBarry Smith    Input Parameters:
1066d763cef2SBarry Smith +  ts - the TS context obtained from TSCreate()
1067d763cef2SBarry Smith -  x - the solution vector
1068d763cef2SBarry Smith 
1069d763cef2SBarry Smith    Level: beginner
1070d763cef2SBarry Smith 
1071d763cef2SBarry Smith .keywords: TS, timestep, set, solution, initial conditions
1072d763cef2SBarry Smith @*/
107363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetSolution(TS ts,Vec x)
1074d763cef2SBarry Smith {
1075d763cef2SBarry Smith   PetscFunctionBegin;
10764482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
10774482741eSBarry Smith   PetscValidHeaderSpecific(x,VEC_COOKIE,2);
1078d763cef2SBarry Smith   ts->vec_sol        = ts->vec_sol_always = x;
1079d763cef2SBarry Smith   PetscFunctionReturn(0);
1080d763cef2SBarry Smith }
1081d763cef2SBarry Smith 
1082e74ef692SMatthew Knepley #undef __FUNCT__
1083e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPreStep"
1084ac226902SBarry Smith /*@C
1085000e7ae3SMatthew Knepley   TSSetPreStep - Sets the general-purpose function
1086000e7ae3SMatthew Knepley   called once at the beginning of time stepping.
1087000e7ae3SMatthew Knepley 
1088000e7ae3SMatthew Knepley   Collective on TS
1089000e7ae3SMatthew Knepley 
1090000e7ae3SMatthew Knepley   Input Parameters:
1091000e7ae3SMatthew Knepley + ts   - The TS context obtained from TSCreate()
1092000e7ae3SMatthew Knepley - func - The function
1093000e7ae3SMatthew Knepley 
1094000e7ae3SMatthew Knepley   Calling sequence of func:
1095000e7ae3SMatthew Knepley . func (TS ts);
1096000e7ae3SMatthew Knepley 
1097000e7ae3SMatthew Knepley   Level: intermediate
1098000e7ae3SMatthew Knepley 
1099000e7ae3SMatthew Knepley .keywords: TS, timestep
1100000e7ae3SMatthew Knepley @*/
110163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPreStep(TS ts, PetscErrorCode (*func)(TS))
1102000e7ae3SMatthew Knepley {
1103000e7ae3SMatthew Knepley   PetscFunctionBegin;
11044482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
1105000e7ae3SMatthew Knepley   ts->ops->prestep = func;
1106000e7ae3SMatthew Knepley   PetscFunctionReturn(0);
1107000e7ae3SMatthew Knepley }
1108000e7ae3SMatthew Knepley 
1109e74ef692SMatthew Knepley #undef __FUNCT__
1110e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPreStep"
1111000e7ae3SMatthew Knepley /*@
1112000e7ae3SMatthew Knepley   TSDefaultPreStep - The default pre-stepping function which does nothing.
1113000e7ae3SMatthew Knepley 
1114000e7ae3SMatthew Knepley   Collective on TS
1115000e7ae3SMatthew Knepley 
1116000e7ae3SMatthew Knepley   Input Parameters:
1117000e7ae3SMatthew Knepley . ts  - The TS context obtained from TSCreate()
1118000e7ae3SMatthew Knepley 
1119000e7ae3SMatthew Knepley   Level: developer
1120000e7ae3SMatthew Knepley 
1121000e7ae3SMatthew Knepley .keywords: TS, timestep
1122000e7ae3SMatthew Knepley @*/
112363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPreStep(TS ts)
1124000e7ae3SMatthew Knepley {
1125000e7ae3SMatthew Knepley   PetscFunctionBegin;
1126000e7ae3SMatthew Knepley   PetscFunctionReturn(0);
1127000e7ae3SMatthew Knepley }
1128000e7ae3SMatthew Knepley 
1129e74ef692SMatthew Knepley #undef __FUNCT__
1130e74ef692SMatthew Knepley #define __FUNCT__ "TSSetUpdate"
1131ac226902SBarry Smith /*@C
1132000e7ae3SMatthew Knepley   TSSetUpdate - Sets the general-purpose update function called
1133000e7ae3SMatthew Knepley   at the beginning of every time step. This function can change
1134000e7ae3SMatthew Knepley   the time step.
1135000e7ae3SMatthew Knepley 
1136000e7ae3SMatthew Knepley   Collective on TS
1137000e7ae3SMatthew Knepley 
1138000e7ae3SMatthew Knepley   Input Parameters:
1139000e7ae3SMatthew Knepley + ts   - The TS context obtained from TSCreate()
1140000e7ae3SMatthew Knepley - func - The function
1141000e7ae3SMatthew Knepley 
1142000e7ae3SMatthew Knepley   Calling sequence of func:
1143000e7ae3SMatthew Knepley . func (TS ts, double t, double *dt);
1144000e7ae3SMatthew Knepley 
1145000e7ae3SMatthew Knepley + t   - The current time
1146000e7ae3SMatthew Knepley - dt  - The current time step
1147000e7ae3SMatthew Knepley 
1148000e7ae3SMatthew Knepley   Level: intermediate
1149000e7ae3SMatthew Knepley 
1150000e7ae3SMatthew Knepley .keywords: TS, update, timestep
1151000e7ae3SMatthew Knepley @*/
115263dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetUpdate(TS ts, PetscErrorCode (*func)(TS, PetscReal, PetscReal *))
1153000e7ae3SMatthew Knepley {
1154000e7ae3SMatthew Knepley   PetscFunctionBegin;
11554482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
1156000e7ae3SMatthew Knepley   ts->ops->update = func;
1157000e7ae3SMatthew Knepley   PetscFunctionReturn(0);
1158000e7ae3SMatthew Knepley }
1159000e7ae3SMatthew Knepley 
1160e74ef692SMatthew Knepley #undef __FUNCT__
1161e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultUpdate"
1162000e7ae3SMatthew Knepley /*@
1163000e7ae3SMatthew Knepley   TSDefaultUpdate - The default update function which does nothing.
1164000e7ae3SMatthew Knepley 
1165000e7ae3SMatthew Knepley   Collective on TS
1166000e7ae3SMatthew Knepley 
1167000e7ae3SMatthew Knepley   Input Parameters:
1168000e7ae3SMatthew Knepley + ts  - The TS context obtained from TSCreate()
1169000e7ae3SMatthew Knepley - t   - The current time
1170000e7ae3SMatthew Knepley 
1171000e7ae3SMatthew Knepley   Output Parameters:
1172000e7ae3SMatthew Knepley . dt  - The current time step
1173000e7ae3SMatthew Knepley 
1174000e7ae3SMatthew Knepley   Level: developer
1175000e7ae3SMatthew Knepley 
1176000e7ae3SMatthew Knepley .keywords: TS, update, timestep
1177000e7ae3SMatthew Knepley @*/
117863dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultUpdate(TS ts, PetscReal t, PetscReal *dt)
1179000e7ae3SMatthew Knepley {
1180000e7ae3SMatthew Knepley   PetscFunctionBegin;
1181000e7ae3SMatthew Knepley   PetscFunctionReturn(0);
1182000e7ae3SMatthew Knepley }
1183000e7ae3SMatthew Knepley 
1184e74ef692SMatthew Knepley #undef __FUNCT__
1185e74ef692SMatthew Knepley #define __FUNCT__ "TSSetPostStep"
1186ac226902SBarry Smith /*@C
1187000e7ae3SMatthew Knepley   TSSetPostStep - Sets the general-purpose function
1188000e7ae3SMatthew Knepley   called once at the end of time stepping.
1189000e7ae3SMatthew Knepley 
1190000e7ae3SMatthew Knepley   Collective on TS
1191000e7ae3SMatthew Knepley 
1192000e7ae3SMatthew Knepley   Input Parameters:
1193000e7ae3SMatthew Knepley + ts   - The TS context obtained from TSCreate()
1194000e7ae3SMatthew Knepley - func - The function
1195000e7ae3SMatthew Knepley 
1196000e7ae3SMatthew Knepley   Calling sequence of func:
1197000e7ae3SMatthew Knepley . func (TS ts);
1198000e7ae3SMatthew Knepley 
1199000e7ae3SMatthew Knepley   Level: intermediate
1200000e7ae3SMatthew Knepley 
1201000e7ae3SMatthew Knepley .keywords: TS, timestep
1202000e7ae3SMatthew Knepley @*/
120363dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetPostStep(TS ts, PetscErrorCode (*func)(TS))
1204000e7ae3SMatthew Knepley {
1205000e7ae3SMatthew Knepley   PetscFunctionBegin;
12064482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
1207000e7ae3SMatthew Knepley   ts->ops->poststep = func;
1208000e7ae3SMatthew Knepley   PetscFunctionReturn(0);
1209000e7ae3SMatthew Knepley }
1210000e7ae3SMatthew Knepley 
1211e74ef692SMatthew Knepley #undef __FUNCT__
1212e74ef692SMatthew Knepley #define __FUNCT__ "TSDefaultPostStep"
1213000e7ae3SMatthew Knepley /*@
1214000e7ae3SMatthew Knepley   TSDefaultPostStep - The default post-stepping function which does nothing.
1215000e7ae3SMatthew Knepley 
1216000e7ae3SMatthew Knepley   Collective on TS
1217000e7ae3SMatthew Knepley 
1218000e7ae3SMatthew Knepley   Input Parameters:
1219000e7ae3SMatthew Knepley . ts  - The TS context obtained from TSCreate()
1220000e7ae3SMatthew Knepley 
1221000e7ae3SMatthew Knepley   Level: developer
1222000e7ae3SMatthew Knepley 
1223000e7ae3SMatthew Knepley .keywords: TS, timestep
1224000e7ae3SMatthew Knepley @*/
122563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSDefaultPostStep(TS ts)
1226000e7ae3SMatthew Knepley {
1227000e7ae3SMatthew Knepley   PetscFunctionBegin;
1228000e7ae3SMatthew Knepley   PetscFunctionReturn(0);
1229000e7ae3SMatthew Knepley }
1230000e7ae3SMatthew Knepley 
1231d763cef2SBarry Smith /* ------------ Routines to set performance monitoring options ----------- */
1232d763cef2SBarry Smith 
12334a2ae208SSatish Balay #undef __FUNCT__
1234a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSet"
1235d763cef2SBarry Smith /*@C
1236a6570f20SBarry Smith    TSMonitorSet - Sets an ADDITIONAL function that is to be used at every
1237d763cef2SBarry Smith    timestep to display the iteration's  progress.
1238d763cef2SBarry Smith 
1239d763cef2SBarry Smith    Collective on TS
1240d763cef2SBarry Smith 
1241d763cef2SBarry Smith    Input Parameters:
1242d763cef2SBarry Smith +  ts - the TS context obtained from TSCreate()
1243d763cef2SBarry Smith .  func - monitoring routine
1244329f5518SBarry Smith .  mctx - [optional] user-defined context for private data for the
1245b3006f0bSLois Curfman McInnes              monitor routine (use PETSC_NULL if no context is desired)
1246b3006f0bSLois Curfman McInnes -  monitordestroy - [optional] routine that frees monitor context
1247b3006f0bSLois Curfman McInnes           (may be PETSC_NULL)
1248d763cef2SBarry Smith 
1249d763cef2SBarry Smith    Calling sequence of func:
1250a7cc72afSBarry Smith $    int func(TS ts,PetscInt steps,PetscReal time,Vec x,void *mctx)
1251d763cef2SBarry Smith 
1252d763cef2SBarry Smith +    ts - the TS context
1253d763cef2SBarry Smith .    steps - iteration number
12541f06c33eSBarry Smith .    time - current time
1255d763cef2SBarry Smith .    x - current iterate
1256d763cef2SBarry Smith -    mctx - [optional] monitoring context
1257d763cef2SBarry Smith 
1258d763cef2SBarry Smith    Notes:
1259d763cef2SBarry Smith    This routine adds an additional monitor to the list of monitors that
1260d763cef2SBarry Smith    already has been loaded.
1261d763cef2SBarry Smith 
1262*025f1a04SBarry Smith    Fortran notes: Only a single monitor function can be set for each TS object
1263*025f1a04SBarry Smith 
1264d763cef2SBarry Smith    Level: intermediate
1265d763cef2SBarry Smith 
1266d763cef2SBarry Smith .keywords: TS, timestep, set, monitor
1267d763cef2SBarry Smith 
1268a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorCancel()
1269d763cef2SBarry Smith @*/
1270a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSet(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void*))
1271d763cef2SBarry Smith {
1272d763cef2SBarry Smith   PetscFunctionBegin;
12734482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
1274d763cef2SBarry Smith   if (ts->numbermonitors >= MAXTSMONITORS) {
127529bbc08cSBarry Smith     SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Too many monitors set");
1276d763cef2SBarry Smith   }
1277d763cef2SBarry Smith   ts->monitor[ts->numbermonitors]           = monitor;
1278329f5518SBarry Smith   ts->mdestroy[ts->numbermonitors]          = mdestroy;
1279d763cef2SBarry Smith   ts->monitorcontext[ts->numbermonitors++]  = (void*)mctx;
1280d763cef2SBarry Smith   PetscFunctionReturn(0);
1281d763cef2SBarry Smith }
1282d763cef2SBarry Smith 
12834a2ae208SSatish Balay #undef __FUNCT__
1284a6570f20SBarry Smith #define __FUNCT__ "TSMonitorCancel"
1285d763cef2SBarry Smith /*@C
1286a6570f20SBarry Smith    TSMonitorCancel - Clears all the monitors that have been set on a time-step object.
1287d763cef2SBarry Smith 
1288d763cef2SBarry Smith    Collective on TS
1289d763cef2SBarry Smith 
1290d763cef2SBarry Smith    Input Parameters:
1291d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
1292d763cef2SBarry Smith 
1293d763cef2SBarry Smith    Notes:
1294d763cef2SBarry Smith    There is no way to remove a single, specific monitor.
1295d763cef2SBarry Smith 
1296d763cef2SBarry Smith    Level: intermediate
1297d763cef2SBarry Smith 
1298d763cef2SBarry Smith .keywords: TS, timestep, set, monitor
1299d763cef2SBarry Smith 
1300a6570f20SBarry Smith .seealso: TSMonitorDefault(), TSMonitorSet()
1301d763cef2SBarry Smith @*/
1302a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorCancel(TS ts)
1303d763cef2SBarry Smith {
1304d952e501SBarry Smith   PetscErrorCode ierr;
1305d952e501SBarry Smith   PetscInt       i;
1306d952e501SBarry Smith 
1307d763cef2SBarry Smith   PetscFunctionBegin;
13084482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
1309d952e501SBarry Smith   for (i=0; i<ts->numbermonitors; i++) {
1310d952e501SBarry Smith     if (ts->mdestroy[i]) {
1311d952e501SBarry Smith       ierr = (*ts->mdestroy[i])(ts->monitorcontext[i]);CHKERRQ(ierr);
1312d952e501SBarry Smith     }
1313d952e501SBarry Smith   }
1314d763cef2SBarry Smith   ts->numbermonitors = 0;
1315d763cef2SBarry Smith   PetscFunctionReturn(0);
1316d763cef2SBarry Smith }
1317d763cef2SBarry Smith 
13184a2ae208SSatish Balay #undef __FUNCT__
1319a6570f20SBarry Smith #define __FUNCT__ "TSMonitorDefault"
1320d8e5e3e6SSatish Balay /*@
1321a6570f20SBarry Smith    TSMonitorDefault - Sets the Default monitor
13225516499fSSatish Balay 
13235516499fSSatish Balay    Level: intermediate
132441251cbbSSatish Balay 
13255516499fSSatish Balay .keywords: TS, set, monitor
13265516499fSSatish Balay 
132741251cbbSSatish Balay .seealso: TSMonitorDefault(), TSMonitorSet()
132841251cbbSSatish Balay @*/
1329a6570f20SBarry Smith PetscErrorCode TSMonitorDefault(TS ts,PetscInt step,PetscReal ptime,Vec v,void *ctx)
1330d763cef2SBarry Smith {
1331dfbe8321SBarry Smith   PetscErrorCode          ierr;
1332a34d58ebSBarry Smith   PetscViewerASCIIMonitor viewer = (PetscViewerASCIIMonitor)ctx;
1333d132466eSBarry Smith 
1334d763cef2SBarry Smith   PetscFunctionBegin;
1335a34d58ebSBarry Smith   if (!ctx) {
13367adad957SLisandro Dalcin     ierr = PetscViewerASCIIMonitorCreate(((PetscObject)ts)->comm,"stdout",0,&viewer);CHKERRQ(ierr);
1337a34d58ebSBarry Smith   }
1338a34d58ebSBarry Smith   ierr = PetscViewerASCIIMonitorPrintf(viewer,"timestep %D dt %G time %G\n",step,ts->time_step,ptime);CHKERRQ(ierr);
1339a34d58ebSBarry Smith   if (!ctx) {
1340a34d58ebSBarry Smith     ierr = PetscViewerASCIIMonitorDestroy(viewer);CHKERRQ(ierr);
1341a34d58ebSBarry Smith   }
1342d763cef2SBarry Smith   PetscFunctionReturn(0);
1343d763cef2SBarry Smith }
1344d763cef2SBarry Smith 
13454a2ae208SSatish Balay #undef __FUNCT__
13464a2ae208SSatish Balay #define __FUNCT__ "TSStep"
1347d763cef2SBarry Smith /*@
1348d763cef2SBarry Smith    TSStep - Steps the requested number of timesteps.
1349d763cef2SBarry Smith 
1350d763cef2SBarry Smith    Collective on TS
1351d763cef2SBarry Smith 
1352d763cef2SBarry Smith    Input Parameter:
1353d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
1354d763cef2SBarry Smith 
1355d763cef2SBarry Smith    Output Parameters:
1356d763cef2SBarry Smith +  steps - number of iterations until termination
1357142b95e3SSatish Balay -  ptime - time until termination
1358d763cef2SBarry Smith 
1359d763cef2SBarry Smith    Level: beginner
1360d763cef2SBarry Smith 
1361d763cef2SBarry Smith .keywords: TS, timestep, solve
1362d763cef2SBarry Smith 
1363d763cef2SBarry Smith .seealso: TSCreate(), TSSetUp(), TSDestroy()
1364d763cef2SBarry Smith @*/
136563dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSStep(TS ts,PetscInt *steps,PetscReal *ptime)
1366d763cef2SBarry Smith {
1367dfbe8321SBarry Smith   PetscErrorCode ierr;
1368d763cef2SBarry Smith 
1369d763cef2SBarry Smith   PetscFunctionBegin;
13704482741eSBarry Smith   PetscValidHeaderSpecific(ts, TS_COOKIE,1);
1371d405a339SMatthew Knepley   if (!ts->setupcalled) {
1372d405a339SMatthew Knepley     ierr = TSSetUp(ts);CHKERRQ(ierr);
1373d405a339SMatthew Knepley   }
1374d405a339SMatthew Knepley 
1375d5ba7fb7SMatthew Knepley   ierr = PetscLogEventBegin(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr);
1376d405a339SMatthew Knepley   ierr = (*ts->ops->prestep)(ts);CHKERRQ(ierr);
1377000e7ae3SMatthew Knepley   ierr = (*ts->ops->step)(ts, steps, ptime);CHKERRQ(ierr);
1378d405a339SMatthew Knepley   ierr = (*ts->ops->poststep)(ts);CHKERRQ(ierr);
1379d5ba7fb7SMatthew Knepley   ierr = PetscLogEventEnd(TS_Step, ts, 0, 0, 0);CHKERRQ(ierr);
1380d405a339SMatthew Knepley 
13814bb05414SBarry Smith   if (!PetscPreLoadingOn) {
13827adad957SLisandro Dalcin     ierr = TSViewFromOptions(ts,((PetscObject)ts)->name);CHKERRQ(ierr);
1383d405a339SMatthew Knepley   }
1384d763cef2SBarry Smith   PetscFunctionReturn(0);
1385d763cef2SBarry Smith }
1386d763cef2SBarry Smith 
13874a2ae208SSatish Balay #undef __FUNCT__
13886a4d4014SLisandro Dalcin #define __FUNCT__ "TSSolve"
13896a4d4014SLisandro Dalcin /*@
13906a4d4014SLisandro Dalcin    TSSolve - Steps the requested number of timesteps.
13916a4d4014SLisandro Dalcin 
13926a4d4014SLisandro Dalcin    Collective on TS
13936a4d4014SLisandro Dalcin 
13946a4d4014SLisandro Dalcin    Input Parameter:
13956a4d4014SLisandro Dalcin +  ts - the TS context obtained from TSCreate()
13966a4d4014SLisandro Dalcin -  x - the solution vector, or PETSC_NULL if it was set with TSSetSolution()
13976a4d4014SLisandro Dalcin 
13986a4d4014SLisandro Dalcin    Level: beginner
13996a4d4014SLisandro Dalcin 
14006a4d4014SLisandro Dalcin .keywords: TS, timestep, solve
14016a4d4014SLisandro Dalcin 
14026a4d4014SLisandro Dalcin .seealso: TSCreate(), TSSetSolution(), TSStep()
14036a4d4014SLisandro Dalcin @*/
14046a4d4014SLisandro Dalcin PetscErrorCode PETSCTS_DLLEXPORT TSSolve(TS ts, Vec x)
14056a4d4014SLisandro Dalcin {
14066a4d4014SLisandro Dalcin   PetscInt       steps;
14076a4d4014SLisandro Dalcin   PetscReal      ptime;
14086a4d4014SLisandro Dalcin   PetscErrorCode ierr;
14096a4d4014SLisandro Dalcin   PetscFunctionBegin;
14106a4d4014SLisandro Dalcin   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
14116a4d4014SLisandro Dalcin   /* set solution vector if provided */
14126a4d4014SLisandro Dalcin   if (x) { ierr = TSSetSolution(ts, x); CHKERRQ(ierr); }
14136a4d4014SLisandro Dalcin   /* reset time step and iteration counters */
14146a4d4014SLisandro Dalcin   ts->steps = 0; ts->linear_its = 0; ts->nonlinear_its = 0;
14156a4d4014SLisandro Dalcin   /* steps the requested number of timesteps. */
14166a4d4014SLisandro Dalcin   ierr = TSStep(ts, &steps, &ptime);CHKERRQ(ierr);
14176a4d4014SLisandro Dalcin   PetscFunctionReturn(0);
14186a4d4014SLisandro Dalcin }
14196a4d4014SLisandro Dalcin 
14206a4d4014SLisandro Dalcin #undef __FUNCT__
14214a2ae208SSatish Balay #define __FUNCT__ "TSMonitor"
1422d763cef2SBarry Smith /*
1423d763cef2SBarry Smith      Runs the user provided monitor routines, if they exists.
1424d763cef2SBarry Smith */
1425a7cc72afSBarry Smith PetscErrorCode TSMonitor(TS ts,PetscInt step,PetscReal ptime,Vec x)
1426d763cef2SBarry Smith {
14276849ba73SBarry Smith   PetscErrorCode ierr;
1428a7cc72afSBarry Smith   PetscInt i,n = ts->numbermonitors;
1429d763cef2SBarry Smith 
1430d763cef2SBarry Smith   PetscFunctionBegin;
1431d763cef2SBarry Smith   for (i=0; i<n; i++) {
1432142b95e3SSatish Balay     ierr = (*ts->monitor[i])(ts,step,ptime,x,ts->monitorcontext[i]);CHKERRQ(ierr);
1433d763cef2SBarry Smith   }
1434d763cef2SBarry Smith   PetscFunctionReturn(0);
1435d763cef2SBarry Smith }
1436d763cef2SBarry Smith 
1437d763cef2SBarry Smith /* ------------------------------------------------------------------------*/
1438d763cef2SBarry Smith 
14394a2ae208SSatish Balay #undef __FUNCT__
1440a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGCreate"
1441d763cef2SBarry Smith /*@C
1442a6570f20SBarry Smith    TSMonitorLGCreate - Creates a line graph context for use with
1443d763cef2SBarry Smith    TS to monitor convergence of preconditioned residual norms.
1444d763cef2SBarry Smith 
1445d763cef2SBarry Smith    Collective on TS
1446d763cef2SBarry Smith 
1447d763cef2SBarry Smith    Input Parameters:
1448d763cef2SBarry Smith +  host - the X display to open, or null for the local machine
1449d763cef2SBarry Smith .  label - the title to put in the title bar
14507c922b88SBarry Smith .  x, y - the screen coordinates of the upper left coordinate of the window
1451d763cef2SBarry Smith -  m, n - the screen width and height in pixels
1452d763cef2SBarry Smith 
1453d763cef2SBarry Smith    Output Parameter:
1454d763cef2SBarry Smith .  draw - the drawing context
1455d763cef2SBarry Smith 
1456d763cef2SBarry Smith    Options Database Key:
1457a6570f20SBarry Smith .  -ts_monitor_draw - automatically sets line graph monitor
1458d763cef2SBarry Smith 
1459d763cef2SBarry Smith    Notes:
1460a6570f20SBarry Smith    Use TSMonitorLGDestroy() to destroy this line graph, not PetscDrawLGDestroy().
1461d763cef2SBarry Smith 
1462d763cef2SBarry Smith    Level: intermediate
1463d763cef2SBarry Smith 
14647c922b88SBarry Smith .keywords: TS, monitor, line graph, residual, seealso
1465d763cef2SBarry Smith 
1466a6570f20SBarry Smith .seealso: TSMonitorLGDestroy(), TSMonitorSet()
14677c922b88SBarry Smith 
1468d763cef2SBarry Smith @*/
1469a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGCreate(const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *draw)
1470d763cef2SBarry Smith {
1471b0a32e0cSBarry Smith   PetscDraw      win;
1472dfbe8321SBarry Smith   PetscErrorCode ierr;
1473d763cef2SBarry Smith 
1474d763cef2SBarry Smith   PetscFunctionBegin;
1475b0a32e0cSBarry Smith   ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr);
1476b0a32e0cSBarry Smith   ierr = PetscDrawSetType(win,PETSC_DRAW_X);CHKERRQ(ierr);
1477b0a32e0cSBarry Smith   ierr = PetscDrawLGCreate(win,1,draw);CHKERRQ(ierr);
1478b0a32e0cSBarry Smith   ierr = PetscDrawLGIndicateDataPoints(*draw);CHKERRQ(ierr);
1479d763cef2SBarry Smith 
148052e6d16bSBarry Smith   ierr = PetscLogObjectParent(*draw,win);CHKERRQ(ierr);
1481d763cef2SBarry Smith   PetscFunctionReturn(0);
1482d763cef2SBarry Smith }
1483d763cef2SBarry Smith 
14844a2ae208SSatish Balay #undef __FUNCT__
1485a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLG"
1486a6570f20SBarry Smith PetscErrorCode TSMonitorLG(TS ts,PetscInt n,PetscReal ptime,Vec v,void *monctx)
1487d763cef2SBarry Smith {
1488b0a32e0cSBarry Smith   PetscDrawLG    lg = (PetscDrawLG) monctx;
148987828ca2SBarry Smith   PetscReal      x,y = ptime;
1490dfbe8321SBarry Smith   PetscErrorCode ierr;
1491d763cef2SBarry Smith 
1492d763cef2SBarry Smith   PetscFunctionBegin;
14937c922b88SBarry Smith   if (!monctx) {
14947c922b88SBarry Smith     MPI_Comm    comm;
1495b0a32e0cSBarry Smith     PetscViewer viewer;
14967c922b88SBarry Smith 
14977c922b88SBarry Smith     ierr   = PetscObjectGetComm((PetscObject)ts,&comm);CHKERRQ(ierr);
1498b0a32e0cSBarry Smith     viewer = PETSC_VIEWER_DRAW_(comm);
1499b0a32e0cSBarry Smith     ierr   = PetscViewerDrawGetDrawLG(viewer,0,&lg);CHKERRQ(ierr);
15007c922b88SBarry Smith   }
15017c922b88SBarry Smith 
1502b0a32e0cSBarry Smith   if (!n) {ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);}
150387828ca2SBarry Smith   x = (PetscReal)n;
1504b0a32e0cSBarry Smith   ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr);
1505d763cef2SBarry Smith   if (n < 20 || (n % 5)) {
1506b0a32e0cSBarry Smith     ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
1507d763cef2SBarry Smith   }
1508d763cef2SBarry Smith   PetscFunctionReturn(0);
1509d763cef2SBarry Smith }
1510d763cef2SBarry Smith 
15114a2ae208SSatish Balay #undef __FUNCT__
1512a6570f20SBarry Smith #define __FUNCT__ "TSMonitorLGDestroy"
1513d763cef2SBarry Smith /*@C
1514a6570f20SBarry Smith    TSMonitorLGDestroy - Destroys a line graph context that was created
1515a6570f20SBarry Smith    with TSMonitorLGCreate().
1516d763cef2SBarry Smith 
1517b0a32e0cSBarry Smith    Collective on PetscDrawLG
1518d763cef2SBarry Smith 
1519d763cef2SBarry Smith    Input Parameter:
1520d763cef2SBarry Smith .  draw - the drawing context
1521d763cef2SBarry Smith 
1522d763cef2SBarry Smith    Level: intermediate
1523d763cef2SBarry Smith 
1524d763cef2SBarry Smith .keywords: TS, monitor, line graph, destroy
1525d763cef2SBarry Smith 
1526a6570f20SBarry Smith .seealso: TSMonitorLGCreate(),  TSMonitorSet(), TSMonitorLG();
1527d763cef2SBarry Smith @*/
1528a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorLGDestroy(PetscDrawLG drawlg)
1529d763cef2SBarry Smith {
1530b0a32e0cSBarry Smith   PetscDraw      draw;
1531dfbe8321SBarry Smith   PetscErrorCode ierr;
1532d763cef2SBarry Smith 
1533d763cef2SBarry Smith   PetscFunctionBegin;
1534b0a32e0cSBarry Smith   ierr = PetscDrawLGGetDraw(drawlg,&draw);CHKERRQ(ierr);
1535b0a32e0cSBarry Smith   ierr = PetscDrawDestroy(draw);CHKERRQ(ierr);
1536b0a32e0cSBarry Smith   ierr = PetscDrawLGDestroy(drawlg);CHKERRQ(ierr);
1537d763cef2SBarry Smith   PetscFunctionReturn(0);
1538d763cef2SBarry Smith }
1539d763cef2SBarry Smith 
15404a2ae208SSatish Balay #undef __FUNCT__
15414a2ae208SSatish Balay #define __FUNCT__ "TSGetTime"
1542d763cef2SBarry Smith /*@
1543d763cef2SBarry Smith    TSGetTime - Gets the current time.
1544d763cef2SBarry Smith 
1545d763cef2SBarry Smith    Not Collective
1546d763cef2SBarry Smith 
1547d763cef2SBarry Smith    Input Parameter:
1548d763cef2SBarry Smith .  ts - the TS context obtained from TSCreate()
1549d763cef2SBarry Smith 
1550d763cef2SBarry Smith    Output Parameter:
1551d763cef2SBarry Smith .  t  - the current time
1552d763cef2SBarry Smith 
1553d763cef2SBarry Smith    Contributed by: Matthew Knepley
1554d763cef2SBarry Smith 
1555d763cef2SBarry Smith    Level: beginner
1556d763cef2SBarry Smith 
1557d763cef2SBarry Smith .seealso: TSSetInitialTimeStep(), TSGetTimeStep()
1558d763cef2SBarry Smith 
1559d763cef2SBarry Smith .keywords: TS, get, time
1560d763cef2SBarry Smith @*/
156163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetTime(TS ts,PetscReal* t)
1562d763cef2SBarry Smith {
1563d763cef2SBarry Smith   PetscFunctionBegin;
15644482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
15654482741eSBarry Smith   PetscValidDoublePointer(t,2);
1566d763cef2SBarry Smith   *t = ts->ptime;
1567d763cef2SBarry Smith   PetscFunctionReturn(0);
1568d763cef2SBarry Smith }
1569d763cef2SBarry Smith 
15704a2ae208SSatish Balay #undef __FUNCT__
15716a4d4014SLisandro Dalcin #define __FUNCT__ "TSSetTime"
15726a4d4014SLisandro Dalcin /*@
15736a4d4014SLisandro Dalcin    TSSetTime - Allows one to reset the time.
15746a4d4014SLisandro Dalcin 
15756a4d4014SLisandro Dalcin    Collective on TS
15766a4d4014SLisandro Dalcin 
15776a4d4014SLisandro Dalcin    Input Parameters:
15786a4d4014SLisandro Dalcin +  ts - the TS context obtained from TSCreate()
15796a4d4014SLisandro Dalcin -  time - the time
15806a4d4014SLisandro Dalcin 
15816a4d4014SLisandro Dalcin    Level: intermediate
15826a4d4014SLisandro Dalcin 
15836a4d4014SLisandro Dalcin .seealso: TSGetTime(), TSSetDuration()
15846a4d4014SLisandro Dalcin 
15856a4d4014SLisandro Dalcin .keywords: TS, set, time
15866a4d4014SLisandro Dalcin @*/
15876a4d4014SLisandro Dalcin PetscErrorCode PETSCTS_DLLEXPORT TSSetTime(TS ts, PetscReal t)
15886a4d4014SLisandro Dalcin {
15896a4d4014SLisandro Dalcin   PetscFunctionBegin;
15906a4d4014SLisandro Dalcin   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
15916a4d4014SLisandro Dalcin   ts->ptime = t;
15926a4d4014SLisandro Dalcin   PetscFunctionReturn(0);
15936a4d4014SLisandro Dalcin }
15946a4d4014SLisandro Dalcin 
15956a4d4014SLisandro Dalcin #undef __FUNCT__
15964a2ae208SSatish Balay #define __FUNCT__ "TSSetOptionsPrefix"
1597d763cef2SBarry Smith /*@C
1598d763cef2SBarry Smith    TSSetOptionsPrefix - Sets the prefix used for searching for all
1599d763cef2SBarry Smith    TS options in the database.
1600d763cef2SBarry Smith 
1601d763cef2SBarry Smith    Collective on TS
1602d763cef2SBarry Smith 
1603d763cef2SBarry Smith    Input Parameter:
1604d763cef2SBarry Smith +  ts     - The TS context
1605d763cef2SBarry Smith -  prefix - The prefix to prepend to all option names
1606d763cef2SBarry Smith 
1607d763cef2SBarry Smith    Notes:
1608d763cef2SBarry Smith    A hyphen (-) must NOT be given at the beginning of the prefix name.
1609d763cef2SBarry Smith    The first character of all runtime options is AUTOMATICALLY the
1610d763cef2SBarry Smith    hyphen.
1611d763cef2SBarry Smith 
1612d763cef2SBarry Smith    Contributed by: Matthew Knepley
1613d763cef2SBarry Smith 
1614d763cef2SBarry Smith    Level: advanced
1615d763cef2SBarry Smith 
1616d763cef2SBarry Smith .keywords: TS, set, options, prefix, database
1617d763cef2SBarry Smith 
1618d763cef2SBarry Smith .seealso: TSSetFromOptions()
1619d763cef2SBarry Smith 
1620d763cef2SBarry Smith @*/
162163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSSetOptionsPrefix(TS ts,const char prefix[])
1622d763cef2SBarry Smith {
1623dfbe8321SBarry Smith   PetscErrorCode ierr;
1624d763cef2SBarry Smith 
1625d763cef2SBarry Smith   PetscFunctionBegin;
16264482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
1627d763cef2SBarry Smith   ierr = PetscObjectSetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr);
1628d763cef2SBarry Smith   switch(ts->problem_type) {
1629d763cef2SBarry Smith     case TS_NONLINEAR:
163059580b9cSBarry Smith       if (ts->snes) {
1631d763cef2SBarry Smith         ierr = SNESSetOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr);
163259580b9cSBarry Smith       }
1633d763cef2SBarry Smith       break;
1634d763cef2SBarry Smith     case TS_LINEAR:
163559580b9cSBarry Smith       if (ts->ksp) {
163694b7f48cSBarry Smith         ierr = KSPSetOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr);
163759580b9cSBarry Smith       }
1638d763cef2SBarry Smith       break;
1639d763cef2SBarry Smith   }
1640d763cef2SBarry Smith   PetscFunctionReturn(0);
1641d763cef2SBarry Smith }
1642d763cef2SBarry Smith 
1643d763cef2SBarry Smith 
16444a2ae208SSatish Balay #undef __FUNCT__
16454a2ae208SSatish Balay #define __FUNCT__ "TSAppendOptionsPrefix"
1646d763cef2SBarry Smith /*@C
1647d763cef2SBarry Smith    TSAppendOptionsPrefix - Appends to the prefix used for searching for all
1648d763cef2SBarry Smith    TS options in the database.
1649d763cef2SBarry Smith 
1650d763cef2SBarry Smith    Collective on TS
1651d763cef2SBarry Smith 
1652d763cef2SBarry Smith    Input Parameter:
1653d763cef2SBarry Smith +  ts     - The TS context
1654d763cef2SBarry Smith -  prefix - The prefix to prepend to all option names
1655d763cef2SBarry Smith 
1656d763cef2SBarry Smith    Notes:
1657d763cef2SBarry Smith    A hyphen (-) must NOT be given at the beginning of the prefix name.
1658d763cef2SBarry Smith    The first character of all runtime options is AUTOMATICALLY the
1659d763cef2SBarry Smith    hyphen.
1660d763cef2SBarry Smith 
1661d763cef2SBarry Smith    Contributed by: Matthew Knepley
1662d763cef2SBarry Smith 
1663d763cef2SBarry Smith    Level: advanced
1664d763cef2SBarry Smith 
1665d763cef2SBarry Smith .keywords: TS, append, options, prefix, database
1666d763cef2SBarry Smith 
1667d763cef2SBarry Smith .seealso: TSGetOptionsPrefix()
1668d763cef2SBarry Smith 
1669d763cef2SBarry Smith @*/
167063dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSAppendOptionsPrefix(TS ts,const char prefix[])
1671d763cef2SBarry Smith {
1672dfbe8321SBarry Smith   PetscErrorCode ierr;
1673d763cef2SBarry Smith 
1674d763cef2SBarry Smith   PetscFunctionBegin;
16754482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
1676d763cef2SBarry Smith   ierr = PetscObjectAppendOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr);
1677d763cef2SBarry Smith   switch(ts->problem_type) {
1678d763cef2SBarry Smith     case TS_NONLINEAR:
16791ac94b3bSBarry Smith       if (ts->snes) {
1680d763cef2SBarry Smith         ierr = SNESAppendOptionsPrefix(ts->snes,prefix);CHKERRQ(ierr);
16811ac94b3bSBarry Smith       }
1682d763cef2SBarry Smith       break;
1683d763cef2SBarry Smith     case TS_LINEAR:
16841ac94b3bSBarry Smith       if (ts->ksp) {
168594b7f48cSBarry Smith         ierr = KSPAppendOptionsPrefix(ts->ksp,prefix);CHKERRQ(ierr);
16861ac94b3bSBarry Smith       }
1687d763cef2SBarry Smith       break;
1688d763cef2SBarry Smith   }
1689d763cef2SBarry Smith   PetscFunctionReturn(0);
1690d763cef2SBarry Smith }
1691d763cef2SBarry Smith 
16924a2ae208SSatish Balay #undef __FUNCT__
16934a2ae208SSatish Balay #define __FUNCT__ "TSGetOptionsPrefix"
1694d763cef2SBarry Smith /*@C
1695d763cef2SBarry Smith    TSGetOptionsPrefix - Sets the prefix used for searching for all
1696d763cef2SBarry Smith    TS options in the database.
1697d763cef2SBarry Smith 
1698d763cef2SBarry Smith    Not Collective
1699d763cef2SBarry Smith 
1700d763cef2SBarry Smith    Input Parameter:
1701d763cef2SBarry Smith .  ts - The TS context
1702d763cef2SBarry Smith 
1703d763cef2SBarry Smith    Output Parameter:
1704d763cef2SBarry Smith .  prefix - A pointer to the prefix string used
1705d763cef2SBarry Smith 
1706d763cef2SBarry Smith    Contributed by: Matthew Knepley
1707d763cef2SBarry Smith 
1708d763cef2SBarry Smith    Notes: On the fortran side, the user should pass in a string 'prifix' of
1709d763cef2SBarry Smith    sufficient length to hold the prefix.
1710d763cef2SBarry Smith 
1711d763cef2SBarry Smith    Level: intermediate
1712d763cef2SBarry Smith 
1713d763cef2SBarry Smith .keywords: TS, get, options, prefix, database
1714d763cef2SBarry Smith 
1715d763cef2SBarry Smith .seealso: TSAppendOptionsPrefix()
1716d763cef2SBarry Smith @*/
1717e060cb09SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSGetOptionsPrefix(TS ts,const char *prefix[])
1718d763cef2SBarry Smith {
1719dfbe8321SBarry Smith   PetscErrorCode ierr;
1720d763cef2SBarry Smith 
1721d763cef2SBarry Smith   PetscFunctionBegin;
17224482741eSBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE,1);
17234482741eSBarry Smith   PetscValidPointer(prefix,2);
1724d763cef2SBarry Smith   ierr = PetscObjectGetOptionsPrefix((PetscObject)ts,prefix);CHKERRQ(ierr);
1725d763cef2SBarry Smith   PetscFunctionReturn(0);
1726d763cef2SBarry Smith }
1727d763cef2SBarry Smith 
17284a2ae208SSatish Balay #undef __FUNCT__
17294a2ae208SSatish Balay #define __FUNCT__ "TSGetRHSJacobian"
1730d763cef2SBarry Smith /*@C
1731d763cef2SBarry Smith    TSGetRHSJacobian - Returns the Jacobian J at the present timestep.
1732d763cef2SBarry Smith 
1733d763cef2SBarry Smith    Not Collective, but parallel objects are returned if TS is parallel
1734d763cef2SBarry Smith 
1735d763cef2SBarry Smith    Input Parameter:
1736d763cef2SBarry Smith .  ts  - The TS context obtained from TSCreate()
1737d763cef2SBarry Smith 
1738d763cef2SBarry Smith    Output Parameters:
1739d763cef2SBarry Smith +  J   - The Jacobian J of F, where U_t = F(U,t)
1740d763cef2SBarry Smith .  M   - The preconditioner matrix, usually the same as J
1741d763cef2SBarry Smith - ctx - User-defined context for Jacobian evaluation routine
1742d763cef2SBarry Smith 
1743d763cef2SBarry Smith    Notes: You can pass in PETSC_NULL for any return argument you do not need.
1744d763cef2SBarry Smith 
1745d763cef2SBarry Smith    Level: intermediate
1746d763cef2SBarry Smith 
174726d46c62SHong Zhang .seealso: TSGetTimeStep(), TSGetMatrices(), TSGetTime(), TSGetTimeStepNumber()
1748d763cef2SBarry Smith 
1749d763cef2SBarry Smith .keywords: TS, timestep, get, matrix, Jacobian
1750d763cef2SBarry Smith @*/
175163dd3a1aSKris Buschelman PetscErrorCode PETSCTS_DLLEXPORT TSGetRHSJacobian(TS ts,Mat *J,Mat *M,void **ctx)
1752d763cef2SBarry Smith {
1753d763cef2SBarry Smith   PetscFunctionBegin;
175426d46c62SHong Zhang   if (J) *J = ts->Arhs;
175526d46c62SHong Zhang   if (M) *M = ts->B;
175626d46c62SHong Zhang   if (ctx) *ctx = ts->jacP;
1757d763cef2SBarry Smith   PetscFunctionReturn(0);
1758d763cef2SBarry Smith }
1759d763cef2SBarry Smith 
17601713a123SBarry Smith #undef __FUNCT__
1761a6570f20SBarry Smith #define __FUNCT__ "TSMonitorSolution"
17621713a123SBarry Smith /*@C
1763a6570f20SBarry Smith    TSMonitorSolution - Monitors progress of the TS solvers by calling
17641713a123SBarry Smith    VecView() for the solution at each timestep
17651713a123SBarry Smith 
17661713a123SBarry Smith    Collective on TS
17671713a123SBarry Smith 
17681713a123SBarry Smith    Input Parameters:
17691713a123SBarry Smith +  ts - the TS context
17701713a123SBarry Smith .  step - current time-step
1771142b95e3SSatish Balay .  ptime - current time
17721713a123SBarry Smith -  dummy - either a viewer or PETSC_NULL
17731713a123SBarry Smith 
17741713a123SBarry Smith    Level: intermediate
17751713a123SBarry Smith 
17761713a123SBarry Smith .keywords: TS,  vector, monitor, view
17771713a123SBarry Smith 
1778a6570f20SBarry Smith .seealso: TSMonitorSet(), TSMonitorDefault(), VecView()
17791713a123SBarry Smith @*/
1780a6570f20SBarry Smith PetscErrorCode PETSCTS_DLLEXPORT TSMonitorSolution(TS ts,PetscInt step,PetscReal ptime,Vec x,void *dummy)
17811713a123SBarry Smith {
1782dfbe8321SBarry Smith   PetscErrorCode ierr;
17831713a123SBarry Smith   PetscViewer    viewer = (PetscViewer) dummy;
17841713a123SBarry Smith 
17851713a123SBarry Smith   PetscFunctionBegin;
1786a34d58ebSBarry Smith   if (!dummy) {
17877adad957SLisandro Dalcin     viewer = PETSC_VIEWER_DRAW_(((PetscObject)ts)->comm);
17881713a123SBarry Smith   }
17891713a123SBarry Smith   ierr = VecView(x,viewer);CHKERRQ(ierr);
17901713a123SBarry Smith   PetscFunctionReturn(0);
17911713a123SBarry Smith }
17921713a123SBarry Smith 
17931713a123SBarry Smith 
17941713a123SBarry Smith 
1795