From f48d076602cccdb8fef7093595322827f193a96e Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Sat, 4 Jan 2025 22:27:35 +0800 Subject: [PATCH] fix compile --- source/module_esolver/esolver_ks_lcaopw.cpp | 2 +- source/module_esolver/esolver_ks_pw.cpp | 26 +- source/module_hsolver/test/hsolver_pw_sup.h | 36 -- .../test/hsolver_supplementary_mock.h | 6 - .../module_hsolver/test/test_hsolver_sdft.cpp | 3 - .../module_io/test/for_testing_input_conv.h | 12 - source/module_psi/psi_init.cpp | 7 +- source/module_psi/psi_init.h | 3 +- source/module_psi/test/CMakeLists.txt | 3 + .../test/psi_initializer_unit_test.cpp | 401 ++++-------------- source/module_ri/exx_lip.h | 5 +- source/module_ri/exx_lip.hpp | 9 +- 12 files changed, 109 insertions(+), 404 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index c816696f20..08d1043a4a 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -106,7 +106,7 @@ namespace ModuleESolver this->exx_lip = std::unique_ptr>(new Exx_Lip(GlobalC::exx_info.info_lip, ucell.symm, &this->kv, - this->p_psi_init, + this->psi_local, this->kspw_psi, this->pw_wfc, this->pw_rho, diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index 11dad8fd25..fd1acd5e62 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -386,27 +386,11 @@ void ESolver_KS_PW::before_scf(UnitCell& ucell, const int istep) auto* dftu = ModuleDFTU::DFTU::get_instance(); dftu->init(ucell, nullptr, this->kv.get_nks()); } - // after init_rho (in pelec->init_scf), we have rho now. - // before hamilt2density, we update Hk and initialize psi - - // before_scf function will be called everytime before scf. However, once - // atomic coordinates changed, structure factor will change, therefore all - // atomwise properties will change. So we need to reinitialize psi every - // time before scf. But for random wavefunction, we dont, because random - // wavefunction is not related to atomic coordinates. What the old strategy - // does is only to initialize for once... - if (((PARAM.inp.init_wfc == "random") && (istep == 0)) || (PARAM.inp.init_wfc != "random")) - { - this->p_psi_init->initialize_psi(this->psi, - this->kspw_psi, - this->p_hamilt, - GlobalV::ofs_running, - this->already_initpsi); - - if (this->already_initpsi == false) - { - this->already_initpsi = true; - } + + if (!this->already_initpsi) + { + this->p_psi_init->initialize_psi(this->psi, this->kspw_psi, this->p_hamilt, GlobalV::ofs_running); + this->already_initpsi = true; } ModuleBase::timer::tick("ESolver_KS_PW", "before_scf"); diff --git a/source/module_hsolver/test/hsolver_pw_sup.h b/source/module_hsolver/test/hsolver_pw_sup.h index c065128de9..fcb2862a29 100644 --- a/source/module_hsolver/test/hsolver_pw_sup.h +++ b/source/module_hsolver/test/hsolver_pw_sup.h @@ -180,39 +180,3 @@ template class DiagoIterAssist, base_device::DEVICE_CPU>; template class DiagoIterAssist, base_device::DEVICE_CPU>; } // namespace hsolver - -namespace hamilt { - -template <> -void diago_PAO_in_pw_k2( - const base_device::DEVICE_CPU* ctx, - const int& ik, - psi::Psi, base_device::DEVICE_CPU>& wvf, - ModulePW::PW_Basis_K* wfc_basis, - wavefunc* p_wf, - const ModuleBase::realArray& tab_at, - const int& lmaxkb, - const UnitCell& ucell, - hamilt::Hamilt, base_device::DEVICE_CPU>* phm_in) { - for (int i = 0; i < wvf.size(); i++) { - wvf.get_pointer()[i] = std::complex((float)i + 1, 0); - } -} - -template <> -void diago_PAO_in_pw_k2( - const base_device::DEVICE_CPU* ctx, - const int& ik, - psi::Psi, base_device::DEVICE_CPU>& wvf, - ModulePW::PW_Basis_K* wfc_basis, - wavefunc* p_wf, - const ModuleBase::realArray& tab_at, - const int& lmaxkb, - const UnitCell& ucell, - hamilt::Hamilt, base_device::DEVICE_CPU>* phm_in) { - for (int i = 0; i < wvf.size(); i++) { - wvf.get_pointer()[i] = std::complex((double)i + 1, 0); - } -} - -}//namespace hsolver diff --git a/source/module_hsolver/test/hsolver_supplementary_mock.h b/source/module_hsolver/test/hsolver_supplementary_mock.h index 0876dd33e5..e670adfe15 100644 --- a/source/module_hsolver/test/hsolver_supplementary_mock.h +++ b/source/module_hsolver/test/hsolver_supplementary_mock.h @@ -152,9 +152,3 @@ K_Vectors::K_Vectors() K_Vectors::~K_Vectors() { } -WF_atomic::WF_atomic() -{ -} -WF_atomic::~WF_atomic() -{ -} diff --git a/source/module_hsolver/test/test_hsolver_sdft.cpp b/source/module_hsolver/test/test_hsolver_sdft.cpp index f16e95d20d..f0e6e6cbc3 100644 --- a/source/module_hsolver/test/test_hsolver_sdft.cpp +++ b/source/module_hsolver/test/test_hsolver_sdft.cpp @@ -130,8 +130,6 @@ void Stochastic_Iter::cal_storho(const UnitCell& ucell, } template class Stochastic_Iter, base_device::DEVICE_CPU>; -template class Stochastic_Iter, base_device::DEVICE_CPU>; - Charge::Charge(){}; Charge::~Charge(){}; @@ -157,7 +155,6 @@ class TestHSolverPW_SDFT : public ::testing::Test ModulePW::PW_Basis_K pwbk; Stochastic_WF> stowf; K_Vectors kv; - wavefunc wf; StoChe stoche; hamilt::HamiltSdftPW>* p_hamilt_sto = nullptr; hsolver::HSolverPW_SDFT, base_device::DEVICE_CPU> hs_d diff --git a/source/module_io/test/for_testing_input_conv.h b/source/module_io/test/for_testing_input_conv.h index d97d6972d7..88b1f304e2 100644 --- a/source/module_io/test/for_testing_input_conv.h +++ b/source/module_io/test/for_testing_input_conv.h @@ -165,18 +165,6 @@ Structure_Factor::Structure_Factor() Structure_Factor::~Structure_Factor() { } -WF_atomic::WF_atomic() -{ -} -WF_atomic::~WF_atomic() -{ -} -wavefunc::wavefunc() -{ -} -wavefunc::~wavefunc() -{ -} UnitCell::UnitCell() { itia2iat.create(1, 1); diff --git a/source/module_psi/psi_init.cpp b/source/module_psi/psi_init.cpp index 6bdd85d482..fcfd67b3fe 100644 --- a/source/module_psi/psi_init.cpp +++ b/source/module_psi/psi_init.cpp @@ -84,17 +84,12 @@ template void PSIInit::initialize_psi(Psi>* psi, psi::Psi* kspw_psi, hamilt::Hamilt* p_hamilt, - std::ofstream& ofs_running, - const bool is_already_initpsi) + std::ofstream& ofs_running) { if (kspw_psi->get_nbands() == 0 || GlobalV::MY_STOGROUP != 0) { return; } - if (is_already_initpsi) - { - return; - } if (this->basis_type == "lcao_in_pw") { return; diff --git a/source/module_psi/psi_init.h b/source/module_psi/psi_init.h index 0a405e2217..453d27b072 100644 --- a/source/module_psi/psi_init.h +++ b/source/module_psi/psi_init.h @@ -37,8 +37,7 @@ class PSIInit void initialize_psi(Psi>* psi, psi::Psi* kspw_psi, hamilt::Hamilt* p_hamilt, - std::ofstream& ofs_running, - const bool is_already_initpsi); + std::ofstream& ofs_running); /** * @brief initialize NAOs in plane wave basis, only for LCAO_IN_PW diff --git a/source/module_psi/test/CMakeLists.txt b/source/module_psi/test/CMakeLists.txt index 08ef34ded7..979143dc28 100644 --- a/source/module_psi/test/CMakeLists.txt +++ b/source/module_psi/test/CMakeLists.txt @@ -17,6 +17,9 @@ AddTest( ../../module_cell/parallel_kpoints.cpp ../../module_cell/test/support/mock_unitcell.cpp ../../module_io/orb_io.cpp + ../../module_io/write_pao.cpp + ../../module_io/read_wfc_pw.cpp + ../../module_io/binstream.cpp ) endif() diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index 99576f39d0..5935b5da23 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -9,6 +9,7 @@ #include "../psi_initializer_nao_random.h" #include "../psi_initializer_random.h" #include "module_hamilt_pw/hamilt_pwdft/VL_in_pw.h" +#include "module_cell/klist.h" /* ========================= @@ -89,18 +90,21 @@ std::complex* Structure_Factor::get_sk(int ik, int it, int ia, ModulePW: return sk; } +int K_Vectors::get_ik_global(const int& ik, const int& nkstot) +{ + return ik; +} + class PsiIntializerUnitTest : public ::testing::Test { public: Structure_Factor* p_sf = nullptr; ModulePW::PW_Basis_K* p_pw_wfc = nullptr; UnitCell* p_ucell = nullptr; pseudopot_cell_vnl* p_pspot_vnl = nullptr; - #ifdef __MPI Parallel_Kpoints* p_parakpts = nullptr; - #endif int random_seed = 1; - psi_initializer, base_device::DEVICE_CPU>* psi_init; + psi_initializer>* psi_init; private: protected: @@ -111,9 +115,7 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_pw_wfc = new ModulePW::PW_Basis_K(); this->p_ucell = new UnitCell(); this->p_pspot_vnl = new pseudopot_cell_vnl(); - #ifdef __MPI this->p_parakpts = new Parallel_Kpoints(); - #endif // mock PARAM.input.nbands = 1; PARAM.input.nspin = 1; @@ -259,10 +261,8 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_pspot_vnl->lmaxkb = 0; - #ifdef __MPI this->p_parakpts->startk_pool.resize(1); this->p_parakpts->startk_pool[0] = 0; - #endif } void TearDown() override @@ -271,250 +271,81 @@ class PsiIntializerUnitTest : public ::testing::Test { delete this->p_pw_wfc; delete this->p_ucell; delete this->p_pspot_vnl; - #ifdef __MPI delete this->p_parakpts; - #endif } }; TEST_F(PsiIntializerUnitTest, ConstructorRandom) { - this->psi_initer = new psi_initializer_random, base_device::DEVICE_CPU>(); - EXPECT_EQ("random", this->psi_initer->method()); + this->psi_init = new psi_initializer_random>(); + EXPECT_EQ("random", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorAtomic) { - this->psi_initer = new psi_initializer_atomic, base_device::DEVICE_CPU>(); - EXPECT_EQ("atomic", this->psi_initer->method()); + this->psi_init = new psi_initializer_atomic>(); + EXPECT_EQ("atomic", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorAtomicRandom) { - this->psi_initer = new psi_initializer_atomic_random, base_device::DEVICE_CPU>(); - EXPECT_EQ("atomic+random", this->psi_initer->method()); + this->psi_init = new psi_initializer_atomic_random>(); + EXPECT_EQ("atomic+random", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorNao) { - this->psi_initer = new psi_initializer_nao, base_device::DEVICE_CPU>(); - EXPECT_EQ("nao", this->psi_initer->method()); + this->psi_init = new psi_initializer_nao>(); + EXPECT_EQ("nao", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorNaoRandom) { - this->psi_initer = new psi_initializer_nao_random, base_device::DEVICE_CPU>(); - EXPECT_EQ("nao+random", this->psi_initer->method()); + this->psi_init = new psi_initializer_nao_random>(); + EXPECT_EQ("nao+random", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, CastToT) { - this->psi_initer = new psi_initializer_random, base_device::DEVICE_CPU>(); + this->psi_init = new psi_initializer_random>(); std::complex cd = {1.0, 2.0}; std::complex cf = {1.0, 2.0}; double d = 1.0; float f = 1.0; - EXPECT_EQ(this->psi_initer->template cast_to_T>(cd), cd); - EXPECT_EQ(this->psi_initer->template cast_to_T>(cd), cf); - EXPECT_EQ(this->psi_initer->template cast_to_T(cd), d); - EXPECT_EQ(this->psi_initer->template cast_to_T(cd), f); -} - -TEST_F(PsiIntializerUnitTest, AllocateRandom) { - PARAM.input.init_wfc = "random"; - this->psi_initer = new psi_initializer_random, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->p_parakpts, - this->random_seed, - this->p_pspot_vnl, - GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - EXPECT_EQ(0, this->psi_initer->nbands_complem()); - EXPECT_EQ(1, psi->get_nk()); - EXPECT_EQ(1, psi->get_nbands()); - EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_initer->share_psig().lock(); - EXPECT_EQ(1, psig->get_nk()); - EXPECT_EQ(1, psig->get_nbands()); - EXPECT_EQ(1, psig->get_nbasis()); - delete psi; -} - -TEST_F(PsiIntializerUnitTest, AllocateAtomic) { - PARAM.input.init_wfc = "atomic"; - this->psi_initer = new psi_initializer_atomic, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->p_parakpts, - this->random_seed, - this->p_pspot_vnl, - GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - EXPECT_EQ(0, this->psi_initer->nbands_complem()); - EXPECT_EQ(1, psi->get_nk()); - EXPECT_EQ(1, psi->get_nbands()); - EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_initer->share_psig().lock(); - EXPECT_EQ(1, psig->get_nk()); - EXPECT_EQ(4, psig->get_nbands()); - EXPECT_EQ(1, psig->get_nbasis()); - delete psi; -} - -TEST_F(PsiIntializerUnitTest, AllocateAtomicRandom) { - PARAM.input.init_wfc = "atomic+random"; - this->psi_initer = new psi_initializer_atomic_random, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->p_parakpts, - this->random_seed, - this->p_pspot_vnl, - GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - EXPECT_EQ(0, this->psi_initer->nbands_complem()); - EXPECT_EQ(1, psi->get_nk()); - EXPECT_EQ(1, psi->get_nbands()); - EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_initer->share_psig().lock(); - EXPECT_EQ(1, psig->get_nk()); - EXPECT_EQ(4, psig->get_nbands()); - EXPECT_EQ(1, psig->get_nbasis()); - delete psi; -} - -TEST_F(PsiIntializerUnitTest, AllocateNao) { - PARAM.input.init_wfc = "nao"; - this->psi_initer = new psi_initializer_nao, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->p_parakpts, - this->random_seed, - this->p_pspot_vnl, - GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - EXPECT_EQ(0, this->psi_initer->nbands_complem()); - EXPECT_EQ(1, psi->get_nk()); - EXPECT_EQ(1, psi->get_nbands()); - EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_initer->share_psig().lock(); - EXPECT_EQ(1, psig->get_nk()); - EXPECT_EQ(13, psig->get_nbands()); - EXPECT_EQ(1, psig->get_nbasis()); - delete psi; -} - -TEST_F(PsiIntializerUnitTest, AllocateNaoRandom) { - PARAM.input.init_wfc = "nao+random"; - this->psi_initer = new psi_initializer_nao_random, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->p_parakpts, - this->random_seed, - this->p_pspot_vnl, - GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - EXPECT_EQ(0, this->psi_initer->nbands_complem()); - EXPECT_EQ(1, psi->get_nk()); - EXPECT_EQ(1, psi->get_nbands()); - EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_initer->share_psig().lock(); - EXPECT_EQ(1, psig->get_nk()); - EXPECT_EQ(13, psig->get_nbands()); - EXPECT_EQ(1, psig->get_nbasis()); - delete psi; + EXPECT_EQ(this->psi_init->template cast_to_T>(cd), cd); + EXPECT_EQ(this->psi_init->template cast_to_T>(cd), cf); + EXPECT_EQ(this->psi_init->template cast_to_T(cd), d); + EXPECT_EQ(this->psi_init->template cast_to_T(cd), f); } TEST_F(PsiIntializerUnitTest, CalPsigRandom) { PARAM.input.init_wfc = "random"; - this->psi_initer = new psi_initializer_random, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_random>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } TEST_F(PsiIntializerUnitTest, CalPsigAtomic) { PARAM.input.init_wfc = "atomic"; - this->psi_initer = new psi_initializer_atomic, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_atomic>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } @@ -525,25 +356,19 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSoc) { PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = false; this->p_ucell->natomwfc *= 2; - this->psi_initer = new psi_initializer_atomic, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_atomic>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); PARAM.input.nspin = 1; PARAM.sys.npol = 1; @@ -558,25 +383,19 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = true; this->p_ucell->natomwfc *= 2; - this->psi_initer = new psi_initializer_atomic, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_atomic>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); PARAM.input.nspin = 1; PARAM.sys.npol = 1; @@ -587,75 +406,57 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { TEST_F(PsiIntializerUnitTest, CalPsigAtomicRandom) { PARAM.input.init_wfc = "atomic+random"; - this->psi_initer = new psi_initializer_atomic_random, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_atomic_random>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } TEST_F(PsiIntializerUnitTest, CalPsigNao) { PARAM.input.init_wfc = "nao"; - this->psi_initer = new psi_initializer_nao, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_nao>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } TEST_F(PsiIntializerUnitTest, CalPsigNaoRandom) { PARAM.input.init_wfc = "nao+random"; - this->psi_initer = new psi_initializer_nao_random, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_nao_random>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } @@ -667,25 +468,19 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSoc) { this->p_ucell->atoms[0].ncpp.has_so = false; PARAM.sys.domag = false; PARAM.sys.domag_z = false; - this->psi_initer = new psi_initializer_nao, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_nao>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } @@ -697,25 +492,19 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSo) { this->p_ucell->atoms[0].ncpp.has_so = true; PARAM.sys.domag = false; PARAM.sys.domag_z = false; - this->psi_initer = new psi_initializer_nao, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_nao>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } @@ -727,25 +516,19 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSoDOMAG) { this->p_ucell->atoms[0].ncpp.has_so = true; PARAM.sys.domag = true; PARAM.sys.domag_z = false; - this->psi_initer = new psi_initializer_nao, base_device::DEVICE_CPU>(); -#ifdef __MPI - this->psi_initer->initialize(this->p_sf, + this->psi_init = new psi_initializer_nao>(); + this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, this->p_parakpts, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); - #else - this->psi_initer->initialize(this->p_sf, - this->p_pw_wfc, - this->p_ucell, - this->random_seed, - this->p_pspot_vnl); - #endif - this->psi_initer->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG - psi::Psi>* psi = this->psi_initer->allocate(); - this->psi_initer->proj_ao_onkG(0); + this->psi_init->tabulate(); // always: new, initialize, tabulate, allocate, proj_ao_onkG + const int nbands_start = this->psi_init->nbands_start(); + const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol; + psi::Psi>* psi = new psi::Psi>(1, nbands_start, nbasis, nullptr); + this->psi_init->init_psig(psi->get_pointer(), 0); EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12); delete psi; } diff --git a/source/module_ri/exx_lip.h b/source/module_ri/exx_lip.h index 307f58ab9f..9f19560c10 100644 --- a/source/module_ri/exx_lip.h +++ b/source/module_ri/exx_lip.h @@ -38,8 +38,7 @@ class Exx_Lip Exx_Lip(const Exx_Info::Exx_Info_Lip& info_in, const ModuleSymmetry::Symmetry& symm, K_Vectors* kv_ptr_in, - // wavefunc* wf_ptr_in, - psi::PSIInit* wf_ptr_in, + psi::Psi* psi_local_in, psi::Psi* kspw_psi_ptr_in, const ModulePW::PW_Basis_K* wfc_basis_in, const ModulePW::PW_Basis* rho_basis_in, @@ -79,7 +78,7 @@ class Exx_Lip K_Vectors* kv_ptr = nullptr; // wavefunc* wf_ptr; psi::Psi* kspw_psi_ptr = nullptr; ///< PW wavefunction - psi::PSIInit* wf_ptr = nullptr; + psi::Psi* psi_local = nullptr; ///< NAOs in PW ModuleBase::matrix wf_wg; /// @brief LCAO wavefunction, the eigenvectors from lapack diagonalization diff --git a/source/module_ri/exx_lip.hpp b/source/module_ri/exx_lip.hpp index eda9a157ef..a892fa67e4 100644 --- a/source/module_ri/exx_lip.hpp +++ b/source/module_ri/exx_lip.hpp @@ -83,9 +83,8 @@ template Exx_Lip::Exx_Lip(const Exx_Info::Exx_Info_Lip& info_in, const ModuleSymmetry::Symmetry& symm, K_Vectors* kv_ptr_in, - psi::PSIInit* wf_ptr_in, + psi::Psi* psi_local_in, psi::Psi* kspw_psi_ptr_in, - // wavefunc* wf_ptr_in, const ModulePW::PW_Basis_K* wfc_basis_in, const ModulePW::PW_Basis* rho_basis_in, const Structure_Factor& sf, @@ -98,7 +97,7 @@ Exx_Lip::Exx_Lip(const Exx_Info::Exx_Info_Lip& info_in, this->k_pack = new k_package; this->k_pack->kv_ptr = kv_ptr_in; - this->k_pack->wf_ptr = wf_ptr_in; + this->k_pack->psi_local = psi_local_in; this->k_pack->pelec = pelec_in; this->k_pack->kspw_psi_ptr = kspw_psi_ptr_in; this->wfc_basis = wfc_basis_in; @@ -183,7 +182,7 @@ Exx_Lip::~Exx_Lip() else if (PARAM.inp.init_chg == "file") { delete this->q_pack->kv_ptr; this->q_pack->kv_ptr = nullptr; - delete this->q_pack->wf_ptr; this->q_pack->wf_ptr = nullptr; + // delete this->q_pack->wf_ptr; this->q_pack->wf_ptr = nullptr; // delete[] this->q_pack->hvec_array; this->q_pack->hvec_array=nullptr; delete this->q_pack; this->q_pack = nullptr; } @@ -215,7 +214,7 @@ void Exx_Lip::phi_cal(k_package* kq_pack, const int ikq) for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw) { // this->wfc_basis->recip2real(&kq_pack->wf_ptr->wanf2[ikq](iw,0), porter.data(), ikq); - this->wfc_basis->recip2real(&(kq_pack->wf_ptr->get_psig().lock()->operator()(ikq, iw, 0)), porter.data(), ikq); + this->wfc_basis->recip2real(&(kq_pack->psi_local->operator()(ikq, iw, 0)), porter.data(), ikq); int ir = 0; for (int ix = 0; ix < this->rho_basis->nx; ++ix) {