Repository navigation
refactor(dfpt): Ewald ion-ion follows QE d2ionq structure, shares module_ewald rgen - #8393
Open
Zanthoxylum wants to merge 1 commit into
Open
Zanthoxylum wants to merge 1 commit into
Zanthoxylum wants to merge 1 commit into
Conversation
Zanthoxylum
force-pushed
the
refactor-dfpt-ewald-ionion
branch
from
November 25, 2026 12:03
7b40cee to
cca17b4
Compare
…ule_ewald rgen Rewrite DFPT_Phon::ion_ion real-space/reciprocal-space split following the three-part structure of QE 6.8 PHonon/PH/d2ionq.f90: 1. reciprocal |G+q| kernel summed over ALL atom pairs (na == nb included, trivial phase on the diagonal) so diagonal blocks need no separate self machinery; 2. Gamma-kernel subtraction on diagonal blocks only, structure-factor phases summed over all neighbors (ASR-preserving bookkeeping); 3. real-space erfc-screened pair sum over shells from the shared H_Ewald_pw::rgen generator (same routine as ground-state energy/force/stress Ewald sums), replacing the file-local cube enumeration; integer triplets recovered exactly as n = R.G^T (a_i.g_j = delta_ij convention) to keep phase arguments exact. The in-memory mass scaling keeps the ABACUS convention D = Phi/sqrt(Ma Mb) (pair blocks 1/sqrt(Ma Mb), diagonal 1/Ma). Element-exact agreement with a verbatim QE d2ionq transcription verified on fcc Si at Gamma and TR-invariant q=(0.5,0,0); anchored by the new IonIonFccSiQHalfEwaldConsistency serial test (Hermiticity, alpha independence, Gamma anchor, determinism). Verification: - MODULE_DFPT_phon_serial 21/21, MODULE_DFPT_rho/pert/q0/write_dyn/stern green, MODULE_DFPT_pw_run_test (MPI) 3/3 - Si_qsmall end-to-end: dyn.q0/dyn.q1 bitwise identical to pre-refactor - agent_governance_check: no findings
Zanthoxylum
force-pushed
the
refactor-dfpt-ewald-ionion
branch
from
November 25, 2026 13:04
cca17b4 to
4c41e82
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rewrite the Ewald ion-ion part of
DFPT_Phon::ion_ionfollowing the three-partstructure of QE 6.8
PHonon/PH/d2ionq.f90, and remove the file-localneighbor-shell enumeration in favor of the shared
H_Ewald_pw::rgengeneratorthat the ground-state energy (
esolver_fp.cpp), force (force_pw.cpp) andstress (
stress_ewa.cpp) Ewald sums already use.Structure of the rewrite:
na == nb, where the phase is trivially 1), so the diagonal blocks need noseparate self-term machinery.
structure-factor phases summed over ALL neighbor atoms — the
acoustic-sum-rule-preserving bookkeeping of QE
d2ionq.H_Ewald_pw::rgengenerator, with the full complex phasee^{i 2pi q.L} on the pair blocks and the phase-free negative counterpart
accumulated on the row atom's diagonal in the same loop.
The integer triplet of each shell translation is recovered exactly as
n = R·G^T (the ABACUS reciprocal convention is a_i·g_j = delta_ij, no 2pi), so
the phase argument stays exact in small integers instead of going through a
R·q_cart floating-point path.
rgenreturns shells sorted by increasinglength and guards its buffer with
H_Ewald_pw::estimate_mxr; both are reusedunchanged.
The in-memory matrix keeps the ABACUS convention D = Phi/sqrt(Ma Mb)
(pair blocks carry 1/sqrt(Ma Mb), diagonal blocks 1/Ma), so downstream
consumers of
DFPT_Phonare untouched. Numerically the rewrite isequivalent to the previous implementation up to summation order: the
three-part split changes the floating-point accumulation order of the
ion-ion matrix, so the dynamical matrix elements shift by ~1e-7 relative
and the printed dfpt_si_g optical-mode frequencies move by ~2.5e-4 cm^-1
(relative 3.4e-7). The ground-state path is untouched:
etotreproducesthe old reference bitwise. The element-exact anchor is now the verbatim
QE
d2ionqtranscription (fcc Si at Gamma and TR-invariant q = (0.5,0,0)),which the rewritten sums match exactly.
Reference update (tests/01_PW/dfpt_si_g/result.ref)
The dfpt_freq_q0_m3/m4/m5 keys moved by -2.5e-4 cm^-1 (old 726.293102 /
727.655079 / 727.946529 -> new 726.292854 / 727.654832 / 727.946281) and
the three near-zero Gamma modes by a few 1e-6;
etotref/etotperatomrefare unchanged bitwise. The case threshold fordfpt_freq_* is 1e-4 (Autotest.sh: "same-binary reruns reproduce the six
printed decimals exactly"), so the summation-order shift crosses it by
design intent of the strict bound rather than by a physics change. The
new values come from a full rerun of the case on this PR and anchor to
the QE d2ionq oracle.
No documentation update required: internal refactor with no user-facing
behavior change — INPUT keys, output formats, and the build tree are
unchanged (the only test-layout change is moving the touched test file
into the
unittests/directory per the governance layout rule; the testbinary and case names are identical).
Why
enumeration duplicated ~80 lines of the trickiest pure-geometry code).
d2ionqstructure removes the diagonal self-block special casingand makes the ASR bookkeeping explicit, which eases future cross-checking
against QE (the Ewald term was recently exonerated in an unrelated
commensurate-q investigation by exactly such an element-level oracle
comparison; this rewrite keeps the code in a form where that comparison
is cheap to redo).
Verification
ctest -R MODULE_DFPT— 10/10 passed, including the newIonIonFccSiQHalfEwaldConsistencyinMODULE_DFPT_phon_serial(21 gtestcases green) covering Hermiticity, alpha independence, the Gamma anchor
value, and determinism on an fcc Si cell at q = (0.5, 0, 0).
MODULE_DFPT_pw_run_testandMODULE_DFPT_stern_testgreen (3/3 gtest cases in the former).
produces a
dyn.q1bitwise identical to the pre-refactor binary(max|old-new| = 0.000e+00 over the full 6x6 complex matrix), and
dyn.q0matches line-for-line.python3 tools/03_code_analysis/agent_governance_check.py --staged:no findings.
Notes for reviewers
test_dfpt_phon_ewald.cppmoves from the legacytest_serial/directory intounittests/(governance unit-test layoutrule: legacy test directories may only shrink; test(stodft): add Sto_Func coverage and consolidate unit tests #8334 set the precedent
with
test_dfpt_xc_analytic.cpp). It is still compiled by the sameMODULE_DFPT_phon_serialtarget — the SOURCES entry intest_serial/CMakeLists.txtreferences../unittests/, matching theexisting pattern; the shared fixture header is included as
../test_serial/dfpt_test_tool.h(the relative-../include style usedacross
source_relax/unittests/).test_serial/CMakeLists.txtandtest/CMakeLists.txtaddmodule_ewald/h_ewald_pw.cpp+dnrm2.cppto the DFPT test targets asraw sources (not the
hamilt_generalOBJECT library) because thatlibrary is built with MPI definitions and the serial test targets
compile without
__MPI(same ABI reason documented at the top oftest_serial/CMakeLists.txt).H_Ewald_pw::alpha/H_Ewald_pw::mxrmembers are not readon this path:
rgenandestimate_mxrtake everything as parameters,and the DFPT alpha search stays local (
ewald_alpha_search), mirroringQE's per-call-site alpha handling.