Skip to content

Commit 08bd7fa

Browse files
author
dyzheng
committed
Feat(deltaspin): enable first_order acceleration for nspin=4
Remove nspin_==2 restriction on first_order mode. For nspin=4: - Skip spin_sign (scalar ±1) which doesn't apply to spinors - Use direct delta_epsilon shift via λ_z component only - PI_sub_diag from the complex HContainer cache provides correct diagonal elements for the spinor structure The first_order mode is an approximation (frozen wavefunctions), but removing the hard guard allows it to be used as a fallback when subspace mode is too expensive for nspin=4.
1 parent 66696b6 commit 08bd7fa

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

source/source_lcao/module_deltaspin/cal_mw_from_lambda.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,18 +772,20 @@ void spinconstrain::SpinConstrain<std::complex<double>>::cal_mw_from_lambda(
772772
const int nloc_wfc = this->ParaV->nloc_wfc;
773773
const int nn = nbands * nbands;
774774

775-
if (this->sc_acceleration_mode_ == "first_order" && this->nspin_ == 2)
775+
if (this->sc_acceleration_mode_ == "first_order")
776776
{
777777
// ---------------------------------------------------------
778778
// First-order response mode
779779
// ---------------------------------------------------------
780780
// Δε_ib = Σ_I Δλ_I · ⟨ψ_ib | D_I | ψ_ib⟩
781781
// Only eigenvalues shift; wavefunctions are frozen at reference.
782782
// Valid when Δλ is small enough that wavefunction mixing is negligible.
783+
//
784+
// nspin=2: Uses σ_z sign (±1) for up/down spin channels.
785+
// nspin=4: Uses Δλ_z only (z-component dominates in collinear-like states).
783786
// ---------------------------------------------------------
784787
for (int ik = 0; ik < nk; ik++)
785788
{
786-
int spin_sign = this->get_spin_sign(ik);
787789
for (int ib = 0; ib < nbands; ib++)
788790
{
789791
double delta_epsilon = 0.0;
@@ -793,7 +795,17 @@ void spinconstrain::SpinConstrain<std::complex<double>>::cal_mw_from_lambda(
793795
double dl = this->lambda_[iat].z - this->lcao_lambda_in_sub_[iat].z;
794796
delta_epsilon += dl * p_diag;
795797
}
796-
this->pelec->ekb(ik, ib) = this->lcao_ekb_save_[ik * nbands + ib] - spin_sign * delta_epsilon;
798+
if (this->nspin_ == 2)
799+
{
800+
int spin_sign = this->get_spin_sign(ik);
801+
this->pelec->ekb(ik, ib) = this->lcao_ekb_save_[ik * nbands + ib]
802+
- spin_sign * delta_epsilon;
803+
}
804+
else
805+
{
806+
this->pelec->ekb(ik, ib) = this->lcao_ekb_save_[ik * nbands + ib]
807+
- delta_epsilon;
808+
}
797809
}
798810
}
799811

0 commit comments

Comments
 (0)