diff --git a/source/source_esolver/esolver_ks.cpp b/source/source_esolver/esolver_ks.cpp index 18b08d0c64..f19bbc8bdf 100644 --- a/source/source_esolver/esolver_ks.cpp +++ b/source/source_esolver/esolver_ks.cpp @@ -70,6 +70,7 @@ void ESolver_KS::before_all_runners(UnitCell& ucell, const Input_para //! 4) setup Exc for the first element '0' (all elements have same exc) XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func); + GlobalV::ofs_running<set_mixing(inp.mixing_mode, inp.mixing_beta, inp.mixing_ndim, diff --git a/source/source_hamilt/module_xc/test/CMakeLists.txt b/source/source_hamilt/module_xc/test/CMakeLists.txt index f1ecb49d70..b02ad72aca 100644 --- a/source/source_hamilt/module_xc/test/CMakeLists.txt +++ b/source/source_hamilt/module_xc/test/CMakeLists.txt @@ -2,13 +2,13 @@ AddTest( TARGET XCTest_PBE LIBS parameter MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. SOURCES test_xc.cpp ../xc_functional.cpp ../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp ../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp ../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp - ../xc_functional_libxc_wrapper_gcxc.cpp ../xc_functional_libxc.cpp + ../xc_functional_libxc_wrapper_gcxc.cpp ../xc_functional_libxc.cpp ../../../source_base/tool_title.cpp ) AddTest( TARGET XCTest_HSE LIBS parameter MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. - SOURCES test_xc1.cpp ../xc_functional.cpp ../xc_functional_libxc.cpp + SOURCES test_xc1.cpp ../xc_functional.cpp ../xc_functional_libxc.cpp ../../../source_base/tool_title.cpp ) @@ -16,7 +16,7 @@ AddTest( TARGET XCTest_PZ_SPN LIBS parameter MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. SOURCES test_xc2.cpp ../xc_functional.cpp ../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp ../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp ../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp - ../xc_functional_libxc_wrapper_gcxc.cpp ../xc_functional_libxc_wrapper_xc.cpp ../xc_functional_libxc.cpp + ../xc_functional_libxc_wrapper_gcxc.cpp ../xc_functional_libxc_wrapper_xc.cpp ../xc_functional_libxc.cpp ../../../source_base/tool_title.cpp ) if (USE_CUDA) @@ -41,6 +41,7 @@ AddTest( ../../../source_base/libm/branred.cpp ../../../source_base/libm/sincos.cpp ../../../source_base/module_external/blas_connector_base.cpp ../../../source_base/module_external/blas_connector_vector.cpp ../../../source_base/module_external/blas_connector_matrix.cpp + ../../../source_base/tool_title.cpp ../../../source_base/module_fft/fft_bundle.cpp ../../../source_base/module_fft/fft_cpu.cpp ${FFT_SRC} @@ -57,6 +58,7 @@ AddTest( ../xc_functional_libxc_wrapper_tauxc.cpp ../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp ../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp + ../../../source_base/tool_title.cpp ) AddTest( @@ -77,6 +79,7 @@ AddTest( ../../../source_base/matrix.cpp ../../../source_base/memory.cpp ../../../source_base/timer.cpp + ../../../source_base/tool_title.cpp ../../../source_base/libm/branred.cpp ../../../source_base/libm/sincos.cpp ../../../source_base/module_fft/fft_bundle.cpp diff --git a/source/source_hamilt/module_xc/xc_functional.cpp b/source/source_hamilt/module_xc/xc_functional.cpp index 2462f8ac42..5af5eb113a 100644 --- a/source/source_hamilt/module_xc/xc_functional.cpp +++ b/source/source_hamilt/module_xc/xc_functional.cpp @@ -2,6 +2,7 @@ #include "source_pw/module_pwdft/global.h" #include "source_io/module_parameter/parameter.h" #include "source_base/global_function.h" +#include "source_base/tool_title.h" #ifdef USE_LIBXC #include "xc_functional_libxc.h" @@ -25,28 +26,41 @@ void XC_Functional::set_hybrid_alpha(const double alpha_in) void XC_Functional::set_xc_first_loop(const UnitCell& ucell) { + ModuleBase::TITLE("XC_Functional", "set_xc_first_loop"); /** 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 == "HSE" - || ucell.atoms[0].ncpp.xc_func == "PBE0"|| ucell.atoms[0].ncpp.xc_func == "LC_PBE" - || ucell.atoms[0].ncpp.xc_func == "LC_WPBE" || ucell.atoms[0].ncpp.xc_func == "LRC_WPBEH" - || ucell.atoms[0].ncpp.xc_func == "CAM_PBEH") { + 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"); + else if ( ucell.atoms[0].ncpp.xc_func == "LC_PBE" || ucell.atoms[0].ncpp.xc_func == "LC_WPBE" + || ucell.atoms[0].ncpp.xc_func == "LRC_WPBEH" || ucell.atoms[0].ncpp.xc_func == "CAM_PBEH" ) + { + XC_Functional::set_xc_type("pbe"); + } + // added by jghan, 2024-07-07 + else if ( ucell.atoms[0].ncpp.xc_func == "MULLER" || ucell.atoms[0].ncpp.xc_func == "POWER" + || ucell.atoms[0].ncpp.xc_func == "WP22" || ucell.atoms[0].ncpp.xc_func == "CWP22" ) + { + XC_Functional::set_xc_type("pbe"); } - else if (ucell.atoms[0].ncpp.xc_func == "B3LYP") { + else if (ucell.atoms[0].ncpp.xc_func == "B3LYP") + { XC_Functional::set_xc_type("blyp"); } + 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/ void XC_Functional::set_xc_type(const std::string xc_func_in) { + ModuleBase::TITLE("XC_Functional", "set_xc_type"); //Note : due to the separation of gcx_spin and gcc_spin, //when you are adding new GGA functionals, //please put exchange first, followed by correlation, @@ -316,3 +330,42 @@ void XC_Functional::set_xc_type(const std::string xc_func_in) #endif } + +std::string XC_Functional::output_info() +{ + #ifdef USE_LIBXC + if(use_libxc) + { + std::stringstream ss; + ss<<" Libxc v"< funcs = XC_Functional_Libxc::init_func(func_id, XC_UNPOLARIZED); + for(const auto &func : funcs) + { + const xc_func_info_type *info = xc_func_get_info(&func); + ss<<" XC: "< func_id; // libxc id of functional diff --git a/source/source_hamilt/module_xc/xc_functional_libxc.cpp b/source/source_hamilt/module_xc/xc_functional_libxc.cpp index ca1f0099a7..696f3d1631 100644 --- a/source/source_hamilt/module_xc/xc_functional_libxc.cpp +++ b/source/source_hamilt/module_xc/xc_functional_libxc.cpp @@ -40,7 +40,7 @@ bool not_supported_xc_with_nonlocal_vdw(const std::string& xc_func_in) if(xc_func.find("VV10") != std::string::npos) { return true; } /* known excluded: GGA_XC_VV10, HYB_GGA_XC_LC_VV10, MGGA_C_REVSCAN_VV10, MGGA_C_SCAN_VV10, - MGGA_C_SCANL_VV10, MGGA_XC_VCML_RVV10 */ + MGGA_C_SCANL_VV10, MGGA_XC_VCML_RVV10 */ const std::vector not_supported = {"C09X", "VCML", "HYB_MGGA_XC_WB97M_V", "MGGA_XC_B97M_V"}; for(const std::string& str : not_supported) @@ -54,8 +54,8 @@ bool not_supported_xc_with_nonlocal_vdw(const std::string& xc_func_in) { std::cout << " WARNING: range-seperated XC omega-B97 family with nonlocal correction term is used.\n" << " if you are not planning to use these functionals like wB97X-D3BJ that:\n" - << " XC_GGA_XC_WB97X_V with specified D3BJ DFT-D3 parameters, this is not what\n" - << " you want." << std::endl; + << " XC_GGA_XC_WB97X_V with specified D3BJ DFT-D3 parameters, this is not what\n" + << " you want." << std::endl; } return false; } @@ -92,7 +92,8 @@ int xc_func_type_classifier(const std::string& xc_func, std::pair> XC_Functional_Libxc::set_xc_type_libxc(const std::string& xc_func_in) { - // check if the functional involves Laplacian of rho + ModuleBase::TITLE("XC_Functional", "set_xc_type_libxc"); + // check if the functional involves Laplacian of rho if (not_supported_xc_with_laplacian(xc_func_in)) { ModuleBase::WARNING_QUIT("XC_Functional::set_xc_type_libxc", @@ -120,14 +121,14 @@ XC_Functional_Libxc::set_xc_type_libxc(const std::string& xc_func_in) } // check if there is None (no, we dont check it) - int func_type = xcfunc_type_.front(); // all functionals are of the same type + int func_type = xcfunc_type_.front(); // all functionals are of the same type // if (func_type == 0) // { // ModuleBase::WARNING_QUIT("XC_Functional::set_xc_type_libxc", // "Unrecognized functional type in '" + xc_func_in + "'."); // } - // determine the functional id + // determine the functional id std::vector func_id(xcfunc_words_.size(), -1); std::transform(xcfunc_words_.begin(), xcfunc_words_.end(), func_id.begin(), [](const std::string& func) { return xc_functional_get_number(func.c_str()); }); @@ -144,7 +145,7 @@ XC_Functional_Libxc::set_xc_type_libxc(const std::string& xc_func_in) } // return - return std::make_pair(func_type, func_id); + return std::make_pair(func_type, func_id); } const std::vector in_built_xc_func_ext_params(const int id) @@ -176,45 +177,45 @@ const std::vector in_built_xc_func_ext_params(const int id) return {0.04918, 0.132, 0.2533, 0.349, 0.35/2.29, 2.0/2.29, GlobalC::exx_info.info_global.hse_omega}; // Long-range corrected functionals: - case XC_HYB_GGA_XC_LC_PBEOP: // LC version of PBE + case XC_HYB_GGA_XC_LC_PBEOP: // LC version of PBE { - // This is a range-separated hybrid functional with range-separation constant 0.330, - // and 0.0% short-range and 100.0% long-range exact exchange, - // using the error function kernel. + // This is a range-separated hybrid functional with range-separation constant 0.330, + // and 0.0% short-range and 100.0% long-range exact exchange, + // using the error function kernel. return { GlobalC::exx_info.info_global.hse_omega }; //Range separation constant: 0.33 } - case XC_HYB_GGA_XC_LC_WPBE: // Long-range corrected PBE (LC-wPBE) by Vydrov and Scuseria + case XC_HYB_GGA_XC_LC_WPBE: // Long-range corrected PBE (LC-wPBE) by Vydrov and Scuseria { - // This is a range-separated hybrid functional with range-separation constant 0.400, - // and 0.0% short-range and 100.0% long-range exact exchange, - // using the error function kernel. + // This is a range-separated hybrid functional with range-separation constant 0.400, + // and 0.0% short-range and 100.0% long-range exact exchange, + // using the error function kernel. return { std::stod(PARAM.inp.exx_fock_alpha[0]), //Fraction of Hartree-Fock exchange: 1.0 std::stod(PARAM.inp.exx_erfc_alpha[0]), //Fraction of short-range exact exchange: -1.0 GlobalC::exx_info.info_global.hse_omega }; //Range separation constant: 0.4 } - case XC_HYB_GGA_XC_LRC_WPBE: // Long-range corrected PBE (LRC-wPBE) by by Rohrdanz, Martins and Herbert + case XC_HYB_GGA_XC_LRC_WPBE: // Long-range corrected PBE (LRC-wPBE) by by Rohrdanz, Martins and Herbert { - // This is a range-separated hybrid functional with range-separation constant 0.300, - // and 0.0% short-range and 100.0% long-range exact exchange, - // using the error function kernel. + // This is a range-separated hybrid functional with range-separation constant 0.300, + // and 0.0% short-range and 100.0% long-range exact exchange, + // using the error function kernel. return { std::stod(PARAM.inp.exx_fock_alpha[0]), //Fraction of Hartree-Fock exchange: 1.0 std::stod(PARAM.inp.exx_erfc_alpha[0]), //Fraction of short-range exact exchange: -1.0 GlobalC::exx_info.info_global.hse_omega }; //Range separation constant: 0.3 } - case XC_HYB_GGA_XC_LRC_WPBEH: // Long-range corrected short-range hybrid PBE (LRC-wPBEh) by Rohrdanz, Martins and Herbert + case XC_HYB_GGA_XC_LRC_WPBEH: // Long-range corrected short-range hybrid PBE (LRC-wPBEh) by Rohrdanz, Martins and Herbert { - // This is a range-separated hybrid functional with range-separation constant 0.200, - // and 20.0% short-range and 100.0% long-range exact exchange, - // using the error function kernel. + // This is a range-separated hybrid functional with range-separation constant 0.200, + // and 20.0% short-range and 100.0% long-range exact exchange, + // using the error function kernel. return { std::stod(PARAM.inp.exx_fock_alpha[0]), //Fraction of Hartree-Fock exchange: 1.0 std::stod(PARAM.inp.exx_erfc_alpha[0]), //Fraction of short-range exact exchange: -0.8 GlobalC::exx_info.info_global.hse_omega }; //Range separation constant: 0.2 } - case XC_HYB_GGA_XC_CAM_PBEH: // CAM hybrid screened exchange PBE version + case XC_HYB_GGA_XC_CAM_PBEH: // CAM hybrid screened exchange PBE version { - // This is a range-separated hybrid functional with range-separation constant 0.700, - // and 100.0% short-range and 20.0% long-range exact exchange, - // using the error function kernel. + // This is a range-separated hybrid functional with range-separation constant 0.700, + // and 100.0% short-range and 20.0% long-range exact exchange, + // using the error function kernel. return { std::stod(PARAM.inp.exx_fock_alpha[0]), //Fraction of Hartree-Fock exchange: 0.2 std::stod(PARAM.inp.exx_erfc_alpha[0]), //Fraction of short-range exact exchange: 0.8 GlobalC::exx_info.info_global.hse_omega }; //Range separation constant: 0.7 @@ -287,10 +288,10 @@ XC_Functional_Libxc::init_func(const std::vector &func_id, void XC_Functional_Libxc::finish_func(std::vector &funcs) { - for(xc_func_type func : funcs) + for(xc_func_type func : funcs) { - xc_func_end(&func); - } + xc_func_end(&func); + } } #endif \ No newline at end of file diff --git a/source/source_hamilt/module_xc/xc_functional_libxc.h b/source/source_hamilt/module_xc/xc_functional_libxc.h index 948db289db..defd851faa 100644 --- a/source/source_hamilt/module_xc/xc_functional_libxc.h +++ b/source/source_hamilt/module_xc/xc_functional_libxc.h @@ -53,13 +53,13 @@ namespace XC_Functional_Libxc // xc_functional_libxc_vxc.cpp //------------------- - extern std::tuple v_xc_libxc( - const std::vector &func_id, - const int &nrxx, // number of real-space grid - const double &omega, // volume of cell - const double tpiba, - const Charge* const chr, // charge density - const std::map* scaling_factor = nullptr); // added by jghan, 2024-10-10 + extern std::tuple v_xc_libxc( + const std::vector &func_id, + const int &nrxx, // number of real-space grid + const double &omega, // volume of cell + const double tpiba, + const Charge* const chr, // charge density + const std::map* scaling_factor = nullptr); // added by jghan, 2024-10-10 // for mGGA functional extern std::tuple v_xc_meta( diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.hpp b/source/source_lcao/module_ri/Exx_LRI_interface.hpp index 802f02a4f8..6f133c05df 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.hpp +++ b/source/source_lcao/module_ri/Exx_LRI_interface.hpp @@ -135,20 +135,7 @@ void Exx_LRI_Interface::exx_beforescf(const int istep, } else { - 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"); - } - // added by jghan, 2024-07-07 - else if ( ucell.atoms[0].ncpp.xc_func == "MULLER" || ucell.atoms[0].ncpp.xc_func == "POWER" - || ucell.atoms[0].ncpp.xc_func == "WP22" || ucell.atoms[0].ncpp.xc_func == "CWP22" ) - { - XC_Functional::set_xc_type("pbe"); - } + XC_Functional::set_xc_first_loop(ucell); } this->cal_exx_ions(ucell,PARAM.inp.out_ri_cv); @@ -313,7 +300,7 @@ void Exx_LRI_Interface::exx_iter_finish(const K_Vectors& kv, { chgmix.close_kerker_gg0(); } -// mohan update 2025-11-04 + // mohan update 2025-11-04 this->dm_last_step = dm; conv_esolver = this->exx_after_converge( ucell,