Skip to content

Fix SCF residuals and density mixing on double grids - #8513

Open
AsTonyshment wants to merge 6 commits into
deepmodeling:developfrom
AsTonyshment:fix/scf_thr_type
Open

AsTonyshment wants to merge 6 commits into
deepmodeling:developfrom
AsTonyshment:fix/scf_thr_type

Conversation

@AsTonyshment

@AsTonyshment AsTonyshment commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

What's Changed?

Fix #8510.

  • Use the full density grid for real-space residuals and mixing, fixing skipped grid points and incorrect convergence checks with scf_thr_type=2.
  • Compute kinetic-energy density on the wavefunction grid and interpolate it to the dense grid, fixing buffer overruns in meta-GGA calculations.
  • Add a unit test for double-grid residuals and mixing, and run the SCAN density-output test with double grids on CPU and GPU.

@AsTonyshment
AsTonyshment force-pushed the fix/scf_thr_type branch 2 times, most recently from 1dd61f3 to 3f0626f Compare December 4, 2026 09:17
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes Solve before 3.11 labels Dec 4, 2026
for (int j = 0; j < 3; j++)
{
setmem_complex_op()(this->wfcr, 0, this->charge->nrxx);
setmem_complex_op()(this->wfcr, 0, this->basis->nmaxgr);

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.

it's not clear to me, what is 'basis->nmaxgr' instead of 'charge->nrxx'?

@AsTonyshment AsTonyshment Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Here, nmaxgr = max(npw, nrxx): npw is the number of plane-wave coefficients, and nrxx is the number of real-space grid points on this MPI process. We use wfcr for an in-place FFT, so it first holds the reciprocal-space coefficients and then the real-space data. It needs enough space for whichever is larger.

With double grids, charge->nrxx refers to the larger density grid, so using it here can write past the end of wfcr, causing segmentation fault.

The name is indeed pretty cryptic :( I'd guess parameters with odd names like this were probably all inherited from QE. I've added comments in the code to explain this.

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

Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes Solve before 3.11

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scf_thr_type=2 uses the wrong grid size for residuals and mixing with double grids

2 participants