Skip to content

Commit 707f092

Browse files
mohanchenabacus_fixerErjieWu
authored
Formatting files in /source/source_hamilt/module_xc, try to remove GlobalC::exx_info (#7399)
* Refactor: Improve code style in xc_functional_libxc files - 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 * update * Refactor XC functional files for code style compliance - 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 * modify * update * update * update xc * update * fix bug * change libxc.h to libxc_abacus.h * format libxc_setup.cpp * update libxc_setup.cpp * refactor: split Exx_Info struct into independent header files This is the first step of removing GlobalC::exx_info global variable. ## Changes - Split Exx_Info into 4 independent header files: - exx_info_global.h: Exx_Info_Global (core global settings) - exx_info_lip.h: Exx_Info_Lip (LIP method parameters) - exx_info_ri.h: Exx_Info_RI (RI method parameters) - exx_info_opt_abfs.h: Exx_Info_Opt_ABFs (optimized ABF parameters) - Modified exx_info.h to include the 4 new headers - Updated all references from Exx_Info::Exx_Info_* to Exx_Info_* ## Benefits 1. Reduced coupling: modules can now include only needed headers 2. Types are now independent, preparing for parameter passing 3. GlobalC::exx_info remains unchanged, fully backward compatible ## Next Steps (Phase 2-3) Phase 2: Replace references with value copies in Exx_Info_Lip/RI - Exx_Info_Lip: ccp_type& and hse_omega& -> value copies - Exx_Info_RI: coulomb_param& -> value copy - This removes dependency on Exx_Info_Global lifetime Phase 3: Remove GlobalC::exx_info global variable - Pass Exx_Info_* as parameters instead of global access - Update ~60 files that use GlobalC::exx_info - Modules: module_xc, module_ri, source_lcao, source_esolver, source_pw * update * update * fix * refactor: phase2 - replace references with value copies in Exx_Info_Lip/RI ## Changes ### 1. Modified struct definitions **`exx_info_lip.h`**: Changed references to value copies - `const Ccp_Type& ccp_type` → `Ccp_Type ccp_type` - `const double& hse_omega` → `double hse_omega = 0.11` - Removed constructor dependency on Exx_Info_Global **`exx_info_ri.h`**: Changed reference to value copy - `const std::map<...>& coulomb_param` → `std::map<...> coulomb_param` - Removed constructor dependency on Exx_Info_Global ### 2. Added sync method in exx_info.h ```cpp void sync_from_global() { info_lip.ccp_type = info_global.ccp_type; info_lip.hse_omega = info_global.hse_omega; info_ri.coulomb_param = info_global.coulomb_param; } ``` ### 3. Added sync calls | File | Location | Purpose | |------|----------|----------| | `input_conv.cpp` | Line 520 | After EXX parameter initialization | | `esolver_lrtd_lcao.cpp` | Lines 266, 404 | After setting ccp_type | | `RPA_LRI.hpp` | Line 148 | After setting ccp_type | ## Benefits 1. **Eliminated lifetime dependency**: Exx_Info_Lip and Exx_Info_RI are now independent 2. **Safe to copy/move**: No dangling reference risks 3. **Ready for parameter passing**: Structs can be safely passed as function parameters 4. **Fully backward compatible**: GlobalC::exx_info still exists and works unchanged ## Next Steps (Phase 3) Remove GlobalC::exx_info global variable by: - Passing Exx_Info_* structs as parameters - Updating ~60 files that access GlobalC::exx_info - Modules: module_xc, module_ri, source_lcao, source_esolver, source_pw * update --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn> Co-authored-by: Erjie Wu <110683255+ErjieWu@users.noreply.github.com>
1 parent 33cedb4 commit 707f092

58 files changed

Lines changed: 3575 additions & 2866 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/Makefile.Objects

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -502,20 +502,20 @@ OBJS_SYMMETRY=symm_other.o\
502502

503503
OBJS_XC=xc_functional.o\
504504
xc_functional_op.o\
505-
xc_functional_vxc.o\
506-
xc_functional_gradcorr.o\
507-
xc_functional_wrapper_xc.o\
508-
xc_functional_wrapper_gcxc.o\
509-
xc_functional_libxc.o\
510-
xc_functional_libxc_tools.o\
511-
xc_functional_libxc_vxc.o\
512-
xc_functional_libxc_wrapper_xc.o\
513-
xc_functional_libxc_wrapper_gcxc.o\
514-
xc_functional_libxc_wrapper_tauxc.o\
515-
xc_funct_exch_lda.o\
516-
xc_funct_corr_lda.o\
517-
xc_funct_exch_gga.o\
518-
xc_funct_corr_gga.o\
505+
xc_pot.o\
506+
xc_grad.o\
507+
xc_lda_wrap.o\
508+
xc_gga_wrap.o\
509+
libxc_setup.o\
510+
libxc_tools.o\
511+
libxc_pot.o\
512+
libxc_lda_wrap.o\
513+
libxc_gga_wrap.o\
514+
libxc_mgga_wrap.o\
515+
xc_lda_exch.o\
516+
xc_lda_corr.o\
517+
xc_gga_exch.o\
518+
xc_gga_corr.o\
519519
xc_funct_hcth.o\
520520
exx_info.o\
521521

source/source_estate/module_pot/pot_xc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "source_hamilt/module_xc/xc_functional.h"
55

66
#ifdef USE_LIBXC
7-
#include "source_hamilt/module_xc/xc_functional_libxc.h"
7+
#include "source_hamilt/module_xc/libxc_abacus.h"
88
#endif
99

1010
namespace elecstate

source/source_hamilt/module_surchem/test/CMakeLists.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,28 @@ AddTest(
3030
TARGET MODULE_HAMILT_surchem_cal_vcav
3131
LIBS parameter ${math_libs} planewave device base container
3232
SOURCES cal_vcav_test.cpp ../cal_vcav.cpp ../surchem.cpp ../../../source_pw/module_pwdft/parallel_grid.cpp
33-
../../module_xc/xc_functional_gradcorr.cpp ../../module_xc/xc_functional.cpp
34-
../../module_xc/xc_functional_wrapper_xc.cpp ../../module_xc/xc_functional_wrapper_gcxc.cpp
35-
../../module_xc/xc_functional_libxc.cpp
36-
../../module_xc/xc_functional_libxc_vxc.cpp
37-
../../module_xc/xc_functional_libxc_wrapper_xc.cpp
38-
../../module_xc/xc_functional_libxc_wrapper_gcxc.cpp
39-
../../module_xc/xc_functional_libxc_wrapper_tauxc.cpp
40-
../../module_xc/xc_funct_corr_gga.cpp ../../module_xc/xc_funct_corr_lda.cpp ../../module_xc/xc_funct_exch_gga.cpp
41-
../../module_xc/xc_funct_exch_lda.cpp ../../module_xc/xc_funct_hcth.cpp
33+
../../module_xc/xc_grad.cpp ../../module_xc/xc_functional.cpp
34+
../../module_xc/xc_lda_wrap.cpp ../../module_xc/xc_gga_wrap.cpp
35+
../../module_xc/libxc_setup.cpp
36+
../../module_xc/libxc_pot.cpp
37+
../../module_xc/libxc_lda_wrap.cpp
38+
../../module_xc/libxc_gga_wrap.cpp
39+
../../module_xc/libxc_mgga_wrap.cpp
40+
../../module_xc/xc_gga_corr.cpp ../../module_xc/xc_lda_corr.cpp ../../module_xc/xc_gga_exch.cpp
41+
../../module_xc/xc_lda_exch.cpp ../../module_xc/xc_hcth.cpp
4242
)
4343

4444
AddTest(
4545
TARGET MODULE_HAMILT_surchem_cal_vel
4646
LIBS parameter ${math_libs} planewave device base container
4747
SOURCES cal_vel_test.cpp ../cal_vel.cpp ../surchem.cpp ../cal_epsilon.cpp ../minimize_cg.cpp ../../../source_pw/module_pwdft/parallel_grid.cpp
48-
../../module_xc/xc_functional_gradcorr.cpp ../../module_xc/xc_functional.cpp
49-
../../module_xc/xc_functional_wrapper_xc.cpp ../../module_xc/xc_functional_wrapper_gcxc.cpp
50-
../../module_xc/xc_functional_libxc.cpp
51-
../../module_xc/xc_functional_libxc_vxc.cpp
52-
../../module_xc/xc_functional_libxc_wrapper_xc.cpp
53-
../../module_xc/xc_functional_libxc_wrapper_gcxc.cpp
54-
../../module_xc/xc_functional_libxc_wrapper_tauxc.cpp
55-
../../module_xc/xc_funct_corr_gga.cpp ../../module_xc/xc_funct_corr_lda.cpp ../../module_xc/xc_funct_exch_gga.cpp
56-
../../module_xc/xc_funct_exch_lda.cpp ../../module_xc/xc_funct_hcth.cpp
48+
../../module_xc/xc_grad.cpp ../../module_xc/xc_functional.cpp
49+
../../module_xc/xc_lda_wrap.cpp ../../module_xc/xc_gga_wrap.cpp
50+
../../module_xc/libxc_setup.cpp
51+
../../module_xc/libxc_pot.cpp
52+
../../module_xc/libxc_lda_wrap.cpp
53+
../../module_xc/libxc_gga_wrap.cpp
54+
../../module_xc/libxc_mgga_wrap.cpp
55+
../../module_xc/xc_gga_corr.cpp ../../module_xc/xc_lda_corr.cpp ../../module_xc/xc_gga_exch.cpp
56+
../../module_xc/xc_lda_exch.cpp ../../module_xc/xc_hcth.cpp
5757
)

source/source_hamilt/module_xc/CMakeLists.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ add_library(
22
xc_
33
OBJECT
44
xc_functional.cpp
5-
xc_functional_vxc.cpp
6-
xc_functional_gradcorr.cpp
7-
xc_functional_wrapper_xc.cpp
8-
xc_functional_wrapper_gcxc.cpp
9-
xc_funct_exch_lda.cpp
10-
xc_funct_corr_lda.cpp
11-
xc_funct_exch_gga.cpp
12-
xc_funct_corr_gga.cpp
13-
xc_funct_hcth.cpp
14-
xc_functional_libxc.cpp
15-
xc_functional_libxc_tools.cpp
16-
xc_functional_libxc_vxc.cpp
17-
xc_functional_libxc_wrapper_xc.cpp
18-
xc_functional_libxc_wrapper_gcxc.cpp
19-
xc_functional_libxc_wrapper_tauxc.cpp
5+
xc_pot.cpp
6+
xc_grad.cpp
7+
xc_lda_wrap.cpp
8+
xc_gga_wrap.cpp
9+
xc_lda_exch.cpp
10+
xc_lda_corr.cpp
11+
xc_gga_exch.cpp
12+
xc_gga_corr.cpp
13+
xc_hcth.cpp
14+
libxc_setup.cpp
15+
libxc_tools.cpp
16+
libxc_pot.cpp
17+
libxc_lda_wrap.cpp
18+
libxc_gga_wrap.cpp
19+
libxc_mgga_wrap.cpp
2020
exx_info.cpp
2121
)
2222

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,23 @@
11
#ifndef EXX_INFO_H
22
#define EXX_INFO_H
33

4-
#include "source_lcao/module_ri/conv_coulomb_pot_k.h"
5-
6-
#include <vector>
7-
#include <map>
8-
#include <string>
4+
#include "exx_info_global.h"
5+
#include "exx_info_lip.h"
6+
#include "exx_info_ri.h"
7+
#include "exx_info_opt_abfs.h"
98

109
struct Exx_Info
1110
{
12-
struct Exx_Info_Global
13-
{
14-
bool cal_exx = false;
15-
16-
std::map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> coulomb_param;
17-
18-
// Fock:
19-
// "alpha": "0"
20-
// "singularity_correction": "limits" / "spencer" / "revised_spencer" / "massidda" / "carrier"
21-
// "lambda": "0.3"
22-
// "Rcut"
23-
// Erfc:
24-
// "alpha": "0"
25-
// "omega": "0.11"
26-
// "singularity_correction": "limits" / "spencer" / "revised_spencer"
27-
// "Rcut"
28-
29-
Conv_Coulomb_Pot_K::Ccp_Type ccp_type;
30-
double hybrid_alpha = 0.25;
31-
double hse_omega = 0.11;
32-
double mixing_beta_for_loop1 = 1.0;
33-
34-
bool separate_loop = true;
35-
size_t hybrid_step = 1;
36-
};
3711
Exx_Info_Global info_global;
38-
39-
struct Exx_Info_Lip
40-
{
41-
const Conv_Coulomb_Pot_K::Ccp_Type& ccp_type;
42-
const double& hse_omega;
43-
double lambda = 0.3;
44-
45-
Exx_Info_Lip(const Exx_Info::Exx_Info_Global& info_global)
46-
:ccp_type(info_global.ccp_type),
47-
hse_omega(info_global.hse_omega) {}
48-
};
4912
Exx_Info_Lip info_lip;
50-
51-
struct Exx_Info_RI
52-
{
53-
const std::map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> &coulomb_param;
54-
55-
bool real_number = false;
56-
bool coul_moment = false;
57-
bool rotate_abfs = false;
58-
59-
double pca_threshold = 0;
60-
std::vector<std::string> files_abfs;
61-
std::vector<std::string> files_shrink_abfs;
62-
double C_threshold = 0;
63-
double V_threshold = 0;
64-
double dm_threshold = 0;
65-
double C_grad_threshold = 0;
66-
double V_grad_threshold = 0;
67-
double C_grad_R_threshold = 0;
68-
double V_grad_R_threshold = 0;
69-
double ccp_rmesh_times = 10;
70-
bool exx_symmetry_realspace = true;
71-
double kmesh_times = 4;
72-
double Cs_inv_thr = -1;
73-
74-
double shrink_abfs_pca_thr = -1;
75-
double shrink_LU_inv_thr = 1e-6;
76-
double multip_moments_threshold = 1e-10;
77-
double exx_cs_inv_thr = -1;
78-
79-
int abfs_Lmax = 0; // tmp
80-
81-
Exx_Info_RI(const Exx_Info::Exx_Info_Global& info_global)
82-
: coulomb_param(info_global.coulomb_param)
83-
{
84-
}
85-
};
8613
Exx_Info_RI info_ri;
87-
88-
struct Exx_Info_Opt_ABFs
89-
{
90-
int abfs_Lmax = 0;
91-
double ecut_exx = 60;
92-
double tolerence = 1E-12;
93-
std::vector<std::string> files_jles;
94-
95-
double pca_threshold = 0;
96-
std::vector<std::string> files_abfs;
97-
98-
double kmesh_times = 4;
99-
};
10014
Exx_Info_Opt_ABFs info_opt_abfs;
10115

102-
Exx_Info() : info_lip(this->info_global), info_ri(this->info_global)
16+
void sync_from_global()
10317
{
18+
info_lip.ccp_type = info_global.ccp_type;
19+
info_lip.hse_omega = info_global.hse_omega;
20+
info_ri.coulomb_param = info_global.coulomb_param;
10421
}
10522
};
10623

@@ -109,4 +26,4 @@ namespace GlobalC
10926
extern Exx_Info exx_info;
11027
}
11128

