Skip to content

Commit c0bdbfb

Browse files
committed
git revert a145293
1 parent 5f96c22 commit c0bdbfb

File tree

11 files changed

+376
-777
lines changed

11 files changed

+376
-777
lines changed

source/module_hamilt_general/module_xc/exx_info.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ struct Exx_Info
1515
{
1616
bool cal_exx = false;
1717

18-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Method,
19-
std::pair<bool,
20-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type,
21-
std::vector<std::map<std::string,std::string>>>>> coulomb_settings;
18+
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> coulomb_param;
2219
// Fock:
2320
// "alpha": "0"
2421
// "Rcut_type": "limits" / "spencer"
@@ -55,10 +52,7 @@ struct Exx_Info
5552

5653
struct Exx_Info_RI
5754
{
58-
const std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Method,
59-
std::pair<bool,
60-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type,
61-
std::vector<std::map<std::string,std::string>>>>> &coulomb_settings;
55+
const std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> &coulomb_param;
6256

6357
bool real_number = false;
6458

@@ -80,7 +74,7 @@ struct Exx_Info
8074
int abfs_Lmax = 0; // tmp
8175

8276
Exx_Info_RI(const Exx_Info::Exx_Info_Global& info_global)
83-
: coulomb_settings(info_global.coulomb_settings)
77+
: coulomb_param(info_global.coulomb_param)
8478
{
8579
}
8680
};

source/module_io/input_conv.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,41 +328,35 @@ void Input_Conv::Convert()
328328
{
329329
GlobalC::exx_info.info_global.cal_exx = true;
330330
GlobalC::exx_info.info_global.ccp_type = Conv_Coulomb_Pot_K::Ccp_Type::Hf;
331-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> coulomb_param;
332-
coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Fock] = {{
331+
GlobalC::exx_info.info_global.coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Fock] = {{
333332
{"alpha", "1"},
334333
{"Rcut_type", "spencer"},
335334
{"lambda", std::to_string(PARAM.inp.exx_lambda)} }};
336-
GlobalC::exx_info.info_global.coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair(true, coulomb_param);
337335
}
338336
// use the error function erf(w|r-r'|), exx just has the short-range part
339337
else if (dft_functional_lower == "hse"
340338
|| dft_functional_lower == "cwp22")
341339
{
342340
GlobalC::exx_info.info_global.cal_exx = true;
343341
GlobalC::exx_info.info_global.ccp_type = Conv_Coulomb_Pot_K::Ccp_Type::Erfc;
344-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> coulomb_param;
345-
coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Erfc] = {{
342+
GlobalC::exx_info.info_global.coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Erfc] = {{
346343
{"alpha", "1"},
347344
{"omega", std::to_string(PARAM.inp.exx_hse_omega)},
348345
{"Rcut_type", "limits"} }};
349-
GlobalC::exx_info.info_global.coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair(true, coulomb_param);
350346
}
351347
// use the error function erf(w|r-r'|), exx just has the long-range part
352348
else if ( dft_functional_lower == "wp22" )
353349
{
354350
GlobalC::exx_info.info_global.cal_exx = true;
355351
GlobalC::exx_info.info_global.ccp_type = Conv_Coulomb_Pot_K::Ccp_Type::Erf;
356-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> coulomb_param;
357-
coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Fock] = {{
352+
GlobalC::exx_info.info_global.coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Fock] = {{
358353
{"alpha", "1"},
359354
{"Rcut_type", "spencer"},
360355
{"lambda", std::to_string(PARAM.inp.exx_lambda)} }};
361-
coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Erfc] = {{
356+
GlobalC::exx_info.info_global.coulomb_param[Conv_Coulomb_Pot_K::Coulomb_Type::Erfc] = {{
362357
{"alpha", "-1"},
363358
{"omega", std::to_string(PARAM.inp.exx_hse_omega)},
364359
{"Rcut_type", "limits"} }};
365-
GlobalC::exx_info.info_global.coulomb_settings[Conv_Coulomb_Pot_K::Coulomb_Method::Center2] = std::make_pair(true, coulomb_param);
366360
}
367361
#ifdef __EXX
368362
else if (dft_functional_lower == "opt_orb")

source/module_ri/Exx_LRI.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <vector>
1616
#include <array>
1717
#include <map>
18-
#include <unordered_map>
1918
#include <deque>
2019
#include <mpi.h>
2120

@@ -38,15 +37,6 @@
3837
class OperatorLREXX;
3938
}
4039

41-
template<typename Tdata>
42-
class Exx_Obj
43-
{
44-
// match with Conv_Coulomb_Pot_K::Coulomb_Method
45-
public:
46-
LRI_CV<Tdata> cv;
47-
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs_ccp;
48-
};
49-
5040
template<typename Tdata>
5141
class Exx_LRI
5242
{
@@ -95,9 +85,9 @@ class Exx_LRI
9585

9686
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> lcaos;
9787
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs;
98-
//std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs_ccp;
99-
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Method, Exx_Obj<Tdata>> exx_objs;
100-
//LRI_CV<Tdata> cv;
88+
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs_ccp;
89+
90+
LRI_CV<Tdata> cv;
10191
RI::Exx<TA,Tcell,Ndim,Tdata> exx_lri;
10292

10393
void post_process_Hexx( std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> &Hexxs_io ) const;

source/module_ri/Exx_LRI.hpp

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ void Exx_LRI<Tdata>::init(const MPI_Comm &mpi_comm_in,
4848
{ this->abfs = Exx_Abfs::IO::construct_abfs( abfs_same_atom, orb, this->info.files_abfs, this->info.kmesh_times ); }
4949
Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running);
5050

51+
const std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>>
52+
coulomb_param_updated = RI_Util::update_coulomb_param(this->info.coulomb_param, ucell.omega, this->p_kv->get_nkstot_full());
53+
this->abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp(this->abfs, coulomb_param_updated, this->info.ccp_rmesh_times);
54+
5155
for( size_t T=0; T!=this->abfs.size(); ++T )
5256
{ GlobalC::exx_info.info_ri.abfs_Lmax = std::max( GlobalC::exx_info.info_ri.abfs_Lmax, static_cast<int>(this->abfs[T].size())-1 ); }
5357

54-
for(const auto &settings_list : this->info.coulomb_settings)
55-
{
56-
const std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>>
57-
coulomb_param_updated = RI_Util::update_coulomb_param(settings_list.second.second, ucell.omega, this->p_kv->get_nkstot_full());
58-
this->exx_objs[settings_list.first].abfs_ccp = Conv_Coulomb_Pot_K::cal_orbs_ccp(this->abfs, coulomb_param_updated, this->info.ccp_rmesh_times);
59-
this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb,
60-
this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp,
61-
this->info.kmesh_times, this->info.ccp_rmesh_times );
62-
}
58+
this->cv.set_orbitals(
59+
ucell,
60+
orb,
61+
this->lcaos, this->abfs, this->abfs_ccp,
62+
this->info.kmesh_times, this->info.ccp_rmesh_times );
63+
6364
ModuleBase::timer::tick("Exx_LRI", "init");
6465
}
6566

