+
Skip to content

jacobwilliams/rklib

Repository files navigation

rklib

rklib: A modern Fortran library of fixed and variable-step Runge-Kutta solvers.

Language GitHub release CI Status codecov last-commit

Description

This is a work in progress!

The focus of this library is single-step, explicit Runge-Kutta solvers for 1st order differential equations.

Novel features:

  • The library includes a wide range of both fixed and variable-step Runge-Kutta methods, from very low to very high order.
  • It is object-oriented and written in modern Fortran.
  • It allows for defining a variable-step size integrator with a custom-tuned step size selection method. See stepsize_class in the code.
  • The real kind is selectable via a compiler directive (REAL32, REAL64, or REAL128).
  • Integration to an event is also supported.

Available Runge-Kutta methods:

Fixed-step methods:

Name Properties Order Stages Registers CFL Reference
euler 1 1 1 1.0 Euler (1768)
midpoint 2 2 2 ?
heun 2 2 2 ?
rkssp22 SSP 2 2 1 1.0 Shu & Oscher (1988)
rk3 3 3 3 ?
rkssp33 SSP 3 3 1 1.0 Shu & Oscher (1988)
rkssp53 SSP 3 5 2 2.65 Ruuth (2006)
rk4 4 4 4 Kutta (1901)
rks4 4 4 4 Shanks (1965)
rkls44 LS 4 4 2 Jiang and Shu (1988)
rkls54 LS 4 5 2 0.32 Carpenter & Kennedy (1994)
rkssp54 SSP 4 5 4 1.51 Ruuth (2006)
rks5 5 5 5 Shanks (1965)
rk5 5 6 6 ?
rkc5 5 6 6 Cassity (1966)
rkl5 5 6 6 Lawson (1966)
rkb6 6 7 7 Butcher (1963)
rk7 7 9 9 Shanks (1965)
rk8_10 8 10 10 Shanks (1965)
rkcv8 8 11 11 Cooper & Verner (1972)
rk8_12 8 12 12 Shanks (1965)
rkz10 10 16 16 Zhang (2019)
rko10 10 17 17 Ono (2003)
rkh10 10 17 17 Hairer (2003)

Variable-step methods:

Name Properties Order Stages Registers CFL Reference
rkbs32 FSAL 3 4 4 Bogacki & Shampine (1989)
rkssp43 SSP, LS 3 4 2 2.0 Kraaijevanger (1991), Conde et al. (2018)
rkf45 4 6 6 Fehlberg (1969)
rkck54 5 6 6 Cash & Karp (1990)
rkdp54 FSAL 5 7 7 Dormand & Prince (1980)
rkt54 FSAL 5 7 7 Tsitouras (2011)
rks54 FSAL 5 7 7 Stepanov (2022)
rkpp54 FSAL 5 7 7 Papakostas & Papageorgiou (1996)
rkdp65 6 8 8 Dormand & Prince (1981)
rkc65 6 9 9 Calvo (1990)
rktp64 6 7 7 Tsitouras & Papakostas (1999)
rkv65e FSAL 6 9 9 Verner (1994)
rkv65r FSAL 6 9 9 Verner (1994)
rkv65 6 8 8 Verner (2006)
rktf65 FSAL 6 9 9 Tsitouras & Famelis (2006)
rktp75 7 9 9 Tsitouras & Papakostas (1999)
rktmy7 7 10 10 Tanaka, Muramatsu & Yamashita (1992)
rkv76e 7 10 10 Verner (1978)
rkv76r 7 10 10 Verner (1978)
rkf78 7 13 13 Fehlberg (1968)
rkv78 7 13 13 Verner (1978)
dverk78 7 13 13 Verner (?)
rktp86 8 12 12 Tsitouras & Papakostas (1999)
rkdp87 8 13 13 Prince & Dormand (1981)
rkv87e 8 13 13 Verner (1978)
rkv87r 8 13 13 Verner (1978)
rkk87 8 13 13 Kovalnogov, Fedorov, Karpukhina, Simos, Tsitouras (2022)
rkf89 8 17 17 Fehlberg (1968)
rkv89 8 16 16 Verner (1978)
rkt98a 9 16 16 Tsitouras (2001)
rkv98e 9 16 16 Verner (1978)
rkv98r 9 16 16 Verner (1978)
rkf108 10 17 17 Feagin (2006)
rkc108 10 21 21 Curtis (1975)
rkb109 10 21 21 Baker (?)
rks1110a 11 26 26 Stone (2015)
rkf1210 12 25 25 Feagin (2006)
rko129 12 29 29 Ono (2006)
rkf1412 14 35 35 Feagin (2006)

Properties key:

  • LS = Low storage
  • SSP = Strong stability preserving
  • FSAL = First same as last
  • CFL = Courant-Friedrichs-Lewy

Example use case

Basic use of the library is shown here (this uses the rktp86 method):

program rklib_example

  use rklib_module, wp => rk_module_rk
  use iso_fortran_env, only: output_unit

  implicit none

  integer,parameter :: n = 2 !! dimension of the system
  real(wp),parameter :: tol = 1.0e-12_wp !! integration tolerance
  real(wp),parameter :: t0 = 0.0_wp !! initial t value
  real(wp),parameter :: dt = 1.0_wp !! initial step size
  real(wp),parameter :: tf = 100.0_wp !! endpoint of integration
  real(wp),dimension(n),parameter :: x0 = [0.0_wp,0.1_wp] !! initial x value

  real(wp),dimension(n) :: xf !! final x value
  type(rktp86_class) :: prop
  character(len=:),allocatable :: message

  call prop%initialize(n=n,f=fvpol,rtol=[tol],atol=[tol])
  call prop%integrate(t0,x0,dt,tf,xf)
  call prop%status(message=message)

  write (output_unit,'(A)') message
  write (output_unit,'(A,F7.2/,A,2E18.10)') &
              'tf =',tf ,'xf =',xf(1),xf(2)

contains

  subroutine fvpol(me,t,x,f)
    !! Right-hand side of van der Pol equation

    class(rk_class),intent(inout)     :: me
    real(wp),intent(in)               :: t
    real(wp),dimension(:),intent(in)  :: x
    real(wp),dimension(:),intent(out) :: f

    f(1) = x(2)
    f(2) = 0.2_wp*(1.0_wp-x(1)**2)*x(2) - x(1)

  end subroutine fvpol

end program rklib_example

The result is:

Success
tf = 100.00
xf = -0.1360372426E+01  0.1325538438E+01

Example performance comparison

Running the unit tests will generate some performance plots. The following is for the variable-step methods compiled with quadruple precision (e.g, fpm test rk_test_variable_step --compiler ifort --flag "-DREAL128"):

rk_test_variable_step_R16

Compiling

A Fortran Package Manager manifest file is included, so that the library and test cases can be compiled with FPM. For example:

fpm build --profile release
fpm test --profile release

To use rklib within your FPM project, add the following to your fpm.toml file:

[dependencies]
rklib = { git="https://github.com/jacobwilliams/rklib.git" }

By default, the library is built with double precision (real64) real values. Explicitly specifying the real kind can be done using the following processor flags:

Preprocessor flag Kind Number of bytes
REAL32 real(kind=real32) 4
REAL64 real(kind=real64) 8
REAL128 real(kind=real128) 16

For example, to build a single precision version of the library, use:

fpm build --profile release --flag "-DREAL32"

To generate the documentation using FORD, run:

ford ford.md

3rd Party Dependencies

Both of these will be automatically downloaded by FPM.

Documentation

The latest API documentation for the master branch can be found here. This was generated from the source code using FORD.

Notes

The original version of this code was split off from the Fortran Astrodynamics Toolkit in September 2022.

License

The rklib source code and related files and documentation are distributed under a permissive free software license (BSD-3).

References

See also

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载