Skip to content

Commit d093c58

Browse files
PeizeLinmaki49
andauthored
Feature: update LibRI v0.2.0 (deepmodeling#4830)
* Fix C++ compiler warning * Refactor Exx_LRI::cal_exx_stress() to LibRI loop3 * Feature: add input and info CV_grad_R_threshold for exx * Delete exx_lri.set_csm_threshold() * Update LibRI in toolchain to v0.2.0 * Update submodule deps/LibRI to v0.2.0 * fix include * change ref in integrate_test * change ref in integrate_test * change ref results for no cauchy screening (dyzheng#3) --------- Co-authored-by: LUNASEA <33978601+maki49@users.noreply.github.com>
1 parent 3c9ceb4 commit d093c58

23 files changed

Lines changed: 178 additions & 103 deletions

File tree

deps/LibRI

Submodule LibRI updated 74 files

source/module_hamilt_general/module_xc/exx_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct Exx_Info
4747
double cauchy_threshold = 0;
4848
double C_grad_threshold = 0;
4949
double V_grad_threshold = 0;
50+
double C_grad_R_threshold = 0;
51+
double V_grad_R_threshold = 0;
5052
double cauchy_force_threshold = 0;
5153
double cauchy_stress_threshold = 0;
5254
double ccp_rmesh_times = 10;

source/module_io/input_conv.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ void Input_Conv::Convert()
497497
GlobalC::exx_info.info_ri.cauchy_threshold = PARAM.inp.exx_cauchy_threshold;
498498
GlobalC::exx_info.info_ri.C_grad_threshold = PARAM.inp.exx_c_grad_threshold;
499499
GlobalC::exx_info.info_ri.V_grad_threshold = PARAM.inp.exx_v_grad_threshold;
500+
GlobalC::exx_info.info_ri.C_grad_R_threshold = PARAM.inp.exx_c_grad_r_threshold;
501+
GlobalC::exx_info.info_ri.V_grad_R_threshold = PARAM.inp.exx_v_grad_r_threshold;
500502
GlobalC::exx_info.info_ri.cauchy_force_threshold = PARAM.inp.exx_cauchy_force_threshold;
501503
GlobalC::exx_info.info_ri.cauchy_stress_threshold = PARAM.inp.exx_cauchy_stress_threshold;
502504
GlobalC::exx_info.info_ri.ccp_rmesh_times = std::stod(PARAM.inp.exx_ccp_rmesh_times);

source/module_io/read_input_item_exx_dftu.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ void ReadInput::item_exx()
149149
read_sync_double(input.exx_v_grad_threshold);
150150
this->add_item(item);
151151
}
152+
{
153+
Input_Item item("exx_c_grad_r_threshold");
154+
item.annotation = "threshold to screen nabla C matrix in exx";
155+
read_sync_double(input.exx_c_grad_r_threshold);
156+
this->add_item(item);
157+
}
158+
{
159+
Input_Item item("exx_v_grad_r_threshold");
160+
item.annotation = "threshold to screen nabla V matrix in exx";
161+
read_sync_double(input.exx_v_grad_r_threshold);
162+
this->add_item(item);
163+
}
152164
{
153165
Input_Item item("exx_cauchy_force_threshold");
154166
item.annotation = "threshold to screen exx force using Cauchy-Schwartz inequality";

source/module_parameter/input_parameter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ struct Input_para
471471
double exx_cauchy_threshold = 1e-07; ///< threshold to screen exx using Cauchy-Schwartz inequality
472472
double exx_c_grad_threshold = 0.0001; ///< threshold to screen nabla C matrix in exx
473473
double exx_v_grad_threshold = 0.1; ///< threshold to screen nabla V matrix in exx
474+
double exx_c_grad_r_threshold = 0.0001; ///< threshold to screen nabla C matrix in exx
475+
double exx_v_grad_r_threshold = 0.1; ///< threshold to screen nabla V matrix in exx
474476
double exx_cauchy_force_threshold = 1e-07; ///< threshold to screen exx force using Cauchy-Schwartz
475477
///< inequality
476478
double exx_cauchy_stress_threshold = 1e-07; ///< threshold to screen exx stress using Cauchy-Schwartz

source/module_ri/Exx_LRI.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ void Exx_LRI<Tdata>::cal_exx_ions()
140140
{{"writable_dVws",true}});
141141
this->cv.dVws = LRI_CV_Tools::get_dCVws(dVs);
142142
this->exx_lri.set_dVs(std::move(dVs), this->info.V_grad_threshold);
143+
if(GlobalV::CAL_STRESS)
144+
{
145+
std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(dVs);
146+
this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold);
147+
}
143148
}
144149

