Skip to content

Commit 7b4e28e

Browse files
committed
namespace Singular_Value
1 parent 84a67ce commit 7b4e28e

File tree

4 files changed

+121
-99
lines changed

4 files changed

+121
-99
lines changed

source/module_hamilt_general/module_xc/exx_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define EXX_INFO_H
33

44
#include "module_ri/conv_coulomb_pot_k.h"
5-
#include "module_ri/singular_value.h"
5+
#include "module_ri/fq_type.h"
66
#include "xc_functional.h"
77

88
struct Exx_Info

source/module_ri/fq_type.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//=======================
2+
// AUTHOR : jiyy
3+
// DATE : 2025-05-16
4+
//=======================
5+
6+
#ifndef FQ_TYPE_H
7+
#define FQ_TYPE_H
8+
9+
namespace Singular_Value
10+
{
11+
enum class Fq_type
12+
{
13+
Type_0, // Phys. Rev. B, 75:205126, May 2007.
14+
Type_1, // Phys. Rev. B 48, 5058. August 1993.
15+
};
16+
}
17+
18+
#endif

source/module_ri/singular_value.cpp

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include <cmath>
2020
#include <numeric>
2121

22+
namespace Singular_Value
23+
{
2224
// for analytic integral of fq
23-
double Singular_Value::sum_for_solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
24-
const T_cal_fq_type& func_cal_fq,
25-
const double& fq_int)
25+
double sum_for_solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
26+
const T_cal_fq_type& func_cal_fq,
27+
const double& fq_int)
2628
{
2729
const int nks = kvec_c.size();
2830

@@ -37,13 +39,13 @@ double Singular_Value::sum_for_solve_chi(const std::vector<ModuleBase::Vector3<d
3739
}
3840

3941
// for numerical integral of fq
40-
double Singular_Value::solve_chi(const ModuleBase::Matrix3 &G,
41-
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
42-
const T_cal_fq_type& func_cal_fq,
43-
const std::array<int, 3>& nq_arr,
44-
const int& niter,
45-
const double& eps,
46-
const int& a_rate)
42+
double solve_chi(const ModuleBase::Matrix3& G,
43+
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
44+
const T_cal_fq_type& func_cal_fq,
45+
const std::array<int, 3>& nq_arr,
46+
const int& niter,
47+
const double& eps,
48+
const int& a_rate)
4749
{
4850
// cal fq integral
4951
double fq_int = Iter_Integral(G, func_cal_fq, nq_arr, niter, eps, a_rate);
@@ -52,26 +54,26 @@ double Singular_Value::solve_chi(const ModuleBase::Matrix3 &G,
5254
}
5355

5456
// for analytic integral of fq
55-
double Singular_Value::solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
56-
const T_cal_fq_type& func_cal_fq,
57-
const double& fq_int)
57+
double solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
58+
const T_cal_fq_type& func_cal_fq,
59+
const double& fq_int)
5860
{
5961
return sum_for_solve_chi(kvec_c, func_cal_fq, fq_int);
6062
}
6163

6264
// for analytic integral of fq with gaussian sum
63-
double Singular_Value::solve_chi(const int& nks, const T_cal_fq_type_no& func_cal_fq, const double& fq_int)
65+
double solve_chi(const int& nks, const T_cal_fq_type_no& func_cal_fq, const double& fq_int)
6466
{
6567
double chi = fq_int * nks - func_cal_fq();
6668

6769
return chi;
6870
}
6971

70-
double Singular_Value::fq_type_0(const double& tpiba,
71-
const ModuleBase::Vector3<double>& qvec,
72-
const int& qdiv,
73-
std::vector<ModuleBase::Vector3<double>>& avec,
74-
std::vector<ModuleBase::Vector3<double>>& bvec)
72+
double fq_type_0(const double& tpiba,
73+
const ModuleBase::Vector3<double>& qvec,
74+
const int& qdiv,
75+
std::vector<ModuleBase::Vector3<double>>& avec,
76+
std::vector<ModuleBase::Vector3<double>>& bvec)
7577
{
7678
assert(qvec.norm2());
7779

@@ -101,13 +103,13 @@ double Singular_Value::fq_type_0(const double& tpiba,
101103
return fq;
102104
}
103105

104-
double Singular_Value::cal_type_0(const UnitCell& ucell,
105-
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
106-
const int& qdiv,
107-
const double& qdense,
108-
const int& niter,
109-
const double& eps,
110-
const int& a_rate)
106+
double cal_type_0(const UnitCell& ucell,
107+
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
108+
const int& qdiv,
109+
const double& qdense,
110+
const int& niter,
111+
const double& eps,
112+
const int& a_rate)
111113
{
112114
ModuleBase::TITLE("Singular_Value", "cal_type_0");
113115
ModuleBase::timer::tick("Singular_Value", "cal_type_0");
@@ -136,14 +138,19 @@ double Singular_Value::cal_type_0(const UnitCell& ucell,
136138
int index = static_cast<int>(vec.norm() * qdense_tpiba);
137139
return index ? index - index % a_rate : a_rate;
138140
});
139-
const T_cal_fq_type func_cal_fq_type_0 = std::bind(&fq_type_0, ucell.tpiba, std::placeholders::_1, qdiv, avec, bvec);
141+
const T_cal_fq_type func_cal_fq_type_0
142+
= std::bind(&fq_type_0, ucell.tpiba, std::placeholders::_1, qdiv, avec, bvec);
140143

141144
double val = solve_chi(ucell.G, kvec_c, func_cal_fq_type_0, nq_arr, niter, eps, a_rate);
142145
ModuleBase::timer::tick("Singular_Value", "cal_type_0");
143146
return val;
144147
}
145148

