ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
write_vxc_r.hpp
Go to the documentation of this file.
1#ifndef __WRITE_VXC_R_H_
2#define __WRITE_VXC_R_H_
8#ifdef __EXX
11#endif
12
13#ifndef TGINT_H
14#define TGINT_H
15template <typename T>
16struct TGint;
17
18template <>
19struct TGint<double>
20{
22};
23
24template <>
25struct TGint<std::complex<double>>
26{
27 using type = Gint_k;
28};
29#endif
30
31namespace ModuleIO
32{
33
34#ifndef SET_GINT_POINTER_H
35#define SET_GINT_POINTER_H
36template <typename T>
37void set_gint_pointer(Gint_Gamma& gint_gamma, Gint_k& gint_k, typename TGint<T>::type*& gint);
38
39template <>
40void set_gint_pointer<double>(Gint_Gamma& gint_gamma, Gint_k& gint_k, typename TGint<double>::type*& gint)
41{
42 gint = &gint_gamma;
43}
44
45template <>
46void set_gint_pointer<std::complex<double>>(Gint_Gamma& gint_gamma,
47 Gint_k& gint_k,
48 typename TGint<std::complex<double>>::type*& gint)
49{
50 gint = &gint_k;
51}
52#endif
53
54template <typename TR> std::set<Abfs::Vector3_Order<int>> get_R_range(const hamilt::HContainer<TR>& hR)
55{
56 std::set<Abfs::Vector3_Order<int>> all_R_coor;
57
58 return all_R_coor;
59}
60
61template <typename TR>
62std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, TR>>>
64 const int current_spin,
65 const double sparse_thr);
66
67template <>
68std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, double>>>
70 const int current_spin,
71 const double sparse_thr)
72{
73 std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, double>>> target;
74 sparse_format::cal_HContainer_d(*hR.get_paraV(), current_spin, sparse_thr, hR, target);
75 return target;
76}
77template <>
78std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>>
79cal_HR_sparse(const hamilt::HContainer<std::complex<double>>& hR,
80 const int current_spin,
81 const double sparse_thr)
82{
83 std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, std::complex<double>>>> target;
84 sparse_format::cal_HContainer_cd(*hR.get_paraV(), current_spin, sparse_thr, hR, target);
85 return target;
86}
87
90template <typename TK, typename TR>
91void write_Vxc_R(const int nspin,
92 const Parallel_Orbitals* pv,
93 const UnitCell& ucell,
95 surchem& solvent,
96 const ModulePW::PW_Basis& rho_basis,
97 const ModulePW::PW_Basis& rhod_basis,
98 const ModuleBase::matrix& vloc,
99 const Charge& chg,
100 Gint_Gamma& gint_gamma,
101 Gint_k& gint_k,
102 const K_Vectors& kv,
103 const std::vector<double>& orb_cutoff,
104 Grid_Driver& gd,
105#ifdef __EXX
106 const std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* const Hexxd,
107 const std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* const Hexxc,
108#endif
109const double sparse_thr=1e-10)
110{
111 ModuleBase::TITLE("ModuleIO", "write_Vxc_R");
112 // 1. real-space xc potential
113 // ModuleBase::matrix vr_xc(nspin, chg.nrxx);
114 double etxc = 0.0;
115 double vtxc = 0.0;
116 // elecstate::PotXC* potxc(&rho_basis, &etxc, vtxc, nullptr);
117 // potxc.cal_v_eff(&chg, &ucell, vr_xc);
119 = new elecstate::Potential(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
120 std::vector<std::string> compnents_list = {"xc"};
121 potxc->pot_register(compnents_list);
122 potxc->update_from_charge(&chg, &ucell);
123
124 // 2. allocate H(R)
125 // (the number of hR: 1 for nspin=1, 4; 2 for nspin=2)
126 int nspin0 = (nspin == 2) ? 2 : 1;
127 std::vector<hamilt::HContainer<TR>> vxcs_R_ao(nspin0, hamilt::HContainer<TR>(ucell, pv)); // call move constructor
128#ifdef __EXX
129 std::array<int, 3> Rs_period = { kv.nmp[0], kv.nmp[1], kv.nmp[2] };
130 const auto cell_nearest = hamilt::init_cell_nearest(ucell, Rs_period);
131#endif
132 for (int is = 0; is < nspin0; ++is)
133 {
134 if (std::is_same<TK, double>::value) { vxcs_R_ao[is].fix_gamma(); }
135#ifdef __EXX
136 if (GlobalC::exx_info.info_global.cal_exx)
137 {
139 hamilt::reallocate_hcontainer(*Hexxd, &vxcs_R_ao[is], &cell_nearest) :
140 hamilt::reallocate_hcontainer(*Hexxc, &vxcs_R_ao[is], &cell_nearest);
141 }
142#endif
143 }
144
145 // 3. calculate the Vxc(R)
146 hamilt::HS_Matrix_K<TK> vxc_k_ao(pv, 1); // only hk is needed, sk is skipped
147 typename TGint<TK>::type* gint = nullptr;
148 set_gint_pointer<TK>(gint_gamma, gint_k, gint);
149 std::vector<hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>*> vxcs_op_ao(nspin0);
150 for (int is = 0; is < nspin0; ++is)
151 {
152 vxcs_op_ao[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(gint,
153 &vxc_k_ao, kv.kvec_d, potxc, &vxcs_R_ao[is], &ucell, orb_cutoff, &gd, nspin);
154 vxcs_op_ao[is]->contributeHR();
155#ifdef __EXX
156 if (GlobalC::exx_info.info_global.cal_exx)
157 {
159 RI_2D_Comm::add_HexxR(is, GlobalC::exx_info.info_global.hybrid_alpha, *Hexxd, *pv, ucell.get_npol(), vxcs_R_ao[is], &cell_nearest) :
160 RI_2D_Comm::add_HexxR(is, GlobalC::exx_info.info_global.hybrid_alpha, *Hexxc, *pv, ucell.get_npol(), vxcs_R_ao[is], &cell_nearest);
161 }
162#endif
163 }
164
165 // test: fold Vxc(R) and check whether it is equal to Vxc(k)
166 // for (int ik = 0; ik < kv.get_nks(); ++ik)
167 // {
168 // vxc_k_ao.set_zero_hk();
169 // dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(vxcs_op_ao[kv.isk[ik]])->contributeHk(ik);
170
171 // // output Vxc(k) (test)
172 // const TK* const hk = vxc_k_ao.get_hk();
173 // std::cout << "ik=" << ik << ", Vxc(K): " << std::endl;
174 // for (int i = 0; i < pv->get_row_size(); i++)
175 // {
176 // for (int j = 0; j < pv->get_col_size(); j++)
177 // {
178 // std::cout << hk[j * pv->get_row_size() + i] << " ";
179 // }
180 // std::cout << std::endl;
181 // }
182 // }
183
184 // 4. write Vxc(R) in csr format
185 for (int is = 0; is < nspin0; ++is)
186 {
187 std::set<Abfs::Vector3_Order<int>> all_R_coor = sparse_format::get_R_range(vxcs_R_ao[is]);
188 const std::string filename = "Vxc_R_spin" + std::to_string(is);
190 cal_HR_sparse(vxcs_R_ao[is], is, sparse_thr),
191 all_R_coor,
192 sparse_thr,
193 false, //binary
194 PARAM.globalv.global_out_dir + filename + ".csr",
195 *pv,
196 filename,
197 -1,
198 true); //all-reduce
199 }
200}
201} // namespace ModuleIO
202#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 nmp[3]
distinguish spin up and down k points
Definition klist.h:23
std::vector< ModuleBase::Vector3< double > > kvec_d
Cartesian coordinates of k points.
Definition klist.h:16
Definition matrix.h:19
A class which can convert a function of "r" to the corresponding linear superposition of plane waves ...
Definition pw_basis.h:56
Definition parallel_orbitals.h:9
const System_para & globalv
Definition parameter.h:30
Definition structure_factor.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 hcontainer.h:144
const Parallel_Orbitals * get_paraV() const
get parallel orbital pointer to check parallel information
Definition hcontainer.h:192
Definition hs_matrix_k.hpp:11
Definition veff_lcao.h:20
void contributeHR()
Definition veff_lcao.cpp:60
Definition surchem.h:15
std::complex< double > complex
Definition diago_cusolver.cpp:13
Exx_Info exx_info
Definition test_xc.cpp:29
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
This class has two functions: restart psi from the previous calculation, and write psi to the disk.
Definition cal_dos.h:9
std::pair< int, TC > TAC
Definition restart_exx_csr.h:11
void set_gint_pointer< double >(Gint_Gamma &gint_gamma, Gint_k &gint_k, typename TGint< double >::type *&gint)
Definition write_vxc.hpp:136
void write_Vxc_R(const int nspin, const Parallel_Orbitals *pv, 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 std::vector< double > &orb_cutoff, Grid_Driver &gd, const double sparse_thr=1e-10)
write the Vxc matrix in KS orbital representation, usefull for GW calculation including terms: local/...
Definition write_vxc_r.hpp:91
void set_gint_pointer(Gint_Gamma &gint_gamma, Gint_k &gint_k, typename TGint< T >::type *&gint)
std::set< Abfs::Vector3_Order< int > > get_R_range(const hamilt::HContainer< TR > &hR)
Definition write_vxc_r.hpp:54
std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, TR > > > cal_HR_sparse(const hamilt::HContainer< TR > &hR, const int current_spin, const double sparse_thr)
void save_sparse(const std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, Tdata > > > &smat, const std::set< Abfs::Vector3_Order< int > > &all_R_coor, const double &sparse_thr, const bool &binary, const std::string &filename, const Parallel_Orbitals &pv, const std::string &label, const int &istep=-1, const bool &reduce=true)
Definition write_HS_sparse.cpp:704
void add_HexxR(const int current_spin, const double alpha, const std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > &Hs, const Parallel_Orbitals &pv, const int npol, hamilt::HContainer< TR > &HlocR, const RI::Cell_Nearest< int, int, 3, double, 3 > *const cell_nearest=nullptr)
Definition RI_2D_Comm.hpp:238
std::set< Abfs::Vector3_Order< int > > get_R_range(const hamilt::HContainer< T > &hR)
Definition spar_hsr.h:16
void cal_HContainer_d(const Parallel_Orbitals &pv, const int &current_spin, const double &sparse_threshold, const hamilt::HContainer< double > &hR, std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, double > > > &target)
Definition spar_hsr.cpp:182
void cal_HContainer_cd(const Parallel_Orbitals &pv, const int &current_spin, const double &sparse_threshold, const hamilt::HContainer< std::complex< double > > &hR, std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, std::complex< double > > > > &target)
Definition spar_hsr.cpp:225
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 real_number
Definition exx_info.h:56
Exx_Info_RI info_ri
Definition exx_info.h:78
std::string global_out_dir
global output directory
Definition system_parameter.h:42
Definition write_vxc.hpp:16