Description
Describe the Code Quality Issue
Spotted two sets of parameters are hard-coded in the Abacus code.
One is the functional type set, which are usually referred to as hard-coded 3 or 5 in the code.
The other is the threshold parameter for rho, which is also called density or charge, and for gradients. More strangely, the threshold parameters seem to mean different things in different code.
In xc_functional_libxc_tools.cpp (files mentioned hereafter are all in path/to/abacus/source/module_hamilt_general/module_xc), the threshold for rho is called "vanishing_charge" and is set to 1e-10 (the unit for thresholds are all in hartree, or atomic unit. ps: I had a brainfart here. The unit should be particle per volume.). In xc_functional_gradcorr.cpp, the threshold for rho is called epsr and is set to 1e-6. In xc_functional_wrapper_gcxc.cpp, the threshold for rho is called small and is set to 1e-10. HOWEVER, another threshold parameter in this file is called epsr and is set to 1e-6, and is used to control the threshold for spin magnetization. See below the code.
double epsr = 1.0e-6;
if (std::abs(zeta) - 1.0 > small || rho <= small || sqrt(std::abs(grho)) <= small)
{
return;
}
else
{
// ... ( - 1.0 + epsr ) < zeta < ( 1.0 - epsr )
// zeta = SIGN( MIN( ABS( zeta ), ( 1.D0 - epsr ) ) , zeta )
x = std::min(std::abs(zeta), (1.0 - epsr));
if(zeta>0)
{
zeta = x;
}
else
{
zeta = -x;
}
} //endif
Additional Context
No response
Task list for Issue attackers (only for developers)
- Identify the specific code file or section with the code quality issue.
- Investigate the issue and determine the root cause.
- Research best practices and potential solutions for the identified issue.
- Refactor the code to improve code quality, following the suggested solution.
- Ensure the refactored code adheres to the project's coding standards.
- Test the refactored code to ensure it functions as expected.
- Update any relevant documentation, if necessary.
- Submit a pull request with the refactored code and a description of the changes made.