Skip to content

Move the dV/dR sparse conversion out of module_gint and narrow three header includes - #8230

Open
Critsium-xy wants to merge 2 commits into
deepmodeling:developfrom
Critsium-xy:refactor/hamilt-drop-lcao-pw-includes
Open

Critsium-xy wants to merge 2 commits into
deepmodeling:developfrom
Critsium-xy:refactor/hamilt-drop-lcao-pw-includes

Conversation

@Critsium-xy

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Part of #7599 and #7604. This removes two of the includes from source_hamilt into source_lcao and source_pw, and one from source_pw into source_lcao. The remaining source_hamilt ones (exx_info_ri.h, cal_pseudo.cpp) overlap open PRs #8176 and #8222 and are left for later.

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • python3 tools/03_code_analysis/agent_governance_check.py --staged --format text: warnings only, listed under Governance Notes.
    • A static include-closure comparison against develop @ e5ad53046 for every file that reaches one of the changed headers. No file loses a header whose classes, aliases or macros it uses.
  • Result summary: not compiled locally yet. This is a draft until CI builds it.
  • Checks not run, with reason:
    • No local build or tests: the remote build machine I normally use was unavailable.
    • The relocated conversion only runs with out_mat_dh 1, nspin 2 and gamma_only 0. The two existing out_mat_dh cases (02_NAO_Gamma/scf_out_dh, 03_NAO_multik/scf_out_dh_t) use gamma_only 1 and nspin 1, so no CI case reaches it. Before marking this ready, I will run a copy of 03_NAO_multik/scf_out_dh_t with nspin 2 on this branch and on develop, and compare the written dH matrices.

What's changed?

Two commits, no intended behavior change:

  1. Narrow three header includes to what the header actually uses.
    • source_hamilt/module_xc/kernels/xc_functional_op.h: source_psi/psi.h → source_base/module_device/types.h. The kernel only needs GetTypeReal (already included from source_base/macros.h) and the base_device tags.
    • source_hamilt/module_vdw/vdwd2_parameters.h: source_io/module_parameter/parameter.h → input_parameter.h. Only Input_para is used; none of its includers touch PARAM.
    • source_pw/module_pwdft/op_pw_exx.h: source_lcao/module_ri/conv_coulomb_pot_k.h → source_hamilt/module_xc/coulomb_config.h. Only Conv_Coulomb_Pot_K::Coulomb_Type is used, and it is defined there. The two files that call conv_coulomb_pot_k.h functions (ewald_vq.hpp, exx_lri.hpp) include it directly.
  2. Move the dV/dR sparse conversion from module_gint to source_lcao.
    • Gint_dvlocal::cal_dvlocal() integrates ⟨φ|V|∇φ⟩ on the grid into three HContainers; that part stays.
    • Its other two members, cal_dvlocal_R_sparse and distribute_pvdpR_sparse, only converted that result into the LCAO_HS_Arrays format of the dH output. They were why module_gint included source_lcao/lcao_hs_arrays.h and source_lcao/module_ri/abfs_vector3_order.h.
    • Both are now file-local functions in source_lcao/spar_dh.cpp, next to their only caller sparse_format::cal_dH, and take the HContainers from the existing get_pvdpR*() getters.
    • The bodies are unchanged. The only edits: dead locals and the unused nspin/Grid_Driver parameters are dropped, and trace_lo is read through the public Gint::get_gint_info() instead of the protected member.
    • The wrapper ModuleGint::cal_dvlocal_R_sparse and the LCAO_HS_Arrays forward declaration in gint_interface.h are removed. veff_dh.cpp, the other user of Gint_dvlocal, only calls cal_dvlocal() and the getters and is untouched.

Governance Notes

  • INPUT/docs changes: none; no INPUT parameter or output format changes.
  • Core module impact: source_hamilt/module_gint, module_xc (kernel header), module_vdw (one header), source_pw/module_pwdft/op_pw_exx.h, source_lcao/spar_dh.cpp. No new files, so no CMake or Makefile changes.
  • Exceptions requested:
    • Global dependency budget: net 0. The one PARAM.globalv.nlocal line in spar_dh.cpp is the existing call site, reformatted.
    • Header include warnings (three): each one replaces an include with a narrower one.

🤖 Generated with Claude Code

Critsium-xy and others added 2 commits October 28, 2026 17:14
- xc_functional_op.h only needs GetTypeReal (source_base/macros.h) and the
  base_device tags its instantiations use; it no longer pulls source_psi/psi.h
  into the XC kernel.
- vdwd2_parameters.h only names Input_para, so it includes input_parameter.h
  instead of parameter.h and the global PARAM object.
- op_pw_exx.h only uses Conv_Coulomb_Pot_K::Coulomb_Type, which is defined in
  source_hamilt/module_xc/coulomb_config.h; it no longer includes the LCAO RI
  header conv_coulomb_pot_k.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gint_dvlocal::cal_dvlocal() integrates <phi|V|dphi> on the real-space grid.
Its other two members only converted that result into the LCAO_HS_Arrays
sparse format used by the dH output, which made module_gint include
source_lcao/lcao_hs_arrays.h and source_lcao/module_ri/abfs_vector3_order.h.

The conversion now lives next to its only caller, sparse_format::cal_dH in
source_lcao/spar_dh.cpp, as file-local functions that take the three
HContainers from Gint_dvlocal's existing getters. The bodies are unchanged;
the dead locals and unused nspin/Grid_Driver parameters are dropped, and the
wrapper ModuleGint::cal_dvlocal_R_sparse is removed. source_hamilt no longer
includes source_lcao from module_gint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Critsium-xy
Critsium-xy marked this pull request as ready for review October 28, 2026 13:48

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Static review found no implementation defect in the relocation or narrowed headers. git diff --check passed; build, runtime, and CI results were not verified.

Comment on lines +327 to +329
ModuleGint::Gint_dvlocal gint_dvlocal(vr_eff1, nspin, npol);
gint_dvlocal.cal_dvlocal();
cal_dvlocal_R_sparse(*gint_dvlocal.get_pvdpRx(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: Please retain the planned nspin=2, multi-k out_mat_dh comparison as a regression for all three Cartesian components in both spin channels. The existing legacy CSR checks in tests/integrate/validation_tools/props_mat.sh compare only s1 files, so reusing them unchanged would leave s2 unchecked.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants