GCC Code Coverage Report


Directory: ./
File: src/restart.f90
Date: 2026-10-22 05:02:02
Coverage Exec Excl Total
Lines: 96.0% 48 0 50
Functions: 100.0% 2 0 2
Branches: 72.9% 51 0 70

Line Branch Exec Source
1 module restart_mod
2 use, intrinsic :: iso_fortran_env, only: dp => real64
3 use finite_check, only: is_finite
4 use params, only: ntestpart, times_lost, orbit_exit_code, &
5 boundary_event_radial_residual, boundary_event_time_width, &
6 trap_par, perp_inv, zend, &
7 confpart_pass, confpart_trap, ntimstep, kt_macro, &
8 v0, dtaumin, trace_time, ORBIT_EXIT_COMPLETED, &
9 ORBIT_EXIT_LCFS, ORBIT_EXIT_WALL, ORBIT_EXIT_NUMERICAL_CONFINED
10 implicit none
11 private
12
13 public :: particle_done, read_restart_data, restore_confined_counts
14
15 logical, allocatable :: particle_done(:)
16
17 contains
18
19 4 subroutine read_restart_data()
20 integer :: i, idx, unit, ios, exit_code
21 real(dp) :: tl, tp, s1, pi_val, exit_time, radial_residual, time_width
22 real(dp) :: ze(5)
23
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (allocated(particle_done)) deallocate(particle_done)
25
7/14
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 4 times.
12 allocate (particle_done(ntestpart))
26
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 4 times.
47 particle_done = .false.
27
28 open (newunit=unit, file='times_lost.dat', status='old', &
29 4 action='read', iostat=ios, recl=1024)
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ios /= 0) then
31 ✗ print *, 'restart: cannot open times_lost.dat, starting from scratch'
32 ✗ return
33 end if
34
35
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 4 times.
47 do i = 1, ntestpart
36 43 read (unit, *, iostat=ios) idx, tl, tp, s1, pi_val, ze
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (ios /= 0) exit
38
2/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 43 times.
43 if (idx < 1 .or. idx > ntestpart) cycle
39
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 18 times.
43 if (.not. is_finite(tl) .or. tl < 0.0d0) cycle
40 18 times_lost(idx) = tl
41
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
18 if (tl >= trace_time) then
42 13 particle_done(idx) = .true.
43 13 orbit_exit_code(idx) = ORBIT_EXIT_COMPLETED
44 end if
45 18 trap_par(idx) = tp
46 18 perp_inv(idx) = pi_val
47
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
137 zend(:, idx) = ze
48 end do
49
50 4 close (unit)
51
52 open (newunit=unit, file='orbit_exit_code.dat', status='old', &
53 4 action='read', iostat=ios, recl=1024)
54
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (ios == 0) then
55
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 do i = 1, ntestpart
56 9 read (unit, *, iostat=ios) idx, exit_code, exit_time, &
57 18 radial_residual, time_width
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ios /= 0) exit
59
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (idx < 1 .or. idx > ntestpart) cycle
60
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 5 times.
9 if (.not. is_finite(exit_time) .or. exit_time < 0d0) cycle
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (abs(exit_time - times_lost(idx)) > &
62 16d0*epsilon(exit_time)*max(1d0, abs(exit_time))) cycle
63 5 orbit_exit_code(idx) = exit_code
64 5 boundary_event_radial_residual(idx) = radial_residual
65 5 boundary_event_time_width(idx) = time_width
66 particle_done(idx) = exit_code == ORBIT_EXIT_COMPLETED .or. &
67 exit_code == ORBIT_EXIT_LCFS .or. &
68 exit_code == ORBIT_EXIT_WALL .or. &
69 11 exit_code == ORBIT_EXIT_NUMERICAL_CONFINED
70 end do
71 2 close (unit)
72 end if
73
4/4
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 26 times.
47 print *, 'restart: loaded', count(particle_done), '/', ntestpart, &
74 8 'finished particles'
75 end subroutine read_restart_data
76
77 2 subroutine restore_confined_counts()
78 integer :: i, it
79 real(dp) :: survived_steps
80 logical :: passing
81
82
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 2 times.
38 do i = 1, ntestpart
83
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 22 times.
36 if (.not. particle_done(i)) cycle
84 14 passing = trap_par(i) < 0.0d0
85 14 survived_steps = times_lost(i)*v0/dtaumin
86
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 562 times.
576 do it = 1, ntimstep
87
2/2
✓ Branch 0 taken 555 times.
✓ Branch 1 taken 7 times.
562 if (orbit_exit_code(i) == ORBIT_EXIT_COMPLETED) then
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 555 times.
555 if (real(kt_macro(it), dp) > survived_steps) exit
89 else
90
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
7 if (real(kt_macro(it), dp) >= survived_steps) exit
91 end if
92
2/2
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 305 times.
596 if (passing) then
93 255 confpart_pass(it) = confpart_pass(it) + 1.0d0
94 else
95 305 confpart_trap(it) = confpart_trap(it) + 1.0d0
96 end if
97 end do
98 end do
99 2 end subroutine restore_confined_counts
100
101 end module restart_mod
102