ampsci
High-precision calculations for one- and two-valence atomic systems
CSF.hpp
1#pragma once
2#include "LinAlg/include.hpp"
3#include "Wavefunction/DiracSpinor.hpp"
4#include <array>
5#include <optional>
6#include <utility>
7#include <vector>
8
9namespace CI {
10
11//==============================================================================
12//! Very basic two-electron CSF. Only two-electron is implemented.
13class CSF2 {
14 int m_parity;
15
16public:
17 // nb: array of states is always sorted
18 std::array<DiracSpinor::Index, 2> states;
19
20 CSF2(const DiracSpinor &a, const DiracSpinor &b);
21
22 DiracSpinor::Index state(std::size_t i) const;
23
24 friend bool operator==(const CSF2 &A, const CSF2 &B);
25 friend bool operator!=(const CSF2 &A, const CSF2 &B);
26
27 //! Returns number of different orbitals between two CSFs
28 static int num_different(const CSF2 &A, const CSF2 &B);
29
30 //! returns _different_ orbitals, for case where CSFs differ by 1.
31 //! i.e., returns {n,a} where |V> = |X_a^n> (i.e., V has n, but not a)
32 static std::array<DiracSpinor::Index, 2> diff_1_na(const CSF2 &V,
33 const CSF2 &X);
34 //! Returns the state in A and B that is the same (assumes A and B differ by 1)
35 static DiracSpinor::Index same_1_j(const CSF2 &A, const CSF2 &B);
36
37 //! Parity of the CSF, +/-1
38 int parity() const;
39
40 //! Single-particle configuration as a string, in relativistic or non-rel form
41 std::string config(bool relativistic = false) const;
42};
43
44//==============================================================================
45//! Forms list of all possible (2-particle) CSFs with given J and parity
46std::vector<CSF2> form_CSFs(int twoJ, int parity,
47 const std::vector<DiracSpinor> &cisp_basis);
48
49//==============================================================================
50//! Basic configuration info for each CI level solution
51struct ConfigInfo {
52 // configuration (typically uses non-rel notation)
53 std::string config{};
54 // square of config coeficient (if non-rel, sum of all)
55 double ci2{0.0};
56 double gJ{0.0};
57 double L{-1.0};
58 double twoS{-1.0};
59};
60
61//==============================================================================
62//! Stores the CI Solutions for given J and parity (only two-electron).
63class PsiJPi {
64
65 int m_twoj{-1};
66 int m_pi{0};
67
68 // Number of solutions stored:
69 std::size_t m_num_solutions{0};
70 // List of CSFs
71 std::vector<CSF2> m_CSFs{};
72 // Energy, and CI expansion coeficients
73 std::pair<LinAlg::Vector<double>, LinAlg::Matrix<double>> m_Solution{};
74 std::vector<ConfigInfo> m_Info{};
75
76public:
77 //! Construct containter for CI solutions.
78 //! Constructs the CSFs, but doesn't solve system; have to call solve().
79 PsiJPi(int twoJ, int pi, const std::vector<DiracSpinor> &cisp_basis)
80 : m_twoj(twoJ), m_pi(pi), m_CSFs(form_CSFs(twoJ, pi, cisp_basis)) {}
81
82 PsiJPi() {}
83
84 //! Solves the CI equation for Hamiltonian matrix Hci;
85 //! finds first num_solutions solutions.
86 //! Doesn't set the Config info: have to call update_config_info() manually.
87 //! @details If num_solutions<=0 (or not given), will calculate _all_ solutions
88 void solve(const LinAlg::Matrix<double> &Hci, int num_solutions = 0,
89 std::optional<double> all_below = {});
90
91 //! You must manuall update the config. info for each solution (if required)
92 void update_config_info(std::size_t i, const ConfigInfo &info);
93
94 //! Full list of CSFs
95 const std::vector<CSF2> &CSFs() const;
96
97 //! The ith CSF
98 const CSF2 &CSF(std::size_t i) const;
99
100 //! Energy of the ith CI solution
101 double energy(std::size_t i) const;
102
103 //! List of CI expansion coefs for the ith CI solution
104 LinAlg::View<const double> coefs(std::size_t i) const;
105
106 //! The CI coeficient for the ith CI solution, corresponding to the jth CSF
107 double coef(std::size_t i, std::size_t j) const;
108
109 //! Parity for the CI solutions (+/-1)
110 int parity() const;
111
112 //! 2J for the CI solutions
113 int twoJ() const;
114
115 //! Number of CI solutions stored
116 std::size_t num_solutions() const;
117
118 //! Configuration info for the ith CI solution, if it has been set
119 const ConfigInfo &info(std::size_t i) const;
120};
121
122} // namespace CI
Very basic two-electron CSF. Only two-electron is implemented.
Definition CSF.hpp:13
static DiracSpinor::Index same_1_j(const CSF2 &A, const CSF2 &B)
Returns the state in A and B that is the same (assumes A and B differ by 1)
Definition CSF.cpp:55
std::string config(bool relativistic=false) const
Single-particle configuration as a string, in relativistic or non-rel form.
Definition CSF.cpp:70
int parity() const
Parity of the CSF, +/-1.
Definition CSF.cpp:68
static int num_different(const CSF2 &A, const CSF2 &B)
Returns number of different orbitals between two CSFs.
Definition CSF.cpp:30
static std::array< DiracSpinor::Index, 2 > diff_1_na(const CSF2 &V, const CSF2 &X)
returns different orbitals, for case where CSFs differ by 1. i.e., returns {n,a} where |V> = |X_a^n> ...
Definition CSF.cpp:41
Stores the CI Solutions for given J and parity (only two-electron).
Definition CSF.hpp:63
void solve(const LinAlg::Matrix< double > &Hci, int num_solutions=0, std::optional< double > all_below={})
Solves the CI equation for Hamiltonian matrix Hci; finds first num_solutions solutions....
Definition CSF.cpp:128
double energy(std::size_t i) const
Energy of the ith CI solution.
Definition CSF.cpp:165
PsiJPi(int twoJ, int pi, const std::vector< DiracSpinor > &cisp_basis)
Construct containter for CI solutions. Constructs the CSFs, but doesn't solve system; have to call so...
Definition CSF.hpp:79
LinAlg::View< const double > coefs(std::size_t i) const
List of CI expansion coefs for the ith CI solution.
Definition CSF.cpp:171
const ConfigInfo & info(std::size_t i) const
Configuration info for the ith CI solution, if it has been set.
Definition CSF.cpp:192
std::size_t num_solutions() const
Number of CI solutions stored.
Definition CSF.cpp:189
const CSF2 & CSF(std::size_t i) const
The ith CSF.
Definition CSF.cpp:162
double coef(std::size_t i, std::size_t j) const
The CI coeficient for the ith CI solution, corresponding to the jth CSF.
Definition CSF.cpp:177
const std::vector< CSF2 > & CSFs() const
Full list of CSFs.
Definition CSF.cpp:159
int twoJ() const
2J for the CI solutions
Definition CSF.cpp:186
void update_config_info(std::size_t i, const ConfigInfo &info)
You must manuall update the config. info for each solution (if required)
Definition CSF.cpp:153
int parity() const
Parity for the CI solutions (+/-1)
Definition CSF.cpp:183
Stores radial Dirac spinor: F_nk = (f, g)
Definition DiracSpinor.hpp:41
Matrix class; row-major.
Definition Matrix.hpp:35
Proved a "view" onto an array.
Definition Matrix.ipp:7
Functions and classes for Configuration Interaction calculations.
Definition CI_Integrals.cpp:11
std::vector< CSF2 > form_CSFs(int twoJ, int parity, const std::vector< DiracSpinor > &cisp_basis)
Forms list of all possible (2-particle) CSFs with given J and parity.
Definition CSF.cpp:86
Basic configuration info for each CI level solution.
Definition CSF.hpp:51