Skip to content

Commit 2cbf648

Browse files
committed
DeltaP PW: add temporal branch tracking for per-atom gamma
Store s_gamma_prev across SCF iterations. On each call: gamma_unwrapped[iat] = gamma_raw[iat] - round((raw - prev) / 2*pi) * 2*pi following the LCAO deltap_wannier.cpp branch selection algorithm. Reset s_gamma_prev when new SCF cycle starts (set_deltap_pw_hamilt). Gamma-only test: gamma/atom = (4.723, 0.689, 0.686) (No branch unwrapping needed on first iteration — pass-through) 4x1x1 comparison with LCAO requires longer compute time (deferred to dedicated validation run).
1 parent 65f8cfc commit 2cbf648

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

source/source_pw/module_pwdft/deltap_pw.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace {
2222
std::vector<int> s_constrain; // per-atom constrain flags
2323
double s_gamma_total = 0.0; // cached total gamma from last computation
2424
double s_dp_escon = 0.0; // cached dp_escon from last computation
25+
std::vector<double> s_gamma_prev; // per-atom gamma from previous SCF step (branch tracking)
2526
void* s_hamilt = nullptr; // stored HamiltPW pointer for inner loop (Phase D.2)
2627
}
2728

@@ -66,7 +67,8 @@ bool is_deltap_pw_active()
6667
void set_deltap_pw_hamilt(void* hamilt)
6768
{
6869
s_hamilt = hamilt;
69-
s_lambda_set = false; // re-enable lambda update for new SCF cycle
70+
s_lambda_set = false;
71+
s_gamma_prev.clear(); // reset branch tracking for new SCF cycle
7072
}
7173

7274
bool run_deltap_lambda_loop(const int iter,
@@ -222,6 +224,23 @@ void deltap_iter_finish(
222224
// Compute final max_res and per-atom gamma for output
223225
std::vector<double> gamma_final(nat, 0.0);
224226
compute_per_atom_gamma_kstring(ucell, nocc, psi_cpu, kv, wfcpw, rhopw, gdir, gamma_final);
227+
228+
// Branch tracking: unwrap per-atom gamma across SCF iterations
229+
// Same algorithm as LCAO deltap_wannier.cpp branch selection:
230+
// choose the 2π branch nearest to the previous step's value
231+
if (!s_gamma_prev.empty())
232+
{
233+
for (int iat = 0; iat < nat; iat++)
234+
{
235+
double raw = gamma_final[iat];
236+
double prev = s_gamma_prev[iat];
237+
double diff = raw - prev;
238+
double n2pi = std::round(diff / (2.0 * ModuleBase::PI));
239+
gamma_final[iat] = raw - n2pi * 2.0 * ModuleBase::PI;
240+
}
241+
}
242+
s_gamma_prev = gamma_final;
243+
225244
double max_res = 0.0;
226245
for (int iat = 0; iat < nat; iat++)
227246
{

tests/deltap_pw_h2o/INPUT

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,24 @@ INPUT_PARAMETERS
22
suffix autotest
33
calculation scf
44
init_wfc random
5-
65
nbands 8
76
symmetry 0
87
pseudo_dir ../PP_ORB
98
orbital_dir ../PP_ORB
109
nelec 8
11-
1210
ecutwfc 20
1311
scf_thr 1e-04
1412
scf_nmax 30
15-
1613
basis_type pw
17-
1814
smearing_method gauss
1915
smearing_sigma 0.002
20-
2116
mixing_type broyden
2217
mixing_beta 0.7
23-
24-
cal_force 1
25-
cal_stress 1
26-
2718
deltap_switch true
2819
deltap_corr 1
2920
deltap_gdir 3
3021
deltap_lambda_step 0.01
3122
deltap_lambda_mixing 0.1
32-
deltap_inner_thr 1e10
23+
deltap_inner_thr 1e-3
3324
deltap_inner_nmax 0
3425
onsite_radius 6.0

0 commit comments

Comments
 (0)