Skip to content

Add ENERGY_ONLY bit to eflag parameter for force computation#4914

Merged
akohlmey merged 6 commits into
lammps:developfrom
akohlmey:compute-energy-only
Mar 30, 2026
Merged

Add ENERGY_ONLY bit to eflag parameter for force computation#4914
akohlmey merged 6 commits into
lammps:developfrom
akohlmey:compute-energy-only

Conversation

@akohlmey

@akohlmey akohlmey commented Mar 12, 2026

Copy link
Copy Markdown
Member

Summary

This adds a new bit, ENERGY_ONLY, to the eflag variable which indicates that only the (global) energy is required. This can be used by force styles to skip over steps only required for computing forces and may result in significant savings for computations like MC fixes when they need to do a full energy computation.

Related Issue(s)

This addresses the feature request and thus closes #4847

Author(s)

Axel Kohlmeyer, Temple U

Licensing

By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).

Artificial Intelligence (AI) Tools Usage

By submitting this pull request, I confirm that I did NOT use any AI tools to generate
all or parts of the code and modifications in this pull request.

Backward Compatibility

Yes.

Implementation Notes

Rather than using "magic" numbers we now use the symbolic constants to set eflag and vflag to make the desired intent more obvious.

Post Submission Checklist

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The source code follows the LAMMPS formatting guidelines
  • Suitable new documentation files and/or updates to the existing docs are included
  • The added/updated documentation is integrated and tested with the documentation build system
  • The feature has been verified to work with the conventional build system
  • The feature has been verified to work with the CMake based build system
  • Suitable tests have been added to the unittest tree.

this adds a new bit flag ENERGY_ONLY to the eflag variable
and adds code to force computing styles to convert this into
an eflag_only variable that is zero or non-zero based on eflag
for fixes and computes calling force styles' compute() method
and only use the global energy add ENERGY_ONLY bit to eflag.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends LAMMPS’ energy/virial flag plumbing by introducing an ENERGY_ONLY bit, intended for call sites that only need the global potential energy (and no virial/per-atom tallies), and propagates this through core force components and several fixes/computes that frequently evaluate energies.

Changes:

  • Add ENERGY_ONLY to the energy flag enum and thread a corresponding eflag_only state through Pair, KSpace, Bond, Angle, Dihedral, Improper, and Fix EV setup logic.
  • Update multiple MC/FEP/DIELECTRIC/EXTRA-FIX call sites to request ENERGY_GLOBAL | ENERGY_ONLY and to use VIRIAL_NONE instead of literal 0.
  • Minor formatting/indentation cleanups in several headers.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/force.h Adds ENERGY_ONLY bit to energy flags; reformats related enums.
src/pair.h Tracks eflag_only in the Pair class state.
src/pair.cpp Masks eflag_either, computes eflag_only, and clears it in ev_unset().
src/kspace.h Tracks eflag_only in KSpace and resets it in ev_init() fast-path.
src/kspace.cpp Masks eflag_either and computes eflag_only in KSpace::ev_setup().
src/bond.h Adds eflag_only to bond EV flag state and reset chain.
src/bond.cpp Masks eflag_either and computes eflag_only in Bond::ev_setup().
src/angle.h Adds eflag_only to angle EV flag state and reset chain.
src/angle.cpp Masks eflag_either and computes eflag_only in Angle::ev_setup().
src/dihedral.h Adds eflag_only to dihedral EV flag state and reset chain.
src/dihedral.cpp Masks eflag_either and computes eflag_only in Dihedral::ev_setup().
src/improper.h Adds eflag_only to improper EV flag state and reset chain.
src/improper.cpp Masks eflag_either and computes eflag_only in Improper::ev_setup().
src/fix.h Adds eflag_only to fix EV flag state and reset chain; minor whitespace tweak.
src/fix.cpp Computes eflag_only in Fix::ev_setup() and documents ENERGY_ONLY.
src/MC/fix_widom.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/MC/fix_gcmc.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/MC/fix_sgcmc.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/MC/fix_neighbor_swap.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/MC/fix_mol_swap.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/MC/fix_atom_swap.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/MC/fix_charge_regulation.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/FEP/compute_fep.cpp Switches compute to request global-energy-only evaluation via `ENERGY_GLOBAL
src/FEP/compute_fep_ta.cpp Switches compute to request global-energy-only evaluation via `ENERGY_GLOBAL
src/EXTRA-FIX/fix_numdiff.cpp Uses `ENERGY_GLOBAL
src/EXTRA-FIX/fix_numdiff_virial.cpp Uses `ENERGY_GLOBAL
src/DIELECTRIC/fix_polarize_bem_icc.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL
src/DIELECTRIC/fix_polarize_bem_gmres.cpp Requests global-energy-only evaluation via `ENERGY_GLOBAL

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/FEP/compute_fep.cpp
Comment thread src/FEP/compute_fep_ta.cpp
Comment thread src/fix.cpp
Comment thread src/fix.cpp
Comment thread src/fix.h Outdated
Comment thread src/improper.cpp Outdated
@akohlmey
akohlmey marked this pull request as ready for review March 12, 2026 17:15
@akohlmey akohlmey moved this from In Progress to Ready for Review or Merge in LAMMPS Pull Requests Mar 12, 2026

@athomps athomps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I approve.

@akohlmey
akohlmey merged commit 1568ec3 into lammps:develop Mar 30, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review or Merge to Done in LAMMPS Pull Requests Mar 30, 2026
@akohlmey
akohlmey deleted the compute-energy-only branch March 30, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[Feature Request] Energy-only calculation flag for pair style to speed up Monte Carlo moves evaluation

4 participants