Saltar al contenido principal

SUNDIALS Overview

SUNDIALS Fortran Framework

Introduction

SUNDIALS (Suite of Nonlinear and Differential/Algebraic Equation Solvers) is a software package that provides a collection of numerical solvers for ordinary differential equations (ODEs) and differential algebraic equations (DAEs). It is widely used in scientific and engineering applications for solving complex systems of equations.

The Fortran framework of SUNDIALS offers a set of solvers implemented in Fortran, a popular programming language for scientific and numerical computations. This tutorial provides a detailed step-by-step guide on the SUNDIALS Fortran framework, including its history, features, and examples.

History

The SUNDIALS project was initiated in the late 1980s at the Center for Research on Parallel Computation at Rice University. It aimed to develop a suite of robust and efficient numerical solvers for differential equations. Over the years, the project has evolved and expanded, and the Fortran framework was added to provide support for Fortran programmers.

Features

The SUNDIALS Fortran framework offers several key features that make it a powerful tool for solving differential equations:

  1. Wide range of solvers: SUNDIALS provides a variety of solvers for different types of ODEs and DAEs, including explicit and implicit methods. Some of the available solvers include CVODE, IDA, and ARKODE.

  2. Efficient time-stepping algorithms: The solvers in SUNDIALS utilize advanced time-stepping algorithms to efficiently solve the differential equations. These algorithms adaptively adjust the time step size to ensure accuracy and efficiency.

  3. Support for stiff and non-stiff problems: SUNDIALS can handle both stiff and non-stiff ODEs and DAEs. Stiff problems involve equations with widely varying time scales, and SUNDIALS' solvers are specifically designed to handle such cases.

  4. User-friendly interface: The Fortran interface of SUNDIALS provides a user-friendly and intuitive way to interact with the solvers. It offers a set of callable routines that handle the initialization, integration, and output of the solvers.

  5. Parallel computing support: SUNDIALS is designed to take advantage of parallel computing architectures, such as multi-core processors and distributed memory systems. It provides options for parallelizing the solvers to improve performance.

  6. Extensibility and customization: SUNDIALS is highly modular and allows users to customize various aspects of the solvers. It provides options for specifying user-defined functions, setting solver parameters, and handling specific problem requirements.

Examples

Let's explore a few examples to demonstrate the usage of SUNDIALS Fortran framework.

Example 1: Solving a simple ODE

Consider the following ordinary differential equation:

dy/dt = -k * y

where y is the dependent variable, t is the independent variable (time), and k is a constant. This equation represents exponential decay.

program example1
implicit none

integer, parameter :: NEQ = 1
real(kind=8) :: y(NEQ)
real(kind=8) :: t, tout
real(kind=8) :: k
integer :: flag, iout

! Set initial conditions and parameters
y(1) = 1.0
t = 0.0
tout = 1.0
k = 0.5

! Initialize solver
call CVodeInit(NEQ, RHS, t, y, CV_NORMAL, CV_NEWTON, CV_DENSE, .false., .false.)

! Set user data (optional)
! call CVodeSetUserData(user_data)

! Set tolerances (optional)
! call CVodeSStolerances(reltol, abstol)

! Integrate the ODE
do iout = 1, 10
call CVode(tout, y, t, flag, CV_NORMAL)
write(*,*) t, y(1)
tout = tout + 1.0
end do

! Cleanup
call CVodeFree()

contains

subroutine RHS(t, y, ydot)
real(kind=8), intent(in) :: t, y(:)
real(kind=8), intent(out) :: ydot(:)

ydot(1) = -k * y(1)
end subroutine RHS
end program example1

In this example, the program initializes the solver using the CVodeInit routine, sets up the initial conditions and parameters, and integrates the ODE using the CVode routine. The right-hand side function RHS calculates the derivative of y with respect to t based on the given equation.

Example 2: Solving a DAE with IDA

Consider the following differential algebraic equation:

x'' - 2 * x' + x = 0

where x is the dependent variable, and ' denotes differentiation with respect to t. This equation represents a damped harmonic oscillator.

program example2
implicit none

integer, parameter :: NEQ = 2
real(kind=8) :: y(NEQ)
real(kind=8) :: t, tout
integer :: flag, iout

! Set initial conditions
y(1) = 1.0
y(2) = 0.0
t = 0.0
tout = 1.0

! Initialize solver
call IDAInit(NEQ, RHS, t, y, IDA_SS, IDA_NEWTON, .false.)

! Set user data (optional)
! call IDASetUserData(user_data)

! Set tolerances (optional)
! call IDASStolerances(reltol, abstol)

! Integrate the DAE
do iout = 1, 10
call IDASolve(tout, y, t, flag, IDA_NORMAL)
write(*,*) t, y(1)
tout = tout + 1.0
end do

! Cleanup
call IDAFree()

contains

subroutine RHS(t, y, ydot, res)
real(kind=8), intent(in) :: t, y(:)
real(kind=8), intent(out) :: ydot(:), res(:)

ydot(1) = y(2)
ydot(2) = 2.0 * y(2) - y(1)
res(1) = ydot(1) - y(2)
res(2) = y(1) + ydot(2) - 2.0 * y(2)
end subroutine RHS
end program example2

In this example, the program initializes the IDA solver using the IDAInit routine, sets up the initial conditions, and integrates the DAE using the IDASolve routine. The right-hand side function RHS calculates the first and second derivatives of x with respect to t based on the given equation.

Conclusion

The SUNDIALS Fortran framework is a powerful tool for solving ordinary differential equations and differential algebraic equations. It offers a wide range of solvers, efficient time-stepping algorithms, and support for both stiff and non-stiff problems. The user-friendly interface and customization options make it a versatile choice for scientific and engineering applications.

For more information and detailed documentation on the SUNDIALS Fortran framework, you can visit the official website: SUNDIALS Official Site

(Note: The code snippets in this tutorial are simplified examples and may require additional setup and modifications to work properly in a specific programming environment.)