@@ -94,40 +95,26 @@ void Exx_LRI<Tdata>::cal_exx_ions(const UnitCell& ucell,
9495
const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
9596
list_As_Vs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2, false);
9697

97-
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Vs;
98-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, Ndim>>> dVs;
99-
for(const auto &settings_list : this->info.coulomb_settings)
100-
{
101-
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>
102-
Vs_temp = this->exx_objs[settings_list.first].cv.cal_Vs(ucell,
103-
list_As_Vs.first, list_As_Vs.second[0],
104-
{{"writable_Vws",true}});
105-
this->exx_objs[settings_list.first].cv.Vws = LRI_CV_Tools::get_CVws(ucell,Vs_temp);
106-
Vs = Vs.empty() ? Vs_temp : LRI_CV_Tools::add(Vs, Vs_temp);
107-
108-
if(PARAM.inp.cal_force || PARAM.inp.cal_stress)
109-
{
110-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, Ndim>>>
111-
dVs_temp = this->exx_objs[settings_list.first].cv.cal_dVs(ucell,
112-
list_As_Vs.first, list_As_Vs.second[0],
113-
{{"writable_dVws",true}});
114-
this->exx_objs[settings_list.first].cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs_temp);
115-
dVs = dVs.empty() ? dVs_temp : LRI_CV_Tools::add(dVs, dVs_temp);
116-
}
117-
118-
}
98+
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>
99+
Vs = this->cv.cal_Vs(ucell,
100+
list_As_Vs.first, list_As_Vs.second[0],
101+
{{"writable_Vws",true}});
102+
this->cv.Vws = LRI_CV_Tools::get_CVws(ucell,Vs);
119103
if (write_cv && GlobalV::MY_RANK == 0)
120104
{ LRI_CV_Tools::write_Vs_abf(Vs, PARAM.globalv.global_out_dir + "Vs"); }
121105
this->exx_lri.set_Vs(std::move(Vs), this->info.V_threshold);
122106

