Skip to content

Fix missing last term in B-spline factor for structure factor - #8210

Open
Cstandardlib wants to merge 2 commits into
deepmodeling:developfrom
Cstandardlib:fix-nbspline
Open

Cstandardlib wants to merge 2 commits into
deepmodeling:developfrom
Cstandardlib:fix-nbspline

Conversation

@Cstandardlib

@Cstandardlib Cstandardlib commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fix missing last term in B-spline deconvolution factor for structure factor (nbspline).

Summary

Fix an error in the B-spline correction coefficients used by Structure_Factor::bsplinecoef.

The previous denominator sum omitted the last nonzero integer sample of the Cardinal B-spline.
This gives incorrect structure factors when nbspline is enabled, with a particularly large error at low orders.
For nbspline = 2, the zero-frequency structure factor is multiplied by 8, which also scales the integrated
atomic-superposition initial density before any subsequent normalization.

Linked Issue

Fix #8092

Unit Tests and/or Case Tests for my changes

  • Commands run:
  • Result summary:
  • Checks not run, with reason:

What's changed?

  • Example: brief summary of the user-visible or developer-facing change.

Governance Notes

  • INPUT/docs changes:
  • Core module impact:
  • Exceptions requested:

… by (1-1/N!)^-3

The denominator loop in Structure_Factor::bsplinecoef missed the last integer-point sample M_{N+1}(N) = 1/N! of the Cardinal B-spline, so the G=0 deconvolution factor was 1/(1-1/N!) per direction instead of 1, and S(G=0) -- the integrated electron number -- was scaled by (1-1/N!)^-3 (8x at nbspline=2). The method is exact at G=0 at any order by partition of unity, so this was an off-by-one implementation error, not low-order interpolation error.

Add a unit test asserting b(0)=1 for norder = 2,4,6,10,20 and a low-order OFDFT integration case 35_OF_LPS_bspline; regenerate references of the six existing nbspline=10 cases (energies shift by ~1e-4 eV, the intended behavior change).
@Cstandardlib Cstandardlib changed the title Fix missing last term in structure factor (nbspline) Fix missing last term in B-spline factor for structure factor Oct 25, 2026
@Cstandardlib
Cstandardlib marked this pull request as ready for review October 25, 2026 17:09

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review found the endpoint correction consistent with the spline support, phase and FFT normalization on the documented cutoff or odd-full-grid paths. Runtime tests and CI diagnostics were not run; the existing even-full-grid Nyquist limitation remains outside this validation. Two nonblocking follow-ups below.

totalforceref 0.787244
totalstressref 107.895762
totaltimeref +1.49612
etotref -231.6927874142393

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Please record the exact commands, producing source/executable identity, build configuration, and results used to generate the six replacement references and the new case. The correction explains why spline results change, but the blank validation section leaves their numerical provenance unverified. Please also note unrun checks and why this algorithm-only correction needs no INPUT-doc update.

@@ -0,0 +1,30 @@
INPUT_PARAMETERS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Please trim the trailing spaces in the new INPUT and STRU files (INPUT line 1; STRU lines 8–10 and 18). They are harmless to parsing, but currently make git diff --check fail; cleanup can be a follow-up after merge.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] nbspline gives wrong structure factors at low orders:

2 participants