Commit 5ff084e
abacus_fixer
deltaspin: lift 6 lambda-loop helpers out of SpinConstrain class
Phase 1 of god-class slimming: lift six lambda-loop helper methods
(check_rms_stop, check_restriction, check_gradient_decay,
cal_alpha_opt, print_header, print_termination) out of the
SpinConstrain<TK> class template and into free function templates
in the spinconstrain namespace.
Motivation
----------
spin_constrain.h is a god class with 7+ mixed responsibilities. The
lambda-loop workflow helpers are pure algorithms / I/O routines that
do not need to be part of the class interface; lifting them shrinks
the public API surface and clarifies the boundary between state
(SpinConstrain) and algorithm (free functions).
Changes
-------
- New header lambda_loop_helper.h declares 6 free function templates
taking 'const SpinConstrain<TK>&' as first parameter.
- lambda_loop_helper.cpp: 6 explicit specializations on
SpinConstrain<std::complex<double>> rewritten as free function
templates with explicit instantiation for std::complex<double>.
- template_helpers.cpp: 6 corresponding no-op stubs for
SpinConstrain<double> re-expressed as free function explicit
specializations (preserves linker surface for the nspin=2 stub).
- spin_constrain.h: removed 6 member-function declarations; added
public getters get_Mi() and get_current_sc_thr() so helpers can
read internal state without friendship.
- spin_constrain.cpp: get_nat/get_ntype/get_decay_grad(itype)/
get_decay_grad() promoted to const (required for const ref
parameter); get_decay_grad(itype) uses map::find instead of
operator[] to remain const-correct.
- lambda_loop.cpp: 7 call sites switched from
'this->helper(...)' to 'helper(*this, ...)'.
- test/template_helpers_test.cpp: call sites updated.
- test/CMakeLists.txt: MODULE_LCAO_deltaspin_template_helpers now
links lambda_loop_helper.cpp and basic_funcs.cpp (transitive
deps of the new free function implementations).
Verification
------------
- 'make -j 30' in build_max_para_test: clean build, abacus +
abacus_basic_para + all MODULE_LCAO_deltaspin_* targets linked.
- 'ctest -R deltaspin --output-on-failure': 5/5 tests passed
(basic_func, spin_constrain, template_helpers, pw, core).
Out of scope
------------
PW-specific methods (cal_mi_pw, update_psi_charge_pw_*,
calculate_delta_hcc) and LCAO-specific helpers (cal_mi_lcao,
convert, calculate_MW, collect_MW) remain as member functions
for now; they will be lifted in subsequent phases.1 parent ac49785 commit 5ff084e
8 files changed
Lines changed: 336 additions & 192 deletions
File tree
- source/source_lcao/module_deltaspin
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
| 262 | + | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
| 319 | + | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
358 | | - | |
| 357 | + | |
| 358 | + | |
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
| |||
Lines changed: 112 additions & 102 deletions
Large diffs are not rendered by default.
Lines changed: 139 additions & 0 deletions
| 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 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
622 | 622 | | |
623 | | - | |
| 623 | + | |
| 624 | + | |
624 | 625 | | |
625 | 626 | | |
626 | 627 | | |
| |||
638 | 639 | | |
639 | 640 | | |
640 | 641 | | |
641 | | - | |
| 642 | + | |
642 | 643 | | |
643 | 644 | | |
644 | 645 | | |
| |||
684 | 685 | | |
685 | 686 | | |
686 | 687 | | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
687 | 702 | | |
688 | 703 | | |
689 | 704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
371 | 346 | | |
372 | 347 | | |
373 | 348 | | |
| |||
450 | 425 | | |
451 | 426 | | |
452 | 427 | | |
453 | | - | |
| 428 | + | |
454 | 429 | | |
455 | | - | |
| 430 | + | |
456 | 431 | | |
457 | 432 | | |
458 | 433 | | |
| |||
464 | 439 | | |
465 | 440 | | |
466 | 441 | | |
467 | | - | |
| 442 | + | |
468 | 443 | | |
469 | 444 | | |
470 | 445 | | |
471 | | - | |
| 446 | + | |
472 | 447 | | |
473 | 448 | | |
474 | 449 | | |
| |||
482 | 457 | | |
483 | 458 | | |
484 | 459 | | |
| 460 | + | |
| 461 | + | |
485 | 462 | | |
486 | 463 | | |
487 | 464 | | |
| |||
492 | 469 | | |
493 | 470 | | |
494 | 471 | | |
| 472 | + | |
| 473 | + | |
495 | 474 | | |
496 | 475 | | |
497 | 476 | | |
| |||
0 commit comments