123107
if(PARAM.inp.cal_force || PARAM.inp.cal_stress)
124108
{
125-
std::array<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>, Ndim>
126-
dVs_order = LRI_CV_Tools::change_order(std::move(dVs));
127-
this->exx_lri.set_dVs(std::move(dVs_order), this->info.V_grad_threshold);
109+
std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>
110+
dVs = this->cv.cal_dVs(ucell,
111+
list_As_Vs.first, list_As_Vs.second[0],
112+
{{"writable_dVws",true}});
113+
this->cv.dVws = LRI_CV_Tools::get_dCVws(ucell,dVs);
114+
this->exx_lri.set_dVs(std::move(dVs), this->info.V_grad_threshold);
128115
if(PARAM.inp.cal_stress)
129116
{
130-
std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(ucell,dVs_order);
117+
std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(ucell,dVs);
131118
this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold);
132119
}
133120
}
@@ -136,47 +123,29 @@ void Exx_LRI<Tdata>::cal_exx_ions(const UnitCell& ucell,
136123
const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA,std::array<Tcell,Ndim>>>>>
137124
list_As_Cs = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2, false);
138125

139-
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Cs;
140-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> dCs;
141-
for(const auto &settings_list : this->info.coulomb_settings)
142-
{
143-
if(settings_list.second.first)
144-
{
145-
std::pair<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
146-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
147-
Cs_dCs = this->exx_objs[settings_list.first].cv.cal_Cs_dCs(
148-
ucell,
149-
list_As_Cs.first, list_As_Cs.second[0],
150-
{{"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress},
151-
{"writable_Cws",true}, {"writable_dCws",true}, {"writable_Vws",false}, {"writable_dVws",false}});
152-
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> &Cs_temp = std::get<0>(Cs_dCs);
153-
this->exx_objs[settings_list.first].cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs_temp);
154-
Cs = Cs.empty() ? Cs_temp : LRI_CV_Tools::add(Cs, Cs_temp);
155-
156-
if(PARAM.inp.cal_force || PARAM.inp.cal_stress)
157-
{
158-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> &dCs_temp = std::get<1>(Cs_dCs);
159-
this->exx_objs[settings_list.first].cv.dCws = LRI_CV_Tools::get_dCVws(ucell,dCs_temp);
160-
dCs = dCs.empty() ? dCs_temp : LRI_CV_Tools::add(dCs, dCs_temp);
161-
}
162-
}
163-
}
126+
std::pair<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>, std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>>
127+
Cs_dCs = this->cv.cal_Cs_dCs(
128+
ucell,
129+
list_As_Cs.first, list_As_Cs.second[0],
130+
{{"cal_dC",PARAM.inp.cal_force||PARAM.inp.cal_stress},
131+
{"writable_Cws",true}, {"writable_dCws",true}, {"writable_Vws",false}, {"writable_dVws",false}});
132+
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> &Cs = std::get<0>(Cs_dCs);
133+
this->cv.Cws = LRI_CV_Tools::get_CVws(ucell,Cs);
164134
if (write_cv && GlobalV::MY_RANK == 0)
165135
{ LRI_CV_Tools::write_Cs_ao(Cs, PARAM.globalv.global_out_dir + "Cs"); }
166136
this->exx_lri.set_Cs(std::move(Cs), this->info.C_threshold);
167137

168138
if(PARAM.inp.cal_force || PARAM.inp.cal_stress)
169139
{
170-
std::array<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>, Ndim>
171-
dCs_order = LRI_CV_Tools::change_order(std::move(dCs));
172-
this->exx_lri.set_dCs(std::move(dCs_order), this->info.C_grad_threshold);
140+
std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3> &dCs = std::get<1>(Cs_dCs);
141+
this->cv.dCws = LRI_CV_Tools::get_dCVws(ucell,dCs);
142+
this->exx_lri.set_dCs(std::move(dCs), this->info.C_grad_threshold);
173143
if(PARAM.inp.cal_stress)
174144
{
175-
std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(ucell,dCs_order);
145+
std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(ucell,dCs);
176146
this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold);
177147
}
178148
}
179-
180149
ModuleBase::timer::tick("Exx_LRI", "cal_exx_ions");
181150
}
182151

