Loading...
Searching...
No Matches
constants.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * Physical constants (SI, CGS, atomic units).
5 *
6 * The SI values are the NIST 2018 CODATA recommended values; four of them
7 * (Planck, Boltzmann, elementary charge, electronvolt) are exact by the 2019
8 * SI redefinition rather than measured. CODATA is the authority: any code
9 * quoting the same revision quotes the same digits.
10 *
11 * Derived factors are one-line dimensional identities over those values --
12 * there is only one way to convert Hartree to eV -- evaluated in IEEE-754
13 * double. Agreement with another code's conversion factors is therefore a
14 * consequence of agreeing on CODATA, not of arranging the arithmetic in any
15 * particular way, and nothing in the test suite gates a last-ulp difference.
16 */
17
19
20namespace q3 {
21namespace constants {
22
23// ─── Mathematical constants ─────────────────────────────────────────────────
24inline constexpr Real pi = 3.14159265358979323846;
25inline constexpr Real two_pi = 2.0 * pi; // 2π
26inline constexpr Real four_pi = 4.0 * pi; // 4π
27inline constexpr Real sqrt_pi = 1.77245385090551602729;
28inline constexpr Real sqrt2 = 1.41421356237309504880;
29inline constexpr Real degrees_to_radians = pi / 180.0;
30
31// ─── Rydberg atomic units ───────────────────────────────────────────────────
32inline constexpr Real electron_charge_squared_rydberg = 2.0; // e² in Ry units
33inline constexpr Real spin_degeneracy = 2.0; // number of spins per level
34
35// ─── Physics defaults ───────────────────────────────────────────────────────
36/**
37 * Starting magnetization applied to every species when a spin-polarized (LSDA)
38 * run gives no starting_magnetization at all: large enough to break spin
39 * symmetry so a magnetic ground state can be found, small enough not to bias
40 * the SCF toward an artificial high-moment minimum. Explicit user values —
41 * including explicit zeros — are always honored instead.
42 */
43inline constexpr Real default_starting_magnetization = 0.2;
44
45/**
46 * How many non-monotone iterations of the DFT+U occupation matrix it takes
47 * before the SCF starts damping it.
48 *
49 * Damping perturbs the converged answer at first order in its own lag, so it
50 * is switched on by evidence rather than by default and a monotonically
51 * converging run must never trip it. Three tolerates the isolated backward
52 * step a well-behaved run can take while the wavefunctions settle, and is
53 * reached almost immediately by a genuine oscillation, which alternates every
54 * iteration.
55 */
56inline constexpr int hubbard_damping_trigger_iterations = 3;
57
58/**
59 * How many Davidson iterations a non-self-consistent pass allows each k-point.
60 *
61 * A self-consistent run re-diagonalizes every iteration, so the solver's own
62 * short cap only defers work to the next one. A non-self-consistent pass
63 * diagonalizes once and keeps whatever a capped solve leaves unconverged:
64 * copper's fourteen-band 4x4x4 capture takes 17 of the solver's 20 iterations
65 * at a basis four times the band count, and ran into them at twice, with up
66 * to seven bands unconverged at 48 of 140 k-point solves. The cap bounds a
67 * pathological solve; a converging one exits as soon as every band meets the
68 * tolerance, and one that does not is reported.
69 */
71
72/**
73 * The smallest Davidson working basis, as a multiple of the band count, that a
74 * non-self-consistent pass runs with unless the deck names a factor itself.
75 *
76 * The pass seeds each k-point from its neighbour's vectors and keeps what the
77 * solver returns. With a basis only twice the band count Davidson can settle
78 * on eigenpairs that skip a state the seed lacks, and every residual test still
79 * passes: copper's sixteen-band NSCF against direct diagonalization of the same
80 * Hamiltonian has band 16 1.18 eV high at one k-point at a factor of 2 -- a
81 * state skipped -- and more than 1 meV off at 15 of 64, against 1.2 meV at one
82 * k-point at 4. A self-consistent run re-diagonalizes every iteration and
83 * recovers, so the smaller default stays there; a deck that names a smaller
84 * factor keeps it for the pass too, and is warned.
85 */
87
88/**
89 * Clamp on the Anderson extrapolation coefficient for the DFT+U occupation
90 * matrix.
91 *
92 * The two-point secant is exact only where the residual map is locally linear.
93 * Away from that it can ask for an arbitrarily long step, so the coefficient is
94 * bounded: inside the bound Anderson does its work, at the bound the update is
95 * still a damped step in the descent direction rather than a leap.
96 */
97inline constexpr Real hubbard_anderson_theta_limit = 0.9;
98
99/**
100 * Smallest |r - r_prev|^2 for which an Anderson secant step is trusted.
101 *
102 * Two nearly identical residuals make the secant denominator vanish and the
103 * extrapolation coefficient explode; below this the step degrades to plain
104 * damping, which is slower but never wild. Kept beside the other DFT+U mixing
105 * knobs so tuning the occupation mixer means reading one place, not two.
106 */
108
109/**
110 * ─── Physical constants, SI (NIST 2018 CODATA) ─────────────────────────────
111 * Identical to the values Quantum ESPRESSO uses.
112 */
113inline constexpr Real PLANCK_CONSTANT_SI = 6.62607015e-34; // J·s
114inline constexpr Real BOLTZMANN_CONSTANT_SI = 1.380649e-23; // J/K
115inline constexpr Real ELECTRON_CHARGE_SI = 1.602176634e-19; // C
116inline constexpr Real ELECTRONVOLT_SI = 1.602176634e-19; // J
117inline constexpr Real ELECTRON_MASS_SI = 9.1093837015e-31; // kg
118inline constexpr Real HARTREE_SI = 4.3597447222071e-18; // J
119inline constexpr Real RYDBERG_SI = HARTREE_SI / 2.0; // J
120inline constexpr Real BOHR_RADIUS_SI = 0.529177210903e-10; // m
121inline constexpr Real ATOMIC_MASS_UNIT_SI = 1.66053906660e-27; // kg
122inline constexpr Real SPEED_OF_LIGHT_SI = 2.99792458e+8; // m/s
123
124/**
125 * ─── Derived unit conversion factors ────────────────────────────────────────
126 * Each is a dimensional identity over the SI values above, evaluated in
127 * IEEE-754 double at compile time. The names in parentheses are the
128 * corresponding Quantum ESPRESSO constants, given only so a reader can
129 * cross-check a value against a published number; they are labels, not the
130 * source of the definitions.
131 */
132
133/// Hartree → eV (AUTOEV)
135
136/// Bohr radius in Ångströms (BOHR_RADIUS_SI * 1e10; BOHR_RADIUS_ANGSTROM)
137inline constexpr Real BOHR_RADIUS_ANGSTROM = BOHR_RADIUS_SI * 1.0e10;
138
139/// Ångström → Bohr (ANGSTROM_AU)
141
142/// AMU → Rydberg atomic units (AMU_RY)
144
145/// Rydberg → kbar (RY_KBAR): 10 * AU_GPA / 2
146inline constexpr Real RYDBERG_TO_KILOBAR =
147 10.0 * (HARTREE_SI / (BOHR_RADIUS_SI * BOHR_RADIUS_SI * BOHR_RADIUS_SI) / 1.0e9) / 2.0;
148
149/// Boltzmann constant in Rydberg units (K_BOLTZMANN_RY)
151
152// ─── Tolerance constants (matching Quantum ESPRESSO) ────────────────────────
153inline constexpr Real epsilon_1e_minus_4 = 1.0e-4;
154inline constexpr Real epsilon_1e_minus_6 = 1.0e-6;
155inline constexpr Real epsilon_1e_minus_8 = 1.0e-8;
156inline constexpr Real epsilon_1e_minus_12 = 1.0e-12;
157inline constexpr Real epsilon_1e_minus_14 = 1.0e-14;
158inline constexpr Real epsilon_1e_minus_16 = 1.0e-16;
159
160// ─── Backward-compatible aliases ────────────────────────────────────────────
161inline constexpr Real RY_TO_EV = HARTREE_TO_EV / 2.0;
162
163} // namespace constants
164} // namespace q3
constexpr Real BOLTZMANN_CONSTANT_SI
constexpr Real hubbard_anderson_secant_minimum_denominator
constexpr Real epsilon_1e_minus_12
constexpr int hubbard_damping_trigger_iterations
Definition constants.hpp:56
constexpr Real SPEED_OF_LIGHT_SI
constexpr Real RYDBERG_SI
constexpr Real epsilon_1e_minus_6
constexpr Real RYDBERG_TO_KILOBAR
Rydberg → kbar (RY_KBAR): 10 * AU_GPA / 2.
constexpr Real sqrt_pi
Definition constants.hpp:27
constexpr Real electron_charge_squared_rydberg
Definition constants.hpp:32
constexpr Real epsilon_1e_minus_4
constexpr Real degrees_to_radians
Definition constants.hpp:29
constexpr Real BOLTZMANN_CONSTANT_RY
Boltzmann constant in Rydberg units (K_BOLTZMANN_RY)
constexpr Real epsilon_1e_minus_8
constexpr Real pi
Definition constants.hpp:24
constexpr Real ATOMIC_MASS_UNIT_SI
constexpr Real spin_degeneracy
Definition constants.hpp:33
constexpr Real epsilon_1e_minus_14
constexpr int non_self_consistent_field_minimum_davidson_basis_expansion_factor
Definition constants.hpp:86
constexpr Real two_pi
Definition constants.hpp:25
constexpr Real ANGSTROM_TO_BOHR
Ångström → Bohr (ANGSTROM_AU)
constexpr Real RY_TO_EV
constexpr Real BOHR_RADIUS_SI
constexpr int non_self_consistent_field_maximum_davidson_iterations
Definition constants.hpp:70
constexpr Real hubbard_anderson_theta_limit
Definition constants.hpp:97
constexpr Real default_starting_magnetization
Definition constants.hpp:43
constexpr Real epsilon_1e_minus_16
constexpr Real HARTREE_SI
constexpr Real ELECTRONVOLT_SI
constexpr Real HARTREE_TO_EV
Hartree → eV (AUTOEV)
constexpr Real ELECTRON_CHARGE_SI
constexpr Real ELECTRON_MASS_SI
constexpr Real BOHR_RADIUS_ANGSTROM
Bohr radius in Ångströms (BOHR_RADIUS_SI * 1e10; BOHR_RADIUS_ANGSTROM)
constexpr Real PLANCK_CONSTANT_SI
constexpr Real four_pi
Definition constants.hpp:26
constexpr Real sqrt2
Definition constants.hpp:28
constexpr Real ATOMIC_MASS_UNIT_RY
AMU → Rydberg atomic units (AMU_RY)
double Real