forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdlib_quadrature.fypp
106 lines (92 loc) · 3.62 KB
/
stdlib_quadrature.fypp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#:include "common.fypp"
module stdlib_quadrature
!! ([Specification](../page/specs/stdlib_quadrature.html#description))
use stdlib_kinds, only: sp, dp, qp
implicit none
private
! array integration
public :: trapz
public :: trapz_weights
public :: simps
public :: simps_weights
interface trapz
!! version: experimental
!!
!! Integrates sampled values using trapezoidal rule
!! ([Specification](../page/specs/stdlib_quadrature.html#description))
#:for k1, t1 in REAL_KINDS_TYPES
pure module function trapz_dx_${k1}$(y, dx) result(integral)
${t1}$, dimension(:), intent(in) :: y
${t1}$, intent(in) :: dx
${t1}$ :: integral
end function trapz_dx_${k1}$
#:endfor
#:for k1, t1 in REAL_KINDS_TYPES
module function trapz_x_${k1}$(y, x) result(integral)
${t1}$, dimension(:), intent(in) :: y
${t1}$, dimension(:), intent(in) :: x
${t1}$ :: integral
end function trapz_x_${k1}$
#:endfor
end interface trapz
interface trapz_weights
!! version: experimental
!!
!! Integrates sampled values using trapezoidal rule weights for given abscissas
!! ([Specification](../page/specs/stdlib_quadrature.html#description_1))
#:for k1, t1 in REAL_KINDS_TYPES
pure module function trapz_weights_${k1}$(x) result(w)
${t1}$, dimension(:), intent(in) :: x
${t1}$, dimension(size(x)) :: w
end function trapz_weights_${k1}$
#:endfor
end interface trapz_weights
interface simps
!! version: experimental
!!
!! Integrates sampled values using Simpson's rule
!! ([Specification](../page/specs/stdlib_quadrature.html#description_3))
! "recursive" is an implementation detail
#:for k1, t1 in REAL_KINDS_TYPES
pure recursive module function simps_dx_${k1}$(y, dx, even) result(integral)
${t1}$, dimension(:), intent(in) :: y
${t1}$, intent(in) :: dx
integer, intent(in), optional :: even
${t1}$ :: integral
end function simps_dx_${k1}$
#:endfor
#:for k1, t1 in REAL_KINDS_TYPES
recursive module function simps_x_${k1}$(y, x, even) result(integral)
${t1}$, dimension(:), intent(in) :: y
${t1}$, dimension(:), intent(in) :: x
integer, intent(in), optional :: even
${t1}$ :: integral
end function simps_x_${k1}$
#:endfor
end interface simps
interface simps_weights
!! version: experimental
!!
!! Integrates sampled values using trapezoidal rule weights for given abscissas
!! ([Specification](../page/specs/stdlib_quadrature.html#description_3))
#:for k1, t1 in REAL_KINDS_TYPES
pure recursive module function simps_weights_${k1}$(x, even) result(w)
${t1}$, dimension(:), intent(in) :: x
integer, intent(in), optional :: even
${t1}$, dimension(size(x)) :: w
end function simps_weights_${k1}$
#:endfor
end interface simps_weights
! Interface for a simple f(x)-style integrand function.
! Could become fancier as we learn about the performance
! ramifications of different ways to do callbacks.
abstract interface
#:for k1, t1 in REAL_KINDS_TYPES
pure function integrand_${k1}$(x) result(f)
import :: ${k1}$
${t1}$, intent(in) :: x
${t1}$ :: f
end function integrand_${k1}$
#:endfor
end interface
end module stdlib_quadrature