From d41a0e1d81b21bf58ba1e52a62603b7b5a229d3d Mon Sep 17 00:00:00 2001 From: linpz Date: Sat, 13 Jul 2024 13:00:22 +0800 Subject: [PATCH 1/6] Fix C++ compiler warning --- source/module_hamilt_lcao/module_gint/gint.h | 2 +- source/module_lr/utils/lr_util.cpp | 2 +- source/module_lr/utils/lr_util.h | 4 ++-- source/module_lr/utils/lr_util.hpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/module_hamilt_lcao/module_gint/gint.h b/source/module_hamilt_lcao/module_gint/gint.h index b4fb0a3b74..3416ebef6b 100644 --- a/source/module_hamilt_lcao/module_gint/gint.h +++ b/source/module_hamilt_lcao/module_gint/gint.h @@ -22,7 +22,7 @@ class Gint { hamilt::HContainer* get_hRGint() const { return hRGint; } std::vector*> get_DMRGint() const { return DMRGint; } - const int get_ncxyz() const { return ncxyz; } + int get_ncxyz() const { return ncxyz; } // the unified interface to grid integration void cal_gint(Gint_inout* inout); diff --git a/source/module_lr/utils/lr_util.cpp b/source/module_lr/utils/lr_util.cpp index 83491eb343..ea6eca97f9 100644 --- a/source/module_lr/utils/lr_util.cpp +++ b/source/module_lr/utils/lr_util.cpp @@ -5,7 +5,7 @@ namespace LR_Util { /// =================PHYSICS==================== - const int cal_nocc(int nelec) { return nelec / ModuleBase::DEGSPIN + nelec % static_cast(ModuleBase::DEGSPIN); } + int cal_nocc(int nelec) { return nelec / ModuleBase::DEGSPIN + nelec % static_cast(ModuleBase::DEGSPIN); } std::pair>> set_ix_map_diagonal(bool mode, int nocc, int nvirt) diff --git a/source/module_lr/utils/lr_util.h b/source/module_lr/utils/lr_util.h index 147fce62ce..f569d3b105 100644 --- a/source/module_lr/utils/lr_util.h +++ b/source/module_lr/utils/lr_util.h @@ -20,11 +20,11 @@ namespace LR_Util /// @tparam TCell /// @param ucell template - const int cal_nelec(const TCell& ucell); + int cal_nelec(const TCell& ucell); /// @brief calculate the number of occupied orbitals /// @param nelec - const int cal_nocc(int nelec); + int cal_nocc(int nelec); /// @brief set the index map: ix to (ic, iv) and vice versa /// by diagonal traverse the c-v pairs diff --git a/source/module_lr/utils/lr_util.hpp b/source/module_lr/utils/lr_util.hpp index 0e2b29e44c..90ae84c84a 100644 --- a/source/module_lr/utils/lr_util.hpp +++ b/source/module_lr/utils/lr_util.hpp @@ -10,7 +10,7 @@ namespace LR_Util /// =================PHYSICS==================== template - const int cal_nelec(const TCell& ucell) { + int cal_nelec(const TCell& ucell) { int nelec = 0; for (int it = 0; it < ucell.ntype; ++it) nelec += ucell.atoms[it].ncpp.zv * ucell.atoms[it].na; From a21dc75720c0b19a725005c7f44926d754013601 Mon Sep 17 00:00:00 2001 From: linpz Date: Sat, 13 Jul 2024 22:35:29 +0800 Subject: [PATCH 2/6] Refactor Exx_LRI::cal_exx_stress() to LibRI loop3 --- source/module_ri/Exx_LRI.hpp | 12 ++++++++- source/module_ri/LRI_CV_Tools.h | 7 +++++- source/module_ri/LRI_CV_Tools.hpp | 41 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/source/module_ri/Exx_LRI.hpp b/source/module_ri/Exx_LRI.hpp index 63f6d5c5a9..cd3eb06128 100644 --- a/source/module_ri/Exx_LRI.hpp +++ b/source/module_ri/Exx_LRI.hpp @@ -140,6 +140,11 @@ void Exx_LRI::cal_exx_ions() {{"writable_dVws",true}}); this->cv.dVws = LRI_CV_Tools::get_dCVws(dVs); this->exx_lri.set_dVs(std::move(dVs), this->info.V_grad_threshold); + if(GlobalV::CAL_STRESS) + { + std::array>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(dVs); + this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_threshold); + } } const std::array period_Cs = LRI_CV_Tools::cal_latvec_range(2); @@ -160,6 +165,11 @@ void Exx_LRI::cal_exx_ions() std::array>>,3> &dCs = std::get<1>(Cs_dCs); this->cv.dCws = LRI_CV_Tools::get_dCVws(dCs); this->exx_lri.set_dCs(std::move(dCs), this->info.C_grad_threshold); + if(GlobalV::CAL_STRESS) + { + std::array>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(dCs); + this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_threshold); + } } ModuleBase::timer::tick("Exx_LRI", "cal_exx_ions"); } @@ -209,7 +219,7 @@ void Exx_LRI::post_process_Hexx( std::map -double Exx_LRI::post_process_Eexx(const double& Eexx_in) const +double Exx_LRI::post_process_Eexx(const double& Eexx_in) const { ModuleBase::TITLE("Exx_LRI","post_process_Eexx"); const double SPIN_multiple = std::map{ {1,2}, {2,1}, {4,1} }.at(GlobalV::NSPIN); // why? diff --git a/source/module_ri/LRI_CV_Tools.h b/source/module_ri/LRI_CV_Tools.h index ebf6c80526..a40bdbbf49 100644 --- a/source/module_ri/LRI_CV_Tools.h +++ b/source/module_ri/LRI_CV_Tools.h @@ -84,7 +84,12 @@ namespace LRI_CV_Tools template extern std::map,std::array,3>>>> get_dCVws( - const std::array>,RI::Tensor>>,3> &dCVs); + const std::array>,RI::Tensor>>,3> &dCVs); + + template + extern std::array,RI::Tensor>>,3>,3> + cal_dMRs( + const std::array,RI::Tensor>>,3> &dMs); } #include "LRI_CV_Tools.hpp" diff --git a/source/module_ri/LRI_CV_Tools.hpp b/source/module_ri/LRI_CV_Tools.hpp index 8ad95c3715..6333c208b8 100644 --- a/source/module_ri/LRI_CV_Tools.hpp +++ b/source/module_ri/LRI_CV_Tools.hpp @@ -312,4 +312,45 @@ LRI_CV_Tools::get_dCVws( return dCVws; } + +// dMRs[ipos0][ipos1] = \nabla_{ipos0} M R_{ipos1} +template +std::array,RI::Tensor>>,3>,3> +LRI_CV_Tools::cal_dMRs( + const std::array,RI::Tensor>>,3> &dMs) +{ + auto get_R_delta = [&](const TA &iat0, const std::pair &A1) -> std::array + { + const TA iat1 = A1.first; + const TC &cell1 = A1.second; + const int it0 = GlobalC::ucell.iat2it[iat0]; + const int ia0 = GlobalC::ucell.iat2ia[iat0]; + const int it1 = GlobalC::ucell.iat2it[iat1]; + const int ia1 = GlobalC::ucell.iat2ia[iat1]; + const ModuleBase::Vector3 tau0 = GlobalC::ucell.atoms[it0].tau[ia0]; + const ModuleBase::Vector3 tau1 = GlobalC::ucell.atoms[it1].tau[ia1]; + const Abfs::Vector3_Order R_delta = -tau0+tau1+(RI_Util::array3_to_Vector3(cell1)*GlobalC::ucell.latvec); + return std::array{R_delta.x, R_delta.y, R_delta.z}; + }; + constexpr int Npos = 3; + std::array,RI::Tensor>>,Npos>,Npos> dMRs; + for(int ipos0=0; ipos0 A1 = dMs_B.first; + const RI::Tensor &dM = dMs_B.second; + const std::array R_delta = get_R_delta(iat0, A1); + dMRs[ipos0][ipos1][iat0][A1] = dM * R_delta[ipos1]; + } + } + } + } + return dMRs; +} #endif \ No newline at end of file From 1e716e1e82015daeec92ef7511b538a6d5ca0710 Mon Sep 17 00:00:00 2001 From: linpz Date: Mon, 29 Jul 2024 19:17:42 +0800 Subject: [PATCH 3/6] Feature: add input and info CV_grad_R_threshold for exx --- source/module_hamilt_general/module_xc/exx_info.h | 2 ++ source/module_io/input_conv.cpp | 2 ++ source/module_io/read_input_item_other.cpp | 12 ++++++++++++ source/module_parameter/input_parameter.h | 2 ++ source/module_ri/Exx_LRI.hpp | 4 ++-- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/module_hamilt_general/module_xc/exx_info.h b/source/module_hamilt_general/module_xc/exx_info.h index 80a609e929..b0f2dae935 100644 --- a/source/module_hamilt_general/module_xc/exx_info.h +++ b/source/module_hamilt_general/module_xc/exx_info.h @@ -47,6 +47,8 @@ struct Exx_Info double cauchy_threshold = 0; double C_grad_threshold = 0; double V_grad_threshold = 0; + double C_grad_R_threshold = 0; + double V_grad_R_threshold = 0; double cauchy_force_threshold = 0; double cauchy_stress_threshold = 0; double ccp_rmesh_times = 10; diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index f6d7e8b4cf..bd706695e2 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -684,6 +684,8 @@ void Input_Conv::Convert() GlobalC::exx_info.info_ri.cauchy_threshold = PARAM.inp.exx_cauchy_threshold; GlobalC::exx_info.info_ri.C_grad_threshold = PARAM.inp.exx_c_grad_threshold; GlobalC::exx_info.info_ri.V_grad_threshold = PARAM.inp.exx_v_grad_threshold; + GlobalC::exx_info.info_ri.C_grad_R_threshold = PARAM.inp.exx_c_grad_r_threshold; + GlobalC::exx_info.info_ri.V_grad_R_threshold = PARAM.inp.exx_v_grad_r_threshold; GlobalC::exx_info.info_ri.cauchy_force_threshold = PARAM.inp.exx_cauchy_force_threshold; GlobalC::exx_info.info_ri.cauchy_stress_threshold = PARAM.inp.exx_cauchy_stress_threshold; GlobalC::exx_info.info_ri.ccp_rmesh_times = std::stod(PARAM.inp.exx_ccp_rmesh_times); diff --git a/source/module_io/read_input_item_other.cpp b/source/module_io/read_input_item_other.cpp index 991cfb5f72..9c629317d0 100644 --- a/source/module_io/read_input_item_other.cpp +++ b/source/module_io/read_input_item_other.cpp @@ -552,6 +552,18 @@ void ReadInput::item_others() read_sync_double(exx_v_grad_threshold); this->add_item(item); } + { + Input_Item item("exx_c_grad_r_threshold"); + item.annotation = "threshold to screen nabla C matrix in exx"; + read_sync_double(exx_c_grad_r_threshold); + this->add_item(item); + } + { + Input_Item item("exx_v_grad_r_threshold"); + item.annotation = "threshold to screen nabla V matrix in exx"; + read_sync_double(exx_v_grad_r_threshold); + this->add_item(item); + } { Input_Item item("exx_cauchy_force_threshold"); item.annotation = "threshold to screen exx force using Cauchy-Schwartz inequality"; diff --git a/source/module_parameter/input_parameter.h b/source/module_parameter/input_parameter.h index d755145dbc..bcd630dc67 100644 --- a/source/module_parameter/input_parameter.h +++ b/source/module_parameter/input_parameter.h @@ -369,6 +369,8 @@ struct Input_para double exx_cauchy_threshold = 1e-07; ///< threshold to screen exx using Cauchy-Schwartz inequality double exx_c_grad_threshold = 0.0001; ///< threshold to screen nabla C matrix in exx double exx_v_grad_threshold = 0.1; ///< threshold to screen nabla V matrix in exx + double exx_c_grad_r_threshold = 0.0001; ///< threshold to screen nabla C matrix in exx + double exx_v_grad_r_threshold = 0.1; ///< threshold to screen nabla V matrix in exx double exx_cauchy_force_threshold = 1e-07; ///< threshold to screen exx force using Cauchy-Schwartz ///< inequality double exx_cauchy_stress_threshold = 1e-07; ///< threshold to screen exx stress using Cauchy-Schwartz diff --git a/source/module_ri/Exx_LRI.hpp b/source/module_ri/Exx_LRI.hpp index cd3eb06128..0ed3681138 100644 --- a/source/module_ri/Exx_LRI.hpp +++ b/source/module_ri/Exx_LRI.hpp @@ -143,7 +143,7 @@ void Exx_LRI::cal_exx_ions() if(GlobalV::CAL_STRESS) { std::array>>,3>,3> dVRs = LRI_CV_Tools::cal_dMRs(dVs); - this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_threshold); + this->exx_lri.set_dVRs(std::move(dVRs), this->info.V_grad_R_threshold); } } @@ -168,7 +168,7 @@ void Exx_LRI::cal_exx_ions() if(GlobalV::CAL_STRESS) { std::array>>,3>,3> dCRs = LRI_CV_Tools::cal_dMRs(dCs); - this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_threshold); + this->exx_lri.set_dCRs(std::move(dCRs), this->info.C_grad_R_threshold); } } ModuleBase::timer::tick("Exx_LRI", "cal_exx_ions"); From a9c8ce41d33dd9075d504ee2b8e46dc24cd78f87 Mon Sep 17 00:00:00 2001 From: linpz Date: Mon, 29 Jul 2024 20:12:08 +0800 Subject: [PATCH 4/6] Delete exx_lri.set_csm_threshold() --- source/module_ri/Exx_LRI.hpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/module_ri/Exx_LRI.hpp b/source/module_ri/Exx_LRI.hpp index 0ed3681138..a8b63f19d0 100644 --- a/source/module_ri/Exx_LRI.hpp +++ b/source/module_ri/Exx_LRI.hpp @@ -182,8 +182,6 @@ void Exx_LRI::cal_exx_elec(const std::vector, std::set>> judge = RI_2D_Comm::get_2D_judge(pv); - this->exx_lri.set_csm_threshold(this->info.cauchy_threshold); - this->Hexxs.resize(GlobalV::NSPIN); this->Eexx = 0; for(int is=0; is::cal_exx_force() { ModuleBase::TITLE("Exx_LRI","cal_exx_force"); ModuleBase::timer::tick("Exx_LRI", "cal_exx_force"); - - this->exx_lri.set_csm_threshold(this->info.cauchy_force_threshold); this->force_exx.create(GlobalC::ucell.nat, Ndim); for(int is=0; is::cal_exx_stress() { ModuleBase::TITLE("Exx_LRI","cal_exx_stress"); ModuleBase::timer::tick("Exx_LRI", "cal_exx_stress"); - - this->exx_lri.set_csm_threshold(this->info.cauchy_stress_threshold); this->stress_exx.create(Ndim, Ndim); for(int is=0; is Date: Tue, 30 Jul 2024 02:34:02 +0800 Subject: [PATCH 5/6] Update LibRI in toolchain to v0.2.0 --- toolchain/scripts/stage4/install_libri.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/scripts/stage4/install_libri.sh b/toolchain/scripts/stage4/install_libri.sh index d33fe3068f..78af9ab2ab 100755 --- a/toolchain/scripts/stage4/install_libri.sh +++ b/toolchain/scripts/stage4/install_libri.sh @@ -11,8 +11,8 @@ [ "${BASH_SOURCE[0]}" ] && SCRIPT_NAME="${BASH_SOURCE[0]}" || SCRIPT_NAME=$0 SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_NAME")/.." && pwd -P)" -libri_ver="0.1.1" -libri_sha256="51deb08aa373e54d2c123b57bfd4b3507accac0d496a94b766eaeadccd9e4bd0" +libri_ver="0.2.0" +libri_sha256="ad79dfbc3ed8ff066c85549a2737d29205dbf755b38ea216ab2ab42754f80389" source "${SCRIPT_DIR}"/common_vars.sh source "${SCRIPT_DIR}"/tool_kit.sh source "${SCRIPT_DIR}"/signal_trap.sh From ab01840d99844813260d28f98f9d6ba2041c468b Mon Sep 17 00:00:00 2001 From: linpz Date: Tue, 30 Jul 2024 02:56:11 +0800 Subject: [PATCH 6/6] Update submodule deps/LibRI to v0.2.0 --- deps/LibRI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/LibRI b/deps/LibRI index 553c91c0be..3883b699f5 160000 --- a/deps/LibRI +++ b/deps/LibRI @@ -1 +1 @@ -Subproject commit 553c91c0be1d60a86e7666f0502ef866c366c600 +Subproject commit 3883b699f50eccd84993e849843452e22d035015