Skip to content

Evaluate vdW corrections once per ionic step - #7712

Open
Growl1234 wants to merge 1 commit into
deepmodeling:developfrom
Growl1234:dftd4
Open

Evaluate vdW corrections once per ionic step#7712
Growl1234 wants to merge 1 commit into
deepmodeling:developfrom
Growl1234:dftd4

Conversation

@Growl1234

@Growl1234 Growl1234 commented Jul 30, 2026

Copy link
Copy Markdown

Previously, ABACUS evaluated the vdW energy before SCF and then created additional vdW solver instances in the force and stress code paths. Depending on the calculation type, the same dispersion correction could therefore be calculated two or three times within one ionic step. This affected PW, LCAO, OFDFT, and DoubleXC workflows. The duplicated work was particularly noticeable for DFT-D4, where calculations could pause both before and after SCF.

This PR refactor the vdW correction workflow so that the required dispersion quantities are evaluated only once for each ionic configuration.

Closes #7680.

Changes

  • Introduce explicit VdwRequest and VdwResult types.
  • Evaluate the vdW correction once in ESolver_FP::before_scf().
  • Store the resulting energy, forces, and stress for the current ionic step.
  • Pass the cached result explicitly to PW, LCAO, and OFDFT force/stress assembly code.
  • Remove vdW solver construction from downstream force and stress modules.
  • Reuse the same vdW result in the DoubleXC workflow.
  • Remove the previous getter interfaces that could implicitly trigger additional calculations.

The individual vdW implementations were also adjusted so that all requested quantities are produced by one backend evaluation:

  • DFT-D2 accumulates energy, forces, and stress in one pair/image traversal.
  • DFT-D3 accumulates energy during the existing force/stress pair and ATM traversals, avoiding a separate energy evaluation.
  • DFT-D4 obtains energy, gradient, and virial from one dftd4_get_dispersion() call.

For energy-only calculations, the backends retain an energy-only path and avoid unnecessary derivative calculations.

DFT-D3 considerations

The DFT-D3 refactoring requires particular care because its energy and derivative implementations previously followed partially separate paths.

The combined implementation preserves the existing periodic-image counting factors for pair and three-body ATM contributions, including self-image and repeated-index cases. Coordination-number derivatives and the existing force and stress assembly remain unchanged.

Testing

Here is my simple test: test.zip

In the tested cell-relaxation case, the relevant timings changed from:

  • Vdwd4::cal_energy: 4.82 s [Pre-SCF]
  • Vdwd4::cal_force: 17.03 s [Post-SCF]

to:

  • Vdwd4::evaluate: 15.89 s [Pre-SCF]

The total DFT-D4 time was therefore reduced from approximately 21.85 s to 15.89 s, while the total runtime decreased from 49.79 s to 43.16 s.

The pre-SCF DFT-D4 timing apparently increased, which exactly reflects that all requested dispersion quantities are now calculated and accounted for at that point, rather than being split between the pre-SCF and force-assembly stages.

Copilot AI review requested due to automatic review settings July 30, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes labels Jul 30, 2026
Copilot AI review requested due to automatic review settings July 30, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 31, 2026 12:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 31, 2026 12:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 31, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vdW correction calculated more than once in a single ion step

3 participants