Hello, Question in brief: what's a good way, using TS, to solve a system of ODEs which looks like this? M U_t = -K U + f(t) In addition, how can the code be kept nearly identical to allow different TS types to be used (EULER, BEULER, TSRUNGE_KUTTA, TSCRANK_NICHOLSON, etc)? I'd also like to take possible advantages of M and K being constants. Background and what I've tried: If f(t) were not present TSSetMatrices seems like the convenient way ahead. In fact, I can still use the same function in presence of f(t) for an explicit time-stepping method like RK or Euler if I use a MatShell for Arhs, and sneak in f(t) there. But I cannot use an implicit method like Backward Euler with a MatShell for Arhs easily. It needs MatFactor to be implemented for the shell matrix (at least). Is there something I'm missing? This is a common system of equation. Most TS examples solve u_t = u_xx, convenient for TSSetMatrices. ts/examples/tests/ex3.c looks like it should work for a system with f(t). But it needs the Jacobian matrix of RHS and it evaluates it using finite differences. In addition, for each time-step it computes an ILU factorization. Thanks, Chetan
For this we recommend using petsc-dev http://www.mcs.anl.gov/petsc/petsc-as/developers/index.html and using TSSetIFunction() and TSSetIJacobian(). We are transistioning to use this new interface for everything because it handles more general situations than the old interfaces. Barry On Nov 18, 2010, at 4:14 PM, Chetan Jhurani wrote:
Hello,
Question in brief: what's a good way, using TS, to solve a system of ODEs which looks like this?
M U_t = -K U + f(t)
In addition, how can the code be kept nearly identical to allow different TS types to be used (EULER, BEULER, TSRUNGE_KUTTA, TSCRANK_NICHOLSON, etc)? I'd also like to take possible advantages of M and K being constants.
Background and what I've tried:
If f(t) were not present TSSetMatrices seems like the convenient way ahead. In fact, I can still use the same function in presence of f(t) for an explicit time-stepping method like RK or Euler if I use a MatShell for Arhs, and sneak in f(t) there.
But I cannot use an implicit method like Backward Euler with a MatShell for Arhs easily. It needs MatFactor to be implemented for the shell matrix (at least).
Is there something I'm missing? This is a common system of equation.
Most TS examples solve u_t = u_xx, convenient for TSSetMatrices.
ts/examples/tests/ex3.c looks like it should work for a system with f(t). But it needs the Jacobian matrix of RHS and it evaluates it using finite differences. In addition, for each time-step it computes an ILU factorization.
Thanks,
Chetan
On Thu, Nov 18, 2010 at 23:14, Chetan Jhurani <[email protected]>wrote:
M U_t = -K U + f(t)
In addition, how can the code be kept nearly identical to allow different TS types to be used (EULER, BEULER, TSRUNGE_KUTTA, TSCRANK_NICHOLSON, etc)? I'd also like to take possible advantages of M and K being constants.
As Barry says, we are transitioning to a better API for this. You can use TSTHETA (theta=0.5 is Crank-Nicolson, theta=1 is Backward Euler) with TSSetIFunction and TSSetIJacobian (see the man pages or read section 6.1.2 of the users manual). Note that an "explicit" method for your problem above needs to solve with the mass matrix at every time step. Unless it is very cheap (e.g. block diagonal), then it may not be worth it. PETSc's explicit methods do not currently support this, but support for that will be added in the next few months. At present, you would need to do the solve in your RHSFunction. Jed
Thanks Barry and Jed. TSSetIFunction and TSSetIJacobian from petsc-dev are working perfectly. Chetan From: [email protected] [mailto:[email protected]] On Behalf Of Jed Brown Sent: Thursday, November 18, 2010 3:49 PM To: PETSc users list Subject: Re: [petsc-users] TS with inhomogeneous rhs On Thu, Nov 18, 2010 at 23:14, Chetan Jhurani <[email protected]> wrote: M U_t = -K U + f(t) In addition, how can the code be kept nearly identical to allow different TS types to be used (EULER, BEULER, TSRUNGE_KUTTA, TSCRANK_NICHOLSON, etc)? I'd also like to take possible advantages of M and K being constants. As Barry says, we are transitioning to a better API for this. You can use TSTHETA (theta=0.5 is Crank-Nicolson, theta=1 is Backward Euler) with TSSetIFunction and TSSetIJacobian (see the man pages or read section 6.1.2 of the users manual). Note that an "explicit" method for your problem above needs to solve with the mass matrix at every time step. Unless it is very cheap (e.g. block diagonal), then it may not be worth it. PETSc's explicit methods do not currently support this, but support for that will be added in the next few months. At present, you would need to do the solve in your RHSFunction. Jed
participants (3)
-
Barry Smith -
Chetan Jhurani -
Jed Brown