Commit 0aa8d8b
Refactor DFT+U: rename and de-static Plus_U members, step 3 (deepmodeling#7859)
* Refactor DFT+U: rename and de-static Plus_U members
- 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)
* fix bug
* fix bugs
* add an example to test the old DFT+U method with only scf energy, not force and stress
* update CASES_CPU.txt
* delete useless members
* Move LCAO-only DFT+U members from Plus_U_Base to Plus_U
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.
* Inline DFTU template header into dftu_lcao.h
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).
* Rename DFT+U LCAO files to reflect roles
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).
* refactor: eliminate reverse dependency of dftu_lcao.h from PW/base layers
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.
---------
Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>1 parent 8925fdc commit 0aa8d8b
73 files changed
Lines changed: 1769 additions & 1637 deletions
File tree
- source
- source_esolver
- source_estate
- module_charge
- source_hsolver/test
- source_io
- module_ctrl
- module_hs
- module_parameter
- test
- source_lcao
- module_dftu
- test
- source_pw
- module_pwdft
- module_stodft/test
- tests/02_NAO_Gamma
- scf_u_spin2_old
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
511 | 519 | | |
512 | 520 | | |
513 | 521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
213 | 219 | | |
214 | 220 | | |
215 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
| 37 | + | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
| 580 | + | |
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
624 | | - | |
| 624 | + | |
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
| |||
0 commit comments