diff --git a/source/module_hsolver/CMakeLists.txt b/source/module_hsolver/CMakeLists.txt index 8e1ff69905..79e065e971 100644 --- a/source/module_hsolver/CMakeLists.txt +++ b/source/module_hsolver/CMakeLists.txt @@ -4,6 +4,7 @@ list(APPEND objects diago_david.cpp diago_dav_subspace.cpp diago_bpcg.cpp + pawcode_in_hsolverpw.cpp hsolver_pw.cpp hsolver_lcaopw.cpp hsolver_pw_sdft.cpp diff --git a/source/module_hsolver/hsolver_pw.cpp b/source/module_hsolver/hsolver_pw.cpp index 05a4a893eb..260bfb943e 100644 --- a/source/module_hsolver/hsolver_pw.cpp +++ b/source/module_hsolver/hsolver_pw.cpp @@ -21,76 +21,16 @@ #ifdef USE_PAW #include "module_cell/module_paw/paw_cell.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" -// #include "module_base/parallel_global.h" // for MPI -// #include "module_hamilt_pw/hamilt_pwdft/hamilt_pw.h" #endif + namespace hsolver { #ifdef USE_PAW -template -void HSolverPW::paw_func_in_kloop(const int ik) -{ - if (this->use_paw) - { - const int npw = this->wfc_basis->npwk[ik]; - ModuleBase::Vector3* _gk = new ModuleBase::Vector3[npw]; - for (int ig = 0; ig < npw; ig++) - { - _gk[ig] = this->wfc_basis->getgpluskcar(ik, ig); - } - - std::vector kpt(3, 0); - kpt[0] = this->wfc_basis->kvec_c[ik].x; - kpt[1] = this->wfc_basis->kvec_c[ik].y; - kpt[2] = this->wfc_basis->kvec_c[ik].z; - - double** kpg; - double** gcar; - kpg = new double*[npw]; - gcar = new double*[npw]; - for (int ipw = 0; ipw < npw; ipw++) - { - kpg[ipw] = new double[3]; - kpg[ipw][0] = _gk[ipw].x; - kpg[ipw][1] = _gk[ipw].y; - kpg[ipw][2] = _gk[ipw].z; - - gcar[ipw] = new double[3]; - gcar[ipw][0] = this->wfc_basis->getgcar(ik, ipw).x; - gcar[ipw][1] = this->wfc_basis->getgcar(ik, ipw).y; - gcar[ipw][2] = this->wfc_basis->getgcar(ik, ipw).z; - } - - GlobalC::paw_cell.set_paw_k(npw, - wfc_basis->npwk_max, - kpt.data(), - this->wfc_basis->get_ig2ix(ik).data(), - this->wfc_basis->get_ig2iy(ik).data(), - this->wfc_basis->get_ig2iz(ik).data(), - (const double**)kpg, - GlobalC::ucell.tpiba, - (const double**)gcar); - - std::vector().swap(kpt); - for (int ipw = 0; ipw < npw; ipw++) - { - delete[] kpg[ipw]; - delete[] gcar[ipw]; - } - delete[] kpg; - delete[] gcar; - - GlobalC::paw_cell.get_vkb(); - - GlobalC::paw_cell.set_currentk(ik); - } -} - template void HSolverPW::call_paw_cell_set_currentk(const int ik) { - if (this->use_paw) + if (PARAM.inp.use_paw) { GlobalC::paw_cell.set_currentk(ik); } @@ -99,7 +39,7 @@ void HSolverPW::call_paw_cell_set_currentk(const int ik) template void HSolverPW::paw_func_after_kloop(psi::Psi& psi, elecstate::ElecState* pes) { - if (this->use_paw) + if (PARAM.inp.use_paw) { if (typeid(Real) != typeid(double)) { @@ -204,9 +144,9 @@ void HSolverPW::paw_func_after_kloop(psi::Psi& psi, elecst GlobalC::paw_cell.get_nhat(pes->charge->nhat, nhatgr); } } - #endif + template void HSolverPW::cal_ethr_band(const double& wk, const double* wg, @@ -283,7 +223,7 @@ void HSolverPW::solve(hamilt::Hamilt* pHamilt, pHamilt->updateHk(ik); #ifdef USE_PAW - this->paw_func_in_kloop(ik); + this->paw_func_in_kloop(ik, this->wfc_basis); #endif /// update psi pointer for each k point diff --git a/source/module_hsolver/hsolver_pw.h b/source/module_hsolver/hsolver_pw.h index dd71cdf367..81035a2957 100644 --- a/source/module_hsolver/hsolver_pw.h +++ b/source/module_hsolver/hsolver_pw.h @@ -88,7 +88,7 @@ class HSolverPW std::vector ethr_band; #ifdef USE_PAW - void paw_func_in_kloop(const int ik); + void paw_func_in_kloop(const int ik, ModulePW::PW_Basis_K* wfc_basis); void call_paw_cell_set_currentk(const int ik); diff --git a/source/module_hsolver/pawcode_in_hsolverpw.cpp b/source/module_hsolver/pawcode_in_hsolverpw.cpp new file mode 100644 index 0000000000..aefb272c07 --- /dev/null +++ b/source/module_hsolver/pawcode_in_hsolverpw.cpp @@ -0,0 +1,89 @@ +#include "hsolver_pw.h" + +// #include "pawcode_in_hsolverpw.h" + +#include "module_base/global_variable.h" +#include "module_base/timer.h" +#include "module_base/tool_quit.h" +#include "module_elecstate/elecstate_pw.h" +#include "module_hamilt_general/hamilt.h" +#include "module_hamilt_pw/hamilt_pwdft/wavefunc.h" +#include "module_parameter/parameter.h" +#include "module_psi/psi.h" + +#include +#include + +#ifdef USE_PAW +#include "module_cell/module_paw/paw_cell.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#endif + +#ifdef USE_PAW + +namespace hsolver +{ + +template +void HSolverPW::paw_func_in_kloop(const int ik, ModulePW::PW_Basis_K* wfc_basis) +{ + if (PARAM.inp.use_paw) + { + const int npw = this->wfc_basis->npwk[ik]; + ModuleBase::Vector3* _gk = new ModuleBase::Vector3[npw]; + for (int ig = 0; ig < npw; ig++) + { + _gk[ig] = this->wfc_basis->getgpluskcar(ik, ig); + } + + std::vector kpt(3, 0); + kpt[0] = this->wfc_basis->kvec_c[ik].x; + kpt[1] = this->wfc_basis->kvec_c[ik].y; + kpt[2] = this->wfc_basis->kvec_c[ik].z; + + double** kpg; + double** gcar; + kpg = new double*[npw]; + gcar = new double*[npw]; + for (int ipw = 0; ipw < npw; ipw++) + { + kpg[ipw] = new double[3]; + kpg[ipw][0] = _gk[ipw].x; + kpg[ipw][1] = _gk[ipw].y; + kpg[ipw][2] = _gk[ipw].z; + + gcar[ipw] = new double[3]; + gcar[ipw][0] = this->wfc_basis->getgcar(ik, ipw).x; + gcar[ipw][1] = this->wfc_basis->getgcar(ik, ipw).y; + gcar[ipw][2] = this->wfc_basis->getgcar(ik, ipw).z; + } + + GlobalC::paw_cell.set_paw_k(npw, + wfc_basis->npwk_max, + kpt.data(), + this->wfc_basis->get_ig2ix(ik).data(), + this->wfc_basis->get_ig2iy(ik).data(), + this->wfc_basis->get_ig2iz(ik).data(), + (const double**)kpg, + GlobalC::ucell.tpiba, + (const double**)gcar); + + std::vector().swap(kpt); + for (int ipw = 0; ipw < npw; ipw++) + { + delete[] kpg[ipw]; + delete[] gcar[ipw]; + } + delete[] kpg; + delete[] gcar; + + GlobalC::paw_cell.get_vkb(); + + GlobalC::paw_cell.set_currentk(ik); + } +} + + +} // namespace hsolver + +#endif \ No newline at end of file diff --git a/source/module_hsolver/pawcode_in_hsolverpw.h b/source/module_hsolver/pawcode_in_hsolverpw.h new file mode 100644 index 0000000000..b2b24905f7 --- /dev/null +++ b/source/module_hsolver/pawcode_in_hsolverpw.h @@ -0,0 +1,27 @@ +// #ifndef PAW_CODE_IN_HSOLVER +// #define PAW_CODE_IN_HSOLVER + +// #include "module_base/global_variable.h" +// #include "module_base/timer.h" +// #include "module_base/tool_quit.h" +// #include "module_elecstate/elecstate_pw.h" +// #include "module_hamilt_general/hamilt.h" +// #include "module_hamilt_pw/hamilt_pwdft/wavefunc.h" +// #include "module_parameter/parameter.h" +// #include "module_psi/psi.h" +// #include "module_base/macros.h" +// #include "module_basis/module_pw/pw_basis_k.h" +// #include "module_hamilt_pw/hamilt_pwdft/wavefunc.h" + +// #ifdef USE_PAW + +// namespace hsolver +// { + +// void paw_func_in_kloop(const int ik, ModulePW::PW_Basis_K* wfc_basis); + +// } + +// #endif + +// #endif \ No newline at end of file