diff --git a/source/source_estate/module_charge/charge.cpp b/source/source_estate/module_charge/charge.cpp index 32d0b4f8356..72aa1c8fa02 100644 --- a/source/source_estate/module_charge/charge.cpp +++ b/source/source_estate/module_charge/charge.cpp @@ -31,6 +31,7 @@ #include "source_hamilt/module_xc/xc_functional.h" #include "source_io/module_parameter/parameter.h" +#include #include Charge::Charge() @@ -39,6 +40,73 @@ Charge::Charge() allocate_rho_final_scf = false; // LiuXh add 20180619 } +Charge::Charge(Charge&& other) noexcept + : rho(other.rho), + rho_save(other.rho_save), + rhog(other.rhog), + rhog_save(other.rhog_save), + kin_r(other.kin_r), + kin_r_save(other.kin_r_save), + pgrid(other.pgrid), + _space_rho(other._space_rho), + _space_rho_save(other._space_rho_save), + _space_rhog(other._space_rhog), + _space_rhog_save(other._space_rhog_save), + _space_kin_r(other._space_kin_r), + _space_kin_r_save(other._space_kin_r_save), + nhat(other.nhat), + nhat_save(other.nhat_save), + rho_core(other.rho_core), + rhog_core(other.rhog_core), + prenspin(other.prenspin), + nrxx(other.nrxx), + nxyz(other.nxyz), + ngmc(other.ngmc), + nspin(other.nspin), + rhopw(other.rhopw), + cal_elf(other.cal_elf), + omega_(other.omega_), + allocate_rho(other.allocate_rho), + allocate_rho_final_scf(other.allocate_rho_final_scf) +#ifdef __MPI + , + rec(other.rec), + dis(other.dis) +#endif +{ + other.rho = nullptr; + other.rho_save = nullptr; + other.rhog = nullptr; + other.rhog_save = nullptr; + other.kin_r = nullptr; + other.kin_r_save = nullptr; + other.pgrid = nullptr; + other._space_rho = nullptr; + other._space_rho_save = nullptr; + other._space_rhog = nullptr; + other._space_rhog_save = nullptr; + other._space_kin_r = nullptr; + other._space_kin_r_save = nullptr; + other.nhat = nullptr; + other.nhat_save = nullptr; + other.rho_core = nullptr; + other.rhog_core = nullptr; + other.prenspin = 1; + other.nrxx = 0; + other.nxyz = 0; + other.ngmc = 0; + other.nspin = 0; + other.rhopw = nullptr; + other.cal_elf = false; + other.omega_ = nullptr; + other.allocate_rho = false; + other.allocate_rho_final_scf = false; +#ifdef __MPI + other.rec = nullptr; + other.dis = nullptr; +#endif +} + Charge::~Charge() { this->destroy(); diff --git a/source/source_estate/module_charge/charge.h b/source/source_estate/module_charge/charge.h index 9064dfc5fb8..3f6fbbfe959 100644 --- a/source/source_estate/module_charge/charge.h +++ b/source/source_estate/module_charge/charge.h @@ -19,6 +19,7 @@ class Charge public: Charge(); + Charge(Charge&& other) noexcept; ~Charge(); //========================================================== diff --git a/source/source_estate/module_dm/density_matrix.cpp b/source/source_estate/module_dm/density_matrix.cpp index 7414e00fd3b..9414b27b31a 100644 --- a/source/source_estate/module_dm/density_matrix.cpp +++ b/source/source_estate/module_dm/density_matrix.cpp @@ -9,6 +9,8 @@ #include "source_base/constants.h" #include "source_cell/klist.h" +#include + namespace elecstate { @@ -53,6 +55,29 @@ DensityMatrix::DensityMatrix(const Parallel_Orbitals* paraV_in, const in ModuleBase::Memory::record("DensityMatrix::DMK", this->_DMK.size() * this->_DMK[0].size() * sizeof(TK)); } +template +DensityMatrix::DensityMatrix(DensityMatrix&& other) noexcept + : EDMK(std::move(other.EDMK)), +#ifdef __PEXSI + pexsi_EDM(std::move(other.pexsi_EDM)), +#endif + _DMR(std::move(other._DMR)), + _DMR_save(std::move(other._DMR_save)), + _DMR_grid(std::move(other._DMR_grid)), + _DMK(std::move(other._DMK)), + _kvec_d(std::move(other._kvec_d)), + _paraV(other._paraV), + _nspin(other._nspin), + _nk(other._nk), + dmr_origin_(std::move(other.dmr_origin_)), + dmr_tmp_(other.dmr_tmp_) +{ + other._paraV = nullptr; + other._nspin = 1; + other._nk = 0; + other.dmr_tmp_ = nullptr; +} + // calculate DMR from DMK using blas for multi-k calculation diff --git a/source/source_estate/module_dm/density_matrix.h b/source/source_estate/module_dm/density_matrix.h index 90c51e9c061..b3b748f9b7c 100644 --- a/source/source_estate/module_dm/density_matrix.h +++ b/source/source_estate/module_dm/density_matrix.h @@ -89,6 +89,7 @@ class DensityMatrix const int nspin, const std::vector>& kvec_d, const int nk); + DensityMatrix(DensityMatrix&& other) noexcept; /** * @brief Constructor of class DensityMatrix for gamma-only calculation, where kvector is not required @@ -301,7 +302,7 @@ class DensityMatrix /** * @brief K_Vectors object, which is used to get k-point information */ - const std::vector> _kvec_d; + std::vector> _kvec_d; /** * @brief Parallel_Orbitals object, which contain all information of 2D block cyclic distribution diff --git a/source/source_estate/module_pot/H_Hartree_pw.h b/source/source_estate/module_pot/H_Hartree_pw.h index c5ca6bdd0b5..cbba051fa03 100644 --- a/source/source_estate/module_pot/H_Hartree_pw.h +++ b/source/source_estate/module_pot/H_Hartree_pw.h @@ -57,6 +57,7 @@ class PotHartree : public PotBase { public: PotHartree(const ModulePW::PW_Basis* rho_basis_in); + PotHartree(PotHartree&& other) noexcept = default; void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff); }; diff --git a/source/source_estate/module_pot/pot_base.h b/source/source_estate/module_pot/pot_base.h index aaa578bc5bf..cb8dae8e637 100644 --- a/source/source_estate/module_pot/pot_base.h +++ b/source/source_estate/module_pot/pot_base.h @@ -22,6 +22,17 @@ class PotBase { public: PotBase(){} + PotBase(PotBase&& other) noexcept + : fixed_mode(other.fixed_mode), + dynamic_mode(other.dynamic_mode), + rho_basis_(other.rho_basis_), + rho_basis_smooth_(other.rho_basis_smooth_) + { + other.fixed_mode = false; + other.dynamic_mode = false; + other.rho_basis_ = nullptr; + other.rho_basis_smooth_ = nullptr; + } virtual ~PotBase(){} virtual void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix& v_eff){} @@ -40,4 +51,4 @@ class PotBase } // namespace elecstate -#endif \ No newline at end of file +#endif diff --git a/source/source_estate/module_pot/pot_cosikr.cpp b/source/source_estate/module_pot/pot_cosikr.cpp index 66a5ef7849c..6084a4f51da 100644 --- a/source/source_estate/module_pot/pot_cosikr.cpp +++ b/source/source_estate/module_pot/pot_cosikr.cpp @@ -6,15 +6,16 @@ #include "pot_cosikr.h" #include +#include namespace elecstate { Pot_Cosikr::Pot_Cosikr( - const ModulePW::PW_Basis* rho_basis_in, - const ModuleBase::Vector3 &kvec_d_in, - const std::vector &phase_in, - const std::vector &litude_in) + const ModulePW::PW_Basis* rho_basis_in, + const ModuleBase::Vector3 &kvec_d_in, + const std::vector &phase_in, + const std::vector &litude_in) :kvec_d(kvec_d_in), phase(phase_in), amplitude(amplitude_in) @@ -24,6 +25,14 @@ Pot_Cosikr::Pot_Cosikr( this->fixed_mode = false; } +Pot_Cosikr::Pot_Cosikr(Pot_Cosikr&& other) noexcept + : PotBase(std::move(other)), + kvec_d(other.kvec_d), + phase(std::move(other.phase)), + amplitude(std::move(other.amplitude)) +{ +} + void Pot_Cosikr::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff) { @@ -50,4 +59,4 @@ void Pot_Cosikr::cal_v_eff(const Charge*const chg, const UnitCell*const ucell, M ModuleBase::timer::end("Pot_Cosikr", "cal_veff"); } -} \ No newline at end of file +} diff --git a/source/source_estate/module_pot/pot_cosikr.h b/source/source_estate/module_pot/pot_cosikr.h index d6953a5dfe6..73cd8b06b95 100644 --- a/source/source_estate/module_pot/pot_cosikr.h +++ b/source/source_estate/module_pot/pot_cosikr.h @@ -16,21 +16,22 @@ namespace elecstate // ampitude * cos( 2pi*( k * r + phase ) ) class Pot_Cosikr : public PotBase { - public: - Pot_Cosikr( - const ModulePW::PW_Basis* rho_basis_in, - const ModuleBase::Vector3 &kvec_d_in, - const std::vector &phase_in, - const std::vector &litude_in); + public: + Pot_Cosikr( + const ModulePW::PW_Basis* rho_basis_in, + const ModuleBase::Vector3 &kvec_d_in, + const std::vector &phase_in, + const std::vector &litude_in); + Pot_Cosikr(Pot_Cosikr&& other) noexcept; void cal_v_eff(const Charge*const chg, const UnitCell*const ucell, ModuleBase::matrix &v_eff) override; - private: - const ModuleBase::Vector3 kvec_d; - const std::vector phase; - const std::vector amplitude; -}; + private: + ModuleBase::Vector3 kvec_d; + std::vector phase; + std::vector amplitude; +}; } -#endif \ No newline at end of file +#endif diff --git a/source/source_estate/module_pot/pot_xc_fdm.cpp b/source/source_estate/module_pot/pot_xc_fdm.cpp index d0a49cc1012..905cac9fc12 100644 --- a/source/source_estate/module_pot/pot_xc_fdm.cpp +++ b/source/source_estate/module_pot/pot_xc_fdm.cpp @@ -3,11 +3,13 @@ // DATE : 2025-10-01 //======================= -#include "pot_xc_fdm.h" -#include "source_hamilt/module_xc/xc_functional.h" - -namespace elecstate -{ +#include "pot_xc_fdm.h" +#include "source_hamilt/module_xc/xc_functional.h" + +#include + +namespace elecstate +{ PotXC_FDM::PotXC_FDM( const ModulePW::PW_Basis* rho_basis_in, @@ -21,10 +23,18 @@ PotXC_FDM::PotXC_FDM( const std::tuple etxc_vtxc_v_0 = XC_Functional::v_xc(this->chg_0->nrxx, this->chg_0, ucell); - this->v_xc_0 = std::get<2>(etxc_vtxc_v_0); -} - -void PotXC_FDM::cal_v_eff( + this->v_xc_0 = std::get<2>(etxc_vtxc_v_0); +} + +PotXC_FDM::PotXC_FDM(PotXC_FDM&& other) noexcept + : PotBase(std::move(other)), + chg_0(other.chg_0), + v_xc_0(std::move(other.v_xc_0)) +{ + other.chg_0 = nullptr; +} + +void PotXC_FDM::cal_v_eff( const Charge*const chg_1, const UnitCell*const ucell, ModuleBase::matrix& v_eff) diff --git a/source/source_estate/module_pot/pot_xc_fdm.h b/source/source_estate/module_pot/pot_xc_fdm.h index eb1cd880576..6637fed28aa 100644 --- a/source/source_estate/module_pot/pot_xc_fdm.h +++ b/source/source_estate/module_pot/pot_xc_fdm.h @@ -15,20 +15,21 @@ class PotXC_FDM : public PotBase { public: - PotXC_FDM( - const ModulePW::PW_Basis* rho_basis_in, - const Charge*const chg_0_in, - const UnitCell*const ucell); + PotXC_FDM( + const ModulePW::PW_Basis* rho_basis_in, + const Charge*const chg_0_in, + const UnitCell*const ucell); + PotXC_FDM(PotXC_FDM&& other) noexcept; void cal_v_eff( const Charge*const chg_1, const UnitCell*const ucell, ModuleBase::matrix& v_eff) override; - const Charge*const chg_0 = nullptr; - ModuleBase::matrix v_xc_0; + const Charge* chg_0 = nullptr; + ModuleBase::matrix v_xc_0; }; } // namespace elecstate -#endif \ No newline at end of file +#endif diff --git a/source/source_estate/module_pot/potential_new.cpp b/source/source_estate/module_pot/potential_new.cpp index 70b35cdf000..5f1a72c18ac 100644 --- a/source/source_estate/module_pot/potential_new.cpp +++ b/source/source_estate/module_pot/potential_new.cpp @@ -11,6 +11,7 @@ #include "pot_ml_exx.h" #include +#include namespace elecstate { @@ -38,6 +39,46 @@ Potential::Potential(const ModulePW::PW_Basis* rho_basis_in, this->allocate(); } +Potential::Potential(Potential&& other) noexcept + : PotBase(std::move(other)), + v_eff_fixed(std::move(other.v_eff_fixed)), + v_eff(std::move(other.v_eff)), + veff_smooth(std::move(other.veff_smooth)), + vofk_smooth(std::move(other.vofk_smooth)), + v_xc(std::move(other.v_xc)), + s_veff_smooth(other.s_veff_smooth), + s_vofk_smooth(other.s_vofk_smooth), + d_veff_smooth(other.d_veff_smooth), + d_vofk_smooth(other.d_vofk_smooth), + vofk_eff(std::move(other.vofk_eff)), + fixed_done(other.fixed_done), + etxc_(other.etxc_), + vtxc_(other.vtxc_), + vl_of_0(other.vl_of_0), + components(std::move(other.components)), + ucell_(other.ucell_), + vloc_(other.vloc_), + structure_factors_(other.structure_factors_), + solvent_(other.solvent_), + vsep_cell(other.vsep_cell), + use_gpu_(other.use_gpu_) +{ + other.s_veff_smooth = nullptr; + other.s_vofk_smooth = nullptr; + other.d_veff_smooth = nullptr; + other.d_vofk_smooth = nullptr; + other.fixed_done = false; + other.etxc_ = nullptr; + other.vtxc_ = nullptr; + other.use_gpu_ = false; + other.vl_of_0 = 0.0; + other.ucell_ = nullptr; + other.vloc_ = nullptr; + other.structure_factors_ = nullptr; + other.solvent_ = nullptr; + other.vsep_cell = nullptr; +} + Potential::~Potential() { if (this->components.size() > 0) diff --git a/source/source_estate/module_pot/potential_new.h b/source/source_estate/module_pot/potential_new.h index ca79ca02f63..a6f5714ff5a 100644 --- a/source/source_estate/module_pot/potential_new.h +++ b/source/source_estate/module_pot/potential_new.h @@ -63,6 +63,7 @@ class Potential : public PotBase double* etxc_in, double* vtxc_in, VSep* vsep_cell_in = nullptr); + Potential(Potential&& other) noexcept; ~Potential(); // initialize potential when SCF begin diff --git a/source/source_lcao/module_gint/gint_rho.h b/source/source_lcao/module_gint/gint_rho.h index 5bcede5f19f..0febcae958a 100644 --- a/source/source_lcao/module_gint/gint_rho.h +++ b/source/source_lcao/module_gint/gint_rho.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "source_lcao/module_hcontainer/hcontainer.h" #include "gint.h" @@ -18,6 +19,15 @@ class Gint_rho : public Gint double **rho, bool is_dm_symm = true) : dm_vec_(dm_vec), nspin_(nspin), is_dm_symm_(is_dm_symm), rho_(rho) {} + Gint_rho(Gint_rho&& other) noexcept + : Gint(std::move(other)), + dm_vec_(std::move(other.dm_vec_)), + nspin_(other.nspin_), + is_dm_symm_(other.is_dm_symm_), + rho_(other.rho_) + { + other.rho_ = nullptr; + } void cal_gint(); @@ -36,7 +46,7 @@ class Gint_rho : public Gint const std::vector& rho_data) const; // input - const std::vector*> dm_vec_; + std::vector*> dm_vec_; const int nspin_; // if true, it means the DMR matrix is symmetric, diff --git a/source/source_lcao/module_gint/gint_vl.h b/source/source_lcao/module_gint/gint_vl.h index cd21f178c01..ca6eb877d16 100644 --- a/source/source_lcao/module_gint/gint_vl.h +++ b/source/source_lcao/module_gint/gint_vl.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "source_lcao/module_hcontainer/hcontainer.h" #include "gint.h" @@ -15,7 +16,17 @@ class Gint_vl : public Gint Gint_vl( const double* vr_eff, HContainer* hR) - : vr_eff_(vr_eff), hR_(hR), dr3_(gint_info_->get_mgrid_volume()) {} + : vr_eff_(vr_eff), hR_(hR), dr3_(gint_info_ == nullptr ? 0.0 : gint_info_->get_mgrid_volume()) {} + Gint_vl(Gint_vl&& other) noexcept + : Gint(std::move(other)), + vr_eff_(other.vr_eff_), + hR_(other.hR_), + dr3_(other.dr3_) + { + other.vr_eff_ = nullptr; + other.hR_ = nullptr; + other.dr3_ = 0.0; + } void cal_gint(); diff --git a/source/source_lcao/module_hcontainer/base_matrix.cpp b/source/source_lcao/module_hcontainer/base_matrix.cpp index 5e6c7b00a28..23b77b0c0f4 100644 --- a/source/source_lcao/module_hcontainer/base_matrix.cpp +++ b/source/source_lcao/module_hcontainer/base_matrix.cpp @@ -18,7 +18,7 @@ BaseMatrix::BaseMatrix(const int& nrow_, const int& ncol_, T* data_existed) // move constructor template -BaseMatrix::BaseMatrix(BaseMatrix&& matrix) +BaseMatrix::BaseMatrix(BaseMatrix&& matrix) noexcept { this->nrow_local = matrix.nrow_local; this->ncol_local = matrix.ncol_local; diff --git a/source/source_lcao/module_hcontainer/base_matrix.h b/source/source_lcao/module_hcontainer/base_matrix.h index 36044ee187f..990c58b3929 100644 --- a/source/source_lcao/module_hcontainer/base_matrix.h +++ b/source/source_lcao/module_hcontainer/base_matrix.h @@ -24,7 +24,7 @@ class BaseMatrix // copy constructor BaseMatrix(const BaseMatrix& matrix); // move constructor - BaseMatrix(BaseMatrix&& matrix); + BaseMatrix(BaseMatrix&& matrix) noexcept; // Destructor of class BaseMatrix ~BaseMatrix();