source/module_ri/LRI_CV.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class LRI_CV
4747
const std::vector<TA> &list_A0,
4848
const std::vector<TAC> &list_A1,
4949
const std::map<std::string,bool> &flags); // "writable_Vws"
50-
inline std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>
50+
inline std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>
5151
cal_dVs(
5252
const UnitCell &ucell,
5353
const std::vector<TA> &list_A0,
5454
const std::vector<TAC> &list_A1,
5555
const std::map<std::string,bool> &flags); // "writable_dVws"
56-
std::pair<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
57-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
56+
std::pair<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,
57+
std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>>
5858
cal_Cs_dCs(
5959
const UnitCell &ucell,
6060
const std::vector<TA> &list_A0,

source/module_ri/LRI_CV.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ auto LRI_CV<Tdata>::cal_dVs(
146146
const std::vector<TA> &list_A0,
147147
const std::vector<TAC> &list_A1,
148148
const std::map<std::string,bool> &flags) // + "writable_dVws"
149-
-> std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>
149+
-> std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>
150150
{
151151
ModuleBase::TITLE("LRI_CV","cal_dVs");
152152
const T_func_DPcal_data<std::array<RI::Tensor<Tdata>,3>>
153153
func_DPcal_dV = std::bind(
154154
&LRI_CV<Tdata>::DPcal_dV, this,
155155
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
156-
return this->cal_datas(ucell,list_A0, list_A1, flags, this->ccp_rmesh_times, func_DPcal_dV);
156+
return LRI_CV_Tools::change_order(
157+
this->cal_datas(ucell,list_A0, list_A1, flags, this->ccp_rmesh_times, func_DPcal_dV));
157158
}
158159

159160
template<typename Tdata>
@@ -162,9 +163,7 @@ auto LRI_CV<Tdata>::cal_Cs_dCs(
162163
const std::vector<TA> &list_A0,
163164
const std::vector<TAC> &list_A1,
164165
const std::map<std::string,bool> &flags) // "cal_dC" + "writable_Cws", "writable_dCws", "writable_Vws", "writable_dVws"
165-
-> std::pair<
166-
std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
167-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
166+
-> std::pair<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>, std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>>
168167
{
169168
ModuleBase::TITLE("LRI_CV","cal_Cs_dCs");
170169
const T_func_DPcal_data<std::pair<RI::Tensor<Tdata>, std::array<RI::Tensor<Tdata>,3>>>
@@ -174,16 +173,16 @@ auto LRI_CV<Tdata>::cal_Cs_dCs(
174173
std::map<TA,std::map<TAC, std::pair<RI::Tensor<Tdata>, std::array<RI::Tensor<Tdata>,3>>>>
175174
Cs_dCs_tmp = this->cal_datas(ucell,list_A0, list_A1, flags, std::min(1.0,this->ccp_rmesh_times), func_DPcal_C_dC);
176175

177-
std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Cs;
178-
std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> dCs;
179-
for (auto& Cs_dCs_A: Cs_dCs_tmp)
180-
for (auto& Cs_dCs_B: Cs_dCs_A.second) {
181-
Cs[Cs_dCs_A.first][Cs_dCs_B.first]
182-
= std::move(std::get<0>(Cs_dCs_B.second));
183-
if (flags.at("cal_dC"))
184-
dCs[Cs_dCs_A.first][Cs_dCs_B.first]
185-
= std::move(std::get<1>(Cs_dCs_B.second));
186-
}
176+
std::map<TA,std::map<TAC,RI::Tensor<Tdata>>> Cs;
177+
std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3> dCs;
178+
for(auto &Cs_dCs_A : Cs_dCs_tmp)
179+
for(auto &Cs_dCs_B : Cs_dCs_A.second)
180+
{
181+
Cs[Cs_dCs_A.first][Cs_dCs_B.first] = std::move(std::get<0>(Cs_dCs_B.second));
182+
if(flags.at("cal_dC"))
183+
for(int ix=0; ix<3; ++ix)
184+
dCs[ix][Cs_dCs_A.first][Cs_dCs_B.first] = std::move(std::get<1>(Cs_dCs_B.second)[ix]);
185+
}
187186
return std::make_pair(Cs, dCs);
188187
}
189188

0 commit comments

Comments
 (0)