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 Gint_Gamma& gint_gamma, // mohan add 2024-04-01
25 Gint_k& gint_k, // mohan add 2024-04-01
26 const K_Vectors& kv,
27 const ModuleBase::matrix& wg,
28 Grid_Driver& gd,
29 const std::vector<double>& orb_cutoff,
30 const TwoCenterBundle& two_center_bundle
31#ifdef __EXX
32 ,
33 std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* Hexxd = nullptr,
34 std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc = nullptr
35#endif
36)
37 {
38 // 0. prepare
39 const int& nbands = wg.nc;
40 const int& nspin0 = (nspin == 2) ? 2 : 1;
41 double etxc = 0.0;
42 double vtxc = 0.0;
43
44 Parallel_2D p2d;
45
46 set_para2d_MO(*pv, nbands, p2d);
47
48 typename TGint<TK>::type* gint = nullptr;
49
50 set_gint_pointer<TK>(gint_gamma, gint_k, gint);
51
52 auto if_gamma_fix = [](hamilt::HContainer<TR>& hR)
53 {
54 if (std::is_same<TK, double>::value)
55 {
56 hR.fix_gamma();
57 }
58 };
59
60 auto all_band_energy = [&wg](const int ik, const std::vector<double>& e_orb)->double
61 {
62 double e = 0;
63 for (int i = 0; i < e_orb.size(); ++i) { e += e_orb[i] * wg(ik, i); }
64 return e;
65 };
66
67 auto all_k_all_band_energy = [&wg, &all_band_energy](const std::vector<std::vector<double>>& e_orb)->double
68 {
69 double e = 0;
70 for (int ik = 0; ik < e_orb.size(); ++ik)
71 {
72 e += all_band_energy(ik, e_orb[ik]);
73 }
74 return e;
75 };
76
77 // 1. kinetic
78 if (PARAM.inp.t_in_h)
79 {
80 hamilt::HS_Matrix_K<TK> kinetic_k_ao(pv, 1);
81 hamilt::HContainer<TR> kinetic_R_ao(pv);
82 if_gamma_fix(kinetic_R_ao);
83
84 hamilt::EkineticNew<hamilt::OperatorLCAO<TK, TR>> kinetic_op(&kinetic_k_ao, kv.kvec_d,
85 &kinetic_R_ao, &ucell, orb_cutoff, &gd, two_center_bundle.kinetic_orb.get());
86
87 kinetic_op.contributeHR();
88
89 std::vector<std::vector<double>> e_orb_kinetic;
90
91 for (int ik = 0;ik < kv.get_nks();++ik)
92 {
93 kinetic_k_ao.set_zero_hk();
94 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(&kinetic_op)->contributeHk(ik);
95 e_orb_kinetic.emplace_back(orbital_energy(ik, nbands,
96 cVc(kinetic_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
97 }
98
99 write_orb_energy(kv, nspin0, nbands, e_orb_kinetic, "kinetic", "");
100 }
101
102 // 2. pp: local
103 if (PARAM.inp.vl_in_h)
104 {
105 elecstate::Potential pot_local(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
106 pot_local.pot_register({ "local" });
107 pot_local.update_from_charge(&chg, &ucell);
108 hamilt::HS_Matrix_K<TK> v_pp_local_k_ao(pv, 1);
109 hamilt::HContainer<TR> v_pp_local_R_ao(pv);
110 if_gamma_fix(v_pp_local_R_ao);
111 std::vector<std::vector<double>> e_orb_pp_local;
112
114 &v_pp_local_k_ao,
115 kv.kvec_d,
116 &pot_local,
117 &v_pp_local_R_ao,
118 &ucell,
119 orb_cutoff,
120 &gd,
121 nspin);
122
123 v_pp_local_op.contributeHR();
124 for (int ik = 0;ik < kv.get_nks();++ik)
125 {
126 v_pp_local_k_ao.set_zero_hk();
127 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(&v_pp_local_op)->contributeHk(ik);
128 e_orb_pp_local.emplace_back(orbital_energy(ik, nbands,
129 cVc(v_pp_local_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
130 }
131 write_orb_energy(kv, nspin0, nbands, e_orb_pp_local, "vpp_local", "");
132 }
133
134 // 3. pp: nonlocal
135 if (PARAM.inp.vnl_in_h)
136 {
137 hamilt::HS_Matrix_K<TK> v_pp_nonlocal_k_ao(pv, 1);
138 hamilt::HContainer<TR> v_pp_nonlocal_R_ao(pv);
139 if_gamma_fix(v_pp_nonlocal_R_ao);
140 std::vector<std::vector<double>> e_orb_pp_nonlocal;
141 hamilt::NonlocalNew<hamilt::OperatorLCAO<TK, TR>> v_pp_nonlocal_op(&v_pp_nonlocal_k_ao, kv.kvec_d,
142 &v_pp_nonlocal_R_ao, &ucell, orb_cutoff, &gd, two_center_bundle.overlap_orb_beta.get());
143 v_pp_nonlocal_op.contributeHR();
144 for (int ik = 0;ik < kv.get_nks();++ik)
145 {
146 v_pp_nonlocal_k_ao.set_zero_hk();
147 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(&v_pp_nonlocal_op)->contributeHk(ik);
148 e_orb_pp_nonlocal.emplace_back(orbital_energy(ik, nbands,
149 cVc(v_pp_nonlocal_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
150 }
151 write_orb_energy(kv, nspin0, nbands, e_orb_pp_nonlocal, "vpp_nonlocal", "");
152 }
153
154 // 4. hartree
155 if (PARAM.inp.vh_in_h)
156 {
157 elecstate::Potential pot_hartree(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
158 pot_hartree.pot_register({ "hartree" });
159 pot_hartree.update_from_charge(&chg, &ucell);
160 std::vector<hamilt::HContainer<TR>> v_hartree_R_ao(nspin0, hamilt::HContainer<TR>(pv));
161 for (int is = 0; is < nspin0; ++is)
162 {
163 v_hartree_R_ao[is].set_zero();
164 if_gamma_fix(v_hartree_R_ao[is]);
165 }
166 hamilt::HS_Matrix_K<TK> v_hartree_k_ao(pv, 1);
167 std::vector<hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>*> v_hartree_op(nspin0);
168 for (int is = 0; is < nspin0; ++is)
169 {
170 v_hartree_op[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(gint,
171 &v_hartree_k_ao, kv.kvec_d, &pot_hartree, &v_hartree_R_ao[is], &ucell, orb_cutoff, &gd, nspin);
172 v_hartree_op[is]->contributeHR();
173 }
174 std::vector<std::vector<double>> e_orb_hartree;
175 for (int ik = 0;ik < kv.get_nks();++ik)
176 {
177 int is = kv.isk[ik];
178 v_hartree_k_ao.set_zero_hk();
179 dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(v_hartree_op[is])->contributeHk(ik);
180 e_orb_hartree.emplace_back(orbital_energy(ik, nbands,
181 cVc(v_hartree_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d), p2d));
182 }
183 for (auto& op : v_hartree_op) { delete op; }
184 write_orb_energy(kv, nspin0, nbands, e_orb_hartree, "vhartree", "");
185 }
186
187 // 5. xc (including exx)
188 if (!PARAM.inp.out_mat_xc) // avoid duplicate output
189 {
190 write_Vxc<TK, TR>(nspin,
191 nbasis,
192 drank,
193 pv,
194 psi,
195 ucell,
196 sf,
197 solvent,
198 rho_basis,
199 rhod_basis,
200 vloc,
201 chg,
202 gint_gamma,
203 gint_k,
204 kv,
205 orb_cutoff,
206 wg,
207 gd
208#ifdef __EXX
209 ,
210 Hexxd,
211 Hexxc
212#endif
213 );
214 }
215 }
216}
217#endif
Definition charge.h:20
Definition gint_gamma.h:23
Definition gint_k.h:13
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:16
Definition potential_new.h:48
void pot_register(const std::vector< std::string > &components_list)
Definition potential_new.cpp:62
void update_from_charge(const Charge *const chg, const UnitCell *const ucell)
Definition potential_new.cpp:152
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:20
void contributeHR()
Definition veff_lcao.cpp:60
Definition psi.h:37
Definition surchem.h:15
This class has two functions: restart psi from the previous calculation, and write psi to the disk.
Definition cal_dos.h:9
void set_para2d_MO(const Parallel_Orbitals &pv, const int nbands, Parallel_2D &p2d)
Definition write_vxc.hpp:34
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:110
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:45
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:92
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, Gint_Gamma &gint_gamma, Gint_k &gint_k, 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
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:151
Definition exx_lip.h:23
Parameter PARAM
Definition parameter.cpp:3
base device SOURCES math_dngvd_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:622
bool out_mat_xc
Definition input_parameter.h:386
bool vnl_in_h
calculate the vnl or not.
Definition input_parameter.h:624
bool vl_in_h
calculate the vloc or not.
Definition input_parameter.h:623
bool vh_in_h
calculate the hartree potential or not
Definition input_parameter.h:625
Definition write_vxc.hpp:16
const std::map< std::string, std::vector< double > > op
Definition vdwd3_autoset_xcparam.cpp:372