High-precision calculations for one- and two-valence atomic systems
HartreeFock.hpp
1#pragma once
2#include "Coulomb/YkTable.hpp"
3#include "HF/Breit.hpp"
4#include "Physics/PhysConst_constants.hpp"
5#include "Potentials/Parametric_potentials.hpp"
6#include "Potentials/RadPot.hpp"
7#include <memory>
8#include <optional>
9#include <string>
10#include <vector>
11class Wavefunction;
12class DiracSpinor;
13class Grid;
14namespace MBPT {
15class CorrelationPotential;
16}
17
18//! Functions and classes for Hartree-Fock
19namespace HF {
20
21//==============================================================================
22/*!
23 @brief Convergence results of for each self-consistent-field solve.
24 @details
25 Holds the output of solving for an orbital (core or valence) via an
26 iterative HF-like method: the convergence metric, iteration count, and
27 orbital identification symbol for reporting.
28 @param eps Convergence metric: relative change in orbital norm, or similar,
29 from the previous iteration.
30 @param its Number of iterations performed.
31 @param symbol Orbital identification (e.g. "2p-", "1s+") for labelling
32 output tables.
33*/
34struct EpsIts {
35 double eps{0.0};
36 int its{0};
37 std::string symbol{};
38 friend bool operator<(const EpsIts &l, const EpsIts &r) {
39 return std::abs(l.eps) < std::abs(r.eps);
40 }
41};
42
43//==============================================================================
44/*! @brief Methods available for self-consistant field model
45 @details
46 - HartreeFock: Self-consistent Hartree-Fock method
47 - ApproxHF : Approximate (localised) Hartree-Fock method
48 - Hartree : Core-Hartree method. No exchange, Vdir includes self-interaction
49 - KohnSham : Kohn-Sham (Density functional), includes Latter correction
50 - Local : Uses a local parameteric potential. [NOT self-consistant field]
51 */
52enum class Method { HartreeFock, ApproxHF, Hartree, KohnSham, Local };
53
54//! Convers string (name) of method (e.g., HartreeFock) to HF::Method enum
55Method parseMethod(const std::string &in_method);
56//! Convers HF::Method enum to string (name) of method (e.g., HartreeFock)
57std::string parseMethod(const Method &in_method);
58//! Convers HF::Method enum to short string (name) of method (e.g., HF)
59std::string parseMethod_short(const Method &in_method);
60
61//==============================================================================
62//! Forms approx (localised) exchange potential, from scratch
63//! @details Needs existing orbital Fa, and the core orbitals.
64//! k_cut is max multipolarity to sum over for exchange term [can limit to ~1
65//! (e.g.) for speed when high accuracy is not required]
66std::vector<double> vex_approx(const DiracSpinor &Fa,
67 const std::vector<DiracSpinor> &core,
68 int k_cut = 99, double lambda_cut = 0.003);
69
70//! @brief Calculates V_exch * Fa, for any orbital Fa (calculates Coulomb
71//! integral from scratch).
72//! @details k_cut is max multipolarity to sum over for exchange term [can
73//! limit to ~1 (e.g.) for speed when high accuracy is not required]
74DiracSpinor vexFa(const DiracSpinor &Fa, const std::vector<DiracSpinor> &core,
75 int k_cut = 99);
76
77//! @brief Density-based (Kohn-Sham/Slater) local exchange potential, ~rho^1/3.
78//! @details Does not depend on the orbital, so it
79//! conditions all symmetries uniformly -- useful as the local-exchange term on
80//! the LHS of the mixed-states iteration (where vex_approx, which divides by
81//! the perturbation, is poorly conditioned). Grid is taken from @p core.
82std::vector<double> vex_KS(const std::vector<DiracSpinor> &core);
83
84/*!
85 @brief Exchange of a single electron in orbital Fa, acting on Fv: X_a Fv.
86 @details
87
88 \f[ X_a F_v = -\frac{1}{[j_v]\,[j_a]}\sum_k C^k_{va}{}^2\, y^k_{av}(r)\,F_a \f]
89
90 - The b=Fa term of vexFa(), scaled to ONE electron (weight 1/[j_a] rather
91 than the subshell occupancy): the spherically-averaged one-electron
92 self-exchange.
93 - Used for the V^{N-1} (residual ion) potential: removing one electron from
94 subshell a removes y^0_aa from the direct potential and removes this term
95 from the exchange, V^{N-1}_a = V_HF - (y^0_aa + X_a).
96
97 @note All multipoles k allowed by the (v,a) triangle/parity rules are
98 included; the occupation fraction of Fa is NOT applied (exactly one
99 electron is removed).
100*/
101DiracSpinor vexFa_1el(const DiracSpinor &Fv, const DiracSpinor &Fa);
102
103//==============================================================================
104//==============================================================================
105//==============================================================================
106
107//! Solves relativistic Hartree-Fock equations for core and valence. Optionally
108//! includes Breit and QED effects. Can include Sigma (correlations) for valence
109//! states. Class stores nuc. and direct potentials, a set of yk integrals, and
110//! QED potential. Stores the core orbitals.
112
113private:
114 std::shared_ptr<const Grid> m_rgrid;
115 std::vector<DiracSpinor> m_core;
116 std::vector<double> m_vnuc;
117 std::optional<QED::RadPot> m_vrad;
118 std::optional<HF::Breit> m_VBr;
119 double m_alpha;
120 Method m_method;
121 double m_eps_HF;
122 std::vector<double> m_vdir;
123 Coulomb::YkTable m_Yab;
124 int m_max_hf_its = 128;
125
126public:
127 //! @brief Method is enum class, eps_HF is convergence goal.
128 /*! @details
129 Required:
130 - rgrid: Radial grid (shared pointer)
131 - (This is required to allow no core orbitals)
132 - Assumed to be same grid as for core orbitals
133 - vnuc - nuclear potential
134 - Assumed to be same length as radial grid
135 - A copy is stored. May be updated
136 Optional:
137 - alpha (fine structure constant). default = true value
138 - method default = HartreeFock
139 - breit_params - Breit scaling factors. If std::nullopt (default), no Breit.
140 If present, a Breit object is constructed from the params.
141 - eps_HF: convergence goal
142 - potential: which parametric potential used for initial Potential
143 - h and d (or g and t) are parameters for above (if left zero, default
144 will be chosen)
145 - Note: Parametric::Type potential (and parameters H,d) are for
146 initial approx. Usually doesn't matter at all, and defaults should be used.
147 If using local potential [method=Local], these are the final parameters. If
148 any are set to zero - will be looked up.
149 */
150 HartreeFock(std::shared_ptr<const Grid> rgrid, std::vector<double> vnuc,
151 std::vector<DiracSpinor> core,
152 std::optional<QED::RadPot> vrad = std::nullopt,
153 double m_alpha = PhysConst::alpha,
154 Method method = Method::HartreeFock,
155 std::optional<Breit::Params> breit_params = std::nullopt,
156 double eps_HF = 0.0,
157 Parametric::Type potential = Parametric::Type::Green,
158 double H_g = 0.0, double d_t = 0.0);
159
160 //! Solves HF equations self-consitantly for core orbs. Returns epsilon.
161 EpsIts solve_core(bool print = true);
162
163 //! Solves HF for given valence list. They need not already be solutions.
164 //! @details Note: If given energy is set to zero, states assumed to not be
165 //! existing solutions; initial energy is guessed and solved from scratch. If
166 //! initial energy is non-zero, that energy is used and states are assumed to
167 //! already be (approximate) solutions.
168 void
169 solve_valence(std::vector<DiracSpinor> *valence, bool print = true,
170 const MBPT::CorrelationPotential *const Sigma = nullptr) const;
171
172 //! Solves HF equation (+ Sigma) for single valence state.
174 const MBPT::CorrelationPotential *const Sigma = nullptr,
175 std::optional<double> eta = std::nullopt,
176 std::optional<int> prev_its = std::nullopt) const;
177
178 //! Solves HF equation (+ Sigma) for single valence state, alternative method
180 const MBPT::CorrelationPotential *const Sigma) const;
181
182 //! Calculates the HF core energy (not including Breit?)
183 double calculateCoreEnergy() const;
184
185 //! Calculates exchange term Vex*Fa
186 DiracSpinor vexFa(const DiracSpinor &Fa) const {
187 // calls static version with HF core
188 return ::HF::vexFa(Fa, m_core, 99);
189 }
190
191 //! Breit interaction V_Br*Fa
192 DiracSpinor VBr(const DiracSpinor &Fv) const;
193
194 //---------------------------
195
196 //! Resturns a const reference to the radial grid
197 const Grid &grid() const { return *m_rgrid; };
198 //! Resturns copy of shared_ptr to grid [shared resource] - used when we want
199 //! to construct a new object that shares this grid
200 std::shared_ptr<const Grid> grid_sptr() const { return m_rgrid; };
201
202 //! Returns reference to Vdir (direct HF potential)
203 const std::vector<double> &vdir() const { return m_vdir; }
204 std::vector<double> &vdir() { return m_vdir; }
205
206 //! Returns reference to Vnuc (nuclear potential)
207 const std::vector<double> &vnuc() const { return m_vnuc; }
208 std::vector<double> &vnuc() { return m_vnuc; }
209
210 //! Electric part of radiative potential
211 std::vector<double> Hrad_el(int l = 0) const;
212 //! Magnetic (off-diagonal) part of radiative potential. Doesn't currently
213 //! depend on l
214 std::vector<double> Hmag(int l = 0) const;
215
216 //! vlocal = vnuc + vrad_el + vdir
217 std::vector<double> vlocal(int l = 0) const;
218
219 //! Which method used to solve HF
220 Method method() const { return m_method; }
221
222 //! Effective charge at large Z : zion = Z - num_core_electrons
223 double zion() const;
224
225 //! Returns true if exchange not included
226 bool is_localQ() const {
227 return m_core.empty() ||
228 !(m_method == Method::HartreeFock || m_method == Method::ApproxHF);
229 }
230
231 //! vector of core orbitals
232 const std::vector<DiracSpinor> &core() const { return m_core; }
233
234 //! Value of fine-structure constant used
235 double alpha() const { return m_alpha; }
236
237 //! Update the Vrad used inside HF (only used if we want QED into valence but
238 // not core, for testing)
239 void set_Vrad(QED::RadPot in_vrad) { m_vrad = std::move(in_vrad); } // XXX
240 //! Get (const) ptr to Vrad - may be null
241 const QED::RadPot *Vrad() const { return m_vrad ? &*m_vrad : nullptr; }
242 QED::RadPot *Vrad() { return m_vrad ? &*m_vrad : nullptr; }
243
244 //! pointer to Breit - may be nullptr if no breit
245 const HF::Breit *vBreit() const { return m_VBr ? &*m_VBr : nullptr; }
246 //! Breit scale factor (usualy 0 or 1)
247 double x_Breit() const { return m_VBr ? m_VBr->scale_factor() : 0.0; }
248
249 //! Number of electrons in the core
250 int num_core_electrons() const;
251
252private:
253 // Solve Dirac equation for core states (just once) using existing vdir
254 // (usually, vdir set to parametric potential beforehand)
255 EpsIts solve_initial_core(const double eps);
256 // Solve equations self-consistantly for core, using local method (either
257 // core-Hartree or Kohn-Sham)
258 EpsIts selfcon_local_core(const double eps_target_HF);
259 // Solve HF equations self-consistantly for core, using approximate HF method
260 EpsIts hf_approx_core(const double eps_target_HF);
261 // Solve HF equations self-consistantly for core, using Hartree-Fock method
262 EpsIts hartree_fock_core();
263 // Solves HF equation for valence state, assuming local potential (Hartree,
264 // Local, Kohn-Sham or approxHF)
265 EpsIts local_valence(DiracSpinor &Fa) const;
266
267 /*
268 // same as hf_valence, but uses Green method
269 EpsIts hf_valence_Green(
270 DiracSpinor &Fv,
271 const MBPT::CorrelationPotential *const Sigma = nullptr) const;
272 */
273
274 // Solves HF equation for given state, using non-local Green's method for
275 // inhomogeneous ODE (used for hartree_fock_core()).
276 // Solve Dirac Equation (Eigenvalue):
277 // (H0 + Vl + Vx)Fa = 0
278 // (H0 + Vl)Fa = -VxFa
279 // Vl is local (e.g., Vnuc + fVdir), Vx is non-local (e.g., (1-f)Vdir + Vex)
280 // where v0 = (1-f)Vdir [f=1 for valence states!, so v0 may be empty]
281 // Vx also includes Breit, and Sigma
282 // Small energy adjustmenets (and wfs), solve:
283 // (Hl - e) dF = de * F -VxFa
284 // e -> e+de, F->F+dF
285 // Core is input so can call in a thread-safe way! (with a 'old_core' copy)
286 // Only used in dE from dF
287 void hf_orbital_green(
288 DiracSpinor &Fa, double en, const std::vector<double> &vl,
289 const std::vector<double> &H_mag, const DiracSpinor &VxF,
290 const std::vector<DiracSpinor> &static_core,
291 const std::vector<double> &dv0 = {}, const HF::Breit *const VBr = nullptr,
292 const MBPT::CorrelationPotential *const Sigma = nullptr) const;
293
294 // Calc's Vex*Fa, for Fa in the core. Fa must be in the core
295 void vex_Fa_core(const DiracSpinor &Fa, DiracSpinor &vexFa) const;
296
297 // Option to re-scale diract potential so that V(r)~-zion/r at large r
298 enum class ReScale { yes = true, no = false };
299 // Forms direct potential
300 void update_vdir(ReScale re_scale = ReScale::no);
301 // Adds the additional Kohn-Sham parts to Vdir
302 void add_KohnSham_vdir_addition();
303
304 // Sets Vdir to be parametric potential. By default, Greens potential
305 void
306 set_parametric_potential(bool print = true,
307 Parametric::Type potential = Parametric::Type::Green,
308 double H_g = 0.0, double d_t = 0.0);
309
310 // Forms approximate vex for all core states
311 void form_approx_vex_core(std::vector<std::vector<double>> &vex) const;
312 std::vector<std::vector<double>> form_approx_vex_core() const;
313 // Forms approximate vex for given core states
314 void form_approx_vex_core_a(const DiracSpinor &Fa,
315 std::vector<double> &vex_a) const;
316 std::vector<double> form_approx_vex_core_a(const DiracSpinor &Fa) const;
317
318 // Energy guess for core states
319 double enGuessCore(int n, int ka) const;
320 // Energy guess for valence states
321 double enGuessVal(int n, int ka) const;
322};
323
324} // namespace HF
Calculates + stores Hartree Y functions + Angular (w/ look-up), taking advantage of symmetry.
Definition YkTable.hpp:46
Stores radial Dirac spinor: F_nk = (f, g)
Definition DiracSpinor.hpp:44
Non-uniform radial grid with Jacobian, suitable for atomic structure calculations.
Definition Grid.hpp:85
Breit potentials for one- (Hartree-Fock Breit) and two-body Breit integrals.
Definition Breit.hpp:88
Solves relativistic Hartree-Fock equations for core and valence. Optionally includes Breit and QED ef...
Definition HartreeFock.hpp:111
const std::vector< double > & vnuc() const
Returns reference to Vnuc (nuclear potential)
Definition HartreeFock.hpp:207
const Grid & grid() const
Resturns a const reference to the radial grid.
Definition HartreeFock.hpp:197
double x_Breit() const
Breit scale factor (usualy 0 or 1)
Definition HartreeFock.hpp:247
std::vector< double > Hrad_el(int l=0) const
Electric part of radiative potential.
Definition HartreeFock.cpp:1155
double calculateCoreEnergy() const
Calculates the HF core energy (not including Breit?)
Definition HartreeFock.cpp:680
double zion() const
Effective charge at large Z : zion = Z - num_core_electrons.
Definition HartreeFock.cpp:1240
void set_Vrad(QED::RadPot in_vrad)
Update the Vrad used inside HF (only used if we want QED into valence but.
Definition HartreeFock.hpp:239
EpsIts hf_valence_Green(DiracSpinor &Fa, const MBPT::CorrelationPotential *const Sigma) const
Solves HF equation (+ Sigma) for single valence state, alternative method.
Definition HartreeFock.cpp:627
double alpha() const
Value of fine-structure constant used.
Definition HartreeFock.hpp:235
std::vector< double > Hmag(int l=0) const
Magnetic (off-diagonal) part of radiative potential. Doesn't currently depend on l.
Definition HartreeFock.cpp:1158
Method method() const
Which method used to solve HF.
Definition HartreeFock.hpp:220
DiracSpinor vexFa(const DiracSpinor &Fa) const
Calculates exchange term Vex*Fa.
Definition HartreeFock.hpp:186
EpsIts hf_valence(DiracSpinor &Fv, const MBPT::CorrelationPotential *const Sigma=nullptr, std::optional< double > eta=std::nullopt, std::optional< int > prev_its=std::nullopt) const
Solves HF equation (+ Sigma) for single valence state.
Definition HartreeFock.cpp:552
const HF::Breit * vBreit() const
pointer to Breit - may be nullptr if no breit
Definition HartreeFock.hpp:245
const std::vector< double > & vdir() const
Returns reference to Vdir (direct HF potential)
Definition HartreeFock.hpp:203
int num_core_electrons() const
Number of electrons in the core.
Definition HartreeFock.cpp:737
void solve_valence(std::vector< DiracSpinor > *valence, bool print=true, const MBPT::CorrelationPotential *const Sigma=nullptr) const
Solves HF for given valence list. They need not already be solutions.
Definition HartreeFock.cpp:159
DiracSpinor VBr(const DiracSpinor &Fv) const
Breit interaction V_Br*Fa.
Definition HartreeFock.cpp:729
bool is_localQ() const
Returns true if exchange not included.
Definition HartreeFock.hpp:226
EpsIts solve_core(bool print=true)
Solves HF equations self-consitantly for core orbs. Returns epsilon.
Definition HartreeFock.cpp:96
const std::vector< DiracSpinor > & core() const
vector of core orbitals
Definition HartreeFock.hpp:232
std::shared_ptr< const Grid > grid_sptr() const
Resturns copy of shared_ptr to grid [shared resource] - used when we want to construct a new object t...
Definition HartreeFock.hpp:200
const QED::RadPot * Vrad() const
Get (const) ptr to Vrad - may be null.
Definition HartreeFock.hpp:241
std::vector< double > vlocal(int l=0) const
vlocal = vnuc + vrad_el + vdir
Definition HartreeFock.cpp:723
Constructs and stores the Flambaum-Ginges QED Radiative Potential.
Definition RadPot.hpp:16
Stores Wavefunction (set of valence orbitals, grid, HF etc.)
Definition Wavefunction.hpp:38
Functions and classes for Hartree-Fock.
Definition CI_Integrals.hpp:16
std::vector< double > vex_KS(const std::vector< DiracSpinor > &core)
Density-based (Kohn-Sham/Slater) local exchange potential, ~rho^1/3.
Definition HartreeFock.cpp:1036
DiracSpinor vexFa_1el(const DiracSpinor &Fv, const DiracSpinor &Fa)
Exchange of a single electron in orbital Fa, acting on Fv: X_a Fv.
Definition HartreeFock.cpp:1128
std::string parseMethod_short(const Method &in_method)
Convers HF::Method enum to short string (name) of method (e.g., HF)
Definition HartreeFock.cpp:59
std::vector< double > vex_approx(const DiracSpinor &Fa, const std::vector< DiracSpinor > &core, int k_cut, const double lambda_cut)
Forms approx (localised) exchange potential, from scratch.
Definition HartreeFock.cpp:974
Method
Methods available for self-consistant field model.
Definition HartreeFock.hpp:52
DiracSpinor vexFa(const DiracSpinor &Fa, const std::vector< DiracSpinor > &core, int k_cut)
Calculates V_exch * Fa, for any orbital Fa (calculates Coulomb integral from scratch).
Definition HartreeFock.cpp:1093
Method parseMethod(const std::string &in_method)
Convers string (name) of method (e.g., HartreeFock) to HF::Method enum.
Definition HartreeFock.cpp:26
Many-body perturbation theory.
Definition MatrixElements.hpp:12
constexpr double alpha
Fine-structure constant: alpha = 1/137.035 999 177(21) [CODATA 2022].
Definition PhysConst_constants.hpp:24
Convergence results of for each self-consistent-field solve.
Definition HartreeFock.hpp:34