ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
write_eband_terms.hpp
Go to the documentation of this file.
1#ifndef WRITE_EBAND_TERMS_HPP
2#define WRITE_EBAND_TERMS_HPP
3
8
9namespace ModuleIO
10{
11template <typename TK, typename TR>
12void write_eband_terms(const int nspin,
13 const int nbasis,
14 const int drank,
15 const Parallel_Orbitals* pv,
16 const psi::Psi<TK>& psi,
17 const UnitCell& ucell,
19 surchem& solvent,
20 const ModulePW::PW_Basis& rho_basis,
21 const ModulePW::PW_Basis& rhod_basis,
22 const ModuleBase::matrix& vloc,
23 const Charge& chg,
24 const K_Vectors& kv,
25 const ModuleBase::matrix& wg,
26 Grid_Driver& gd,
27 const std::vector<double>& orb_cutoff,
28 const TwoCenterBundle& two_center_bundle
29#ifdef __EXX
30 ,
31 std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* Hexxd = nullptr,
32 std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc = nullptr
33#endif
34)
35 {
36 // 0. prepare
37 const int& nbands = wg.nc;
38 const int& nspin0 = (nspin == 2) ? 2 : 1;
39 double etxc = 0.0;
40 double vtxc = 0.0;
41
42 Parallel_2D p2d;
43
44 set_para2d_MO(*pv, nbands, p2d);
45
46 auto if_gamma_fix = [](hamilt::HContainer<TR>& hR)
47 {
48 if (std::is_same<TK, double>::value)
49 {
50 hR.fix_gamma();
51 }
52 };
53
54 auto all_band_energy = [&wg](const int ik, const std::vector<double>& e_orb)->double
55 {
56 double e = 0;
57 for (int i = 0; i < e_orb.size(); ++i) { e += e_orb[i] * wg(ik, i); }
58 return e;
59 };
60
61 auto all_k_all_band_energy = [&wg, &all_band_energy](const std::vector<std::vector<double>>& e_orb)->double
62 {
63 double e = 0;
64 for (int ik = 0; ik < e_orb.size(); ++ik)
65 {
66 e += all_band_energy(ik, e_orb[ik]);
67 }
68 return e;
69 };
70
71 // 1. kinetic
72 if (PARAM.inp.t_in_h)
73 {
74 hamilt::HS_Matrix_K<TK> kinetic_k_ao(pv, 1);
75 hamilt::HContainer<TR> kinetic_R_ao(pv);
76 if_gamma_fix(kinetic_R_ao);
77
78 hamilt::EkineticNew<hamilt::OperatorLCAO<TK, TR>> kinetic_op(&kinetic_k_ao, kv.kvec_d,
79 &kinetic_R_ao, &ucell, orb_cutoff, &gd, two_center_bundle.kinetic_orb.get());
80
81 kinetic_op.contributeHR();
82
83 std::vector<std::vector<double>> e_orb_kinetic;
84
85 for (int ik = 0;ik < kv.get_nks();++ik)
86 {
87 kinetic_k_ao.set_zero_hk();
88 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(&kinetic_op)->contributeHk(ik);
89 e_orb_kinetic.emplace_back(orbital_energy(ik, nbands,
90 cVc(kinetic_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
91 }
92
93 write_orb_energy(kv, nspin0, nbands, e_orb_kinetic, "kinetic", "");
94 }
95
96 // 2. pp: local
97 if (PARAM.inp.vl_in_h)
98 {
99 elecstate::Potential pot_local(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
100 pot_local.pot_register({ "local" });
101 pot_local.update_from_charge(&chg, &ucell);
102 hamilt::HS_Matrix_K<TK> v_pp_local_k_ao(pv, 1);
103 hamilt::HContainer<TR> v_pp_local_R_ao(pv);
104 if_gamma_fix(v_pp_local_R_ao);
105 std::vector<std::vector<double>> e_orb_pp_local;
106
108 &v_pp_local_k_ao,
109 kv.kvec_d,
110 &pot_local,
111 &v_pp_local_R_ao,
112 &ucell,
113 orb_cutoff,
114 &gd,
115 nspin);
116
117 v_pp_local_op.contributeHR();
118 for (int ik = 0;ik < kv.get_nks();++ik)
119 {
120 v_pp_local_k_ao.set_zero_hk();
121 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(&v_pp_local_op)->contributeHk(ik);
122 e_orb_pp_local.emplace_back(orbital_energy(ik, nbands,
123 cVc(v_pp_local_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
124 }
125 write_orb_energy(kv, nspin0, nbands, e_orb_pp_local, "vpp_local", "");
126 }
127
128 // 3. pp: nonlocal
129 if (PARAM.inp.vnl_in_h)
130 {
131 hamilt::HS_Matrix_K<TK> v_pp_nonlocal_k_ao(pv, 1);
132 hamilt::HContainer<TR> v_pp_nonlocal_R_ao(pv);
133 if_gamma_fix(v_pp_nonlocal_R_ao);
134 std::vector<std::vector<double>> e_orb_pp_nonlocal;
135 hamilt::NonlocalNew<hamilt::OperatorLCAO<TK, TR>> v_pp_nonlocal_op(&v_pp_nonlocal_k_ao, kv.kvec_d,
136 &v_pp_nonlocal_R_ao, &ucell, orb_cutoff, &gd, two_center_bundle.overlap_orb_beta.get());
137 v_pp_nonlocal_op.contributeHR();
138 for (int ik = 0;ik < kv.get_nks();++ik)
139 {
140 v_pp_nonlocal_k_ao.set_zero_hk();
141 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(&v_pp_nonlocal_op)->contributeHk(ik);
142 e_orb_pp_nonlocal.emplace_back(orbital_energy(ik, nbands,
143 cVc(v_pp_nonlocal_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
144 }
145 write_orb_energy(kv, nspin0, nbands, e_orb_pp_nonlocal, "vpp_nonlocal", "");
146 }
147
148 // 4. hartree
149 if (PARAM.inp.vh_in_h)
150 {
151 elecstate::Potential pot_hartree(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
152 pot_hartree.pot_register({ "hartree" });
153 pot_hartree.update_from_charge(&chg, &ucell);
154 std::vector<hamilt::HContainer<TR>> v_hartree_R_ao(nspin0, hamilt::HContainer<TR>(pv));
155 for (int is = 0; is < nspin0; ++is)
156 {
157 v_hartree_R_ao[is].set_zero();
158 if_gamma_fix(v_hartree_R_ao[is]);
159 }
160 hamilt::HS_Matrix_K<TK> v_hartree_k_ao(pv, 1);
161 std::vector<hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>*> v_hartree_op(nspin0);
162 for (int is = 0; is < nspin0; ++is)
163 {
164 v_hartree_op[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(
165 &v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin);
166 v_hartree_op[is]->contributeHR();
167 }
168 std::vector<std::vector<double>> e_orb_hartree;
169 for (int ik = 0;ik < kv.get_nks();++ik)
170 {
171 int is = kv.isk[ik];
172 v_hartree_k_ao.set_zero_hk();
173 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(v_hartree_op[is])->contributeHk(ik);
174 e_orb_hartree.emplace_back(orbital_energy(ik, nbands,
175 cVc(v_hartree_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
176 }
177 for (auto& op : v_hartree_op) { delete op; }
178 write_orb_energy(kv, nspin0, nbands, e_orb_hartree, "vhartree", "");
179 }
180
181 // 5. xc (including exx)
182 if (!PARAM.inp.out_mat_xc) // avoid duplicate output
183 {
184 write_Vxc<TK, TR>(nspin,
185 nbasis,
186 drank,
187 pv,
188 psi,
189 ucell,
190 sf,
191 solvent,
192 rho_basis,
193 rhod_basis,
194 vloc,
195 chg,
196 kv,
197 orb_cutoff,
198 wg,
199 gd
200#ifdef __EXX
201 ,
202 Hexxd,
203 Hexxc
204#endif
205 );
206 }
207 }
208}
209#endif
Definition charge.h:18
Definition sltk_grid_driver.h:43
Definition klist.h:13
int get_nks() const
Definition klist.h:68
std::vector< ModuleBase::Vector3< double > > kvec_d
Cartesian coordinates of k points.
Definition klist.h:16
std::vector< int > isk
ngk, number of plane waves for each k point
Definition klist.h:21
Definition matrix.h:19
int nc
Definition matrix.h:24
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:56
This class packs the basic information of 2D-block-cyclic parallel distribution of an arbitrary matri...
Definition parallel_2d.h:12
Definition parallel_orbitals.h:9
const Input_para & inp
Definition parameter.h:26
Definition structure_factor.h:11
Definition two_center_bundle.h:11
Definition unitcell.h:17
Definition potential_new.h:49
void pot_register(const std::vector< std::string > &components_list)
Definition potential_new.cpp:64
void update_from_charge(const Charge *const chg, const UnitCell *const ucell)
Definition potential_new.cpp:158
Definition ekinetic_new.h:24
Definition hcontainer.h:144
Definition hs_matrix_k.hpp:11
void set_zero_hk()
Definition hs_matrix_k.hpp:29
TK * get_hk()
Definition hs_matrix_k.hpp:23
Definition nonlocal_new.h:26
Definition operator_lcao.h:12
Definition veff_lcao.h:18
void contributeHR()
Definition veff_lcao.cpp:60
Definition psi.h:37
Definition surchem.h:15
Definition cal_dos.h:9
void set_para2d_MO(const Parallel_Orbitals &pv, const int nbands, Parallel_2D &p2d)
Definition write_vxc.hpp:16
std::vector< double > orbital_energy(const int ik, const int nbands, const std::vector< T > &mat_mo, const Parallel_2D &p2d)
Definition write_vxc.hpp:92
std::pair< int, TC > TAC
Definition restart_exx_csr.h:11
std::vector< T > cVc(T *V, T *c, const int nbasis, const int nbands, const Parallel_Orbitals &pv, const Parallel_2D &p2d)
Definition write_vxc.hpp:27
double all_band_energy(const int ik, const std::vector< T > &mat_mo, const Parallel_2D &p2d, const ModuleBase::matrix &wg)
Definition write_vxc.hpp:74
void write_orb_energy(const K_Vectors &kv, const int nspin0, const int nbands, const std::vector< std::vector< double > > &e_orb, const std::string &term, const std::string &label, const bool app=false)
Definition write_vxc.hpp:110
void write_eband_terms(const int nspin, const int nbasis, const int drank, const Parallel_Orbitals *pv, const psi::Psi< TK > &psi, const UnitCell &ucell, Structure_Factor &sf, surchem &solvent, const ModulePW::PW_Basis &rho_basis, const ModulePW::PW_Basis &rhod_basis, const ModuleBase::matrix &vloc, const Charge &chg, const K_Vectors &kv, const ModuleBase::matrix &wg, Grid_Driver &gd, const std::vector< double > &orb_cutoff, const TwoCenterBundle &two_center_bundle)
Definition write_eband_terms.hpp:12
Definition exx_lip.h:23
Parameter PARAM
Definition parameter.cpp:3
base device SOURCES math_hegvd_test cpp endif() if(ENABLE_GOOGLEBENCH) AddTest(TARGET PERF_MODULE_HSOLVER_KERNELS LIBS parameter $
Definition CMakeLists.txt:10
bool t_in_h
calculate the T or not.
Definition input_parameter.h:626
bool out_mat_xc
Definition input_parameter.h:389
bool vnl_in_h
calculate the vnl or not.
Definition input_parameter.h:628
bool vl_in_h
calculate the vloc or not.
Definition input_parameter.h:627
bool vh_in_h
calculate the hartree potential or not
Definition input_parameter.h:629
const std::map< std::string, std::vector< double > > op
Definition vdwd3_autoset_xcparam.cpp:375