diff --git a/source/module_hsolver/hsolver_pw.cpp b/source/module_hsolver/hsolver_pw.cpp index fa09bbaa5a..f562ae2c46 100644 --- a/source/module_hsolver/hsolver_pw.cpp +++ b/source/module_hsolver/hsolver_pw.cpp @@ -35,140 +35,7 @@ HSolverPW::HSolverPW(ModulePW::PW_Basis_K* wfc_basis_in, wavefunc* pw template void HSolverPW::initDiagh(const psi::Psi& psi) { - if (this->method == "cg") - { - // if (this->pdiagh != nullptr) - // { - // if (this->pdiagh->method != this->method) - // { - // delete reinterpret_cast*>(this->pdiagh); - // } - // else - // { - // return; - // } - // } - - // this->pdiagh = new DiagoCG(precondition.data()); - - // // warp the subspace_func into a lambda function - // auto ngk_pointer = psi.get_ngk_pointer(); - // auto subspace_func = [this, ngk_pointer](const ct::Tensor& psi_in, ct::Tensor& psi_out) { - // // psi_in should be a 2D tensor: - // // psi_in.shape() = [nbands, nbasis] - // const auto ndim = psi_in.shape().ndim(); - // REQUIRES_OK(ndim == 2, "dims of psi_in should be less than or equal to 2"); - // // Convert a Tensor object to a psi::Psi object - // auto psi_in_wrapper = psi::Psi(psi_in.data(), - // 1, - // psi_in.shape().dim_size(0), - // psi_in.shape().dim_size(1), - // ngk_pointer); - // auto psi_out_wrapper = psi::Psi(psi_out.data(), - // 1, - // psi_out.shape().dim_size(0), - // psi_out.shape().dim_size(1), - // ngk_pointer); - // auto eigen = ct::Tensor(ct::DataTypeToEnum::value, - // ct::DeviceType::CpuDevice, - // ct::TensorShape({psi_in.shape().dim_size(0)})); - - // DiagoIterAssist::diagH_subspace(hamilt_, psi_in_wrapper, psi_out_wrapper, eigen.data()); - // }; - // this->pdiagh = new DiagoCG(GlobalV::BASIS_TYPE, - // GlobalV::CALCULATION, - // DiagoIterAssist::need_subspace, - // subspace_func, - // DiagoIterAssist::PW_DIAG_THR, - // DiagoIterAssist::PW_DIAG_NMAX, - // GlobalV::NPROC_IN_POOL); - // this->pdiagh->method = this->method; - } - else if (this->method == "dav") - { - // #ifdef __MPI - // const diag_comm_info comm_info = {POOL_WORLD, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL}; - // #else - // const diag_comm_info comm_info = {GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL}; - // #endif - - // if (this->pdiagh != nullptr) - // { - // if (this->pdiagh->method != this->method) - // { - // delete (DiagoDavid*)this->pdiagh; - - // this->pdiagh = new DiagoDavid(precondition.data(), - // GlobalV::PW_DIAG_NDIM, - // GlobalV::use_paw, - // comm_info); - - // this->pdiagh->method = this->method; - // } - // } - // else - // { - // this->pdiagh - // = new DiagoDavid(precondition.data(), GlobalV::PW_DIAG_NDIM, GlobalV::use_paw, - // comm_info); - - // this->pdiagh->method = this->method; - // } - } - else if (this->method == "dav_subspace") - { - // #ifdef __MPI - // const diag_comm_info comm_info = {POOL_WORLD, GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL}; - // #else - // const diag_comm_info comm_info = {GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL}; - // #endif - // if (this->pdiagh != nullptr) - // { - // if (this->pdiagh->method != this->method) - // { - // delete (Diago_DavSubspace*)this->pdiagh; - - // this->pdiagh = new Diago_DavSubspace(precondition.data(), - // GlobalV::PW_DIAG_NDIM, - // DiagoIterAssist::PW_DIAG_THR, - // DiagoIterAssist::PW_DIAG_NMAX, - // DiagoIterAssist::need_subspace, - // comm_info); - - // this->pdiagh->method = this->method; - // } - // } - // else - // { - // this->pdiagh = new Diago_DavSubspace(precondition.data(), - // GlobalV::PW_DIAG_NDIM, - // DiagoIterAssist::PW_DIAG_THR, - // DiagoIterAssist::PW_DIAG_NMAX, - // DiagoIterAssist::need_subspace, - // comm_info); - // this->pdiagh->method = this->method; - // } - } - else if (this->method == "bpcg") - { - // if (this->pdiagh != nullptr) - // { - // if (this->pdiagh->method != this->method) - // { - // delete (DiagoBPCG*)this->pdiagh; - // this->pdiagh = new DiagoBPCG(precondition.data()); - // this->pdiagh->method = this->method; - // reinterpret_cast*>(this->pdiagh)->init_iter(psi); - // } - // } - // else - // { - // this->pdiagh = new DiagoBPCG(precondition.data()); - // this->pdiagh->method = this->method; - // reinterpret_cast*>(this->pdiagh)->init_iter(psi); - // } - } - else + if (this->method != "cg" && this->method != "dav" && this->method != "dav_subspace" && this->method != "bpcg") { ModuleBase::WARNING_QUIT("HSolverPW::solve", "This method of DiagH is not supported!"); } @@ -656,29 +523,6 @@ void HSolverPW::solve(hamilt::Hamilt* pHamilt, // ESolver_ template void HSolverPW::endDiagh() { - // DiagoCG would keep 9*nbasis memory in cache during loop-k - // it should be deleted before calculating charge - // if (this->method == "cg") - // { - // delete reinterpret_cast*>(this->pdiagh); - // this->pdiagh = nullptr; - // } - // if (this->method == "dav") - // { - // delete reinterpret_cast*>(this->pdiagh); - // this->pdiagh = nullptr; - // } - // if (this->method == "dav_subspace") - // { - // delete reinterpret_cast*>(this->pdiagh); - // this->pdiagh = nullptr; - // } - // if (this->method == "bpcg") - // { - // delete reinterpret_cast*>(this->pdiagh); - // this->pdiagh = nullptr; - // } - // in PW base, average iteration steps for each band and k-point should be printing if (DiagoIterAssist::avg_iter > 0.0) { @@ -841,7 +685,6 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, psi::P DiagoIterAssist::PW_DIAG_NMAX, DiagoIterAssist::need_subspace, comm_info); - bool scf; if (GlobalV::CALCULATION == "nscf") { @@ -893,12 +736,9 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, psi::P DiagoIterAssist::avg_iter += static_cast( dav_subspace .diag(hpsi_func, subspace_func, psi.get_pointer(), psi.get_nbasis(), eigenvalue, is_occupied, scf)); - - this->pdiagh = nullptr; } else if (this->method == "bpcg") { - // this->pdiagh->diag(hm, psi, eigenvalue); DiagoBPCG bpcg(precondition.data()); bpcg.init_iter(psi); bpcg.diag(hm, psi, eigenvalue);