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
13namespace ModuleIO
14{
15template <typename TR>
16std::set<Abfs::Vector3_Order<int>> get_R_range(const hamilt::HContainer<TR>& hR)
17{
18 std::set<Abfs::Vector3_Order<int>> all_R_coor;
19
20 return all_R_coor;
21}
22
23template <typename T>
24std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, T>>> cal_HR_sparse(const hamilt::HContainer<T>& hR,
25 const double sparse_thr)
26{
27 std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, T>>> target;
28 sparse_format::cal_HContainer<T>(*hR.get_paraV(), sparse_thr, hR, target);
29 return target;
30}
31
34template <typename TK, typename TR>
35void write_Vxc_R(const int nspin,
36 const Parallel_Orbitals* pv,
37 const UnitCell& ucell,
39 surchem& solvent,
40 const ModulePW::PW_Basis& rho_basis,
41 const ModulePW::PW_Basis& rhod_basis,
42 const ModuleBase::matrix& vloc,
43 const Charge& chg,
44 const K_Vectors& kv,
45 const std::vector<double>& orb_cutoff,
46 Grid_Driver& gd,
47#ifdef __EXX
48 const std::vector<std::map<int, std::map<TAC, RI::Tensor<double>>>>* const Hexxd,
49 const std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* const Hexxc,
50#endif
51 const double sparse_thr = 1e-10)
52{
53 ModuleBase::TITLE("ModuleIO", "write_Vxc_R");
54 // 1. real-space xc potential
55 // ModuleBase::matrix vr_xc(nspin, chg.nrxx);
56 double etxc = 0.0;
57 double vtxc = 0.0;
58 // elecstate::PotXC* potxc(&rho_basis, &etxc, vtxc, nullptr);
59 // potxc.cal_v_eff(&chg, &ucell, vr_xc);
61 = new elecstate::Potential(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
62 std::vector<std::string> compnents_list = {"xc"};
63 potxc->pot_register(compnents_list);
64 potxc->update_from_charge(&chg, &ucell);
65
66 // 2. allocate H(R)
67 // (the number of hR: 1 for nspin=1, 4; 2 for nspin=2)
68 int nspin0 = (nspin == 2) ? 2 : 1;
69 std::vector<hamilt::HContainer<TR>> vxcs_R_ao(nspin0, hamilt::HContainer<TR>(ucell, pv)); // call move constructor
70#ifdef __EXX
71 std::array<int, 3> Rs_period = {kv.nmp[0], kv.nmp[1], kv.nmp[2]};
72 const auto cell_nearest = hamilt::init_cell_nearest(ucell, Rs_period);
73#endif
74 for (int is = 0; is < nspin0; ++is)
75 {
76 if (std::is_same<TK, double>::value)
77 {
78 vxcs_R_ao[is].fix_gamma();
79 }
80#ifdef __EXX
81 if (GlobalC::exx_info.info_global.cal_exx)
82 {
84 ? hamilt::reallocate_hcontainer(*Hexxd, &vxcs_R_ao[is], &cell_nearest)
85 : hamilt::reallocate_hcontainer(*Hexxc, &vxcs_R_ao[is], &cell_nearest);
86 }
87#endif
88 }
89
90 // 3. calculate the Vxc(R)
91 hamilt::HS_Matrix_K<TK> vxc_k_ao(pv, 1); // only hk is needed, sk is skipped
92 std::vector<hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>*> vxcs_op_ao(nspin0);
93 for (int is = 0; is < nspin0; ++is)
94 {
95 vxcs_op_ao[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(&vxc_k_ao,
96 kv.kvec_d,
97 potxc,
98 &vxcs_R_ao[is],
99 &ucell,
100 orb_cutoff,
101 &gd,
102 nspin);
103 vxcs_op_ao[is]->contributeHR();
104#ifdef __EXX
105 if (GlobalC::exx_info.info_global.cal_exx)
106 {
108 GlobalC::exx_info.info_global.hybrid_alpha,
109 *Hexxd,
110 *pv,
111 ucell.get_npol(),
112 vxcs_R_ao[is],
113 &cell_nearest)
115 GlobalC::exx_info.info_global.hybrid_alpha,
116 *Hexxc,
117 *pv,
118 ucell.get_npol(),
119 vxcs_R_ao[is],
120 &cell_nearest);
121 }
122#endif
123 }
124
125 // test: fold Vxc(R) and check whether it is equal to Vxc(k)
126 // for (int ik = 0; ik < kv.get_nks(); ++ik)
127 // {
128 // vxc_k_ao.set_zero_hk();
129 // dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(vxcs_op_ao[kv.isk[ik]])->contributeHk(ik);
130
131 // // output Vxc(k) (test)
132 // const TK* const hk = vxc_k_ao.get_hk();
133 // std::cout << "ik=" << ik << ", Vxc(K): " << std::endl;
134 // for (int i = 0; i < pv->get_row_size(); i++)
135 // {
136 // for (int j = 0; j < pv->get_col_size(); j++)
137 // {
138 // std::cout << hk[j * pv->get_row_size() + i] << " ";
139 // }
140 // std::cout << std::endl;
141 // }
142 // }
143
144 // 4. write Vxc(R) in csr format
145 for (int is = 0; is < nspin0; ++is)
146 {
147 std::set<Abfs::Vector3_Order<int>> all_R_coor = sparse_format::get_R_range(vxcs_R_ao[is]);
148 const std::string filename = "Vxc_R_spin" + std::to_string(is);
149 ModuleIO::save_sparse(cal_HR_sparse(vxcs_R_ao[is], sparse_thr),
150 all_R_coor,
151 sparse_thr,
152 false, // binary
153 PARAM.globalv.global_out_dir + filename + ".csr",
154 *pv,
155 filename,
156 -1,
157 true); // all-reduce
158 }
159}
160} // namespace ModuleIO
161#endif
Definition charge.h:18
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: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 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:18
void contributeHR()
Definition veff_lcao.cpp:60
Definition surchem.h:15
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
Definition cal_dos.h:9
std::pair< int, TC > TAC
Definition restart_exx_csr.h:11
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, 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:35
std::map< Abfs::Vector3_Order< int >, std::map< size_t, std::map< size_t, T > > > cal_HR_sparse(const hamilt::HContainer< T > &hR, const double sparse_thr)
Definition write_vxc_r.hpp:24
std::set< Abfs::Vector3_Order< int > > get_R_range(const hamilt::HContainer< TR > &hR)
Definition write_vxc_r.hpp:16
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:17
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 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