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//==============================================================================
86//==============================================================================
87
88//! Solves relativistic Hartree-Fock equations for core and valence. Optionally
89//! includes Breit and QED effects. Can include Sigma (correlations) for valence
90//! states. Class stores nuc. and direct potentials, a set of yk integrals, and
91//! QED potential. Stores the core orbitals.
93
94private:
95 std::shared_ptr<const Grid> m_rgrid;
96 std::vector<DiracSpinor> m_core;
97 std::vector<double> m_vnuc;
98 std::optional<QED::RadPot> m_vrad;
99 std::optional<HF::Breit> m_VBr;
100 double m_alpha;
101 Method m_method;
102 double m_eps_HF;
103 std::vector<double> m_vdir;
104 Coulomb::YkTable m_Yab;
105 int m_max_hf_its = 128;
106
107public:
108 //! @brief Method is enum class, eps_HF is convergence goal.
109 /*! @details
110 Required:
111 - rgrid: Radial grid (shared pointer)
112 - (This is required to allow no core orbitals)
113 - Assumed to be same grid as for core orbitals
114 - vnuc - nuclear potential
115 - Assumed to be same length as radial grid
116 - A copy is stored. May be updated
117 Optional:
118 - alpha (fine structure constant). default = true value
119 - method default = HartreeFock
120 - breit_params - Breit scaling factors. If std::nullopt (default), no Breit.
121 If present, a Breit object is constructed from the params.
122 - eps_HF: convergence goal
123 - potential: which parametric potential used for initial Potential
124 - h and d (or g and t) are parameters for above (if left zero, default
125 will be chosen)
126 - Note: Parametric::Type potential (and parameters H,d) are for
127 initial approx. Usually doesn't matter at all, and defaults should be used.
128 If using local potential [method=Local], these are the final parameters. If
129 any are set to zero - will be looked up.
130 */
131 HartreeFock(std::shared_ptr<const Grid> rgrid, std::vector<double> vnuc,
132 std::vector<DiracSpinor> core,
133 std::optional<QED::RadPot> vrad = std::nullopt,
134 double m_alpha = PhysConst::alpha,
135 Method method = Method::HartreeFock,
136 std::optional<Breit::Params> breit_params = std::nullopt,
137 double eps_HF = 0.0,
138 Parametric::Type potential = Parametric::Type::Green,
139 double H_g = 0.0, double d_t = 0.0);
140
141 //! Solves HF equations self-consitantly for core orbs. Returns epsilon.
142 EpsIts solve_core(bool print = true);
143
144 //! Solves HF for given valence list. They need not already be solutions.
145 //! @details Note: If given energy is set to zero, states assumed to not be
146 //! existing solutions; initial energy is guessed and solved from scratch. If
147 //! initial energy is non-zero, that energy is used and states are assumed to
148 //! already be (approximate) solutions.
149 void
150 solve_valence(std::vector<DiracSpinor> *valence, bool print = true,
151 const MBPT::CorrelationPotential *const Sigma = nullptr) const;
152
153 //! Solves HF equation (+ Sigma) for single valence state.
155 const MBPT::CorrelationPotential *const Sigma = nullptr,
156 std::optional<double> eta = std::nullopt,
157 std::optional<int> prev_its = std::nullopt) const;
158
159 //! Solves HF equation (+ Sigma) for single valence state, alternative method
161 const MBPT::CorrelationPotential *const Sigma) const;
162
163 //! Calculates the HF core energy (not including Breit?)
164 double calculateCoreEnergy() const;
165
166 //! Calculates exchange term Vex*Fa
167 DiracSpinor vexFa(const DiracSpinor &Fa) const {
168 // calls static version with HF core
169 return ::HF::vexFa(Fa, m_core, 99);
170 }
171
172 //! Breit interaction V_Br*Fa
173 DiracSpinor VBr(const DiracSpinor &Fv) const;
174
175 //---------------------------
176
177 //! Resturns a const reference to the radial grid
178 const Grid &grid() const { return *m_rgrid; };
179 //! Resturns copy of shared_ptr to grid [shared resource] - used when we want
180 //! to construct a new object that shares this grid
181 std::shared_ptr<const Grid> grid_sptr() const { return m_rgrid; };
182
183 //! Returns reference to Vdir (direct HF potential)
184 const std::vector<double> &vdir() const { return m_vdir; }
185 std::vector<double> &vdir() { return m_vdir; }
186
187 //! Returns reference to Vnuc (nuclear potential)
188 const std::vector<double> &vnuc() const { return m_vnuc; }
189 std::vector<double> &vnuc() { return m_vnuc; }
190
191 //! Electric part of radiative potential
192 std::vector<double> Hrad_el(int l = 0) const;
193 //! Magnetic (off-diagonal) part of radiative potential. Doesn't currently
194 //! depend on l
195 std::vector<double> Hmag(int l = 0) const;
196
197 //! vlocal = vnuc + vrad_el + vdir
198 std::vector<double> vlocal(int l = 0) const;
199
200 //! Which method used to solve HF
201 Method method() const { return m_method; }
202
203 //! Effective charge at large Z : zion = Z - num_core_electrons
204 double zion() const;
205
206 //! Returns true if exchange not included
207 bool is_localQ() const {
208 return m_core.empty() ||
209 !(m_method == Method::HartreeFock || m_method == Method::ApproxHF);
210 }
211
212 //! vector of core orbitals
213 const std::vector<DiracSpinor> &core() const { return m_core; }
214
215 //! Value of fine-structure constant used
216 double alpha() const { return m_alpha; }
217
218 //! Update the Vrad used inside HF (only used if we want QED into valence but
219 // not core, for testing)
220 void set_Vrad(QED::RadPot in_vrad) { m_vrad = std::move(in_vrad); } // XXX
221 //! Get (const) ptr to Vrad - may be null
222 const QED::RadPot *Vrad() const { return m_vrad ? &*m_vrad : nullptr; }
223 QED::RadPot *Vrad() { return m_vrad ? &*m_vrad : nullptr; }
224
225 //! pointer to Breit - may be nullptr if no breit
226 const HF::Breit *vBreit() const { return m_VBr ? &*m_VBr : nullptr; }
227 //! Breit scale factor (usualy 0 or 1)
228 double x_Breit() const { return m_VBr ? m_VBr->scale_factor() : 0.0; }
229
230 //! Number of electrons in the core
231 int num_core_electrons() const;
232
233private:
234 // Solve Dirac equation for core states (just once) using existing vdir
235 // (usually, vdir set to parametric potential beforehand)
236 EpsIts solve_initial_core(const double eps);
237 // Solve equations self-consistantly for core, using local method (either
238 // core-Hartree or Kohn-Sham)
239 EpsIts selfcon_local_core(const double eps_target_HF);
240 // Solve HF equations self-consistantly for core, using approximate HF method
241 EpsIts hf_approx_core(const double eps_target_HF);
242 // Solve HF equations self-consistantly for core, using Hartree-Fock method
243 EpsIts hartree_fock_core();
244 // Solves HF equation for valence state, assuming local potential (Hartree,
245 // Local, Kohn-Sham or approxHF)
246 EpsIts local_valence(DiracSpinor &Fa) const;
247
248 /*
249 // same as hf_valence, but uses Green method
250 EpsIts hf_valence_Green(
251 DiracSpinor &Fv,
252 const MBPT::CorrelationPotential *const Sigma = nullptr) const;
253 */
254
255 // Solves HF equation for given state, using non-local Green's method for
256 // inhomogeneous ODE (used for hartree_fock_core()).
257 // Solve Dirac Equation (Eigenvalue):
258 // (H0 + Vl + Vx)Fa = 0
259 // (H0 + Vl)Fa = -VxFa
260 // Vl is local (e.g., Vnuc + fVdir), Vx is non-local (e.g., (1-f)Vdir + Vex)
261 // where v0 = (1-f)Vdir [f=1 for valence states!, so v0 may be empty]
262 // Vx also includes Breit, and Sigma
263 // Small energy adjustmenets (and wfs), solve:
264 // (Hl - e) dF = de * F -VxFa
265 // e -> e+de, F->F+dF
266 // Core is input so can call in a thread-safe way! (with a 'old_core' copy)
267 // Only used in dE from dF
268 void hf_orbital_green(
269 DiracSpinor &Fa, double en, const std::vector<double> &vl,
270 const std::vector<double> &H_mag, const DiracSpinor &VxF,
271 const std::vector<DiracSpinor> &static_core,
272 const std::vector<double> &dv0 = {}, const HF::Breit *const VBr = nullptr,
273 const MBPT::CorrelationPotential *const Sigma = nullptr) const;
274
275 // Calc's Vex*Fa, for Fa in the core. Fa must be in the core
276 void vex_Fa_core(const DiracSpinor &Fa, DiracSpinor &vexFa) const;
277
278 // Option to re-scale diract potential so that V(r)~-zion/r at large r
279 enum class ReScale { yes = true, no = false };
280 // Forms direct potential
281 void update_vdir(ReScale re_scale = ReScale::no);
282 // Adds the additional Kohn-Sham parts to Vdir
283 void add_KohnSham_vdir_addition();
284
285 // Sets Vdir to be parametric potential. By default, Greens potential
286 void
287 set_parametric_potential(bool print = true,
288 Parametric::Type potential = Parametric::Type::Green,
289 double H_g = 0.0, double d_t = 0.0);
290
291 // Forms approximate vex for all core states
292 void form_approx_vex_core(std::vector<std::vector<double>> &vex) const;
293 std::vector<std::vector<double>> form_approx_vex_core() const;
294 // Forms approximate vex for given core states
295 void form_approx_vex_core_a(const DiracSpinor &Fa,
296 std::vector<double> &vex_a) const;
297 std::vector<double> form_approx_vex_core_a(const DiracSpinor &Fa) const;
298
299 // Energy guess for core states
300 double enGuessCore(int n, int ka) const;
301 // Energy guess for valence states
302 double enGuessVal(int n, int ka) const;
303};
304
305} // namespace HF
Calculates + stores Hartree Y functions + Angular (w/ look-up), taking advantage of symmetry.
Definition YkTable.hpp:31
Stores radial Dirac spinor: F_nk = (f, g)
Definition DiracSpinor.hpp:42
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:92
const std::vector< double > & vnuc() const
Returns reference to Vnuc (nuclear potential)
Definition HartreeFock.hpp:188
const Grid & grid() const
Resturns a const reference to the radial grid.
Definition HartreeFock.hpp:178
double x_Breit() const
Breit scale factor (usualy 0 or 1)
Definition HartreeFock.hpp:228
std::vector< double > Hrad_el(int l=0) const
Electric part of radiative potential.
Definition HartreeFock.cpp:1128
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:1213
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:220
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:216
std::vector< double > Hmag(int l=0) const
Magnetic (off-diagonal) part of radiative potential. Doesn't currently depend on l.
Definition HartreeFock.cpp:1131
Method method() const
Which method used to solve HF.
Definition HartreeFock.hpp:201
DiracSpinor vexFa(const DiracSpinor &Fa) const
Calculates exchange term Vex*Fa.
Definition HartreeFock.hpp:167
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:226
const std::vector< double > & vdir() const
Returns reference to Vdir (direct HF potential)
Definition HartreeFock.hpp:184
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:207
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:213
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:181
const QED::RadPot * Vrad() const
Get (const) ptr to Vrad - may be null.
Definition HartreeFock.hpp:222
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:37
Functions and classes for Hartree-Fock.
Definition CI_Integrals.hpp:13
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
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 CI_Integrals.hpp:10
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