Skip to content

vdW correction calculated more than once in a single ion step #7680

Description

@Growl1234

Description

The vdW correction is currently evaluated more than once within a single ionic step.

The energy correction is first calculated before the SCF procedure. The force and stress code paths then create new vdW solver instances and recalculate the same correction from the unchanged atomic structure.

This affects both PW and LCAO calculations. Depending on the requested properties, a single ionic step may perform separate vdW evaluations for energy, forces, and stress.

For DFT-D4 in particular, this duplicated work can be noticeable and results in pauses both before and after the SCF procedure when running MPI-parallelized tasks (keep in mind that dftd4 library does not support MPI). DFT-D2 and DFT-D3 follow the same overall calling pattern, although their computational cost is usually much smaller.

Expected behavior

The vdW correction should be evaluated only once for each ionic configuration.

Before the SCF procedure, ABACUS should determine which quantities are required by the current task and calculate them together:

  • energy for energy-only calculations;
  • energy and forces when forces are requested;
  • energy, forces, and stress when both forces and stress are requested.

The resulting energy, force, and stress corrections should then be stored and reused by the subsequent SCF, force, and stress assembly code paths.

In particular, the force and stress modules should only consume previously calculated vdW results and should not create any new vdW solver instances or trigger additional evaluations.

Scope

This should be implemented at the common vdW interface level and cover all supported vdW methods. I expect D2 and D4 refactor to be straight-forward, while D3 requires extra care because its energy and force/stress paths are partially separated.

The refactoring should also ensure that each backend calculates all requested quantities in a single evaluation or traversal. For example, DFT-D3 should not perform an energy traversal followed by a separate force/stress traversal when derivatives are requested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions