MethodsIDAThe IDA package is part of the SUNDIALS (SUite of Nonlinear and DIfferential/ALgebraic equation Solvers) developed at the Center for Applied Scientific Computing of Lawrence Livermore National Laboratory. As described in the IDA user guide [HT99], "IDA is a general purpose solver for the initial value problem for systems of differential-algebraic equations (DAEs). The name IDA stands for Implicit Differential-Algebraic solver. IDA is based on DASPK ..." DASPK [BHP94], [BHP98] is a FORTRAN code for solving large scale differential-algebraic systems. In Mathematica, an interface has been provided to the IDA package so that rather than needing to write a function in C for evaluating the residual and compiling the program, Mathematica generates the function automatically from the equations you input to NDSolve. IDA solves the system (1) with Backward Differentiation Formula (BDF) methods of orders 1 through 5, implemented using a variable-step form. The BDF of order k is at time is given by the formula The coefficients depend on the order k and past step sizes. Applying the BDF to the DAE (1) gives a system of nonlinear equations to solve:The solution of the system is achieved by Newton-type methods, typically using an approximation to the Jacobian "Its [IDAs] most notable feature is that, in the solution of the underlying nonlinear system at each time step, it offers a choice of Newton/direct methods or an Inexact Newton/Krylov (iterative) method." [HT99] In Mathematica, you can access these solvers using method options or use the default Mathematica LinearSolve, which switches automatically to direct sparse solvers for large problems. At each step of the solution, IDA computes an estimate of the local truncation error and the step size and order are chosen so that the weighted norm is less than 1. The component, , of is given byThe values prec and acc are taken from the NDSolve settings for the PrecisionGoal->prec and AccuracyGoal->acc. Because IDA provides a great deal of flexibility, particularly in the way nonlinear equations are solved, there are a number of method options which allow you to control how this is done. You can use the method options to IDA by giving NDSolve the option Method->{IDA, ida method options}. The options for the IDA method are associated with the symbol IDA in the NDSolve` context. In[34]:=  |
Out[34]=
| IDA method options.When strict accuracy of intermediate values computed with the InterpolatingFunction object returned from NDSolve is important, you will want to use the method option setting "DenseOutput"->True. By default NDSolve stores a minimal amount of data to represent the solution well enough for graphical purposes. Keeping the amount of data small saves on both memory and time for more complicated solutions. Depending on the use you may want to make of the solution, it may be appropriate to choose dense output. As an example which highlights the difference between dense and minimal output, consider tracking a quantity, derived from the solution of a simple linear equation where the exact solution can be computed using DSolve. This defines the function f giving the quantity as a function of time based on solutions x[t] and y[t]. In[35]:=  |
This defines the linear equations along with initial conditions. In[36]:=  |
The exact value of f as a function of time can be computed symbolically using DSolve. In[38]:=  |
Out[38]=
|
The exact solution will be compared with solutions computed with and without dense output. A simple way to track the quantity is to create a function which derives it from the numerical solution of the differential equation. In[39]:=  |
Out[39]=
|
It can also be computed with dense output. In[40]:=  |
Out[40]=
|
This shows a plot showing the error in the two computed solutions. The computed solution at the time steps are indicated by black dots. The default output error is shown in gray and the dense output error in black. In[41]:=  |
From the plot, it is quite apparent that when the time steps get large, the default solution output has much larger error between time steps. The dense output solution represents the solution computed by the solver even between time steps. Keep in mind, however, that the dense output solution takes up much more space: This compares the sizes of the default and dense output solutions. In[43]:=  |
Out[43]=
|
When the quantity you want to derive from the solution is complicated, you can ensure that it is locally kept within tolerances by giving it as an algebraic quantity, forcing the solver to keep its error in control. This adds a dependent variable with an algebraic equation that sets the dependent variable equal to the quantity of interest. In[44]:=  |
Out[44]=
|
This computes the same solution with dense output In[45]:=  |
Out[45]=
|
This makes a plot comparing the error for all four solutions. The time steps for IDA are shown as blue points and the dense output from IDA is shown in blue with the default output shown in light blue. In[46]:=  |
You can see from the plot that the error is somewhat smaller when the quantity is computed algebraically along with the solution. The remainder of this documentation will focus on suboptions of the two possible settings for the ImplicitSolver option, which can be Newton or GMRES. With Newton, the Jacobian or an approximation to it is computed and the linear system is solved to find the Newton step. On the other hand, GMRES is an iterative method and, rather than computing the entire Jacobian, a directional derivative is computed for each iterative step. The Newton method has one method option, LinearSolveMethod, which you can use to tell Mathematica how to solve the linear equations required to find the Newton step. There are several possible values for this option. Possible settings for the LinearSolveMethod option. The GMRES method may be substantially faster, but is typically quite a bit more tricky to use because to really be effective typically requires a preconditioner, which can be supplied via a method option. There are also some other method options that control the Krylov subspace process. To use these, refer to the IDA user guide [HT99]. GMRES method options. As an example problem, consider a two-dimensional Burgers' equation. This can typically be solved with an ordinary differential equation solver, but in this example two things are achieved by using the DAE solver. First, boundary conditions are enforced as algebraic conditions. Second, NDSolve is forced to use conservative differencing by using an algebraic term. For comparison, a known exact solution will be used for initial and boundary conditions. This defines a function that satisfies Burger's equation. In[48]:=  |
This defines initial and boundary conditions for the unit square consistent with the exact solution. In[49]:=  |
This defines the differential equation. In[51]:=  |
This sets the diffusion constant to a value for which we can find a solution in a reasonable amount of time and shows a plot of the solution at t 1. In[52]:=  |
You can see from the plot that with = 0.025, there is a fairly steep front. This moves with constant speed. This solves the problem using the default settings for NDSolve and the IDA method with the exception of the DifferentiateBoundaryConditions option for MethodOfLines, which causes NDSolve to treat the boundary conditions as algebraic. In[54]:=  |
Out[54]=
|
Since there is an exact solution to compare to, the overall solution accuracy can be compared as well. This defines a function that finds the maximum deviation between the exact and computed solutions at the grid points at all of the time steps. In[55]:=  |
This computes the maximal error for the computed solution. In[56]:=  |
Out[56]=
|
In the following, a comparison will be made with different settings for the options of the IDA method. To emphasize the option settings, a function will be defined to time the computation of the solution and give the maximal error. This defines a function for comparing different IDA option settings. In[57]:=  |
No options use the previous defaults. In[58]:=  |
Out[58]=
|
This uses the Band method. In[59]:=  |
Out[59]=
|
The Band method is not very effective because the bandwidth of the Jacobian is relatively large, partly because of the fourth order derivatives used and partly because the one-sided stencils used near the boundary add width at the top and bottom. You can specify the bandwidth explicitly. This uses the Band method with the width set to include the stencil of the differences in only one direction. In[60]:=  |
Out[60]=
|
While the solution time was smaller, notice that the error is slightly greater and the total number of time steps is a lot greater. If the problem was more stiff, the iterations likely would not have converged because it was missing information from the other direction. Ideally, the bandwidth should not eliminate information from an entire dimension. This computes the grids used in the X and Y directions and shows the number of points used. In[61]:=  |
Out[62]=
|
This uses the Band method with the width set to include at least part of the stencil in both directions. In[63]:=  |
Out[63]=
|
With the more appropriate setting of the bandwidth, the solution is still slightly slower than in the default case. The Band method can sometimes be effective on two-dimensional problems, but is usually most effective on one-dimensional problems. This computes the solution using the GMRES implicit solver without a preconditioner. In[64]:=  |
Out[64]=
|
This is incredibly slow! Using the GMRES method without a preconditioner is not recommended for this very reason. However, finding a good preconditioner is not usually trivial. For this example, a diagonal preconditioner will be used. The setting of the Preconditioner option should be a function f, which accepts four arguments that will be given to it by NDSolve such that f[t, x, x', c] returns another function that will apply the preconditioner to the residual vector. (See IDA user guide [HT99] for details on how the preconditioner is used.) The arguments t, x, x', c are the current time, solution vector, solution derivative vector, and the constant c in formula (2) above. For example, if you can determine a procedure that would generate an appropriate preconditioner matrix P as a function of these arguments, you could use
Preconditioner->Function[{t,x,xp,c}, LinearSolve[P[t,x,xp,c]]]
to produce a LinearSolveFunction object which will effectively invert the preconditioner matrix P. Typically, for each time the preconditioner function is set up, it is applied to the residual vector several times, so using some sort of factorization such as is contained in a LinearSolveFunction is a good idea. For the diagonal case, the inverse can be effected simply by using the reciprocal. The most difficult part of setting up a diagonal preconditioner is keeping in mind that values on the boundary should not be affected by it. This finds the diagonal elements of the differentiation matrix for computing the preconditioner. In[65]:=  |
Out[66]//Short=
|
This gets the positions where elements at the boundary that satisfy a simple algebraic condition are in the flattened solution vector. In[67]:=  |
Out[68]//Short=
|
This defines the function that sets up the function called to get the effective inverse of the preconditioner. For the diagonal case, the inverse is done simply by taking the reciprocal. In[69]:=  |
This uses the preconditioned GMRES method to compute the solution. In[70]:=  |
Out[70]=
|
Thus, even with a crude preconditioner, the GMRES method computes the solution faster than the using the direct sparse solvers. For PDE discretizations with higher-order temporal derivatives or systems of PDEs, you may need to look at the corresponding NDSolve`StateData object to determine how the variables are ordered so that you can get the structural form of the preconditioner correctly.
|