145150
const std::array<Tcell,Ndim> period_Cs = LRI_CV_Tools::cal_latvec_range<Tcell>(2);
@@ -160,6 +165,11 @@ void Exx_LRI<Tdata>::cal_exx_ions()
160165
std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3> &dCs = std::get<1>(Cs_dCs);
161166
this->cv.dCws = LRI_CV_Tools::get_dCVws(dCs);
162167
this->exx_lri.set_dCs(std::move(dCs), this->info.C_grad_threshold);
168+
if(GlobalV::CAL_STRESS)
169+
{
170+
std::array<std::array<std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(dCs);
171+
this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold);
172+
}
163173
}
164174
ModuleBase::timer::tick("Exx_LRI", "cal_exx_ions");
165175
}
@@ -172,8 +182,6 @@ void Exx_LRI<Tdata>::cal_exx_elec(const std::vector<std::map<TA,std::map<TAC,RI:
172182

173183
const std::vector<std::tuple<std::set<TA>, std::set<TA>>> judge = RI_2D_Comm::get_2D_judge(pv);
174184

175-
this->exx_lri.set_csm_threshold(this->info.cauchy_threshold);
176-
177185
this->Hexxs.resize(GlobalV::NSPIN);
178186
this->Eexx = 0;
179187
for(int is=0; is<GlobalV::NSPIN; ++is)
@@ -209,7 +217,7 @@ void Exx_LRI<Tdata>::post_process_Hexx( std::map<TA, std::map<TAC, RI::Tensor<Td
209217
}
210218

211219
template<typename Tdata>
212-
double Exx_LRI<Tdata>::post_process_Eexx(const double& Eexx_in) const
220+
double Exx_LRI<Tdata>::post_process_Eexx(const double& Eexx_in) const
213221
{
214222
ModuleBase::TITLE("Exx_LRI","post_process_Eexx");
215223
const double SPIN_multiple = std::map<int, double>{ {1,2}, {2,1}, {4,1} }.at(GlobalV::NSPIN); // why?
@@ -239,8 +247,6 @@ void Exx_LRI<Tdata>::cal_exx_force()
239247
{
240248
ModuleBase::TITLE("Exx_LRI","cal_exx_force");
241249
ModuleBase::timer::tick("Exx_LRI", "cal_exx_force");
242-
243-
this->exx_lri.set_csm_threshold(this->info.cauchy_force_threshold);
244250

245251
this->force_exx.create(GlobalC::ucell.nat, Ndim);
246252
for(int is=0; is<GlobalV::NSPIN; ++is)
@@ -263,8 +269,6 @@ void Exx_LRI<Tdata>::cal_exx_stress()
263269
{
264270
ModuleBase::TITLE("Exx_LRI","cal_exx_stress");
265271
ModuleBase::timer::tick("Exx_LRI", "cal_exx_stress");
266-
267-
this->exx_lri.set_csm_threshold(this->info.cauchy_stress_threshold);
268272

269273
this->stress_exx.create(Ndim, Ndim);
270274
for(int is=0; is<GlobalV::NSPIN; ++is)

source/module_ri/LRI_CV.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
#include "LRI_CV.h"
1010
#include "LRI_CV_Tools.h"
11-
#include "module_ri/exx_abfs-abfs_index.h"
11+
#include "exx_abfs-abfs_index.h"
1212
#include "RI_Util.h"
13-
#include "module_base/tool_title.h"
14-
#include "module_base/timer.h"
13+
#include "../module_base/tool_title.h"
14+
#include "../module_base/timer.h"
15+
#include "../module_hamilt_pw/hamilt_pwdft/global.h"
1516
#include <RI/global/Global_Func-1.h>
1617
#include <omp.h>
1718

source/module_ri/LRI_CV_Tools.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
#ifndef LRI_CV_TOOLS_H
77
#define LRI_CV_TOOLS_H
88

9+
#include "module_base/abfs-vector3_order.h"
10+
911
#include <RI/global/Tensor.h>
1012

1113
#include <cstddef>
1214
#include <array>
1315
#include <vector>
16+
#include <map>
1417

1518
namespace LRI_CV_Tools
1619
{
@@ -84,7 +87,12 @@ namespace LRI_CV_Tools
8487
template<typename TA, typename Tcell, typename Tdata>
8588
extern std::map<int,std::map<int,std::map<Abfs::Vector3_Order<double>,std::array<RI::Tensor<Tdata>,3>>>>
8689
get_dCVws(
87-
const std::array<std::map<TA,std::map<std::pair<TA,std::array<Tcell,3>>,RI::Tensor<Tdata>>>,3> &dCVs);
90+
const std::array<std::map<TA,std::map<std::pair<TA,std::array<Tcell,3>>,RI::Tensor<Tdata>>>,3> &dCVs);
91+
92+
template<typename TA, typename TC, typename Tdata>
93+
extern std::array<std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,3>,3>
94+
cal_dMRs(
95+
const std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,3> &dMs);
8896
}
8997

9098
#include "LRI_CV_Tools.hpp"

source/module_ri/LRI_CV_Tools.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "LRI_CV_Tools.h"
1010
#include "Inverse_Matrix.h"
1111
#include "../module_base/mathzone.h"
12+
#include "../module_hamilt_pw/hamilt_pwdft/global.h"
1213

1314
template<typename Tdata>
1415
RI::Tensor<Tdata>
@@ -54,8 +55,10 @@ template<typename T, std::size_t N>
5455
bool LRI_CV_Tools::exist(const std::array<T,N> &dV)
5556
{
5657
for(size_t i=0; i<3; ++i)
58+
{
5759
if(!dV[i].empty())
5860
return true;
61+
}
5962
return false;
6063
}
6164

@@ -312,4 +315,45 @@ LRI_CV_Tools::get_dCVws(
312315
return dCVws;
313316
}
314317

318+
319+
// dMRs[ipos0][ipos1] = \nabla_{ipos0} M R_{ipos1}
320+
template<typename TA, typename TC, typename Tdata>
321+
std::array<std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,3>,3>
322+
LRI_CV_Tools::cal_dMRs(
323+
const std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,3> &dMs)
324+
{
325+
auto get_R_delta = [&](const TA &iat0, const std::pair<TA,TC> &A1) -> std::array<Tdata,3>
326+
{
327+
const TA iat1 = A1.first;
328+
const TC &cell1 = A1.second;
329+
const int it0 = GlobalC::ucell.iat2it[iat0];
330+
const int ia0 = GlobalC::ucell.iat2ia[iat0];
331+
const int it1 = GlobalC::ucell.iat2it[iat1];
332+
const int ia1 = GlobalC::ucell.iat2ia[iat1];
333+
const ModuleBase::Vector3<double> tau0 = GlobalC::ucell.atoms[it0].tau[ia0];
334+
const ModuleBase::Vector3<double> tau1 = GlobalC::ucell.atoms[it1].tau[ia1];
335+
const Abfs::Vector3_Order<double> R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*GlobalC::ucell.latvec);
336+
return std::array<Tdata,3>{R_delta.x, R_delta.y, R_delta.z};
337+
};
338+
constexpr int Npos = 3;
339+
std::array<std::array<std::map<TA,std::map<std::pair<TA,TC>,RI::Tensor<Tdata>>>,Npos>,Npos> dMRs;
340+
for(int ipos0=0; ipos0<Npos; ++ipos0)
341+
{
342+
for(int ipos1=0; ipos1<Npos; ++ipos1)
343+
{
344+
for(const auto &dMs_A : dMs[ipos0])
345+
{
346+
const TA iat0 = dMs_A.first;
347+
for(const auto &dMs_B : dMs_A.second)
348+
{
349+
const std::pair<TA,TC> A1 = dMs_B.first;
350+
const RI::Tensor<Tdata> &dM = dMs_B.second;
351+
const std::array<Tdata,3> R_delta = get_R_delta(iat0, A1);
352+
dMRs[ipos0][ipos1][iat0][A1] = dM * R_delta[ipos1];
353+
}
354+
}
355+
}
356+
}
357+
return dMRs;
358+
}
315359
#endif
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
6 (-1.039229,-3.6984385e-16) (-1.4337629e-08,8.1948535e-16) (-1.6549262e-15,-2.4275964e-17) (-7.3477682e-14,-2.8317688e-17) (-2.2743308e-08,6.0642134e-16) (-4.7365417e-10,2.7036238e-14)
2-
(-0.96491479,1.2723875e-15) (-6.2469742e-09,-1.8654043e-12) (-8.1614632e-11,8.9132756e-13) (0.12279288,7.8499298e-15) (9.3436543e-14,2.364213e-16)
3-
(-1.064337,2.3693393e-16) (1.0547119e-15,1.5451914e-16) (-6.6444545e-09,2.0880435e-12) (-5.7610897e-10,-3.0200736e-12)
4-
(-1.064337,2.3700845e-16) (6.3717573e-10,-9.9770901e-13) (4.9778198e-10,-3.4757565e-13)
5-
(-0.65449032,1.2140463e-16) (1.8561136e-14,4.810951e-17)
6-
(-0.65138796,-7.4288639e-18)
1+
6 (-1.0394425,-3.7363449e-16) (3.9703113e-10,8.3455762e-16) (4.4417161e-14,5.5568749e-17) (-2.4341466e-13,4.3883506e-17) (-2.0039369e-09,5.8451215e-16) (1.9596449e-11,6.8294051e-12)
2+
(-0.96326621,1.2640312e-15) (-1.4831543e-09,-4.0086346e-12) (8.370459e-10,-5.1125035e-13) (0.12202161,-5.3763309e-15) (1.7561473e-14,3.428681e-15)
3+
(-1.0644129,2.3743998e-16) (-7.1678774e-15,-2.6869918e-16) (-1.4937099e-09,4.0465037e-12) (2.5345497e-09,8.0997135e-10)
4+
(-1.0644129,2.3735151e-16) (8.1785897e-10,5.1608006e-13) (-7.4156745e-10,-2.3462101e-10)
5+
(-0.65468695,1.1556487e-16) (4.4158931e-15,1.0408529e-15)
6+
(-0.65149008,-4.4004079e-17)

0 commit comments

Comments
 (0)