Skip to content

Commit 32094b5

Browse files
committed
DeltaP Phase C.3: refactor esolver_ks_lcao.cpp to use deltap_common.h
Replace inline dp_escon computation with shared deltap_common::compute_dp_escon(). This reduces code duplication and ensures PW and LCAO paths use identical constraint energy correction formulas. Regression tests pass: BN LCAO: γ=(3.999, 3.498), E-field=-1.154e-02 V/A H2O LCAO: γ=(-6.40, -3.17, -3.17), escon-corrected H2O PW: E=-417.011837 eV (unchanged)
1 parent b64368a commit 32094b5

1 file changed

Lines changed: 5 additions & 17 deletions

File tree

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "source_lcao/hamilt_lcao.h"
1414
#include "source_lcao/module_operator_lcao/deltap_lcao.h"
1515
#include "source_lcao/module_deltap/deltap.h"
16+
#include "deltap_common.h"
1617
#include "source_io/module_unk/unk_overlap_lcao.h"
1718
#include "source_io/module_hs/cal_r_overlap_R.h"
1819
#include "source_hsolver/hsolver_lcao.h"
@@ -772,23 +773,10 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
772773

773774
// DeltaP constraint energy correction (analogous to DeltaSpin's escon):
774775
// H_corr contributes ~Σλ·γ to eband. Subtract it to get physical E_DFT.
775-
double dp_escon = 0.0;
776-
if (use_constraint_matrix)
777-
{
778-
for (int a = 0; a < static_cast<int>(deltap_constraint_matrix_.size()); ++a)
779-
{
780-
double cv = 0.0;
781-
for (int i = 0; i < ucell.nat; ++i)
782-
cv += deltap_constraint_matrix_[a][i] * gamma_I[i][alpha];
783-
dp_escon -= deltap_constraint_lambda_[a] * cv;
784-
}
785-
}
786-
else
787-
{
788-
for (int iat = 0; iat < ucell.nat; ++iat)
789-
dp_escon -= lambda[iat] * gamma_I[iat][alpha];
790-
}
791-
this->pelec->f_en.dp_escon = dp_escon;
776+
std::vector<double> gamma_1d(ucell.nat);
777+
for (int iat = 0; iat < ucell.nat; ++iat)
778+
gamma_1d[iat] = gamma_I[iat][alpha];
779+
this->pelec->f_en.dp_escon = deltap_common::compute_dp_escon(lambda, gamma_1d);
792780

793781
// Effective electric field: E_eff = -λ_avg × π / a_alpha (a.u.)
794782
// Convert: 1 a.u. = 51.42 V/Å

0 commit comments

Comments
 (0)