Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_trapz_integration.F90
Go to the documentation of this file.
1 
9 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 #include "sll_working_precision.h"
11 
12  implicit none
13 
14  public :: &
16 
17  private
18 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19 
20 #ifndef DOXYGEN_SHOULD_SKIP_THIS
21  abstract interface
22 
23  function function_1d(x)
24  use sll_m_working_precision ! can't pass a header file because the
25  ! preprocessor prevents double inclusion.
26  ! This is very rare.
27  sll_real64 :: function_1d
28  sll_real64, intent(in) :: x
29  end function function_1d
30  end interface
31 #endif
32 
35  module procedure trapz_integral_1d
36  end interface
37 
38 contains
39 
51  function trapz_integral_1d(f, x, n)
52  sll_real64 :: trapz_integral_1d
53  procedure(function_1d) :: f
54  sll_int32, intent(in) :: n
55  sll_real64, dimension(n) :: x
56  sll_int32 :: k
57  sll_real64 :: ans
58 
59  ans = 0.0_f64
60  do k = 1, n - 1
61  ans = ans + 0.5_f64*(f(x(k)) + f(x(k + 1)))*(x(k + 1) - x(k))
62  end do
63  trapz_integral_1d = ans
64 
65  end function trapz_integral_1d
66 
72  function trapz_weights(n, x) result(w)
73  sll_int32, intent(in) :: n
74  sll_real64, dimension(n) :: x
75  sll_real64, dimension(n) :: w
76  sll_int32 :: k
77 
78  w(1) = 0.5_f64*(x(2) - x(1))
79  do k = 2, n - 1
80  w(k) = 0.5_f64*(x(k + 1) - x(k - 1))
81  end do
82  w(n) = 0.5_f64*(x(n) - x(n - 1))
83 
84  end function trapz_weights
85 
86 end module sll_m_trapz_integration
Integrate numerically with Gauss-Lobatto formula.
Trapezoid formula for numerical integration.
real(kind=f64) function, dimension(n) trapz_weights(n, x)
Returns a 1d array of size (n) containing trapz integration weights in the interval [x(1),...
real(kind=f64) function trapz_integral_1d(f, x, n)
Integrate with trapz formula.
Module to select the kind parameter.
    Report Typos and Errors