Skip to content

[Dependency] module_gint includes source_lcao for the dH sparse output; two headers include more than they use #8232

Closed

Description

@Critsium-xy

Describe the Code Quality Issue

Under the module layering, source_hamilt (Hamiltonian operators) sits below the method modules source_pw and source_lcao, and source_pw sits below source_lcao. A few headers break this order, or include a much broader header than they need.

1. module_gint depends on LCAO output code

source_hamilt/module_gint/gint_dvlocal.h includes:

  • source_lcao/lcao_hs_arrays.h (line 7)
  • source_lcao/module_ri/abfs_vector3_order.h (line 8)

Gint_dvlocal mixes two jobs:

  • cal_dvlocal() integrates ⟨φ|V|∇φ⟩ on the real-space grid into three HContainers. This is grid integration and belongs in module_gint.
  • cal_dvlocal_R_sparse() and distribute_pvdpR_sparse() convert that result into the LCAO_HS_Arrays sparse format written by out_mat_dh. This is LCAO output code. It is the only reason for the two includes above. Its only caller is sparse_format::cal_dH in source_lcao/spar_dh.cpp, reached through the wrapper ModuleGint::cal_dvlocal_R_sparse in gint_interface.h.

A forward declaration does not help, because gint_dvlocal.cpp uses the members of both types.

2. source_pw includes an LCAO RI header for one enum

source_pw/module_pwdft/op_pw_exx.h:11 includes source_lcao/module_ri/conv_coulomb_pot_k.h, but only uses Conv_Coulomb_Pot_K::Coulomb_Type. That enum is defined in source_hamilt/module_xc/coulomb_config.h.

3. Two headers include more than they use

These are not layering violations, but they widen what every includer depends on:

  • source_hamilt/module_xc/kernels/xc_functional_op.h includes source_psi/psi.h. It only needs GetTypeReal, which it already gets from source_base/macros.h, and the base_device tags from source_base/module_device/types.h.
  • source_hamilt/module_vdw/vdwd2_parameters.h includes source_io/module_parameter/parameter.h, which brings in the global PARAM object. It only names Input_para, from input_parameter.h, and none of its includers use PARAM.

Suggested fix

  1. Move the sparse conversion out of Gint_dvlocal into source_lcao, next to its only caller. It can read the grid result through the existing get_pvdpRx/y/z() getters. Keep cal_dvlocal() in module_gint.
  2. In the three headers of items 2 and 3, include the narrower header that declares what they use.

No behavior or output change should result.

Acceptance

  • source_hamilt/module_gint no longer includes source_lcao.
  • op_pw_exx.h no longer includes source_lcao.
  • The full-feature build and the build without LCAO compile, and the unit and integration tests pass.

Additional Context

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

  1. changed the title [-][Dependency] Remove the upward includes from source_hamilt into source_lcao and source_pw (part 1)[/-] [+][Dependency] module_gint includes source_lcao for the dH sparse output; two headers include more than they use[/+] on Oct 29, 2026
  2. ABACUS-PR-BOT commented on Oct 29, 2026

    @ABACUS-PR-BOT
    Collaborator

    #8230 already carries the proposed extraction and all three include replacements. It remains open, so the dependency issue is still present on develop.

    For the two-spin testing tracked here, use out_mat_dh 1, nspin 2, gamma_only 0 and compare all six dhr{x,y,z}s{1,2} files. The follow-up should preserve the converter’s reverse-R mapping, orbital ownership and threshold cancellation; the current collector checks only spin 1.

    This diagnosis is based on source inspection at e5ad53046; no builds or runtime tests were run.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    RefactorRefactor ABACUS codesThe Absolute ZeroReduce the "entropy" of the code to 0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions