Skip to content
loiseaujcPublic

About

Modern Fortran utility to generate optimized finite difference schemes

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Latest commit

 

History

32 Commits

Folders and files

Repository files navigation


Modern Fortran utility to generate optimized finite-differences schemes

Status

Language GitHub release Build Status codecov last-commit

Description

FinDiff is small Fortran utility package to generate optimized (dispersion-relation-preserving) finite difference schemes for regular stencils. Along with the standard central, forward and backward finite difference schemes optimized in the sense of Taylor, it can also compute optimized central finite difference schemes for the first and second derivatives.

Building FinDiff

FinDiff can be built with the Fortran Package Manager fpm using the provided fpm.toml like so:

fpm build --release

Only quadrapule precision (real128) is currently supported. To use FinDiff within your fpm project, add the following line to your fpm.toml file:

[dependencies]
FinDiff = {git="https://github.com/loiseaujc/FinDiff.git"}

Example

In 1993, Tam & Webb proposed dispersion-relation-preserving (DRP) finite difference schemes. They illustrated their approach by deriving a 7 points-DRP scheme which is fourth-order accurate while also minimizing the dispersion error

$$ \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \vert \sum_{k=-m}^{m} w_k e^{i k \alpha} - i \alpha \vert^2 \mathrm{d}\alpha, $$

where $\alpha$ is the reduced wavenumber of the wave. The following code snippet illustrates how to compute the corresponding finite difference stencil.

program tam_webb
    use FinDiff
    implicit none (type, external)
    integer, parameter :: npts = 7, order = 4, nth = 1
    real(qp), parameter :: pi = 4 * atan(1.0_qp)
    real(qp), parameter :: alpha_max = pi/2
    real(qp), allocatable :: weights(:)

    !> Tam & Webb DRP scheme.
    weights = central_drp_findiff(npts=npts, order=order, nth=nth, alpha_max=alpha_max)
    print *, weights
end program tam_webb

References

  • K. Kumari, R. Bhattacharya and D. A. Donzis. A unified approach for deriving optimal finite differences. Journal of Computational Physics, vol. 399, 2019. [PDF]
  • C. K. W. Tam and J. C. Webb. Dispersion-Relation-Preserving Finite Difference Schemes for Computational Acoustics. Journal of Computational Physics, vol. 107, 1993. [PDF]

About

Modern Fortran utility to generate optimized finite difference schemes

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages