version 0.6.0

All the instances of schemes are (and has to be) created with the procedure fd_initialize()

Usage

Use an existing scheme

Schemes are used to directly or indirectly build FD schemes:

Write your own scheme

Todo:
MCO: correct this depracated documentation If you have a particular numerical scheme that you want to implement, you should follow the main scheme_builder_non_uniform interface. To do so, simply write a function that simply:
  1. define the fd_scheme's boundaries (thanks to the fd_scheme%declare_stencil member routine)
  2. fill the fd_scheme%stencilweight array
  3. returns the fd_scheme
Example
We propose here a special example that shows the capacity of FD schemes to touch a wide range of applications. We write the specific scheme for computing a Gaussian weighted mean depending on distances from the central point:
function fd_scheme_gaussian_mean( steps ) result(scheme)
use mod_finite_differences
double precision, dimension(:), intent(in) :: steps
type(t_fd_scheme) :: scheme
double precision :: sigma
double precision :: dist
integer :: sindex, eindex, i
! We assume the steps array to be even
sindex = -size(steps)/2
eindex = size(steps)/2
call scheme%declare_stencil( sindex, eindex )
sigma = 0.25d0*sum(steps)
do i=sindex,eindex
! Compute the distance from the point to the center element
if( i==0 ) then
dist = 0d0
else
dist = sum( steps(min(i,0)+eindex+1:max(i,0)+eindex) )
end if
scheme%stencil%weight(i) = exp(-0.5d0*(dist/sigma)**2)
end do
! Normalize the weights
scheme%stencil%weight(sindex:eindex) = scheme%stencil%weight(sindex:eindex) / sum(scheme%stencil%weight(sindex:eindex))
end function fd_scheme_gaussian_mean
Then, you can easily use your scheme - as long as it is defined in a Fortran module - with the FD computer
result = fd_compute( fd_scheme_gaussian_mean, dx(index-2:index+1), field(index-2:index+2) )
See unit_testing/discretization/node_level_schemes/finite_differences/fd_scheme/finite_differences.f90 for a detailed example.

List of available finite difference schemes

Note
For clarity, the definitions in the table below are simplified, please refer to the code for the actual value (especialy on non uniform grids).
Derivative Order Type Name Definition
First 1 Backward t_fd_scheme_first_o1_backward \( \frac{\phi_{i}-\phi_{i-1}}{\Delta x} \)
First 1 Forward t_fd_scheme_first_o1_forward \( \frac{\phi_{i-1}-\phi_{i}}{\Delta x} \)
First 2 Backward t_fd_scheme_first_o2_backward \( \frac{\phi_{i-2}-4\phi_{i-1}+3\phi_{i}}{2 \Delta x} \)
First 2 Centered fd_scheme_first_o2_centered \( \frac{\phi_{i+1}-\phi_{i-1}}{2 \Delta x} \)
First 2 Forward t_fd_scheme_first_o2_forward \( \frac{-\phi_{i+2}+4\phi_{i+1}-3\phi_{i}}{2 \Delta x} \)
Second 2 Centered fd_scheme_second_o2_centered \( \frac{\phi_{i+1}-2\phi_{i}+\phi_{i-1}}{\Delta x^2} \)