To set up TS for solving an ODE, one must set the following:
ierr = TSSetSolution(TS ts, Vec initialsolution);The vector initialsolution should contain the ``initial conditions'' for the ODE.
ierr = TSSetRHSMatrix(TS ts,Mat A, Mat B,int (*f)(TS,double,Mat*,Mat*, MatStructure*,void*),void *fP);The matrix B (although usually the same as A) allows one to provide a different matrix to be used in the construction of the preconditioner. The function f is used to form the matrices A and B at each timestep if the matrices are time dependent. If the matrix does not depend on time, the user should pass in PETSC_NULL for f. The variable fP allows users to pass in an application context that is passed to the f() function whenever it is called, as the final argument. The user must provide the matrices A and B; if they have the right-hand side only as a linear function, they must construct a MatShell matrix. Note that this is the same interface as that for SNESSetJacobian().
For nonlinear problems (or linear problems solved using
explicit timestepping methods) the user passes the function with
the routine
ierr = TSSetRHSFunction(TS ts,int (*f)(TS,double,Vec,Vec,void*),void *fP);The arguments to the function f() are the timestep context, the current time, the input for the function, the output for the function, and the (optional) user-provided context variable fP.
ierr = TSSetRHSJacobian(TS ts,Mat A, Mat B,int (*f)(TS,double,Vec,Mat*,Mat*, MatStructure*,void*),void *fP);The arguments for the function f() are the timestep context, the current time, the location where the Jacobian is to be computed, the Jacobian matrix, an alternative approximate Jacobian matrix used as a preconditioner, and the optional user-provided context, passed in as fP. The user must provide the Jacobian as a matrix; thus, if using a matrix-free approach is used, the user must create a MatShell matrix. Again, note the similarity to SNESSetJacobian().