ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
hamilt_bse.h
Go to the documentation of this file.
1// Purpose: simplify the hamilt_casida class, and explore to go beyond Tamm-Damcoff Approximation.
2// For simplicity, only ELPA solver with MPI parallization is implementated.
3// Thus, instead of iterative solver such as Davidson, here matrix is constructed directly.
4
5#ifndef ABACUS_SOURCE_LCAO_MODULE_BSE_HAMILT_BSE_H
6#define ABACUS_SOURCE_LCAO_MODULE_BSE_HAMILT_BSE_H
7
8#include "bse_util.h"
9#include "hamilt_bse_solver.h"
10#include "molecular_lri.h"
11
13#include "source_base/timer.h"
25
26namespace BSE
27{
28template <typename T>
30{
31public:
32 std::vector<T> BSE_A_local, BSE_B_local;
33 std::vector<T> VA_local, WA_local;
34 std::vector<T> VB_local, WB_local;
35 int ndim = 0; // dimension of BSE matrix
38 HamiltBSE(const int& nspin,
39 const int& naos,
40 const std::vector<int>& nocc,
41 const std::vector<int>& nvirt,
42 const UnitCell& ucell_in,
43 const std::vector<double>& orb_cutoff_in,
44 const Grid_Driver& gd_in,
45 const psi::Psi<T>& psi_in,
46 const psi::Psi<T>& psi_glb_in,
47 const ModuleBase::matrix& eig_gw_in,
48 MolecularLRI<T>& mo_lri_in,
49 std::weak_ptr<LR::PotHxcLR> pot_in,
50 const K_Vectors& kv_in,
51 const std::vector<Parallel_Blkcyclic>& pX_in,
52 const Parallel_Blkcyclic& pc_in,
53 const Parallel_Orbitals& pmat_in,
54 const std::vector<std::string>& spin_types_in,
55 const std::string& tda,
56 const bool bse_ri_hartree_in,
57 const bool bse_mem_save_in,
58 const int bse_continue_in,
59 const bool out_bse_ab_in,
60 const std::string& out_dir_in,
61 const std::string& readin_dir_in,
62 const int my_rank_in,
63 const int nproc_in,
64 const std::string& ri_hartree_benchmark_in = "none");
66 void cal_V_for_A();
67 void cal_W_for_A();
68 void cal_V_for_B();
69 void cal_W_for_B();
70
73 void init_bse_matrix(const bool is_full, const int& st_index);
74
75 void tda_solver(const int& st_index, const int& nstates, double* ene_out, T* X_out);
76 void full_solver(const int& st_index, const int& nstates, double* ene_out, T* X_out, T* Y_out);
77
78 void cal_V_by_grid(bool is_A);
80
81 inline void write_AB_matrix(const std::string& file, const int& prec, const T* ptr, const Parallel_Blkcyclic& pM)
82 {
83 std::ofstream ofs(file);
84 if (!ofs.is_open()){
85 throw std::runtime_error("Cannot open file " + file);
86 }
87 ofs << file << "(Ry, transpose) with threshold " << prec << std::endl;
88 ofs << std::setprecision(prec) << std::scientific;
89 LR_Util::write_value(ofs, ptr, pM.nrloc(), pM.ncloc());
90 ofs.close();
92 }
93
94 inline void read_AB_matrix(const std::string& file, T* ptr, const Parallel_Blkcyclic& pM)
95 {
96 std::ifstream ifs(file);
97 if (!ifs.is_open()){
98 throw std::runtime_error("Cannot open file " + file);
99 }
100 ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // skip the first line
101 LR_Util::read_value(ifs, ptr, pM.nrloc(), pM.ncloc());
102 ifs.close();
104 }
105
106private:
107 const int nspin;
108 const int naos;
109 const std::vector<int> nocc;
110 const std::vector<int> nvirt;
112 const std::vector<double>& orb_cutoff;
118
119 std::weak_ptr<LR::PotHxcLR> pot;
120 const K_Vectors& kv;
121 int nk = 1;
122 const std::vector<Parallel_Blkcyclic>& pX; // for tda, also pY for full
125 const std::vector<std::string>& spin_types; // singlet, triplet, and rpa, ipa(independent particle approx)
126 const bool bse_ri_hartree;
127 const bool bse_mem_save;
128 const int bse_continue;
129 const bool out_bse_ab;
130 const std::string out_dir;
131 const std::string readin_dir;
132 const int my_rank;
133 const int nproc;
134 const std::string ri_hartree_benchmark;
135
136 std::unique_ptr<module_dm::DensityMatrix<T, T>> DM_trans = nullptr;
137};
138} // namespace BSE
139
140#endif // ABACUS_SOURCE_LCAO_MODULE_BSE_HAMILT_BSE_H
int nk
Definition hamilt_bse.h:121
std::vector< T > BSE_A_local
Definition hamilt_bse.h:32
const bool out_bse_ab
Definition hamilt_bse.h:129
void cal_V_by_grid(bool is_A)
Definition hamilt_bse.cpp:477
std::vector< T > VB_local
Definition hamilt_bse.h:34
const int nspin
Definition hamilt_bse.h:107
std::vector< T > WA_local
Definition hamilt_bse.h:33
std::vector< T > WB_local
Definition hamilt_bse.h:34
const std::vector< int > nvirt
Definition hamilt_bse.h:110
const std::string readin_dir
Definition hamilt_bse.h:131
const Parallel_Orbitals & pmat
Definition hamilt_bse.h:124
MolecularLRI< T > & mo_lri
Definition hamilt_bse.h:117
void cal_V_for_B()
Definition hamilt_bse.cpp:173
const K_Vectors & kv
Definition hamilt_bse.h:120
const psi::Psi< T > & psi_ks_glb
Definition hamilt_bse.h:115
const std::vector< int > nocc
Definition hamilt_bse.h:109
void cal_W_for_A()
Definition hamilt_bse.cpp:202
const bool bse_mem_save
Definition hamilt_bse.h:127
void read_AB_matrix(const std::string &file, T *ptr, const Parallel_Blkcyclic &pM)
Definition hamilt_bse.h:94
const Parallel_Blkcyclic & pc
Definition hamilt_bse.h:123
void init_bse_matrix(const bool is_full, const int &st_index)
initialize BSE matrix
Definition hamilt_bse.cpp:242
const std::vector< std::string > & spin_types
Definition hamilt_bse.h:125
void cal_W_for_B()
Definition hamilt_bse.cpp:221
const int bse_continue
Definition hamilt_bse.h:128
HamiltBSE(const int &nspin, const int &naos, const std::vector< int > &nocc, const std::vector< int > &nvirt, const UnitCell &ucell_in, const std::vector< double > &orb_cutoff_in, const Grid_Driver &gd_in, const psi::Psi< T > &psi_in, const psi::Psi< T > &psi_glb_in, const ModuleBase::matrix &eig_gw_in, MolecularLRI< T > &mo_lri_in, std::weak_ptr< LR::PotHxcLR > pot_in, const K_Vectors &kv_in, const std::vector< Parallel_Blkcyclic > &pX_in, const Parallel_Blkcyclic &pc_in, const Parallel_Orbitals &pmat_in, const std::vector< std::string > &spin_types_in, const std::string &tda, const bool bse_ri_hartree_in, const bool bse_mem_save_in, const int bse_continue_in, const bool out_bse_ab_in, const std::string &out_dir_in, const std::string &readin_dir_in, const int my_rank_in, const int nproc_in, const std::string &ri_hartree_benchmark_in="none")
constructor for BSE_Matrix
Definition hamilt_bse.cpp:12
std::unique_ptr< module_dm::DensityMatrix< T, T > > DM_trans
Definition hamilt_bse.h:136
std::vector< T > VA_local
Definition hamilt_bse.h:33
const std::string out_dir
Definition hamilt_bse.h:130
const psi::Psi< T > & psi_ks
Definition hamilt_bse.h:114
void write_AB_matrix(const std::string &file, const int &prec, const T *ptr, const Parallel_Blkcyclic &pM)
Definition hamilt_bse.h:81
void tda_solver(const int &st_index, const int &nstates, double *ene_out, T *X_out)
Definition hamilt_bse.cpp:363
void cal_V_for_A()
Definition hamilt_bse.cpp:144
std::weak_ptr< LR::PotHxcLR > pot
Definition hamilt_bse.h:119
Parallel_Blkcyclic pA
Definition hamilt_bse.h:36
const bool bse_ri_hartree
Definition hamilt_bse.h:126
std::vector< T > BSE_B_local
Definition hamilt_bse.h:32
int ndim
Definition hamilt_bse.h:35
const int naos
Definition hamilt_bse.h:108
const ModuleBase::matrix & eig_gw
Definition hamilt_bse.h:116
void full_solver(const int &st_index, const int &nstates, double *ene_out, T *X_out, T *Y_out)
void grid_calculation(hamilt::HContainer< T > &VR) const
const int my_rank
Definition hamilt_bse.h:132
const UnitCell & ucell
Definition hamilt_bse.h:111
const std::string ri_hartree_benchmark
Definition hamilt_bse.h:134
const std::vector< double > & orb_cutoff
Definition hamilt_bse.h:112
const std::vector< Parallel_Blkcyclic > & pX
Definition hamilt_bse.h:122
const Grid_Driver & gd
Definition hamilt_bse.h:113
const int nproc
Definition hamilt_bse.h:133
Definition molecular_lri.h:36
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
Class for k-points management.
Definition klist.h:20
Definition matrix.h:15
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
int ncloc() const
Definition parallel_blkcyc.h:40
int nrloc() const
Definition parallel_blkcyc.h:35
Definition parallel_orbitals.h:16
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition hcontainer.h:147
Definition psi.h:37
#define T
Definition exp.cpp:237
Definition hamilt_bse.cpp:10
std::ofstream ofs_running
Definition global_variable.cpp:38
int read_value(std::ifstream &ifs, T *ptr, const int &size)
Definition lr_util_print.h:41
int write_value(std::ofstream &ofs, const T *ptr, const int &size)
Definition lr_util_print.h:63
void DONE(std::ofstream &ofs, const std::string &description, const bool only_rank0)
Definition global_function.cpp:78
file(GLOB ATen_CORE_SRCS "*.cpp") set(ATen_CPU_SRCS $
Definition CMakeLists.txt:1