From eccda6f16b3a9027e2d072e608e600a260608ced Mon Sep 17 00:00:00 2001 From: weiqingzhou Date: Tue, 2 Apr 2024 15:55:56 +0800 Subject: [PATCH 1/2] fix a bug in get_dmk_vector() and make some refactor of get-function --- .../module_dm/density_matrix.cpp | 23 +------------------ .../module_dm/density_matrix.h | 12 +++++----- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/source/module_elecstate/module_dm/density_matrix.cpp b/source/module_elecstate/module_dm/density_matrix.cpp index bdd1947d627..4baab3b1e9f 100644 --- a/source/module_elecstate/module_dm/density_matrix.cpp +++ b/source/module_elecstate/module_dm/density_matrix.cpp @@ -272,27 +272,6 @@ TK* DensityMatrix::get_DMK_pointer(const int ik) const return const_cast(this->_DMK[ik].data()); } -// get _DMK[ik] vector -template -std::vector> DensityMatrix::get_DMK_vector() const -{ - return this->_DMK; -} - -// get _paraV pointer -template -const Parallel_Orbitals* DensityMatrix::get_paraV_pointer() const -{ - return this->_paraV; -} - -// get _kv pointer -template -const K_Vectors* DensityMatrix::get_kv_pointer() const -{ - return this->_kv; -} - // set DMK using a pointer template void DensityMatrix::set_DMK_pointer(const int ik, TK* DMK_in) @@ -327,7 +306,7 @@ void DensityMatrix::set_DMK_zero() // get a matrix element of density matrix dm(k) template -TK DensityMatrix::get_DMK(const int ispin, const int ik, const int i, const int j) const +TK& DensityMatrix::get_DMK(const int ispin, const int ik, const int i, const int j) const { #ifdef __DEBUG assert(ispin > 0 && ispin <= this->_nspin); diff --git a/source/module_elecstate/module_dm/density_matrix.h b/source/module_elecstate/module_dm/density_matrix.h index 1c758ae1395..a236ac85aa8 100644 --- a/source/module_elecstate/module_dm/density_matrix.h +++ b/source/module_elecstate/module_dm/density_matrix.h @@ -110,7 +110,7 @@ class DensityMatrix * @param j column index * @return T a matrix element of density matrix dm(k) */ - TK get_DMK(const int ispin, const int ik, const int i, const int j) const; + TK& get_DMK(const int ispin, const int ik, const int i, const int j) const; /** * @brief get total number of k-points of density matrix dm(k) @@ -139,9 +139,9 @@ class DensityMatrix * @brief get pointer vector of DMR * @return HContainer* vector of DMR */ - std::vector*> get_DMR_vector() const {return this->_DMR;} + std::vector*>& get_DMR_vector() const {return this->_DMR;} - std::vector> get_DMR_save() const {return _DMR_save;} + std::vector>& get_DMR_save() const {return _DMR_save;} /** * @brief get pointer of DMK @@ -153,7 +153,7 @@ class DensityMatrix /** * @brief get pointer vector of DMK */ - std::vector> get_DMK_vector() const; + std::vector>& get_DMK_vector() const {return this->_DMK;} /** * @brief set _DMK using a input TK* pointer @@ -164,9 +164,9 @@ class DensityMatrix /** * @brief get pointer of paraV */ - const Parallel_Orbitals* get_paraV_pointer() const; + const Parallel_Orbitals* get_paraV_pointer() const {return this->_paraV;} - const K_Vectors* get_kv_pointer() const; + const K_Vectors* get_kv_pointer() const {return this->_kv;} /** * @brief calculate density matrix DMR from dm(k) using blas::axpy From 4be7c947654ac3ecd8172e91688c0ca96d1bc371 Mon Sep 17 00:00:00 2001 From: weiqingzhou Date: Tue, 2 Apr 2024 16:35:12 +0800 Subject: [PATCH 2/2] override to avoid compile error --- source/module_elecstate/module_dm/density_matrix.cpp | 2 +- source/module_elecstate/module_dm/density_matrix.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/module_elecstate/module_dm/density_matrix.cpp b/source/module_elecstate/module_dm/density_matrix.cpp index 4baab3b1e9f..53de6eb3e64 100644 --- a/source/module_elecstate/module_dm/density_matrix.cpp +++ b/source/module_elecstate/module_dm/density_matrix.cpp @@ -306,7 +306,7 @@ void DensityMatrix::set_DMK_zero() // get a matrix element of density matrix dm(k) template -TK& DensityMatrix::get_DMK(const int ispin, const int ik, const int i, const int j) const +TK DensityMatrix::get_DMK(const int ispin, const int ik, const int i, const int j) const { #ifdef __DEBUG assert(ispin > 0 && ispin <= this->_nspin); diff --git a/source/module_elecstate/module_dm/density_matrix.h b/source/module_elecstate/module_dm/density_matrix.h index a236ac85aa8..62554018506 100644 --- a/source/module_elecstate/module_dm/density_matrix.h +++ b/source/module_elecstate/module_dm/density_matrix.h @@ -110,7 +110,7 @@ class DensityMatrix * @param j column index * @return T a matrix element of density matrix dm(k) */ - TK& get_DMK(const int ispin, const int ik, const int i, const int j) const; + TK get_DMK(const int ispin, const int ik, const int i, const int j) const; /** * @brief get total number of k-points of density matrix dm(k) @@ -139,9 +139,11 @@ class DensityMatrix * @brief get pointer vector of DMR * @return HContainer* vector of DMR */ - std::vector*>& get_DMR_vector() const {return this->_DMR;} + const std::vector*>& get_DMR_vector() const {return this->_DMR;} + std::vector*>& get_DMR_vector() {return this->_DMR;} - std::vector>& get_DMR_save() const {return _DMR_save;} + const std::vector>& get_DMR_save() const {return this->_DMR_save;} + std::vector>& get_DMR_save() {return this->_DMR_save;} /** * @brief get pointer of DMK @@ -153,7 +155,8 @@ class DensityMatrix /** * @brief get pointer vector of DMK */ - std::vector>& get_DMK_vector() const {return this->_DMK;} + const std::vector>& get_DMK_vector() const {return this->_DMK;} + std::vector>& get_DMK_vector() {return this->_DMK;} /** * @brief set _DMK using a input TK* pointer