Skip to content

Code quality: hamilt::Ekinetic (PW) and hamilt::EKinetic (LCAO) are different class templates differing only by letter case #7930

Description

@Flying-dragon-boxing

Describe the Code Quality Issue

In namespace hamilt, the kinetic-energy operator exists as two unrelated primary class templates whose names differ only by the case of one letter:

  • hamilt::EKinetic — LCAO version, source/source_lcao/module_operator_lcao/ekinetic.h, partial specialization EKinetic<OperatorLCAO<TK, TR>>.
  • hamilt::Ekinetic — PW version, source/source_pw/module_pwdft/op_pw_ekin.h, partial specialization Ekinetic<OperatorPW<T, Device>>.

This is the only operator pair with such a split. All sibling operator pairs (Veff, Meta, Nonlocal) follow a single-name convention: one primary template name shared between the PW and LCAO headers (with the primary body guarded by a shared __VEFFTEMPLATE-style inner macro), each side contributing its own partial specialization. Under that convention, Veff is one template with two specializations — greppable and unambiguous. The kinetic pair deviates: two templates, two names, one letter apart.

This naming already caused real harm, not just confusion:

Suggested fix

Either direction resolves the ambiguity:

  1. Unify with the sibling convention — one primary template name (e.g. Kinetic or EKinetic) with OperatorPW- and OperatorLCAO-based partial specializations. Prefer declaring the primary template once in a shared location instead of relying on the fragile shared __XXXTEMPLATE guard macros (which also use reserved double-underscore identifiers).
  2. Rename the PW class to a clearly distinct name, e.g. EkineticPW (precedent: OperatorEXXPW exists alongside OperatorEXX).

Direction 2 is the smaller change; direction 1 is more consistent with Veff/Meta/Nonlocal.

Additional Context

Surfaced while investigating #7927 (Intel classic build failure); the immediate guard-macro hazard for this pair was cleaned up in #7929, but the case-only naming itself remains.

Task list for Issue attackers (only for developers)

  • Identify the specific code file or section with the code quality issue.
  • Investigate the issue and determine the root cause.
  • Research best practices and potential solutions for the identified issue.
  • Refactor the code to improve code quality, following the suggested solution.
  • Ensure the refactored code adheres to the project's coding standards.
  • Test the refactored code to ensure it functions as expected.
  • Update any relevant documentation, if necessary.
  • Submit a pull request with the refactored code and a description of the changes made.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

RefactorRefactor ABACUS codes

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions