Commit 4397300
DFT+U refactor, step 7 (#7909)
* feat(estate): add OccMatMixer skeleton for DFT+U occupation mixing
Introduce OccMatMixer in source_estate to own the flattened
occupation-matrix buffers (uom/uom_save) currently embedded in
Plus_U_Base. Step 1 only adds the class skeleton (init/seed_save/
begin_iter/collect/mix) and wires occ_mixer.cpp into CMake; the
migration of state and call sites follows in subsequent commits.
* refactor(pwdft): attach OccMatMixer to Plus_U_Base (transitional)
Compose Plus_U_Base with a std::unique_ptr<OccMatMixer>, constructed in
init_base only when mixing_dftu != 0 so that "mixer exists" doubles as
the mixing-on flag. The legacy uom_array/uom_save members and the
is_mixing_enabled/enable_mixing accessors are kept for now; they are
removed in a later commit once all call sites migrate.
Invert the Charge_Mixing dependency: OccMatMixer no longer calls
Charge_Mixing::mix_uom itself. It only owns the flat buffers, exposes
them via uom()/uom_save(), and provides write_back() to deserialize the
mixed result. The PW driver (which already links charge_mixing) feeds
the buffers to mix_uom. This keeps occ_mixer.cpp dependent solely on
occ_matrix.h, so the PW and LCAO dftu unit tests link with just
occ_matrix.cpp + occ_mixer.cpp instead of dragging in the planewave/xc
dependency chain (PW_Basis::real2recip, XC_Functional::ked_flag).
Wire occ_mixer.cpp into the dftu_base_test and dftu_lcao_test sources.
* refactor(pwdft): route cal_occ_pw mixing through OccMatMixer
cal_occ_pw now drives the PW mixing orchestration via the composed
OccMatMixer instead of the legacy uom_array/uom_save members:
begin_iter flattens the saved occ into uom_save, collect flattens the
fresh occ into uom, the buffers are fed to Charge_Mixing::mix_uom, and
write_back deserializes the mixed result. The enable condition switches
from is_mixing_enabled() to has_occ_mixer().
The flat save/new writes now run only when a mixer exists; they were
previously executed unconditionally but their results were only read
inside the mixing branch, so behavior is bit-identical. uom_array and
uom_save are now dead members and are removed in a later commit.
OccMatMixer::begin_iter no longer performs copy_to_save itself; that
snapshot stays in cal_occ_pw because it must precede occmat_.zero().
* refactor(estate): switch PW uom allocation to OccMatMixer flat_size
In chgmixing_ks_pw, drop the now-dead dftu.enable_mixing() call (the
mixer is constructed in init_base and cal_occ_pw reads has_occ_mixer()),
gate the uom_mdata allocation on has_occ_mixer() instead of
inp.mixing_dftu, and size it with occ_mixer().flat_size() which equals
the previous get_size_pot_uterm_pw(). The LCAO branch's dead
enable_mixing() call is left for the PARAM-dependency cleanup step.
* refactor(pwdft): drop dead uom_array/uom_save/is_mixing_enabled
Remove the flat occupation buffers uom_array/uom_save from Plus_U_Base
(now owned by OccMatMixer) together with their resize in init_base, and
the is_mixing_enabled() accessor that has no callers left. enable_mixing()
and the mixing_dftu member stay for now because the LCAO path still calls
enable_mixing(); they are removed alongside the PARAM.inp.mixing_dftu
dependency in the cleanup step.
* refactor(dftu): route LCAO plain mixing through OccMatMixer::mix_plain
Add OccMatMixer::mix_plain(occmat, beta), which delegates to
elecstate::mix_occ_with_save on the nested occupation blocks (the flat
buffers are PW/Broyden-only). Replace the two duplicated LCAO k/gamma
call sites with dftu.occ_mixer().mix_plain(dftu.occmat(), mixing_beta)
and gate them on has_occ_mixer() instead of PARAM.inp.mixing_dftu,
removing that cross-layer global read from dftu_nao_occ.cpp.
* refactor(pwdft): remove mixing_dftu member and dead enable_mixing calls
The mutable workflow switch is fully retired: drop the LCAO branch's dead
dftu.enable_mixing() block in chgmixing_ks_lcao (the flag it set was never
read), the enable_mixing() accessor, and the mixing_dftu member of
Plus_U_Base. The init_base mixing_dftu parameter is kept as the sole
decision input for constructing the OccMatMixer; presence of the mixer is
now the only "mixing on" signal.
* add ut for occ_mixer
* fix(dftu): serialize occ_save in write_save_to_flat; fix test double-free
OccupationMatrix::write_save_to_flat is documented to flatten occ_save_
into the uom_save mixing buffer, but it was reading occ_ instead, so the
first mixing step after seed_save/begin_iter used the wrong history
matrix.
In test_occ_mixer, Statistics::~Statistics() owns and delete[]s
iat2it/iat2ia, so backing them with std::vector storage caused a
double-free. Allocate them with new[] instead and drop the extra
backing vectors.
Verified: cmake --build build --target MODULE_ESTATE_occ_mixer &&
OMP_NUM_THREADS=1 ./build/source/source_estate/test/MODULE_ESTATE_occ_mixer
(4/4 tests pass).
* build(Makefile): add occ_mixer.o to OBJS_ELECSTAT
The Makefile build links dftu_base_occ.o/dftu_nao_occ.o against
OccMatMixer, but occ_mixer.cpp was missing from Makefile.Objects,
causing undefined-reference link errors for write_back/mix_plain.
CMake already wires it via source_estate/CMakeLists.txt.
* fix(base): update test call sites to world_comm_domain()
PR #7888 tests were added before PR #7900 renamed
ModuleBase::world_communication_domain() to
ModuleBase::world_comm_domain(); update the three affected
test files so the parallel test targets build again.
Verified: cmake --build build --target
MODULE_BASE_parallel_domain_grid MODULE_BASE_para_gemm
MODULE_BASE_parallel_device all succeed.
---------
Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>1 parent 912824c commit 4397300
17 files changed
Lines changed: 450 additions & 46 deletions
File tree
- source
- source_base/test_parallel
- source_estate
- module_charge
- test
- source_lcao/module_dftu
- test
- source_pw/module_pwdft
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
| 287 | + | |
287 | 288 | | |
288 | 289 | | |
289 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 135 | + | |
| 136 | + | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
| |||
193 | 191 | | |
194 | 192 | | |
195 | 193 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | 194 | | |
202 | 195 | | |
203 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
| 283 | + | |
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
| 296 | + | |
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
| |||
0 commit comments