[Refactor] Organize cleans of source_base and clean source_psi's dependency#7386
Draft
Critsium-xy wants to merge 7 commits into
Draft
[Refactor] Organize cleans of source_base and clean source_psi's dependency#7386Critsium-xy wants to merge 7 commits into
Critsium-xy wants to merge 7 commits into
Conversation
…i.cpp Store npol as a Psi<T> member instead of reading PARAM.inp.nspin inside get_npol(). Copy/converting constructors and operator= propagate npol from the source Psi. Canonical allocators (psi_prepare::allocate_psi for PW, Setup_Psi::allocate_psi for LCAO) and the two spinor-aware Wannier PW construction sites inject npol via set_npol(). Other Psi construction sites (TDDFT psi_laststep, LCAO+PW psi_local, sDFT stochastic Psi, OFDFT, double-XC, intermediate buffers) keep the default npol=1 -- verified no caller queries get_npol() on them. psi.cpp no longer depends on source_io/module_parameter/parameter.h.
…ection
Plan A (storing npol as a Psi<T> member and threading set_npol() through every construction site) broke nspin==4 calculations because the hpsi_func lambda in hsolver_pw.cpp constructs psi_wrapper via the T* pointer constructor and never sets npol, so to_range() returned half the spinor-padded range. Fixing this would require tracking npol at every Psi wrapper construction site, of which there are many.
Switch to Plan C, mirroring the existing g_quit_out_dir injection pattern: source_base/tool_quit.{h,cpp} exposes set_global_npol() / get_global_npol() backed by an anonymous-namespace int defaulting to 1; Driver::reading() injects PARAM.globalv.npol next to the existing set_quit_out_dir() call; Psi::get_npol() reads ModuleBase::get_global_npol(). Behavior is byte-for-byte identical to the original PARAM.inp.nspin == 4 ? 2 : 1, since globalv.npol is computed from that exact mapping. psi.cpp no longer depends on parameter.h, which was the decoupling goal.
Reverts the Plan A bookkeeping: Psi::npol member, set_npol() setter, copy/operator= propagation, canonical-allocator injections in psi_prepare.cpp / setup_psi.cpp, Wannier injections, and the hsolver_pw.cpp lambda capture changes.
…lobalV
Move the three function-pair injection points that were living in tool_quit (set_quit_out_dir / get_global_out_dir, set_quit_calculation, set_global_npol / get_global_npol) to GlobalV bare extern variables in global_variable.{h,cpp}, matching the existing style of MY_RANK / ofs_running there.
Renames: g_quit_out_dir -> GlobalV::global_out_dir, g_quit_calculation -> GlobalV::calculation, g_global_npol -> GlobalV::npol. tool_quit no longer hosts injection state; only WARNING/QUIT/WARNING_QUIT/CHECK_WARNING_QUIT remain there. Driver writes the three values via direct assignment; psi.cpp reads GlobalV::npol; ORB_atomic_lm.cpp / ORB_nonlocal_lm.cpp read GlobalV::global_out_dir.
…dsp_cluster_id into GlobalV MODULE_HAMILT_XCTest_VXC and _GRADCORR manually list base-layer sources instead of linking the 'base' library, so they did not pull in global_variable.cpp. With GlobalV::npol now read by psi.cpp, the link step fails with an undefined reference. Add global_variable.cpp to both tests' SOURCES lists -- the same pattern they already use for matrix.cpp, timer.cpp, etc. Also move the g_dsp_cluster_id injection out of source_base/module_device/memory_op into GlobalV, for consistency with the other consolidated base-layer injection points: GlobalV::dsp_cluster_id (declared unconditionally, default 0) replaces the anonymous-namespace global, set_dsp_cluster_id() and get_dsp_cluster_id() are deleted, driver.cpp assigns directly, pw_basis_k.cpp reads directly, and memory_op.cpp's internal read uses GlobalV::dsp_cluster_id.
…ble.cpp Previous fix wrongly added source_base/global_variable.cpp to MODULE_HAMILT_XCTest_VXC and _GRADCORR SOURCES, which caused a duplicate-definition link error: xc3_mock.h (included by test_xc3.cpp and test_xc5.cpp) already defines GlobalV::ofs_running and GlobalV::ofs_device locally, so pulling in global_variable.cpp produced two definitions of each. Revert the SOURCES additions and instead add 'int npol = 1;' to the mock's namespace GlobalV block, alongside the existing local ofs_running / ofs_device. Now psi.cpp's GlobalV::npol reference is satisfied by the mock's definition (one per test translation unit, no clash). Verified by sweep: all other psi-linking tests already have 'base' in their LIBS (which carries global_variable.cpp); all tool_quit.cpp / ORB_*_lm.cpp test compilations are paired with global_variable.cpp; the only outliers were these two XC tests.
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

In the process of cleaning source_base, I injected many parameters of parameter.h as static member in modules in source_base. I moved them into a same file to make it clean.
This PR also removes psi.cpp's bad dependency.