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]->set_current_spin(is);
104 vxcs_op_ao[is]->contributeHR();
105#ifdef __EXX
106 if (GlobalC::exx_info.info_global.cal_exx)
107 {
109 GlobalC::exx_info.info_global.hybrid_alpha,
110 *Hexxd,
111 *pv,
112 ucell.get_npol(),
113 vxcs_R_ao[is],
114 &cell_nearest)
116 GlobalC::exx_info.info_global.hybrid_alpha,
117 *Hexxc,
118 *pv,
119 ucell.get_npol(),
120 vxcs_R_ao[is],
121 &cell_nearest);
122 }
123#endif
124 }
125
126 // test: fold Vxc(R) and check whether it is equal to Vxc(k)
127 // for (int ik = 0; ik < kv.get_nks(); ++ik)
128 // {
129 // vxc_k_ao.set_zero_hk();
130 // dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(vxcs_op_ao[kv.isk[ik]])->contributeHk(ik);
131
132 // // output Vxc(k) (test)
133 // const TK* const hk = vxc_k_ao.get_hk();
134 // std::cout << "ik=" << ik << ", Vxc(K): " << std::endl;
135 // for (int i = 0; i < pv->get_row_size(); i++)
136 // {
137 // for (int j = 0; j < pv->get_col_size(); j++)
138 // {
139 // std::cout << hk[j * pv->get_row_size() + i] << " ";
140 // }
141 // std::cout << std::endl;
142 // }
143 // }
144
145 // 4. write Vxc(R) in csr format
146 for (int is = 0; is < nspin0; ++is)
147 {
148 std::set<Abfs::Vector3_Order<int>> all_R_coor = sparse_format::get_R_range(vxcs_R_ao[is]);
149 const std::string filename = "Vxc_R_spin" + std::to_string(is);
150 ModuleIO::save_sparse(cal_HR_sparse(vxcs_R_ao[is], sparse_thr),
151 all_R_coor,
152 sparse_thr,
153 false, // binary
154 PARAM.globalv.global_out_dir + filename + ".csr",
155 *pv,
156 filename,
157 -1,
158 true); // all-reduce
159 }
160}
161} // namespace ModuleIO
162#endif
Definition charge.h:17
Definition sltk_grid_driver.h:40
Definition klist.h:12
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:15
Definition matrix.h:18
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:10
Definition unitcell.h:15
Definition potential_new.h:48
void pot_register(const std::vector< std::string > &components_list)
Definition potential_new.cpp:65
void update_from_charge(const Charge *const chg, const UnitCell *const ucell)
Definition potential_new.cpp:159
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:13
Exx_Info exx_info
Definition exx_info.cpp:8
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
Definition input_help.cpp:10
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::pair< int, TC > TAC
Definition restart_exx_csr.h:12
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:382
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:445
std::set< Abfs::Vector3_Order< int > > get_R_range(const hamilt::HContainer< T > &hR)
Definition spar_hsr.h:22
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:55
Exx_Info_RI info_ri
Definition exx_info.h:86
std::string global_out_dir
global output directory
Definition system_parameter.h:42