High-precision calculations for one- and two-valence atomic systems
YkTable.hpp
1#pragma once
2#include "Angular/CkTable.hpp"
3#include "Angular/SixJTable.hpp"
4#include "Wavefunction/DiracSpinor.hpp"
5#include <vector>
6// #define YKTABLE_USE_STD_MAP
7#ifdef YKTABLE_USE_STD_MAP
8#include <unordered_map>
9#else
10#include "ankerl/unordered_dense.h"
11#endif
12
13namespace Coulomb {
14
15//! Hashmap type used to store the y^k_ab radial functions (one map per k).
16//! @details Defaults to ankerl::unordered_dense::map (fast, densely-stored,
17//! open-addressing). Define YKTABLE_USE_STD_MAP to fall back to
18//! std::unordered_map.
19#ifdef YKTABLE_USE_STD_MAP
20using YkMap = std::unordered_map<uint32_t, std::vector<double>>;
21#else
22using YkMap = ankerl::unordered_dense::map<uint32_t, std::vector<double>>;
23#endif
24
25//! @brief Calculates + stores Hartree Y functions + Angular (w/ look-up),
26//! taking advantage of symmetry
27/*! @details
28
29 Also stores a Ck and 6J table
30
31 Definitions:
32
33 \f[
34 y^k_{ij}(r) = \int_0^\infty \frac{r_<^k}{r_>^{k+1}}\rho_{ij}(r')\,{\rm d}r'
35 \f]
36
37 \f[\rho(r) = f_i(r)f_j(r) + g_i(r)g_j(r)\f]
38
39 with \f$r_< = min(r,r')\f$
40
41 @warning if you request an unstored integral, 0 will be returned without warning.
42 This is not considered an error, but a choice as to which integrals contribute.
43 It is up to the user to ensure any integral we require is included.
44
45*/
46class YkTable {
47
48private:
49 std::vector<YkMap> m_Y{};
50 Angular::CkTable m_Ck{};
51 Angular::SixJTable m_6j{};
52
53public:
54 YkTable(const std::vector<DiracSpinor> &a_orbs,
55 const std::vector<DiracSpinor> &b_orbs) {
56 calculate(a_orbs, b_orbs);
57 }
58 YkTable(const std::vector<DiracSpinor> &a_orbs) { calculate(a_orbs); }
59 YkTable() {}
60
61 //----------------------------------------------------------------------------
62 //! Re-calculates all y_ab functions (will over-ride existing ones); NOTE:
63 //! only calculates for a in as, b in bs
64 //!@details Note: will re-calculate all, so don't use this to 'extend' the
65 //! table.
66 void calculate(const std::vector<DiracSpinor> &as,
67 const std::vector<DiracSpinor> &bs);
68 //! Re-calculates all y_ij functions (will over-ride existing ones) [i and j
69 //! in as]
70 void calculate(const std::vector<DiracSpinor> &as) { calculate(as, as); }
71
72 //! Extends the Ck and 6J tables up to new maximum 2*j
73 void extend_angular(int new_max_2j);
74
75 //! Returns a (const ref) to Ck table [see Angular::CkTable]
76 const Angular::CkTable &Ck() const { return m_Ck; }
77 //! Returns a (const ref) to SixJ table [see Angular::SixJTable]
78 const Angular::SixJTable &SixJ() const { return m_6j; }
79
80 //! Returns a pointer to constant vector y^k_ab. If that integral is not
81 //! stored, returns nullptr.
82 const std::vector<double> *get(const int k, const DiracSpinor &Fa,
83 const DiracSpinor &Fb) const;
84
85 //! Calculates Rk using the existing yk integrals. Note: Ck tables
86 //! *must* include all required values, or behaviour not defined.
87 [[nodiscard]] double R(const int k, const DiracSpinor &Fa,
88 const DiracSpinor &Fb, const DiracSpinor &Fc,
89 const DiracSpinor &Fd) const;
90
91 //! Calculates Qk using the existing yk integrals. Note: Ck tables
92 //! *must* include all required values, or behaviour not defined.
93 [[nodiscard]] double Q(const int k, const DiracSpinor &Fa,
94 const DiracSpinor &Fb, const DiracSpinor &Fc,
95 const DiracSpinor &Fd) const;
96
97 //! Calculates Pk using the existing yk integrals. Note: Ck tables
98 //! *must* include all required values, or behaviour not defined.
99 [[nodiscard]] double P(const int k, const DiracSpinor &Fa,
100 const DiracSpinor &Fb, const DiracSpinor &Fc,
101 const DiracSpinor &Fd) const;
102
103 [[nodiscard]] double P2(const int k, const DiracSpinor &Fa,
104 const DiracSpinor &Fb, const DiracSpinor &Fc,
105 const DiracSpinor &Fd,
106 const std::vector<double> &fk = {}) const;
107
108 //! Calculates Wk=Qk+Pk using the existing yk integrals. Note: Ck
109 //! tables *must* include all required values, or behaviour not defined.
110 [[nodiscard]] double W(const int k, const DiracSpinor &Fa,
111 const DiracSpinor &Fb, const DiracSpinor &Fc,
112 const DiracSpinor &Fd) const;
113
114 //! Calculates Q^K(v)_bcd using existing yk integrals. Note: Ck tables
115 //! *must* include all required values, or behaviour not defined.
116 [[nodiscard]] DiracSpinor Qkv_bcd(const int k, int kappa,
117 const DiracSpinor &Fb,
118 const DiracSpinor &Fc,
119 const DiracSpinor &Fd) const;
120
121 //! Calculates P^K(v)_bcd using existing yk integrals, including (optional)
122 //! screening factors. Note: Ck tables
123 //! *must* include all required values, or behaviour not defined.
124 [[nodiscard]] DiracSpinor
125 Pkv_bcd(const int k, int kappa, const DiracSpinor &Fb, const DiracSpinor &Fc,
126 const DiracSpinor &Fd, const std::vector<double> &f2k = {}) const;
127
128 //! Checks if table is empty
129 bool empty() const { return m_Y.empty(); }
130
131private:
132 // Allocates space for the Yk table, but does not calculate Yk. This is
133 // because allocation cannot be done in parallel, but once allocation is done,
134 // calculation can be done in //
135 void allocate_space(const std::vector<DiracSpinor> &a_orbs,
136 const std::vector<DiracSpinor> &b_orbs);
137
138 // Returns key used for look-up table (unordered_map), considers symmetry
139 uint32_t ab_key(const DiracSpinor &Fa, const DiracSpinor &Fb) const;
140
141 // Returns reference to yk vector at 'key'; if no such vector exists, creates
142 // it first.
143 std::vector<double> &get_or_insert(std::size_t k, uint32_t key);
144
145 // Returns reference to yk vector at 'key'. This vector *must* exist already
146 std::vector<double> &get_ref(const int k, const DiracSpinor &Fa,
147 const DiracSpinor &Fb);
148};
149
150} // namespace Coulomb
Lookup table for Ck_ab reduced matrix elements and the special 3j symbol (j_a, j_b,...
Definition CkTable.hpp:62
Lookup table for Wigner 6j symbols.
Definition SixJTable.hpp:82
Calculates + stores Hartree Y functions + Angular (w/ look-up), taking advantage of symmetry.
Definition YkTable.hpp:46
DiracSpinor Pkv_bcd(const int k, int kappa, const DiracSpinor &Fb, const DiracSpinor &Fc, const DiracSpinor &Fd, const std::vector< double > &f2k={}) const
Calculates P^K(v)_bcd using existing yk integrals, including (optional) screening factors....
Definition YkTable.cpp:229
DiracSpinor Qkv_bcd(const int k, int kappa, const DiracSpinor &Fb, const DiracSpinor &Fc, const DiracSpinor &Fd) const
Calculates Q^K(v)_bcd using existing yk integrals. Note: Ck tables must include all required values,...
Definition YkTable.cpp:207
const Angular::CkTable & Ck() const
Returns a (const ref) to Ck table [see Angular::CkTable].
Definition YkTable.hpp:76
double Q(const int k, const DiracSpinor &Fa, const DiracSpinor &Fb, const DiracSpinor &Fc, const DiracSpinor &Fd) const
Calculates Qk using the existing yk integrals. Note: Ck tables must include all required values,...
Definition YkTable.cpp:129
const Angular::SixJTable & SixJ() const
Returns a (const ref) to SixJ table [see Angular::SixJTable].
Definition YkTable.hpp:78
void calculate(const std::vector< DiracSpinor > &as, const std::vector< DiracSpinor > &bs)
Re-calculates all y_ab functions (will over-ride existing ones); NOTE: only calculates for a in as,...
Definition YkTable.cpp:14
const std::vector< double > * get(const int k, const DiracSpinor &Fa, const DiracSpinor &Fb) const
Returns a pointer to constant vector y^k_ab. If that integral is not stored, returns nullptr.
Definition YkTable.cpp:70
double W(const int k, const DiracSpinor &Fa, const DiracSpinor &Fb, const DiracSpinor &Fc, const DiracSpinor &Fd) const
Calculates Wk=Qk+Pk using the existing yk integrals. Note: Ck tables must include all required values...
Definition YkTable.cpp:201
double R(const int k, const DiracSpinor &Fa, const DiracSpinor &Fb, const DiracSpinor &Fc, const DiracSpinor &Fd) const
Calculates Rk using the existing yk integrals. Note: Ck tables must include all required values,...
Definition YkTable.cpp:118
double P(const int k, const DiracSpinor &Fa, const DiracSpinor &Fb, const DiracSpinor &Fc, const DiracSpinor &Fd) const
Calculates Pk using the existing yk integrals. Note: Ck tables must include all required values,...
Definition YkTable.cpp:147
void extend_angular(int new_max_2j)
Extends the Ck and 6J tables up to new maximum 2*j.
Definition YkTable.cpp:46
void calculate(const std::vector< DiracSpinor > &as)
Re-calculates all y_ij functions (will over-ride existing ones) [i and j in as].
Definition YkTable.hpp:70
bool empty() const
Checks if table is empty.
Definition YkTable.hpp:129
Stores radial Dirac spinor: F_nk = (f, g)
Definition DiracSpinor.hpp:55
Functions (+classes) for computing Coulomb integrals.
Definition CoulombBreit.cpp:13
ankerl::unordered_dense::map< uint32_t, std::vector< double > > YkMap
Hashmap type used to store the y^k_ab radial functions (one map per k).
Definition YkTable.hpp:22