Loading...
Searching...
No Matches
tolerances.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * Numerical tolerances and thresholds used throughout Q3.
5 *
6 * All values are defined as `inline constexpr` to ensure a single definition
7 * across translation units. Separated into pure mathematical thresholds and
8 * physics-specific thresholds.
9 */
10
11namespace q3 {
12namespace math::tolerances {
13
14/**
15 * ─── Pure Mathematical Thresholds ────────────────────────────────────────────
16 * These are numerical-analysis constants independent of any physical domain.
17 */
18
19/**
20 * Threshold below which a vector magnitude is treated as zero.
21 */
22inline constexpr double zero_vector_magnitude_threshold = 1e-10;
23
24/**
25 * Threshold below which a floating-point value is treated as numerically zero.
26 * Used for quantities like overlap coefficients, azimuthal angles, etc.
27 */
28inline constexpr double numerical_zero_threshold = 1e-12;
29
30/**
31 * Minimum finite difference step for numerical derivatives.
32 */
33inline constexpr double minimum_finite_difference_step = 1e-10;
34
35/**
36 * Threshold below which a vector norm squared is treated as zero in iterative solvers.
37 * Used in Davidson diagonalizer for residual norm and orthogonalization checks.
38 */
39inline constexpr double iterative_solver_norm_threshold = 1e-14;
40
41/**
42 * Floor on the magnitude a relative change is measured against, so that an
43 * objective that has reached exactly zero has a relative change at all.
44 */
45inline constexpr double relative_change_scale_floor = 1e-30;
46
47/**
48 * Minimum denominator value for preconditioner in iterative eigensolvers.
49 */
50inline constexpr double preconditioner_denominator_floor = 1e-4;
51
52/**
53 * Empty (unoccupied) bands converge to a looser tolerance than occupied bands:
54 * their eigenvalues do not enter the total energy, so tight convergence is
55 * wasted work. The effective empty-band tolerance is
56 * max(empty_band_tolerance_relaxation_factor * tolerance, empty_band_tolerance_floor).
57 *
58 * Both numbers are iteration-path knobs, not answers: they decide when a band
59 * stops being refined, never what it converges to, so no result in the test
60 * suite distinguishes these values from neighbouring ones. The floor is what
61 * stops the relaxed tolerance chasing the occupied one down as the SCF
62 * tightens; the factor is small enough that a badly-converged empty band still
63 * cannot pollute the subspace it spans.
64 */
65inline constexpr double empty_band_tolerance_relaxation_factor = 5.0;
66inline constexpr double empty_band_tolerance_floor = 1e-5;
67
68/**
69 * Threshold below which a Gaunt coefficient is considered insignificant.
70 */
71inline constexpr double gaunt_coefficient_threshold = 1e-6;
72
73/**
74 * Minimum overlap-matrix eigenvalue accepted by Lowdin orthogonalization.
75 * Below this the atomic-orbital overlap S is treated as singular (linearly
76 * dependent orbitals) and S^{-1/2} would amplify noise by >= 1e5.
77 */
78inline constexpr double lowdin_minimum_overlap_eigenvalue = 1e-10;
79
80/**
81 * ─── Physics-Specific Thresholds ─────────────────────────────────────────────
82 * These encode domain knowledge about DFT, plane-wave methods, or specific
83 * physical quantities.
84 */
85
86/**
87 * Whether to truncate radial integrations at a finite radius.
88 */
89inline constexpr bool use_radial_integration_truncation = true;
90
91/**
92 * Truncation radius (Bohr) for radial integration.
93 */
94inline constexpr double radial_integration_truncation_radius = 10.0;
95
96/**
97 * Threshold below which a D-matrix element is treated as zero.
98 */
99inline constexpr double d_matrix_element_threshold = 1e-15;
100
101/**
102 * Threshold below which a cell volume is treated as zero (uninitialized).
103 */
104inline constexpr double cell_volume_threshold = 1e-10;
105
106/**
107 * Default q-grid spacing (in atomic units) for radial Fourier transform interpolation tables.
108 */
109inline constexpr double default_q_grid_spacing = 0.01;
110
111/**
112 * Default number of q-points for atomic wavefunction interpolation tables.
113 */
115
116/**
117 * Threshold below which an occupation number is treated as zero (unoccupied).
118 */
119inline constexpr double occupation_threshold = 1e-10;
120
121/**
122 * Threshold below which a smearing width is treated as zero (insulating).
123 */
124inline constexpr double smearing_width_threshold = 1e-10;
125
126/**
127 * Rounding tolerance for energy cutoff comparisons (G-vector inclusion).
128 */
129inline constexpr double energy_cutoff_rounding_tolerance = 1e-8;
130
131/**
132 * Default symmetry precision for spglib operations (in Bohr).
133 */
134inline constexpr double default_symmetry_precision = 1e-5;
135
136/**
137 * How far a fractional translation component may sit from 1/n and still be read
138 * as 1/n when the FFT grid is asked to be divisible by n.
139 *
140 * The translations come from spglib and are accurate to the symmetry precision
141 * it was given, so the bound has to be at least that loose; it is two orders
142 * looser so that tightening that precision never starts rejecting a genuine
143 * fraction. What it must separate is coarser than either number by far: the
144 * closest competing value for the smallest accepted denominator is 1/6 against
145 * 1/5 or 1/7, 0.03 away, and the difference that motivated checking at all --
146 * 0.375 read as 1/3 -- is 0.04 away.
147 */
148inline constexpr double fractional_translation_rounding_tolerance = 1e-3;
149
150/**
151 * Finite difference step size for numerical gradient computation in reciprocal space.
152 */
153inline constexpr double reciprocal_space_finite_difference_step = 1e-5;
154
155/**
156 * Threshold below which a spherical Bessel function argument is treated as zero.
157 */
158inline constexpr double bessel_argument_zero_threshold = 1e-8;
159
160/**
161 * Convergence threshold for Fermi energy bisection.
162 */
163inline constexpr double fermi_energy_bisection_convergence = 1e-12;
164
165/**
166 * Electron-count slack that still counts as "on the plateau" when bracketing
167 * a gap to place E_F at its midpoint.
168 *
169 * Across a gap the smeared electron count equals the target only up to the
170 * occupation tails, so the upper-edge bisection needs a tolerance rather than
171 * an exact equality. Loose enough to span a real gap's residual tails. A
172 * metal has a bracket too, this slack over its density of states, and the
173 * midpoint of that one would leave half the slack in the cell as extra charge;
174 * the calculator tells the two apart by comparing the bracket with the
175 * smearing width, not by this value.
176 */
177inline constexpr double fermi_electron_count_plateau = 1e-6;
178
179/**
180 * How far a k-point weight sum may sit from the spin degeneracy and still count
181 * as a Brillouin-zone sampling.
182 *
183 * Loose because the sum is built from symmetry multiplicities over a point
184 * count and carries ordinary rounding; the case it exists to catch misses by
185 * whole integers rather than by rounding, since a band path gives every point
186 * weight 1 and its sum is the number of points.
187 */
188inline constexpr double kpoint_weight_sum = 1e-6;
189
190/**
191 * How far n * k may sit from the common grid offset, in units of the grid
192 * step, and still count as a point of an n-division grid when a grid is
193 * recovered from an explicit k-point list.
194 *
195 * Listed coordinates carry their printing noise, ~1e-10, which the largest
196 * grid tried (1000 divisions) magnifies to ~1e-7. A point genuinely off an
197 * n-division grid, k = p/m, misses it by at least 1/m of a step -- 1e-3 for
198 * the finest grid tried. A q0 displacement of the whole list is common to
199 * every point, so it moves the offset rather than the test.
200 */
201inline constexpr double kpoint_grid_offset_tolerance = 1e-6;
202
203/**
204 * Initial eigenvalue diagonalization tolerance for early SCF iterations.
205 */
206inline constexpr double initial_eigenvalue_tolerance = 1e-2;
207
208/**
209 * Floor for adaptive eigenvalue tolerance to prevent numerical issues.
210 */
211inline constexpr double minimum_eigenvalue_tolerance = 1e-13;
212
213/**
214 * Minimum electron density value to prevent division by zero in XC functionals.
215 */
216inline constexpr double minimum_electron_density = 1e-12;
217
218/**
219 * Ewald summation convergence check threshold.
220 *
221 * Also used by MartynaTuckermanCorrectionCalculator's convergence-parameter
222 * search (select_convergence_parameters()), which bounds the same kind of
223 * erf/erfc-smoothed reciprocal-space truncation error, at the same value
224 * Quantum ESPRESSO uses when it sets up its own Martyna-Tuckerman correction.
225 */
226inline constexpr double ewald_convergence_threshold = 1e-7;
227
228/**
229 * Default threshold for energy consistency checks.
230 */
231inline constexpr double energy_consistency_threshold = 1e-8;
232
233/**
234 * Relative finite difference step scale for stress tensor gradient computation.
235 */
236inline constexpr double stress_finite_difference_scale = 1e-6;
237
238/**
239 * Threshold for the sum of |k_x| + |k_y| + |k_z| (in crystal coordinates)
240 * below which a k-point is treated as the Gamma point.
241 */
242inline constexpr double kpoint_gamma_threshold = 1e-10;
243
244/**
245 * Smallest singular value of the trial-orbital projection A(k) below which
246 * the orbitals are taken not to span the target manifold at that k-point: the
247 * projection gauge A (A^dagger A)^(-1/2) is then singular, and is refused.
248 */
249inline constexpr double wannier_projection_singular_value_threshold = 1e-8;
250
251/**
252 * Modulus of a diagonal neighbour overlap M_nn(k,b) below which the Berry
253 * phase of Wannier function n -- its centre and its spread -- is undefined:
254 * the gauge has collapsed.
255 */
256inline constexpr double wannier_diagonal_overlap_threshold = 1e-10;
257
258/**
259 * How negative the gauge-invariant spread may come out, per Wannier function
260 * in bohr squared, before it is read as overlaps that are not between
261 * orthonormal states rather than as rounding. Omega_I cannot be negative.
262 */
263inline constexpr double wannier_negative_spread_tolerance = 1e-8;
264
265/**
266 * Relative width of a shell of lattice vectors: two |R| closer than this
267 * share a shell when the decay of a real-space Hamiltonian is measured on
268 * its outermost one.
269 */
270inline constexpr double lattice_shell_relative_width = 1e-6;
271
272} // namespace math::tolerances
273} // namespace q3
constexpr double lowdin_minimum_overlap_eigenvalue
constexpr double numerical_zero_threshold
constexpr double smearing_width_threshold
constexpr double iterative_solver_norm_threshold
constexpr double kpoint_gamma_threshold
constexpr double ewald_convergence_threshold
constexpr double wannier_negative_spread_tolerance
constexpr bool use_radial_integration_truncation
constexpr double d_matrix_element_threshold
constexpr double minimum_finite_difference_step
constexpr double stress_finite_difference_scale
constexpr double zero_vector_magnitude_threshold
constexpr double minimum_electron_density
constexpr double radial_integration_truncation_radius
constexpr double wannier_projection_singular_value_threshold
constexpr double preconditioner_denominator_floor
constexpr double minimum_eigenvalue_tolerance
constexpr double lattice_shell_relative_width
constexpr double reciprocal_space_finite_difference_step
constexpr double relative_change_scale_floor
constexpr double default_symmetry_precision
constexpr int default_number_of_q_points_for_atomic_wavefunctions
constexpr double energy_cutoff_rounding_tolerance
constexpr double fractional_translation_rounding_tolerance
constexpr double occupation_threshold
constexpr double empty_band_tolerance_relaxation_factor
constexpr double kpoint_grid_offset_tolerance
constexpr double default_q_grid_spacing
constexpr double fermi_electron_count_plateau
constexpr double empty_band_tolerance_floor
constexpr double gaunt_coefficient_threshold
constexpr double energy_consistency_threshold
constexpr double fermi_energy_bisection_convergence
constexpr double initial_eigenvalue_tolerance
constexpr double kpoint_weight_sum
constexpr double cell_volume_threshold
constexpr double bessel_argument_zero_threshold
constexpr double wannier_diagonal_overlap_threshold