Evaluate vdW corrections once per ionic step - #7712
Open
Growl1234 wants to merge 1 commit into
Open
Conversation
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.
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
VdwRequestandVdwResulttypes.ESolver_FP::before_scf().The individual vdW implementations were also adjusted so that all requested quantities are produced by one backend evaluation:
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.