Formatting files in /source/source_hamilt/module_xc#7399
Conversation
- Add tau_xc overload with hybrid_alpha parameter - Add ElecState::set_exx overload with cal_exx and hybrid_alpha parameters - Format code: one parameter per line, align code, initialize variables, one variable per line, add braces to single-line for/if
- Format function parameters to one per line - Initialize all variables when declared - Separate variable declarations onto individual lines - Add braces for single-line if/for statements - Improve code alignment and readability
zzlinpku
left a comment
There was a problem hiding this comment.
Code Review Summary
This is a well-executed code style refactoring PR. The new file naming scheme (xc_*.cpp for native implementations, libxc_*.cpp for Libxc wrappers) is clear and consistent. A few items to address:
🔴 Must fix: Header guard in libxc.h still uses the old name.
🟡 Consider: Update comment references to old file names, and note the reference member risk in exx_info.h.
zzlinpku
left a comment
There was a problem hiding this comment.
Code Review Summary
This is a well-structured refactoring PR. The file renames are consistent and improve readability, the indentation cleanup is thorough, and the exx_info.h lifetime warning is valuable.
However, there are two issues that should be addressed before merging — one potential name collision risk and one concern about mixing behavioral changes with formatting.
See inline comments for details.
| #endif // USE_LIBXC | ||
|
|
||
| #endif // XC_FUNCTIONAL_LIBXC_H No newline at end of file | ||
| #ifndef LIBXC_H |
There was a problem hiding this comment.
🔴 Header guard LIBXC_H is too generic — risk of collision with the actual libxc library.
The guard was renamed from XC_FUNCTIONAL_LIBXC_H to LIBXC_H. Since this project links against the external libxc library, a guard this generic could collide with libxc's own internal headers (or any future header that uses this common name). If a collision occurs, one header would silently be skipped, causing hard-to-diagnose compilation errors.
Suggestion: use a project-namespaced guard, e.g.:
#ifndef ABACUS_MODULE_XC_LIBXC_H
#define ABACUS_MODULE_XC_LIBXC_H| #include <array> | ||
|
|
||
| //tau_xc and tau_xc_spin: interface for calling xc_mgga_exc_vxc from LIBXC | ||
| //XC_POLARIZED, XC_UNPOLARIZED: internal flags used in LIBXC, |
There was a problem hiding this comment.
🔴 Behavioral change: tau_xc signature now takes hybrid_alpha as a parameter.
The old implementation read GlobalC::exx_info.info_global.hybrid_alpha directly inside the function body. Passing it as a parameter is a good decoupling improvement, but this is a functional change hidden inside a formatting PR.
- Please confirm all call sites have been updated (not just
test_xc4.cpp). The newxc_grad.cppmust also pass the correcthybrid_alphavalue wherevertau_xc/tau_xc_spinare called. - Consider noting this interface change explicitly in the PR description so reviewers don't miss it among ~3000 lines of formatting changes.
| // Perdew gradient correction on correlation: PRB 33, 8822 (1986) | ||
|
|
||
| // USE kinds | ||
| // implicit none |
There was a problem hiding this comment.
🟡 Redundant zero-initialization — all these variables are assigned real values on the very next lines.
For example, p1 is initialized to 0.0 here but immediately set to 0.0232660 two lines below. This pattern repeats throughout xc_gga_corr.cpp, xc_gga_exch.cpp, and xc_gga_wrap.cpp (~200+ lines total). While it suppresses compiler warnings, it significantly inflates the diff and makes it harder to spot the actual logic changes (like the tau_xc signature change).
Suggestion: either combine declaration and assignment (double p1 = 0.0232660;), or keep the original uninitialized declarations since they're assigned before any use.
| }; | ||
| Exx_Info_Global info_global; | ||
|
|
||
| // WARNING: Lifetime dependency |
There was a problem hiding this comment.
🟢 Good addition. This lifetime dependency warning is valuable — the dangling-reference risk with const& members is a subtle trap, and documenting it here will prevent future bugs if Exx_Info is ever copied or moved.
| #ifdef USE_LIBXC | ||
| #include "libxc.h" | ||
| #ifdef __EXX | ||
| #include "source_hamilt/module_xc/exx_info.h" |
There was a problem hiding this comment.
🟡 New #include dependency introduced.
The old xc_functional_gradcorr.cpp included xc_functional_libxc.h under USE_LIBXC, but did NOT include exx_info.h. This new include under __EXX is presumably needed because the old tau_xc read GlobalC::exx_info internally, while the new version requires the caller (gradcorr) to pass hybrid_alpha. This is consistent with the interface change — just flagging it for awareness since it's a new compile-time dependency.
Formatting files in /source/source_hamilt/module_xc