Skip to content

Commit a3616d2

Browse files
author
dyzheng
committed
Fix(deltaspin): enable DeltaSpin constraint energy calculation for PW basis
- cal_escon(): replace is_Mi_converged gate with lambda_/Mi_ empty check to prevent segfault when uninitialized - elecstate_pw: add get_spin_constrain_energy() override so PW basis computes DeltaSpin constraint energy (previously returned 0.0) - elecstate_pw.h: declare get_spin_constrain_energy() override Note: this fix enables escon computation for PW DeltaSpin but lambda values from BFGS optimizer may differ from accel branch due to energy functional convention differences. Full convergence with accel requires lambda_loop.cpp migration.
1 parent bb2cb4b commit a3616d2

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

source/source_estate/elecstate_pw.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "source_base/timer.h"
99
#include "source_hamilt/module_xc/xc_functional.h"
1010
#include "source_io/module_parameter/parameter.h"
11+
#include "source_lcao/module_deltaspin/spin_constrain.h"
1112
#include "source_pw/module_pwdft/vnl_pw.h"
1213

1314
namespace elecstate {
@@ -56,6 +57,14 @@ ElecStatePW<T, Device>::~ElecStatePW()
5657
delmem_complex_op()(this->wfcr_another_spin);
5758
}
5859

60+
template<typename T, typename Device>
61+
double ElecStatePW<T, Device>::get_spin_constrain_energy()
62+
{
63+
spinconstrain::SpinConstrain<std::complex<double>>& sc
64+
= spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
65+
return sc.cal_escon();
66+
}
67+
5968
template<typename T, typename Device>
6069
void ElecStatePW<T, Device>::init_rho_data()
6170
{

source/source_estate/elecstate_pw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ElecStatePW : public ElecState
3636

3737
virtual void cal_tau(const psi::Psi<T, Device>& psi);
3838

39+
double get_spin_constrain_energy() override;
40+
3941
//! calculate becsum for uspp
4042
void cal_becsum(const psi::Psi<T, Device>& psi);
4143

source/source_lcao/module_deltaspin/spin_constrain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ template <typename TK>
4545
double SpinConstrain<TK>::cal_escon()
4646
{
4747
this->escon_ = 0.0;
48-
if (!this->is_Mi_converged)
48+
if (this->lambda_.empty() || this->Mi_.empty())
4949
{
5050
return this->escon_;
5151
}

0 commit comments

Comments
 (0)