From 58b1b062aa71309b6ac9cb0bd7976cbcad0c99f2 Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 10 Jul 2024 11:15:15 +0800 Subject: [PATCH] move set_xc_first_loop to XC_Functional --- source/module_esolver/esolver_ks.cpp | 17 ----------------- source/module_esolver/esolver_ks.h | 2 -- source/module_esolver/esolver_ks_lcao.cpp | 2 +- source/module_esolver/esolver_ks_lcaopw.cpp | 2 +- .../module_xc/xc_functional.cpp | 15 +++++++++++++++ .../module_xc/xc_functional.h | 8 ++++++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 132c11bf27..1392910025 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -849,23 +849,6 @@ ModuleIO::Output_Potential ESolver_KS::create_Output_Potential(int it //! the 16th-20th functions of ESolver_KS //! mohan add 2024-05-12 //------------------------------------------------------------------------------ -template -void ESolver_KS::set_xc_first_loop(const UnitCell& ucell) -{ - /** In the special "two-level" calculation case, - the first scf iteration only calculate the functional without exact - exchange. but in "nscf" calculation, there is no need of "two-level" - method. */ - if (ucell.atoms[0].ncpp.xc_func == "HF" - || ucell.atoms[0].ncpp.xc_func == "PBE0" - || ucell.atoms[0].ncpp.xc_func == "HSE") { - XC_Functional::set_xc_type("pbe"); - } - else if (ucell.atoms[0].ncpp.xc_func == "SCAN0") { - XC_Functional::set_xc_type("scan"); - } -} - //! This is for mixed-precision pw/LCAO basis sets. template class ESolver_KS, base_device::DEVICE_CPU>; template class ESolver_KS, base_device::DEVICE_CPU>; diff --git a/source/module_esolver/esolver_ks.h b/source/module_esolver/esolver_ks.h index 3d3bae0ef4..8ffb1158f9 100644 --- a/source/module_esolver/esolver_ks.h +++ b/source/module_esolver/esolver_ks.h @@ -138,8 +138,6 @@ class ESolver_KS : public ESolver_FP std::string basisname; //PW or LCAO void print_wfcfft(Input& inp, std::ofstream& ofs); - - virtual void set_xc_first_loop(const UnitCell& ucell); }; } // end of namespace #endif diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index db9fe79ff0..4ee07239f7 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -189,7 +189,7 @@ void ESolver_KS_LCAO::before_all_runners(Input& inp, UnitCell& ucell) || GlobalV::CALCULATION == "cell-relax" || GlobalV::CALCULATION == "md") { if (GlobalC::exx_info.info_global.cal_exx) { - this->set_xc_first_loop(ucell); + XC_Functional::set_xc_first_loop(ucell); if (GlobalC::exx_info.info_ri.real_number) { this->exx_lri_double->init(MPI_COMM_WORLD, this->kv); } diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index 1eaf6accf1..906a5c7807 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -91,7 +91,7 @@ namespace ModuleESolver || GlobalV::CALCULATION == "md") if (GlobalC::exx_info.info_global.cal_exx) { - this->set_xc_first_loop(cell); + XC_Functional::set_xc_first_loop(cell); this->exx_lip = std::unique_ptr>(new Exx_Lip(GlobalC::exx_info.info_lip, cell.symm, &this->kv, this->p_wf_init, this->kspw_psi, this->pw_wfc, this->pw_rho, this->sf, &cell, this->pelec)); // this->exx_lip.init(GlobalC::exx_info.info_lip, cell.symm, &this->kv, this->p_wf_init, this->kspw_psi, this->pw_wfc, this->pw_rho, this->sf, &cell, this->pelec); diff --git a/source/module_hamilt_general/module_xc/xc_functional.cpp b/source/module_hamilt_general/module_xc/xc_functional.cpp index d1a365819f..e427743eed 100644 --- a/source/module_hamilt_general/module_xc/xc_functional.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional.cpp @@ -23,6 +23,21 @@ int XC_Functional::get_func_type() { return func_type; } +void XC_Functional::set_xc_first_loop(const UnitCell& ucell) +{ + /** In the special "two-level" calculation case, +the first scf iteration only calculate the functional without exact +exchange. but in "nscf" calculation, there is no need of "two-level" +method. */ + if (ucell.atoms[0].ncpp.xc_func == "HF" + || ucell.atoms[0].ncpp.xc_func == "PBE0" + || ucell.atoms[0].ncpp.xc_func == "HSE") { + XC_Functional::set_xc_type("pbe"); + } + else if (ucell.atoms[0].ncpp.xc_func == "SCAN0") { + XC_Functional::set_xc_type("scan"); + } +} // The setting values of functional id according to the index in LIBXC // for detail, refer to https://www.tddft.org/programs/libxc/functionals/ diff --git a/source/module_hamilt_general/module_xc/xc_functional.h b/source/module_hamilt_general/module_xc/xc_functional.h index 71ce3785cb..7d254935cc 100644 --- a/source/module_hamilt_general/module_xc/xc_functional.h +++ b/source/module_hamilt_general/module_xc/xc_functional.h @@ -80,8 +80,12 @@ class XC_Functional // 4. init_func : which converts func_id into corresponding xc_func_type vector static int get_func_type(); - static void set_xc_type(const std::string xc_func_in); - static void get_hybrid_alpha(const double alpha_in); + static void set_xc_type(const std::string xc_func_in); + + // For hybrid functional + static void get_hybrid_alpha(const double alpha_in); + /// Usually in exx caculation, the first SCF loop should be converged with PBE + static void set_xc_first_loop(const UnitCell& ucell); #ifdef USE_LIBXC static void set_xc_type_libxc(const std::string xc_func_in); static std::vector init_func(const int xc_polarized);