From b22bdca403eb59fb9250883e51f68efcf84765aa Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Mon, 1 Jun 2026 12:57:54 +0800 Subject: [PATCH 1/2] Remove obsolete cross-device copy constructor in HamiltPW --- source/source_pw/module_pwdft/hamilt_pw.cpp | 137 +++++--------------- 1 file changed, 31 insertions(+), 106 deletions(-) diff --git a/source/source_pw/module_pwdft/hamilt_pw.cpp b/source/source_pw/module_pwdft/hamilt_pw.cpp index 3b0f2b8ca7b..47fae9bcb96 100644 --- a/source/source_pw/module_pwdft/hamilt_pw.cpp +++ b/source/source_pw/module_pwdft/hamilt_pw.cpp @@ -1,17 +1,16 @@ #include "hamilt_pw.h" -#include "source_io/module_parameter/parameter.h" -#include "source_base/global_function.h" -#include "source_base/global_variable.h" -#include "source_base/parallel_reduce.h" - -#include "op_pw_veff.h" #include "op_pw_ekin.h" +#include "op_pw_exx.h" #include "op_pw_meta.h" #include "op_pw_nl.h" #include "op_pw_proj.h" -#include "op_pw_exx.h" +#include "op_pw_veff.h" +#include "source_base/global_function.h" +#include "source_base/global_variable.h" +#include "source_base/parallel_reduce.h" #include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info +#include "source_io/module_parameter/parameter.h" namespace hamilt { @@ -22,7 +21,8 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, K_Vectors* pkv, pseudopot_cell_vnl* nlpp, Plus_U* p_dftu, // mohan add 2025-11-06 - const UnitCell* ucell): ucell(ucell) + const UnitCell* ucell) + : ucell(ucell) { this->classname = "HamiltPW"; this->ppcell = nlpp; @@ -39,7 +39,7 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, // Operator* ekinetic = new Ekinetic> Operator* ekinetic = new Ekinetic>(tpiba2, gk2, wfc_basis->nks, wfc_basis->npwk_max); - if(this->ops == nullptr) + if (this->ops == nullptr) { this->ops = ekinetic; } @@ -59,7 +59,7 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, { pot_register_in.push_back("hartree"); } - //no variable can choose xc, maybe it is necessary + // no variable can choose xc, maybe it is necessary pot_register_in.push_back("xc"); if (PARAM.inp.imp_sol) { @@ -78,20 +78,21 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, pot_register_in.push_back("ml_exx"); } // DFT-1/2 - if (PARAM.inp.dfthalf_type == 1) { + if (PARAM.inp.dfthalf_type == 1) + { pot_register_in.push_back("dfthalf"); } - //only Potential is not empty, Veff and Meta are available - if(pot_register_in.size()>0) + // only Potential is not empty, Veff and Meta are available + if (pot_register_in.size() > 0) { - //register Potential by gathered operator + // register Potential by gathered operator pot_in->pot_register(pot_register_in); Operator* veff = new Veff>(isk, pot_in->get_veff_smooth_data(), pot_in->get_veff_smooth().nr, pot_in->get_veff_smooth().nc, wfc_basis); - if(this->ops == nullptr) + if (this->ops == nullptr) { this->ops = veff; } @@ -110,9 +111,8 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, } if (PARAM.inp.vnl_in_h) { - Operator* nonlocal - = new Nonlocal>(isk, this->ppcell, ucell, wfc_basis); - if(this->ops == nullptr) + Operator* nonlocal = new Nonlocal>(isk, this->ppcell, ucell, wfc_basis); + if (this->ops == nullptr) { this->ops = nonlocal; } @@ -121,11 +121,13 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, this->ops->add(nonlocal); } } - if(PARAM.inp.sc_mag_switch || PARAM.inp.dft_plus_u) + if (PARAM.inp.sc_mag_switch || PARAM.inp.dft_plus_u) { - Operator* onsite_proj - = new OnsiteProj>(isk, ucell, p_dftu, - PARAM.inp.sc_mag_switch, (PARAM.inp.dft_plus_u>0)); + Operator* onsite_proj = new OnsiteProj>(isk, + ucell, + p_dftu, + PARAM.inp.sc_mag_switch, + (PARAM.inp.dft_plus_u > 0)); this->ops->add(onsite_proj); } if (GlobalC::exx_info.info_global.cal_exx) @@ -144,97 +146,21 @@ HamiltPW::HamiltPW(elecstate::Potential* pot_in, return; } -template +template HamiltPW::~HamiltPW() { - if(this->ops!= nullptr) + if (this->ops != nullptr) { delete this->ops; } } -template +template void HamiltPW::updateHk(const int ik) { - ModuleBase::TITLE("HamiltPW","updateHk"); + ModuleBase::TITLE("HamiltPW", "updateHk"); this->ops->init(ik); - ModuleBase::TITLE("HamiltPW","updateHk"); -} - -template -template -HamiltPW::HamiltPW(const HamiltPW *hamilt) -{ - this->classname = hamilt->classname; - this->ppcell = hamilt->ppcell; - this->qq_nt = hamilt->qq_nt; - this->qq_so = hamilt->qq_so; - this->vkb = hamilt->vkb; - OperatorPW, Device_in> * node = - reinterpret_cast, Device_in> *>(hamilt->ops); - - while(node != nullptr) { - if (node->classname == "Ekinetic") { - Operator* ekinetic = - new Ekinetic>( - reinterpret_cast>*>(node)); - if(this->ops == nullptr) { - this->ops = ekinetic; - } - else { - this->ops->add(ekinetic); - } - // this->ops = reinterpret_cast*>(node); - } - else if (node->classname == "Nonlocal") { - Operator* nonlocal = - new Nonlocal>( - reinterpret_cast>*>(node)); - if(this->ops == nullptr) { - this->ops = nonlocal; - } - else { - this->ops->add(nonlocal); - } - } - else if (node->classname == "Veff") { - Operator* veff = - new Veff>( - reinterpret_cast>*>(node)); - if(this->ops == nullptr) { - this->ops = veff; - } - else { - this->ops->add(veff); - } - } - else if (node->classname == "Meta") { - Operator* meta = - new Meta>( - reinterpret_cast>*>(node)); - if(this->ops == nullptr) { - this->ops = meta; - } - else { - this->ops->add(meta); - } - } - else if (node->classname == "OnsiteProj") { - Operator* onsite_proj = - new OnsiteProj>( - reinterpret_cast>*>(node)); - if(this->ops == nullptr) { - this->ops = onsite_proj; - } - else { - this->ops->add(onsite_proj); - } - } - else { - ModuleBase::WARNING_QUIT("HamiltPW", "Unrecognized Operator type!"); - } - node = reinterpret_cast, Device_in> *>(node->next_op); - } + ModuleBase::TITLE("HamiltPW", "updateHk"); } // This routine applies the S matrix to m wavefunctions psi and puts @@ -390,8 +316,8 @@ void HamiltPW::sPsi(const T* psi_in, // psi } } -template -void HamiltPW::set_exx_helper(Exx_Helper &exx_helper) +template +void HamiltPW::set_exx_helper(Exx_Helper& exx_helper) { auto op = this->ops; while (op != nullptr) @@ -400,7 +326,6 @@ void HamiltPW::set_exx_helper(Exx_Helper &exx_helper) { exx_helper.op_exx = reinterpret_cast*>(op); exx_helper.set_op(); - } op = op->next_op; } From 27492dccb332c775ecb806cf0d96c5f5858a80e7 Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Mon, 1 Jun 2026 13:01:30 +0800 Subject: [PATCH 2/2] Delete corresponding .h code --- source/source_pw/module_pwdft/hamilt_pw.h | 30 ++++++++++------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/source/source_pw/module_pwdft/hamilt_pw.h b/source/source_pw/module_pwdft/hamilt_pw.h index d3411c54f4d..958f82c8e3b 100644 --- a/source/source_pw/module_pwdft/hamilt_pw.h +++ b/source/source_pw/module_pwdft/hamilt_pw.h @@ -1,15 +1,15 @@ #ifndef HAMILTPW_H #define HAMILTPW_H +#include "source_base/kernels/math_kernel_op.h" #include "source_base/macros.h" #include "source_cell/klist.h" -#include "source_estate/module_pot/potential_new.h" #include "source_esolver/esolver_ks_pw.h" +#include "source_estate/module_pot/potential_new.h" #include "source_hamilt/hamilt.h" -#include "source_pw/module_pwdft/vnl_pw.h" -#include "source_base/kernels/math_kernel_op.h" -#include "source_pw/module_pwdft/exx_helper.h" #include "source_lcao/module_dftu/dftu.h" // mohan add 2025-11-06 +#include "source_pw/module_pwdft/exx_helper.h" +#include "source_pw/module_pwdft/vnl_pw.h" namespace hamilt { @@ -18,22 +18,18 @@ template class HamiltPW : public Hamilt { private: - // Note GetTypeReal::type will - // return T if T is real type(float, double), + // Note GetTypeReal::type will + // return T if T is real type(float, double), // otherwise return the real type of T(complex, std::complex) using Real = typename GetTypeReal::type; public: - - HamiltPW(elecstate::Potential* pot_in, - ModulePW::PW_Basis_K* wfc_basis, - K_Vectors* p_kv, - pseudopot_cell_vnl* nlpp, - Plus_U *p_dftu, // mohan add 2025-11-06 - const UnitCell* ucell); - - template - explicit HamiltPW(const HamiltPW* hamilt); + HamiltPW(elecstate::Potential* pot_in, + ModulePW::PW_Basis_K* wfc_basis, + K_Vectors* p_kv, + pseudopot_cell_vnl* nlpp, + Plus_U* p_dftu, // mohan add 2025-11-06 + const UnitCell* ucell); ~HamiltPW(); @@ -49,7 +45,7 @@ class HamiltPW : public Hamilt void set_exx_helper(Exx_Helper& exx_helper_in); -protected: + protected: // used in sPhi, which are calculated in hPsi or sPhi const pseudopot_cell_vnl* ppcell = nullptr; const UnitCell* const ucell = nullptr;