112-
#endif
29+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef EXX_INFO_GLOBAL_H
2+
#define EXX_INFO_GLOBAL_H
3+
4+
#include "source_lcao/module_ri/conv_coulomb_pot_k.h"
5+
6+
#include <vector>
7+
#include <map>
8+
#include <string>
9+
#include <cstddef>
10+
11+
struct Exx_Info_Global
12+
{
13+
bool cal_exx = false;
14+
15+
std::map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string, std::string>>> coulomb_param;
16+
17+
// Fock:
18+
// "alpha": "0"
19+
// "singularity_correction": "limits" / "spencer" / "revised_spencer" / "massidda" / "carrier"
20+
// "lambda": "0.3"
21+
// "Rcut"
22+
// Erfc:
23+
// "alpha": "0"
24+
// "omega": "0.11"
25+
// "singularity_correction": "limits" / "spencer" / "revised_spencer"
26+
// "Rcut"
27+
28+
Conv_Coulomb_Pot_K::Ccp_Type ccp_type;
29+
double hybrid_alpha = 0.25;
30+
double hse_omega = 0.11;
31+
double mixing_beta_for_loop1 = 1.0;
32+
33+
bool separate_loop = true;
34+
size_t hybrid_step = 1;
35+
};
36+
37+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef EXX_INFO_LIP_H
2+
#define EXX_INFO_LIP_H
3+
4+
#include "source_lcao/module_ri/conv_coulomb_pot_k.h"
5+
6+
struct Exx_Info_Lip
7+
{
8+
Conv_Coulomb_Pot_K::Ccp_Type ccp_type;
9+
double hse_omega = 0.11;
10+
double lambda = 0.3;
11+
};
12+
13+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef EXX_INFO_OPT_ABFS_H
2+
#define EXX_INFO_OPT_ABFS_H
3+
4+
#include <vector>
5+
#include <string>
6+
7+
struct Exx_Info_Opt_ABFs
8+
{
9+
int abfs_Lmax = 0;
10+
double ecut_exx = 60;
11+
double tolerence = 1E-12;
12+
std::vector<std::string> files_jles;
13+
14+
double pca_threshold = 0;
15+
std::vector<std::string> files_abfs;
16+
17+
double kmesh_times = 4;
18+
};
19+
20+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef EXX_INFO_RI_H
2+
#define EXX_INFO_RI_H
3+
4+
#include "source_lcao/module_ri/conv_coulomb_pot_k.h"
5+
6+
#include <vector>
7+
#include <string>
8+
#include <map>
9+
10+
struct Exx_Info_RI
11+
{
12+
std::map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string, std::string>>> coulomb_param;
13+
14+
bool real_number = false;
15+
bool coul_moment = false;
16+
bool rotate_abfs = false;
17+
18+
double pca_threshold = 0;
19+
std::vector<std::string> files_abfs;
20+
std::vector<std::string> files_shrink_abfs;
21+
double C_threshold = 0;
22+
double V_threshold = 0;
23+
double dm_threshold = 0;
24+
double C_grad_threshold = 0;
25+
double V_grad_threshold = 0;
26+
double C_grad_R_threshold = 0;
27+
double V_grad_R_threshold = 0;
28+
double ccp_rmesh_times = 10;
29+
bool exx_symmetry_realspace = true;
30+
double kmesh_times = 4;
31+
double Cs_inv_thr = -1;
32+
33+
double shrink_abfs_pca_thr = -1;
34+
double shrink_LU_inv_thr = 1e-6;
35+
double multip_moments_threshold = 1e-10;
36+
double exx_cs_inv_thr = -1;
37+
38+
int abfs_Lmax = 0;
39+
};
40+
41+
#endif

0 commit comments

Comments
 (0)