Skip to content

Commit 95cdc5e

Browse files
linpeizePeizeLin
andauthored
Simplify Lmax in Center2_Orb and Matrix_Orbs (#6806)
* Refactor: Simplify Lmax in Center2_Orb * Refactor: Simplify Lmax in Center2_Orb * Refactor: split Center2_Orb::init_Lmax() * Refactor: simplify Matrix_Orbs::init() * Refactor: Simplify Center2_Orb::init_Lmax() --------- Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent 7181550 commit 95cdc5e

14 files changed

Lines changed: 150 additions & 237 deletions

source/source_io/cal_r_overlap_R.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,21 @@ cal_r_overlap_R::~cal_r_overlap_R()
1818
void cal_r_overlap_R::initialize_orb_table(const UnitCell& ucell,
1919
const LCAO_Orbitals& orb)
2020
{
21-
int Lmax_used = 0;
22-
int Lmax = 0;
23-
int exx_lmax = 0;
24-
#ifdef __EXX
25-
exx_lmax = GlobalC::exx_info.info_ri.abfs_Lmax;
26-
#endif
27-
2821
const int ntype = orb.get_ntype();
29-
int lmax_orb = -1, lmax_beta = -1;
22+
int lmax_orb = -1;
3023
for (int it = 0; it < ntype; it++)
3124
{
3225
lmax_orb = std::max(lmax_orb, orb.Phi[it].getLmax());
33-
lmax_beta = std::max(lmax_beta, ucell.infoNL.Beta[it].getLmax());
3426
}
3527
const double dr = orb.get_dR();
3628
const double dk = orb.get_dk();
3729
const int kmesh = orb.get_kmesh() * 4 + 1;
3830
int Rmesh = static_cast<int>(orb.get_Rmax() / dr) + 4;
3931
Rmesh += 1 - Rmesh % 2;
4032

41-
Center2_Orb::init_Table_Spherical_Bessel(2,
42-
3,
43-
Lmax_used,
44-
Lmax,
45-
exx_lmax,
46-
lmax_orb,
47-
lmax_beta,
33+
int Lmax, Lmax_used;
34+
std::tie(Lmax_used, Lmax) = Center2_Orb::init_Lmax_2_3(lmax_orb);
35+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
4836
dr,
4937
dk,
5038
kmesh,

source/source_io/to_wannier90_lcao.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,34 +265,22 @@ void toWannier90_LCAO::out_unk(const psi::Psi<std::complex<double>>& psi)
265265

266266
void toWannier90_LCAO::initialize_orb_table(const UnitCell& ucell)
267267
{
268-
int Lmax_used = 0;
269-
int Lmax = 0;
270-
int exx_lmax = 0;
271-
#ifdef __EXX
272-
exx_lmax = GlobalC::exx_info.info_ri.abfs_Lmax;
273-
#endif
274-
275268
#ifdef __LCAO
276269
const int ntype = orb_.get_ntype();
277-
int lmax_orb = -1, lmax_beta = -1;
270+
int lmax_orb = -1;
278271
for (int it = 0; it < ntype; it++)
279272
{
280273
lmax_orb = std::max(lmax_orb, orb_.Phi[it].getLmax());
281-
lmax_beta = std::max(lmax_beta, ucell.infoNL.Beta[it].getLmax());
282274
}
283275
const double dr = orb_.get_dR();
284276
const double dk = orb_.get_dk();
285277
const int kmesh = orb_.get_kmesh() * 4 + 1;
286278
int Rmesh = static_cast<int>(orb_.get_Rmax() / dr) + 4;
287279
Rmesh += 1 - Rmesh % 2;
288280

289-
Center2_Orb::init_Table_Spherical_Bessel(2,
290-
3,
291-
Lmax_used,
292-
Lmax,
293-
exx_lmax,
294-
lmax_orb,
295-
lmax_beta,
281+
int Lmax, Lmax_used;
282+
std::tie(Lmax_used, Lmax) = Center2_Orb::init_Lmax_2_3(lmax_orb);
283+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
296284
dr,
297285
dk,
298286
kmesh,

source/source_io/unk_overlap_lcao.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,21 @@ void unkOverlap_lcao::init(const UnitCell& ucell,
2828
const int nkstot,
2929
const LCAO_Orbitals& orb)
3030
{
31-
32-
int Lmax_used = 0;
33-
int Lmax = 0;
34-
int exx_lmax = 0;
35-
#ifdef __EXX
36-
exx_lmax = GlobalC::exx_info.info_ri.abfs_Lmax;
37-
#endif
38-
3931
const int ntype = orb.get_ntype();
40-
int lmax_orb = -1, lmax_beta = -1;
32+
int lmax_orb = -1;
4133
for (int it = 0; it < ntype; it++)
4234
{
4335
lmax_orb = std::max(lmax_orb, orb.Phi[it].getLmax());
44-
lmax_beta = std::max(lmax_beta, ucell.infoNL.Beta[it].getLmax());
4536
}
4637
const double dr = orb.get_dR();
4738
const double dk = orb.get_dk();
4839
const int kmesh = orb.get_kmesh() * 4 + 1;
4940
int Rmesh = static_cast<int>(orb.get_Rmax() / dr) + 4;
5041
Rmesh += 1 - Rmesh % 2;
5142

52-
Center2_Orb::init_Table_Spherical_Bessel(2,
53-
3,
54-
Lmax_used,
55-
Lmax,
56-
exx_lmax,
57-
lmax_orb,
58-
lmax_beta,
43+
int Lmax, Lmax_used;
44+
std::tie(Lmax_used, Lmax) = Center2_Orb::init_Lmax_2_3(lmax_orb);
45+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
5946
dr,
6047
dk,
6148
kmesh,

source/source_lcao/center2_orb.cpp

Lines changed: 42 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -28,84 +28,56 @@ int Center2_Orb::get_rmesh(const double& R1, const double& R2, const double dr)
2828
return rmesh;
2929
}
3030

31-
// Peize Lin update 2016-01-26
32-
void Center2_Orb::init_Lmax(const int orb_num,
33-
const int mode,
34-
int& Lmax_used,
35-
int& Lmax,
36-
const int& Lmax_exx,
37-
const int lmax_orb,
38-
const int lmax_beta)
31+
// used in <Phi|Phi> or <Beta|Phi>
32+
std::pair<int,int> Center2_Orb::init_Lmax_2_1(const int lmax_orb, const int lmax_beta)
3933
{
34+
const int Lmax = std::max({-1, lmax_orb, lmax_beta});
35+
const int Lmax_used = 2 * Lmax + 1;
36+
assert(Lmax_used >= 1);
37+
return {Lmax_used, Lmax};
38+
}
4039

41-
Lmax = -1;
40+
// used in <jY|jY> or <Abfs|Abfs>
41+
std::pair<int,int> Center2_Orb::init_Lmax_2_2(const int& lmax_exx)
42+
{
43+
const int Lmax = std::max(-1, lmax_exx);
44+
const int Lmax_used = 2 * Lmax + 1;
45+
assert(Lmax_used >= 1);
46+
return {Lmax_used, Lmax};
47+
}
4248

43-
switch (orb_num)
44-
{
45-
case 2:
46-
switch (mode)
47-
{
48-
case 1: // used in <Phi|Phi> or <Beta|Phi>
49-
Lmax = std::max({Lmax, lmax_orb, lmax_beta});
50-
// use 2lmax+1 in dS
51-
Lmax_used = 2 * Lmax + 1;
52-
break;
53-
case 2: // used in <jY|jY> or <Abfs|Abfs>
54-
Lmax = std::max(Lmax, Lmax_exx);
55-
Lmax_used = 2 * Lmax + 1;
56-
break;
57-
case 3: // used in berryphase by jingan
58-
Lmax = std::max(Lmax, lmax_orb);
59-
Lmax++;
60-
Lmax_used = 2 * Lmax + 1;
61-
break;
62-
default:
63-
throw std::invalid_argument("Center2_Orb::init_Lmax orb_num=2, mode error");
64-
break;
65-
}
66-
break;
67-
case 3:
68-
switch (mode)
69-
{
70-
case 1: // used in <jY|PhiPhi> or <Abfs|PhiPhi>
71-
Lmax = std::max(Lmax, lmax_orb);
72-
Lmax_used = 2 * Lmax + 1;
73-
Lmax = std::max(Lmax, Lmax_exx);
74-
Lmax_used += Lmax_exx;
75-
break;
76-
default:
77-
throw std::invalid_argument("Center2_Orb::init_Lmax orb_num=3, mode error");
78-
break;
79-
}
80-
break;
81-
case 4:
82-
switch (mode)
83-
{
84-
case 1: // used in <PhiPhi|PhiPhi>
85-
Lmax = std::max(Lmax, lmax_orb);
86-
Lmax_used = 2 * (2 * Lmax + 1);
87-
break;
88-
default:
89-
throw std::invalid_argument("Center2_Orb::init_Lmax orb_num=4, mode error");
90-
break;
91-
}
92-
break;
93-
default:
94-
throw std::invalid_argument("Center2_Orb::init_Lmax orb_num error");
95-
break;
96-
}
49+
// used in berryphase by jingan
50+
std::pair<int,int> Center2_Orb::init_Lmax_2_3(const int lmax_orb)
51+
{
52+
int Lmax = std::max(-1, lmax_orb);
53+
Lmax++;
54+
const int Lmax_used = 2 * Lmax + 1;
55+
assert(Lmax_used >= 1);
56+
return {Lmax_used, Lmax};
57+
}
58+
59+
// used in <jY|PhiPhi> or <Abfs|PhiPhi>
60+
std::pair<int,int> Center2_Orb::init_Lmax_3_1(const int& lmax_exx, const int lmax_orb)
61+
{
62+
int Lmax = std::max(-1, lmax_orb);
63+
int Lmax_used = 2 * Lmax + 1;
64+
Lmax = std::max(Lmax, lmax_exx);
65+
Lmax_used += lmax_exx;
66+
assert(Lmax_used >= 1);
67+
return {Lmax_used, Lmax};
68+
}
9769

70+
// used in <PhiPhi|PhiPhi>
71+
std::pair<int,int> Center2_Orb::init_Lmax_4_1(const int lmax_orb)
72+
{
73+
const int Lmax = std::max(-1, lmax_orb);
74+
const int Lmax_used = 2 * (2 * Lmax + 1);
9875
assert(Lmax_used >= 1);
76+
return {Lmax_used, Lmax};
9977
}
10078

10179
// Peize Lin update 2016-01-26
102-
void Center2_Orb::init_Table_Spherical_Bessel(const int orb_num,
103-
const int mode,
104-
int& Lmax_used,
105-
int& Lmax,
106-
const int& Lmax_exx,
107-
const int lmax_orb,
108-
const int lmax_beta,
80+
void Center2_Orb::init_Table_Spherical_Bessel(const int Lmax_used,
10981
const double dr,
11082
const double dk,
11183
const int kmesh,
@@ -114,8 +86,6 @@ void Center2_Orb::init_Table_Spherical_Bessel(const int orb_num,
11486
{
11587
ModuleBase::TITLE("Center2_Orb", "init_Table_Spherical_Bessel");
11688

117-
init_Lmax(orb_num, mode, Lmax_used, Lmax, Lmax_exx, lmax_orb, lmax_beta); // Peize Lin add 2016-01-26
118-
11989
for (auto& sb: ModuleBase::Sph_Bessel_Recursive_Pool::D2::sb_pool)
12090
{
12191
if (dr * dk == sb.get_dx())

source/source_lcao/center2_orb.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,18 @@ class Center2_Orb
2525

2626
static int get_rmesh(const double& R1, const double& R2, const double dr);
2727

28-
static void init_Lmax(const int orb_num,
29-
const int mode,
30-
int& Lmax_used,
31-
int& Lmax,
32-
const int& Lmax_exx,
33-
const int lmax_orb,
34-
const int lmax_beta);
28+
// used in <Phi|Phi> or <Beta|Phi>
29+
static std::pair<int,int> init_Lmax_2_1(const int lmax_orb, const int lmax_beta);
30+
// used in <jY|jY> or <Abfs|Abfs>
31+
static std::pair<int,int> init_Lmax_2_2(const int& lmax_exx);
32+
// used in berryphase by jingan
33+
static std::pair<int,int> init_Lmax_2_3(const int lmax_orb);
34+
// used in <jY|PhiPhi> or <Abfs|PhiPhi>
35+
static std::pair<int,int> init_Lmax_3_1(const int& lmax_exx, const int lmax_orb);
36+
// used in <PhiPhi|PhiPhi>
37+
static std::pair<int,int> init_Lmax_4_1(const int lmax_orb);
3538

36-
static void init_Table_Spherical_Bessel(const int orb_num,
37-
const int mode,
38-
int& Lmax_used,
39-
int& Lmax,
40-
const int& Lmax_exx,
41-
const int lmax_orb,
42-
const int lmax_beta,
39+
static void init_Table_Spherical_Bessel(const int Lmax_used,
4340
const double dr,
4441
const double dk,
4542
const int kmesh,

source/source_lcao/module_ri/ABFs_Construct-PCA.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ RI::Tensor<double> get_column_mean0_matrix(const RI::Tensor<double>& m)
182182

183183
Matrix_Orbs21 m_abfslcaos_lcaos;
184184
ORB_gaunt_table MGT;
185-
int Lmax;
186-
m_abfslcaos_lcaos.init(1, ucell, orb, kmesh_times, orb.get_Rmax(), Lmax);
185+
const int Lmax = m_abfslcaos_lcaos.init(1, ucell, orb, kmesh_times, orb.get_Rmax());
187186
MGT.init_Gaunt_CH(Lmax);
188-
MGT.init_Gaunt(Lmax);
187+
MGT.init_Gaunt(Lmax);
189188
m_abfslcaos_lcaos.init_radial(abfs, lcaos, lcaos, MGT);
190189

191190
std::map<std::size_t, std::map<std::size_t, std::set<double>>> delta_R;

source/source_lcao/module_ri/LRI_CV.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ void LRI_CV<Tdata>::set_orbitals(
6969
range_abfs = ModuleBase::Element_Basis_Index::construct_range( abfs );
7070
this->index_abfs = ModuleBase::Element_Basis_Index::construct_index( range_abfs );
7171

72-
int Lmax_v = std::numeric_limits<double>::min();
73-
this->m_abfs_abfs.init(2, ucell, orb, kmesh_times, lcaos_rmax + abfs_ccp_rmax, Lmax_v);
72+
const int Lmax_v = this->m_abfs_abfs.init(2, ucell, orb, kmesh_times, lcaos_rmax + abfs_ccp_rmax);
7473
int Lmax_c = std::numeric_limits<double>::min();
7574
if (init_C)
76-
this->m_abfslcaos_lcaos.init(1, ucell, orb, kmesh_times, lcaos_rmax, Lmax_c);
77-
int Lmax = std::max(Lmax_v, Lmax_c);
75+
Lmax_c = this->m_abfslcaos_lcaos.init(1, ucell, orb, kmesh_times, lcaos_rmax);
76+
const int Lmax = std::max(Lmax_v, Lmax_c);
7877

7978
if (init_MGT) {
8079
MGT.init_Gaunt_CH(Lmax);

source/source_lcao/module_ri/Matrix_Orbs11.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,54 @@
99
#include "source_base/tool_title.h"
1010
#include "source_pw/module_pwdft/global.h"
1111

12-
void Matrix_Orbs11::init(const int mode,
12+
int Matrix_Orbs11::init(const int mode,
1313
const UnitCell& ucell,
1414
const LCAO_Orbitals& orb,
1515
const double kmesh_times,
16-
const double rmax,
17-
int& Lmax)
16+
const double rmax)
1817
{
1918
ModuleBase::TITLE("Matrix_Orbs11", "init");
2019
ModuleBase::timer::tick("Matrix_Orbs11", "init");
2120

22-
int Lmax_used;
2321
this->lat0 = &ucell.lat0;
24-
const int ntype = orb.get_ntype();
25-
int lmax_orb = -1, lmax_beta = -1;
26-
for (int it = 0; it < ntype; it++)
27-
{
28-
lmax_orb = std::max(lmax_orb, orb.Phi[it].getLmax());
29-
lmax_beta = std::max(lmax_beta, ucell.infoNL.Beta[it].getLmax());
30-
}
22+
23+
//const int ntype = orb.get_ntype();
24+
//int lmax_orb = -1, lmax_beta = -1;
25+
//for (int it = 0; it < ntype; it++)
26+
//{
27+
// lmax_orb = std::max(lmax_orb, orb.Phi[it].getLmax());
28+
// lmax_beta = std::max(lmax_beta, ucell.infoNL.Beta[it].getLmax());
29+
//}
30+
int Lmax, Lmax_used;
31+
//if(mode==1)
32+
// { std::tie(Lmax_used, Lmax) = Center2_Orb::init_Lmax_2_1(lmax_orb, lmax_beta); }
33+
if(mode==2)
34+
{ std::tie(Lmax_used, Lmax) = Center2_Orb::init_Lmax_2_2(GlobalC::exx_info.info_ri.abfs_Lmax); }
35+
//else if(mode==3)
36+
// { std::tie(Lmax_used, Lmax) = Center2_Orb::init_Lmax_2_3(lmax_orb); }
37+
else
38+
{ throw std::invalid_argument("mode = "+std::to_string(mode)+"in file "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); }
39+
40+
//=========================================
41+
// (3) make Gaunt coefficients table
42+
//=========================================
43+
// this->MGT.init_Gaunt_CH(Lmax);
44+
// this->MGT.init_Gaunt(Lmax);
45+
3146
const double dr = orb.get_dR();
3247
const double dk = orb.get_dk();
3348
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
3449
int Rmesh = static_cast<int>(rmax / dr) + 4;
3550
Rmesh += 1 - Rmesh % 2;
36-
37-
Center2_Orb::init_Table_Spherical_Bessel(2,
38-
mode,
39-
Lmax_used,
40-
Lmax,
41-
GlobalC::exx_info.info_ri.abfs_Lmax,
42-
lmax_orb,
43-
lmax_beta,
51+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
4452
dr,
4553
dk,
4654
kmesh,
4755
Rmesh,
4856
psb_);
4957

50-
//=========================================
51-
// (3) make Gaunt coefficients table
52-
//=========================================
53-
// this->MGT.init_Gaunt_CH(Lmax);
54-
// this->MGT.init_Gaunt(Lmax);
55-
5658
ModuleBase::timer::tick("Matrix_Orbs11", "init");
59+
return Lmax;
5760
}
5861

5962
void Matrix_Orbs11::init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A,

0 commit comments

Comments
 (0)