GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 39 / 0 / 39
Functions: 100.0% 4 / 0 / 4
Branches: 85.7% 36 / 0 / 42

bspline/m_bspline_recurse.f90
Line Branch Exec Source
1 !> @brief Module for B-spline recursion and knot sequences
2 !>
3 !> This module is used for testing pruposes _only_ and contains functions for evaluating B-splines recursively,
4 module m_bspline_recurse
5 use m_common, only: wp
6 implicit none
7
8 private
9 public :: bspline_recurse_eval, clamped_knotsequence, periodic_knotsequence, greville_points
10
11 contains
12 !> @brief Recursively evaluate a B-spline at a given point
13 !>
14 !> @param[in] x The point at which to evaluate the B-spline
15 !> @param[in] j The index of the B-spline
16 !> @param[in] r The degree of the B-spline
17 !> @param[in] t The knot sequence of the B-spline
18 !>
19 !> @return The value of the B-spline at the point x
20
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 93643220 times.
93643220 pure recursive real(wp) function bspline_recurse_eval(x, j, r, t) result(ans)
21 implicit none
22
23 real(wp), intent(in) :: x
24 integer, intent(in) :: j, r
25 real(wp), intent(in) :: t(-r:)
26
27 real(wp) :: t0, t1
28
29 ans = 0._wp
30
2/2
✓ Branch 4 → 5 taken 46934578 times.
✓ Branch 4 → 8 taken 46708642 times.
93643220 if (r == 0) then
31
4/4
✓ Branch 5 → 6 taken 24326956 times.
✓ Branch 5 → 7 taken 22607622 times.
✓ Branch 6 → 7 taken 22275650 times.
✓ Branch 6 → 12 taken 2051306 times.
46934578 if (t(j - r) <= x .and. x < t(j + 1 - r)) then
32 ans = 1._wp
33 end if
34 else
35 46708642 t0 = t(j - r)
36 46708642 t1 = t(j)
37
2/2
✓ Branch 8 → 9 taken 46417312 times.
✓ Branch 8 → 10 taken 291330 times.
46708642 if (t0 /= t1) then
38 46417312 ans = ((x - t0) / (t1 - t0)) * bspline_recurse_eval(x, j, r - 1, t)
39 end if
40
41 46708642 t0 = t(j + 1 - r)
42 46708642 t1 = t(j + 1)
43
2/2
✓ Branch 10 → 11 taken 46417312 times.
✓ Branch 10 → 12 taken 291330 times.
46708642 if (t0 /= t1) then
44 46417312 ans = ans + ((t1 - x) / (t1 - t0)) * bspline_recurse_eval(x, j + 1, r - 1, t)
45 end if
46 end if
47 93643220 end function
48
49 !> @brief Generate a clamped knot sequence for a B-spline
50 !>
51 !> @param[in] nr_intervals The number of intervals in the B-spline
52 !> @param[in] degree The degree of the B-spline
53 !>
54 !> @return A clamped knot sequence for the B-spline
55
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 328 times.
328 pure function clamped_knotsequence(nr_intervals, degree) result(ans)
56 implicit none
57
58 integer, intent(in) :: nr_intervals
59 integer, intent(in) :: degree
60 real(wp) :: ans(-degree:nr_intervals + degree)
61
62 328 real(wp) :: gridpoints(0:nr_intervals)
63 integer :: i
64
65 ! Create a uniform grid using nr_intervals+1 gridpoints on the interval [0, 1)
66
2/2
✓ Branch 5 → 6 taken 5536 times.
✓ Branch 5 → 7 taken 328 times.
5864 do i = 0, nr_intervals
67 5864 gridpoints(i) = real(i, kind=wp) / nr_intervals
68 end do
69
70
2/2
✓ Branch 9 → 10 taken 328 times.
✓ Branch 9 → 11 taken 1320 times.
1648 ans(-degree:-1) = gridpoints(0)
71
2/2
✓ Branch 12 → 13 taken 5536 times.
✓ Branch 12 → 14 taken 328 times.
5864 ans(0:nr_intervals) = gridpoints
72
2/2
✓ Branch 15 → 16 taken 1320 times.
✓ Branch 15 → 17 taken 328 times.
1648 ans(nr_intervals + 1:nr_intervals + degree) = gridpoints(nr_intervals)
73 328 end function
74
75 !> @brief Generate a periodic knot sequence for a B-spline
76 !>
77 !> @param[in] nr_intervals The number of intervals in the B-spline
78 !> @param[in] degree The degree of the B-spline
79 !>
80 !> @return A periodic knot sequence for the B-spline
81
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 800 times.
800 pure function periodic_knotsequence(nr_intervals, degree) result(ans)
82 implicit none
83
84 integer, intent(in) :: nr_intervals
85 integer, intent(in) :: degree
86 real(wp) :: ans(-degree:nr_intervals + degree)
87
88 800 real(wp) :: gridpoints(0:nr_intervals)
89 integer :: i
90
91 ! Create a uniform grid using nr_intervals+1 gridpoints on the interval [0, 1)
92
2/2
✓ Branch 5 → 6 taken 800 times.
✓ Branch 5 → 8 taken 14744 times.
15544 do i = 0, nr_intervals
93 15544 gridpoints(i) = real(i, kind=wp) / nr_intervals
94 end do
95
96
2/2
✓ Branch 9 → 10 taken 800 times.
✓ Branch 9 → 12 taken 3216 times.
4016 do i = -degree, -1
97 4016 ans(i) = gridpoints(0) + real(i, kind=wp) / nr_intervals
98 end do
99
2/2
✓ Branch 13 → 14 taken 800 times.
✓ Branch 13 → 16 taken 14744 times.
15544 do i = 0, nr_intervals
100 15544 ans(i) = gridpoints(i)
101 end do
102
2/2
✓ Branch 17 → 18 taken 3216 times.
✓ Branch 17 → 19 taken 800 times.
4016 do i = 1, degree
103 4016 ans(nr_intervals + i) = gridpoints(nr_intervals) + real(i, kind=wp) / nr_intervals
104 end do
105
106 800 end function
107
108 !> @brief Calculate the Greville points for a given knot sequence and degree
109 !>
110 !> @param[in] knot_sequence The knot sequence
111 !> @param[in] degree The degree of the B-spline
112 !>
113 !> @return The Greville points of the B-spline
114
2/4
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 220 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 220 times.
220 pure function greville_points(knot_sequence, degree) result(ans)
115 real(wp), intent(in) :: knot_sequence(1:)
116 integer, intent(in) :: degree
117 real(wp) :: ans(1:size(knot_sequence, 1) - degree - 1)
118
119 integer :: j, r
120
121
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 220 times.
220 if (degree < 1) error stop "Greville points are only defined if degree > 0"
122
123
2/2
✓ Branch 9 → 10 taken 5052 times.
✓ Branch 9 → 15 taken 220 times.
5272 do j = 1, size(ans, 1)
124 5052 ans(j) = 0._wp
125
2/2
✓ Branch 11 → 12 taken 23490 times.
✓ Branch 11 → 13 taken 5052 times.
28542 do r = 1, degree
126 28542 ans(j) = ans(j) + knot_sequence(j + r)
127 end do
128 5272 ans(j) = ans(j) / degree
129 end do
130 220 end function
131 end module m_bspline_recurse
132