Skip to content

Refactor DFT+U: rename and de-static Plus_U members, step 3 - #7859

Merged
mohanchen merged 10 commits into
deepmodeling:developfrom
mohanchen:2026-08-25-U2
Aug 26, 2026
Merged

Refactor DFT+U: rename and de-static Plus_U members, step 3#7859
mohanchen merged 10 commits into
deepmodeling:developfrom
mohanchen:2026-08-25-U2

Conversation

@mohanchen

@mohanchen mohanchen commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator
  • Rename U -> u_current, U0 -> u_target, omc -> occ_mat_ctrl, Yukawa -> use_yukawa
  • Rename accessors: get_hubbard_u -> get_u_current, get_hubbard_u0 -> get_u_target
  • Remove static qualifier from all 9 Plus_U_Base members (u_current, u_target, occ_mat_ctrl, use_yukawa, energy_u, orbital_corr, uramping, mixing_dftu, nspin)
  • Convert static accessors (get_energy, set_energy, get_u_current, etc.) and is_mixing_enabled/enable_mixing to non-static member functions
  • Extend Plus_U_Base::init_base() and Plus_U::init() signatures to accept hubbard_u, uramping, occ_mat_ctrl, mixing_dftu; move initialization logic out of input_conv.cpp into init_base() so members are set after the Plus_U instance is constructed (no longer relies on static state)
  • Remove redundant Plus_U assignments from input_conv.cpp; drop its include of dftu.h (dependencies made explicit at call sites)
  • Introduce ElecState::set_dftu_energy() / dftu_energy_ member so get_dftu_energy() no longer depends on Plus_U::get_energy() static state; ESolver_KS_PW and ESolver_KS_LAO push the energy after DFT+U update
  • Replace PARAM.inp.* with inp.* in setup_pot.cpp (inp is already a parameter)
  • Rename Input_para::omc -> occ_mat_ctrl (INPUT keyword 'omc' preserved for backward compatibility)
  • Add an example to test the energy calculation with the old DFT+U method.

- Rename U -> u_current, U0 -> u_target, omc -> occ_mat_ctrl, Yukawa -> use_yukawa
- Rename accessors: get_hubbard_u -> get_u_current, get_hubbard_u0 -> get_u_target
- Remove static qualifier from all 9 Plus_U_Base members (u_current, u_target,
  occ_mat_ctrl, use_yukawa, energy_u, orbital_corr, uramping, mixing_dftu, nspin)
- Convert static accessors (get_energy, set_energy, get_u_current, etc.) and
  is_mixing_enabled/enable_mixing to non-static member functions
- Extend Plus_U_Base::init_base() and Plus_U::init() signatures to accept
  hubbard_u, uramping, occ_mat_ctrl, mixing_dftu; move initialization logic
  out of input_conv.cpp into init_base() so members are set after the Plus_U
  instance is constructed (no longer relies on static state)
- Remove redundant Plus_U assignments from input_conv.cpp; drop its include
  of dftu.h (dependencies made explicit at call sites)
- Introduce ElecState::set_dftu_energy() / dftu_energy_ member so
  get_dftu_energy() no longer depends on Plus_U::get_energy() static state;
  ESolver_KS_PW and ESolver_KS_LAO push the energy after DFT+U update
- Replace PARAM.inp.* with inp.* in setup_pot.cpp (inp is already a parameter)
- Rename Input_para::omc -> occ_mat_ctrl (INPUT keyword 'omc' preserved for
  backward compatibility)

Verification: pending (compilation and tests to be run by user)
@mohanchen
mohanchen requested a review from lanshuyue August 25, 2026 09:54
@mohanchen mohanchen added DFT+U Issues related to DFT plus U function Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Aug 25, 2026
abacus_fixer added 9 commits August 25, 2026 19:41
Seven members (yukawa_lambda, npol, nlocal, gamma_only_local, ks_solver, cal_force, cal_stress) were only read by the LCAO subclass (Plus_U) and its component files under source_lcao/module_dftu/. They are now declared in Plus_U and assigned in Plus_U::init, so Plus_U_Base no longer carries LCAO-specific mutable workflow state.

Accordingly shorten Plus_U_Base::init_base signature by six parameters (yukawa_lambda, nlocal, gamma_only_local, ks_solver, cal_force, cal_stress); update the two call sites (Plus_U::init in dftu.cpp, PW path in setup_pot.cpp). Plus_U::init keeps its original signature so external callers (lcao_set.cpp) are unaffected.
dftu.hpp only provided the empty primary template for hamilt::DFTU. Move it into dftu_lcao.h (the sole includer), guarded by __DFTUTEMPLATE, matching the convention used by sibling LCAO operators (nonlocal.h, ekinetic.h, meta_lcao.h, veff_lcao.h, etc.) that inline the primary template instead of using a separate .hpp file. This also aligns with AGENTS.md rule 4 (avoid .hpp implementation headers).
Three LCAO DFT+U files had confusing names that hid which was the main implementation, the new operator, and the legacy operator. Rename for clarity:

  - dftu.h/.cpp -> dftu_lcao.h/.cpp   : Plus_U class (LCAO DFT+U physics, subclass of Plus_U_Base in dftu_base.h). The name now mirrors dftu_base.h.

  - dftu_lcao.h/.cpp -> dftu_lcao_op.h/.cpp : hamilt::DFTU operator (new method, dft_plus_u==1, onsite_radius projections). Operators now carry the _op suffix.

  - op_dftu_lcao.h/.cpp -> dftu_lcao_op_legacy.h/.cpp : hamilt::OperatorDFTU operator (old method, dft_plus_u==2, NAO first zeta projections, test-only). Renamed to mark it as legacy and group it with the new operator.

Class names are unchanged in this step (Plus_U, hamilt::DFTU, hamilt::OperatorDFTU); only filenames and #include paths change. Updated all ~40 includers across source_lcao, source_pw, source_esolver, source_estate, source_io, plus the module and test CMakeLists (the dftu_lcao_test links the new-operator cpp ../dftu_lcao_op.cpp, not the Plus_U cpp).
…yers

Replace Plus_U (LCAO-derived class) with Plus_U_Base (PW-layer base class) in
all non-LCAO interfaces. All DFT+U calls in PW/estate/test layers only use
base-class members, so the derived-type reference was unnecessary.

Changes:
- Remove #include "source_lcao/module_dftu/dftu_lcao.h" from PW/base headers
- Use #include "source_pw/module_pwdft/dftu_base.h" instead
- Replace Plus_U&/Plus_U* with Plus_U_Base&/Plus_U_Base* in:
  * source_pw/module_pwdft: force_pw, hamilt_pw, onsite_proj, op_pw_proj,
    stress_func, stress_onsite, stress_pw (6 headers + 7 impls)
  * source_estate/module_charge: chgmixing (PW + LCAO mixing functions)
  * source_pw/module_stodft/test: test_hamilt_sto, test_sto_tool
  * source_hsolver/test: diago_mock.h (3 explicit specializations)

Plus_U (derived) instances held by callers (e.g. ESolver_KS::dftu) continue
to work via implicit pointer/reference upcast to Plus_U_Base. No behavioral
change.
@mohanchen
mohanchen merged commit 0aa8d8b into deepmodeling:develop Aug 26, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DFT+U Issues related to DFT plus U function Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants