diff --git a/source/source_estate/elecstate_pw.cpp b/source/source_estate/elecstate_pw.cpp index 7edb7b6bcf..641def5dc4 100644 --- a/source/source_estate/elecstate_pw.cpp +++ b/source/source_estate/elecstate_pw.cpp @@ -8,6 +8,7 @@ #include "source_base/timer.h" #include "source_hamilt/module_xc/xc_functional.h" #include "source_io/module_parameter/parameter.h" +#include "source_lcao/module_deltaspin/spin_constrain.h" #include "source_pw/module_pwdft/vnl_pw.h" namespace elecstate { @@ -56,6 +57,14 @@ ElecStatePW::~ElecStatePW() delmem_complex_op()(this->wfcr_another_spin); } +template +double ElecStatePW::get_spin_constrain_energy() +{ + spinconstrain::SpinConstrain>& sc + = spinconstrain::SpinConstrain>::getScInstance(); + return sc.cal_escon(); +} + template void ElecStatePW::init_rho_data() { diff --git a/source/source_estate/elecstate_pw.h b/source/source_estate/elecstate_pw.h index 623704e178..53e39917a5 100644 --- a/source/source_estate/elecstate_pw.h +++ b/source/source_estate/elecstate_pw.h @@ -36,6 +36,8 @@ class ElecStatePW : public ElecState virtual void cal_tau(const psi::Psi& psi); + double get_spin_constrain_energy() override; + //! calculate becsum for uspp void cal_becsum(const psi::Psi& psi); diff --git a/source/source_estate/test/CMakeLists.txt b/source/source_estate/test/CMakeLists.txt index b9118b01a5..ae09357ac8 100644 --- a/source/source_estate/test/CMakeLists.txt +++ b/source/source_estate/test/CMakeLists.txt @@ -51,6 +51,7 @@ AddTest( ../elecstate.cpp ../occupy.cpp ../module_charge/charge_mpi.cpp + ../../source_lcao/module_deltaspin/spin_constrain.cpp ../../source_psi/psi.cpp ../../source_base/module_device/memory_op.cpp ) diff --git a/source/source_lcao/module_deltaspin/spin_constrain.cpp b/source/source_lcao/module_deltaspin/spin_constrain.cpp index b4048b5e9f..df8b4b20b3 100644 --- a/source/source_lcao/module_deltaspin/spin_constrain.cpp +++ b/source/source_lcao/module_deltaspin/spin_constrain.cpp @@ -45,7 +45,7 @@ template double SpinConstrain::cal_escon() { this->escon_ = 0.0; - if (!this->is_Mi_converged) + if (this->lambda_.empty() || this->Mi_.empty()) { return this->escon_; } diff --git a/source/source_lcao/module_deltaspin/spin_constrain.h b/source/source_lcao/module_deltaspin/spin_constrain.h index 4785e8dfe8..474cef6716 100644 --- a/source/source_lcao/module_deltaspin/spin_constrain.h +++ b/source/source_lcao/module_deltaspin/spin_constrain.h @@ -79,7 +79,7 @@ inline ModuleBase::Vector3 pauli_to_moment(const std::complex oc { return ModuleBase::Vector3( weight * (occ[1] + occ[2]).real(), - -weight * (occ[1] - occ[2]).imag(), + weight * (occ[1] - occ[2]).imag(), weight * (occ[0] - occ[3]).real() ); } diff --git a/tests/17_DS_DFTU/14_PW_DS_S4_XYZ/result.ref b/tests/17_DS_DFTU/14_PW_DS_S4_XYZ/result.ref index f63986cceb..97fc3aaca4 100644 --- a/tests/17_DS_DFTU/14_PW_DS_S4_XYZ/result.ref +++ b/tests/17_DS_DFTU/14_PW_DS_S4_XYZ/result.ref @@ -1,3 +1,3 @@ -etotref -6366.562922988214 -etotperatomref -3183.2814614941 -totaltimeref 4.23 +etotref -6369.19895097706 +etotperatomref -3184.59947548853 +totaltimeref 1.0 diff --git a/tests/17_DS_DFTU/15_PW_DS_S4_Z/result.ref b/tests/17_DS_DFTU/15_PW_DS_S4_Z/result.ref index 07523240a6..3c6f1a967e 100644 --- a/tests/17_DS_DFTU/15_PW_DS_S4_Z/result.ref +++ b/tests/17_DS_DFTU/15_PW_DS_S4_Z/result.ref @@ -1,3 +1,3 @@ -etotref -6366.562433916121 -etotperatomref -3183.2812169581 -totaltimeref 4.26 +etotref -6369.198273166801 +etotperatomref -3184.5991365834007 +totaltimeref 1.0 diff --git a/tests/17_DS_DFTU/16_PW_DS_S4_XY/result.ref b/tests/17_DS_DFTU/16_PW_DS_S4_XY/result.ref index c2ed3287e2..d5b3da693e 100644 --- a/tests/17_DS_DFTU/16_PW_DS_S4_XY/result.ref +++ b/tests/17_DS_DFTU/16_PW_DS_S4_XY/result.ref @@ -1,3 +1,3 @@ -etotref -6366.562695059035 -etotperatomref -3183.2813475295 -totaltimeref 4.19 +etotref -6369.198274098935 +etotperatomref -3184.5991370494676 +totaltimeref 1.0 diff --git a/tests/17_DS_DFTU/19_PW_DFTU_DS_S4_XY/result.ref b/tests/17_DS_DFTU/19_PW_DFTU_DS_S4_XY/result.ref index ed294b0414..e40be3f01b 100644 --- a/tests/17_DS_DFTU/19_PW_DFTU_DS_S4_XY/result.ref +++ b/tests/17_DS_DFTU/19_PW_DFTU_DS_S4_XY/result.ref @@ -1,3 +1,3 @@ -etotref -6355.9841673819892094 -etotperatomref -3177.9920836910 -totaltimeref 5.88 +etotref -6360.5554588729937677 +etotperatomref -3180.277729436497 +totaltimeref 1.0 diff --git a/tests/17_DS_DFTU/21_PW_DFTU_DS_S4_Z/result.ref b/tests/17_DS_DFTU/21_PW_DFTU_DS_S4_Z/result.ref index 1810d27088..b06c7ee03a 100644 --- a/tests/17_DS_DFTU/21_PW_DFTU_DS_S4_Z/result.ref +++ b/tests/17_DS_DFTU/21_PW_DFTU_DS_S4_Z/result.ref @@ -1,3 +1,3 @@ -etotref -6355.9834051938123594 -etotperatomref -3177.9917025969 -totaltimeref 5.46 +etotref -6360.5554655414534864 +etotperatomref -3180.2777327707267 +totaltimeref 1.0 diff --git a/tests/17_DS_DFTU/41_PW_DS_S4_Thr10_XY/result.ref b/tests/17_DS_DFTU/41_PW_DS_S4_Thr10_XY/result.ref index acf31e682c..8d127ea729 100644 --- a/tests/17_DS_DFTU/41_PW_DS_S4_Thr10_XY/result.ref +++ b/tests/17_DS_DFTU/41_PW_DS_S4_Thr10_XY/result.ref @@ -1,3 +1,3 @@ -etotref -6366.564253345298 -etotperatomref -3183.2821266726 -totaltimeref 7.03 +etotref -6369.198254647004 +etotperatomref -3184.599127323502 +totaltimeref 1.0