GCC Code Coverage Report


Directory: ./
File: app/simple_diag_newton.f90
Date: 2026-10-22 05:02:02
Coverage Exec Excl Total
Lines: 0.0% 0 0 66
Functions: 0.0% 0 0 2
Branches: 0.0% 0 0 10

Line Branch Exec Source
1 ✗ program diag_newton_main
2 !> Diagnostic application for newton_midpoint function analysis
3 !>
4 !> Reads configuration from simple.in (default) or specified file,
5 !> validates that integration mode is set to midpoint, initializes the field,
6 !> and provides detailed Newton iteration diagnostics for trapped orbit
7
8 use params, only: read_config, netcdffile, ns_s, ns_tp, multharm, &
9 ✗ integmode, params_init, isw_field_type, dtaumin, dtau, ntau, relerr
10 use simple, only: tracer_t, init_sympl
11 use simple_main, only: init_field
12 use timing, only: init_timer, print_phase_time
13 use diag_newton, only: integrate_orbit_with_newton_debug
14 use orbit_symplectic_base, only: symplectic_integrator_t, MIDPOINT
15 use field_can_mod, only: field_can_t, get_val, eval_field => evaluate
16
17 implicit none
18
19 ! Define dp kind parameter
20 integer, parameter :: dp = kind(1.0d0)
21
22 character(256) :: config_file
23 type(tracer_t) :: norb
24 type(symplectic_integrator_t) :: si
25 type(field_can_t) :: field_can
26 integer, parameter :: NUM_DEBUG_STEPS = 10
27 real(dp), dimension(5) :: z
28
29 ! Initialize timing
30 ✗ call init_timer()
31
32 ! Read configuration file name from command line arguments
33 ✗ if (command_argument_count() == 0) then
34 ✗ config_file = 'simple.in'
35 else
36 ✗ call get_command_argument(1, config_file)
37 end if
38 ✗ call print_phase_time('Command line parsing completed')
39
40 ! Initialize the system following simple.x pattern
41 ✗ call read_config(config_file)
42 ✗ call print_phase_time('Configuration reading completed')
43
44 ! Validate that integration mode is set to midpoint
45 ✗ if (integmode /= MIDPOINT) then
46 ✗ write(*, '(A)') 'ERROR: Newton midpoint diagnostic requires midpoint integration!'
47 ✗ write(*, '(A,I0)') 'Current integmode = ', integmode
48 ✗ write(*, '(A)') 'Please set integmode = 3 in simple.in for midpoint rule'
49 ✗ write(*, '(A)') 'Integration mode mapping:'
50 ✗ write(*, '(A)') ' 0: RK45'
51 ✗ write(*, '(A)') ' 1: Explicit-Implicit Euler'
52 ✗ write(*, '(A)') ' 2: Implicit-Explicit Euler'
53 ✗ write(*, '(A)') ' 3: Midpoint (required for this diagnostic)'
54 ✗ write(*, '(A)') ' 4: GAUSS1'
55 ✗ write(*, '(A)') ' 5: GAUSS2'
56 ✗ write(*, '(A)') ' 6: GAUSS3'
57 ✗ write(*, '(A)') ' 7: GAUSS4'
58 ✗ write(*, '(A)') ' 15: LOBATTO3'
59 ✗ error stop 'Incorrect integration mode for Newton midpoint diagnostic'
60 end if
61 ✗ call print_phase_time('Midpoint integration mode validation completed')
62
63 ! Validate coordinate system
64 ✗ if (isw_field_type /= 4) then
65 ✗ write(*, '(A)') 'WARNING: This diagnostic was designed for Albert coordinates (isw_field_type = 4)'
66 ✗ write(*, '(A,I0)') 'Current isw_field_type = ', isw_field_type
67 ✗ write(*, '(A)') 'The Newton iterations will still be analyzed but results may differ'
68 end if
69
70 ! Use the complete field initialization from simple_main
71 ✗ call init_field(norb, netcdffile, ns_s, ns_tp, multharm, integmode)
72 ✗ call print_phase_time('Complete field initialization completed')
73
74 ✗ call params_init
75 ✗ call print_phase_time('Parameter initialization completed')
76
77 ✗ print *, "Newton Midpoint Diagnostic Program"
78 ✗ print *, "=================================="
79 ✗ print *
80 ✗ print *, "This program provides detailed analysis of Newton iteration convergence"
81 ✗ print *, "during orbit integration using the midpoint rule."
82 ✗ print *
83 ✗ print *, "Focus: Trapped orbit at s=0.6, th=0, ph=0, vpar=0 using Midpoint method"
84 ✗ print '(A,I0,A)', "Integration: ", NUM_DEBUG_STEPS, " time steps"
85 ✗ print *
86
87 ! Initialize trapped orbit coordinates exactly like simple_main.f90
88 ✗ z(1) = 0.6_dp ! s = 0.6
89 ✗ z(2) = 0.0_dp ! theta = 0
90 ✗ z(3) = 0.0_dp ! phi = 0
91 ✗ z(4) = 0.0_dp ! pphi = 0 (trapped orbit with vpar=0)
92 ✗ z(5) = 0.0_dp ! lambda = 0 (vpar=0)
93
94 ! Initialize symplectic integrator EXACTLY like simple_main.f90
95 ✗ if (integmode > 0) call init_sympl(si, field_can, z, dtaumin, dtaumin, relerr, integmode)
96
97 ! Transfer coordinates to integrator
98 ✗ si%z = z(1:4)
99
100 ✗ print '(A,ES12.5)', 'dtau (large time step): ', dtau
101 ✗ print '(A,ES12.5)', 'dtaumin (integration time step): ', si%dt
102 ✗ print '(A,I0)', 'ntau (substeps per dtau): ', si%ntau
103 ✗ print '(A,ES12.5)', 'Absolute tolerance: ', si%atol
104 ✗ print '(A,ES12.5)', 'Relative tolerance: ', si%rtol
105 ✗ print *
106
107 ! Initialize field at starting position
108 ✗ call eval_field(field_can, si%z(1), si%z(2), si%z(3), 0)
109 ✗ call get_val(field_can, si%z(4))
110
111 ✗ print *, "Field initialization completed"
112 ✗ print *
113
114 ! Perform diagnostic integration
115 ✗ call integrate_orbit_with_newton_debug(si, field_can, NUM_DEBUG_STEPS)
116
117 ✗ call print_phase_time('Newton midpoint diagnostic analysis completed')
118
119 ✗ print *
120 ✗ print *, "Newton Midpoint Diagnostic completed successfully!"
121 ✗ print *, "Analysis shows detailed convergence behavior of Newton iterations"
122 ✗ print *, "during symplectic orbit integration using the midpoint rule."
123
124 ✗ end program diag_newton_main
125