146-
double Singular_Value::fq_type_1(const double& tpiba, Gaussian_Abfs& gaussian_abfs, const int& qdiv, const double& lambda, const int& lmax)
149+
double fq_type_1(const double& tpiba,
150+
Gaussian_Abfs& gaussian_abfs,
151+
const int& qdiv,
152+
const double& lambda,
153+
const int& lmax)
147154
{
148155
const size_t ik = 0;
149156
const double qexpo = -abs(qdiv);
@@ -157,12 +164,12 @@ double Singular_Value::fq_type_1(const double& tpiba, Gaussian_Abfs& gaussian_ab
157164
return fq;
158165
}
159166

160-
double Singular_Value::cal_type_1(const UnitCell& ucell,
161-
const std::array<int, 3>& nmp,
162-
const int& qdiv,
163-
const double& start_lambda,
164-
const int& niter,
165-
const double& eps)
167+
double cal_type_1(const UnitCell& ucell,
168+
const std::array<int, 3>& nmp,
169+
const int& qdiv,
170+
const double& start_lambda,
171+
const int& niter,
172+
const double& eps)
166173
{
167174
ModuleBase::TITLE("Singular_Value", "cal_type_1");
168175
ModuleBase::timer::tick("Singular_Value", "cal_type_1");
@@ -188,7 +195,8 @@ double Singular_Value::cal_type_1(const UnitCell& ucell,
188195
Gaussian_Abfs gaussian_abfs;
189196
const double exponent = 1 / lambda;
190197
gaussian_abfs.init(ucell, lmax, qvec, bvec, exponent);
191-
const T_cal_fq_type_no func_cal_fq_type_1 = std::bind(&fq_type_1, ucell.tpiba, gaussian_abfs, qdiv, lambda, lmax);
198+
const T_cal_fq_type_no func_cal_fq_type_1
199+
= std::bind(&fq_type_1, ucell.tpiba, gaussian_abfs, qdiv, lambda, lmax);
192200
double prefactor
193201
= ModuleBase::TWO_PI * std::pow(lambda, -1.0 / qdiv) * ucell.omega / std::pow(ModuleBase::TWO_PI, 3);
194202
double fq_int;
@@ -227,12 +235,12 @@ double Singular_Value::cal_type_1(const UnitCell& ucell,
227235
return val_extra;
228236
}
229237

230-
double Singular_Value::Iter_Integral(const ModuleBase::Matrix3 &G,
231-
const T_cal_fq_type& func_cal_fq,
232-
const std::array<int, 3>& nq_arr,
233-
const int& niter,
234-
const double& eps,
235-
const int& a_rate)
238+
double Iter_Integral(const ModuleBase::Matrix3& G,
239+
const T_cal_fq_type& func_cal_fq,
240+
const std::array<int, 3>& nq_arr,
241+
const int& niter,
242+
const double& eps,
243+
const int& a_rate)
236244
{
237245
bool any_negative = std::any_of(nq_arr.begin(), nq_arr.end(), [](int i) { return i < 0; });
238246
bool any_nthree = std::any_of(nq_arr.begin(), nq_arr.end(), [&a_rate](int i) { return i % a_rate != 0; });
@@ -290,5 +298,6 @@ double Singular_Value::Iter_Integral(const ModuleBase::Matrix3 &G,
290298

291299
return integ;
292300
}
301+
} // namespace Singular_Value
293302

294303
#endif

source/module_ri/singular_value.h

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,69 @@
66
#ifndef AUXILIARY_FUNC_H
77
#define AUXILIARY_FUNC_H
88

9+
#include "fq_type.h"
910
#include "gaussian_abfs.h"
1011
#include "module_basis/module_pw/pw_basis_k.h"
1112
#include "module_cell/klist.h"
1213

1314
#include <array>
1415
#include <vector>
1516

16-
class Singular_Value
17+
namespace Singular_Value
1718
{
18-
public:
19-
enum class Fq_type
20-
{
21-
Type_0, // Phys. Rev. B, 75:205126, May 2007.
22-
Type_1, // Phys. Rev. B 48, 5058. August 1993.
23-
};
19+
using T_cal_fq_type = std::function<double(const ModuleBase::Vector3<double>& gk)>;
20+
using T_cal_fq_type_no = std::function<double()>;
2421

25-
private:
26-
using T_cal_fq_type = std::function<double(const ModuleBase::Vector3<double>& gk)>;
27-
using T_cal_fq_type_no = std::function<double()>;
22+
double cal_type_0(const UnitCell& ucell,
23+
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
24+
const int& qdiv,
25+
const double& qdense,
26+
const int& niter,
27+
const double& eps,
28+
const int& a_rate);
29+
double cal_type_1(const UnitCell& ucell,
30+
const std::array<int, 3>& nmp,
31+
const int& qdiv,
32+
const double& start_lambda,
33+
const int& niter,
34+
const double& eps);
2835

29-
public:
30-
static double cal_type_0(const UnitCell& ucell,
31-
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
32-
const int& qdiv,
33-
const double& qdense,
34-
const int& niter,
35-
const double& eps,
36-
const int& a_rate);
37-
static double cal_type_1(const UnitCell& ucell,
38-
const std::array<int, 3>& nmp,
39-
const int& qdiv,
40-
const double& start_lambda,
41-
const int& niter,
42-
const double& eps);
36+
double solve_chi(const ModuleBase::Matrix3& G,
37+
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
38+
const T_cal_fq_type& func_cal_fq,
39+
const std::array<int, 3>& nq_arr,
40+
const int& niter,
41+
const double& eps,
42+
const int& a_rate);
43+
double solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
44+
const T_cal_fq_type& func_cal_fq,
45+
const double& fq_int);
46+
double solve_chi(const int& nks, const T_cal_fq_type_no& func_cal_fq, const double& fq_int);
47+
double sum_for_solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
48+
const T_cal_fq_type& func_cal_fq,
49+
const double& fq_int);
50+
double Iter_Integral(const ModuleBase::Matrix3& G,
51+
const T_cal_fq_type& func_cal_fq,
52+
const std::array<int, 3>& nq_arr,
53+
const int& niter,
54+
const double& eps,
55+
const int& a_rate);
4356

44-
private:
45-
static double solve_chi(const ModuleBase::Matrix3 &G,
46-
const std::vector<ModuleBase::Vector3<double>>& kvec_c,
47-
const T_cal_fq_type& func_cal_fq,
48-
const std::array<int, 3>& nq_arr,
49-
const int& niter,
50-
const double& eps,
51-
const int& a_rate);
52-
static double solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
53-
const T_cal_fq_type& func_cal_fq,
54-
const double& fq_int);
55-
static double solve_chi(const int& nks, const T_cal_fq_type_no& func_cal_fq, const double& fq_int);
56-
static double sum_for_solve_chi(const std::vector<ModuleBase::Vector3<double>>& kvec_c,
57-
const T_cal_fq_type& func_cal_fq,
58-
const double& fq_int);
59-
static double Iter_Integral(const ModuleBase::Matrix3 &G,
60-
const T_cal_fq_type& func_cal_fq,
61-
const std::array<int, 3>& nq_arr,
62-
const int& niter,
63-
const double& eps,
64-
const int& a_rate);
57+
// TODO: lower dimension please see PHYSICAL REVIEW B 87, 165122 (2013)
6558

66-
// TODO: lower dimension please see PHYSICAL REVIEW B 87, 165122 (2013)
67-
68-
// qdiv=2 i.e. q^{-2} for 3D;
69-
// qdiv=1 i.e. q^{-1} for 2D.
70-
static double fq_type_0(const double& tpiba,
71-
const ModuleBase::Vector3<double>& qvec,
72-
const int& qdiv,
73-
std::vector<ModuleBase::Vector3<double>>& avec,
74-
std::vector<ModuleBase::Vector3<double>>& bvec);
75-
// gamma: chosen as the radius of sphere which has the same volume as the Brillouin zone.
76-
static double fq_type_1(const double& tpiba, Gaussian_Abfs& gaussian_abfs, const int& qdiv, const double& lambda, const int& lmax);
77-
};
59+
// qdiv=2 i.e. q^{-2} for 3D;
60+
// qdiv=1 i.e. q^{-1} for 2D.
61+
double fq_type_0(const double& tpiba,
62+
const ModuleBase::Vector3<double>& qvec,
63+
const int& qdiv,
64+
std::vector<ModuleBase::Vector3<double>>& avec,
65+
std::vector<ModuleBase::Vector3<double>>& bvec);
66+
// gamma: chosen as the radius of sphere which has the same volume as the Brillouin zone.
67+
double fq_type_1(const double& tpiba,
68+
Gaussian_Abfs& gaussian_abfs,
69+
const int& qdiv,
70+
const double& lambda,
71+
const int& lmax);
72+
}; // namespace Singular_Value
7873

7974
#endif

0 commit comments

Comments
 (0)