@@ -35,7 +35,14 @@ function tpsi!(tpsi_var::Ref{ComplexF64}, psi::Float64, n::Int, l::Int,
3535 op_wmats:: Union{Nothing,Array{ComplexF64,3}} = nothing ,
3636 rex_override:: Union{Nothing,Float64} = nothing ,
3737 imx_override:: Union{Nothing,Float64} = nothing ,
38- atol_xlmda:: Float64 = 1e-9 , rtol_xlmda:: Float64 = 1e-6 )
38+ atol_xlmda:: Float64 = 1e-9 , rtol_xlmda:: Float64 = 1e-6 ,
39+ atol_x:: Float64 = NaN , rtol_x:: Float64 = NaN ,
40+ nested_tolerance_margin:: Float64 = 1e-2 )
41+
42+ # The pitch integrand is itself the energy integral, so the energy level is resolved
43+ # tighter than the pitch level (explicit atol_x/rtol_x override the derived values).
44+ atol_energy = isnan (atol_x) ? nested_tolerance_margin * atol_xlmda : atol_x
45+ rtol_energy = isnan (rtol_x) ? nested_tolerance_margin * rtol_xlmda : rtol_x
3946
4047 # Enforce bounds
4148 if psi > 1
@@ -233,7 +240,7 @@ function tpsi!(tpsi_var::Ref{ComplexF64}, psi::Float64, n::Int, l::Int,
233240 B_vpar= B_vpar,
234241 smat= smat_f, tmat= tmat_f, xmat= xmat_f,
235242 ymat= ymat_f, zmat= zmat_f,
236- energy_atol= atol_xlmda , energy_rtol= rtol_xlmda ,
243+ energy_atol= atol_energy , energy_rtol= rtol_energy ,
237244 pitch_atol= atol_xlmda, pitch_rtol= rtol_xlmda,
238245 rex_override= rex_override, imx_override= imx_override)
239246 end
@@ -897,7 +904,9 @@ function compute_kinetic_matrices_at_psi!(
897904 electron:: Bool , equil, intr:: KineticForcesInternal ,
898905 kinetic_profiles:: Equilibrium.KineticProfileSplines ;
899906 nutype:: String = " harmonic" , f0type:: String = " maxwellian" , nufac:: Float64 = 1.0 ,
900- atol_xlmda:: Float64 = 1e-9 , rtol_xlmda:: Float64 = 1e-6 )
907+ atol_xlmda:: Float64 = 1e-9 , rtol_xlmda:: Float64 = 1e-6 ,
908+ atol_x:: Float64 = NaN , rtol_x:: Float64 = NaN ,
909+ nested_tolerance_margin:: Float64 = 1e-2 )
901910
902911 # Bypass ψ > 1 (no kinetic contribution outside plasma)
903912 if psi > 1
@@ -906,13 +915,17 @@ function compute_kinetic_matrices_at_psi!(
906915 return nothing
907916 end
908917
918+ # See tpsi!: the energy integral is the pitch integrand, so it is resolved tighter.
919+ atol_energy = isnan (atol_x) ? nested_tolerance_margin * atol_xlmda : atol_x
920+ rtol_energy = isnan (rtol_x) ? nested_tolerance_margin * rtol_xlmda : rtol_x
921+
909922 state = _setup_surface_state (psi, zi, mi, electron,
910923 equil, intr, kinetic_profiles)
911924
912925 kinetic_energy_matrices_for_euler_lagrange! (
913926 kwmat, ktmat, state, psi, n, l, wdfac, intr;
914927 nutype, f0type, nufac,
915- energy_atol= atol_xlmda , energy_rtol= rtol_xlmda ,
928+ energy_atol= atol_energy , energy_rtol= rtol_energy ,
916929 pitch_atol= atol_xlmda, pitch_rtol= rtol_xlmda)
917930
918931 return nothing
0 commit comments