IDA Method for NDSolve

The 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], [1] is a Fortran code for solving large-scale differential-algebraic systems.

In the Wolfram Language, 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, the Wolfram Language generates the function automatically from the equations you input to NDSolve.

IDA solves index-1 DAE systems of the form:

The index of a DAE is the number of times needed to differentiate the DAEs to get a system of ODEs. For more information on differential algebraic equations and where they come from, please consult the Numerical Solution of Differential-Algebraic Equations tutorial.

IDA solves the system (2) with Backward Differentiation Formula (BDF) methods of orders 1 through 5, implemented using a variable-step form. The BDF of order at time is given by the formula

The coefficients depend on the order and past step sizes. Applying the BDF to the DAE (3) 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 [IDA's] 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 the Wolfram Language, you can access these solvers using method options or the default Wolfram Language 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 Norm[En/wn] is less than 1. The thcomponent, , of is given by

The 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:
IDA method option name
default value
"ImplicitSolver""Newton"how to solve the implicit equations
"MaxDifferenceOrder"5the maximum order BDF to use

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 NDSolve method option setting InterpolationOrder->All that uses interpolation based on the order of the method, sometimes called dense output, to represent the solution between time steps. 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.

As an example which highlights the difference between minimal output and full method interpolation order, 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]:
This defines the linear equations along with initial conditions:
The exact value of f as a function of time can be computed symbolically using DSolve:

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:
It can also be computed with dense output:
This plot shows the relative 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:

From the plot, it is quite apparent that when the time steps get large, the default solution output has a 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.

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:
This makes a plot comparing the relative error for the DAE solution. The time steps for IDA are shown as blue points:

The DAE solution takes far more steps to control the error of the quantity of interest but still uses far less memory than using dense output.

This compares the sizes of the default, dense output, and DAE solutions:

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 nonlinear solver 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 the Wolfram Language how to solve the linear equations required to find the Newton step. There are several possible values for this option.

Automaticthis is the default: automatically switch between using the Wolfram Language LinearSolve and Band methods depending on the bandwidth of the Jacobian; for systems with larger bandwidth, this will automatically switch to a direct sparse solver for large systems with sparse Jacobians
"Band"use the IDA band method (see the IDA user manual for more information)
"Dense"use the IDA dense method (see the IDA user manual for more information)

Possible settings for the "LinearSolveMethod" option.

The "GMRES" method may be substantially faster, but is typically quite a bit trickier to use because to really be effective it 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 option name
default value
"Preconditioner"Automatica Wolfram Language function that returns another function that preconditions
"OrthogonalizationType""ModifiedGramSchmidt"this can also be "ClassicalGramSchmidt" (see variable gstype in the IDA user guide)
"MaxKrylovSubspaceDimension"Automaticmaximum subspace dimension (see variable maxl in the IDA user guide)
"MaxKrylovRestarts"Automaticmaximum number of restarts (see variable maxrs in the IDA user guide)

"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. The computations below will show the difference between the two approaches.

This defines a function that satisfies Burger's equation:
This defines initial and boundary conditions for the unit square consistent with the exact solution:
This defines the differential equation:
This sets the diffusion constant to a value for which you can find a solution in a reasonable amount of time and shows a plot of the solution at :

You can see from the plot that with , 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:

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:
This computes the maximal error for the computed solution:

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:
No options use the previous defaults:
This uses the "Band" method:

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:

While the solution time was smaller and the error is comparable, the total number of time steps is greater. If the problem had been 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 and directions and shows the number of points used:
This uses the "Band" method with the width set to include at least part of the stencil in both directions:

With the more appropriate setting of the bandwidth, the solution time is still slightly faster than for the default choice of the bandwidth but is slower than using the default linear solver. 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:

Using the "GMRES" method without a preconditioner leads to larger computation times and more steps when compared to the default method. It is for this reason that this method is not recommended without a preconditioner. Finding a good preconditioner however 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 (4) above. For example, if you can determine a procedure that would generate an appropriate preconditioner matrix as a function of these arguments, you could use


to produce a LinearSolveFunction object which will effectively invert the preconditioner matrix . 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 affected 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:
This gets the positions where elements at the boundary that satisfy a simple algebraic condition are in the flattened solution vector:
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:
This uses the preconditioned "GMRES" method to compute the solution:

Thus, even with a crude preconditioner, the "GMRES" method computes the solution faster than using the direct sparse solvers.

For PDE discretization 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.