Skip to content

Commit 395d3f2

Browse files
committed
Refactor: simplify Matrix_Orbs::init()
1 parent 2d26f60 commit 395d3f2

9 files changed

Lines changed: 74 additions & 80 deletions

File tree

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: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,25 @@
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

2221
this->lat0 = &ucell.lat0;
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-
const double dr = orb.get_dR();
31-
const double dk = orb.get_dk();
32-
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
33-
int Rmesh = static_cast<int>(rmax / dr) + 4;
34-
Rmesh += 1 - Rmesh % 2;
3522

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;
3631
int Lmax_used;
3732
//if(mode==1)
3833
// { Center2_Orb::init_Lmax_2_1(lmax_orb, lmax_beta, Lmax_used, Lmax); }
@@ -42,20 +37,27 @@ void Matrix_Orbs11::init(const int mode,
4237
// { Center2_Orb::init_Lmax_2_3(lmax_orb, Lmax_used, Lmax); }
4338
else
4439
{ throw std::invalid_argument("mode = "+std::to_string(mode)+"in file "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); }
45-
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
46-
dr,
47-
dk,
48-
kmesh,
49-
Rmesh,
50-
psb_);
5140

5241
//=========================================
5342
// (3) make Gaunt coefficients table
5443
//=========================================
5544
// this->MGT.init_Gaunt_CH(Lmax);
5645
// this->MGT.init_Gaunt(Lmax);
5746

47+
const double dr = orb.get_dR();
48+
const double dk = orb.get_dk();
49+
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
50+
int Rmesh = static_cast<int>(rmax / dr) + 4;
51+
Rmesh += 1 - Rmesh % 2;
52+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
53+
dr,
54+
dk,
55+
kmesh,
56+
Rmesh,
57+
psb_);
58+
5859
ModuleBase::timer::tick("Matrix_Orbs11", "init");
60+
return Lmax;
5961
}
6062

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

source/source_lcao/module_ri/Matrix_Orbs11.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ class Matrix_Orbs11
2424
// mode:
2525
// 1: <lcaos|lcaos>
2626
// 2: <jYs|jYs> <abfs|abfs>
27-
void init(const int mode,
27+
int init(const int mode,
2828
const UnitCell& ucell,
2929
const LCAO_Orbitals& orb,
3030
const double kmesh_times, // extend Kcut, keep dK
31-
const double rmax,
32-
int& Lmax);
31+
const double rmax);
3332

3433
void init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A,
3534
const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_B,

source/source_lcao/module_ri/Matrix_Orbs21.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,26 @@
99
#include "source_base/tool_title.h"
1010
#include "source_pw/module_pwdft/global.h"
1111

12-
void Matrix_Orbs21::init(const int mode,
12+
int Matrix_Orbs21::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_Orbs21", "init");
2019
ModuleBase::timer::tick("Matrix_Orbs21", "init");
20+
this->lat0 = &ucell.lat0;
2121

2222
const int ntype = orb.get_ntype();
23-
this->lat0 = &ucell.lat0;
2423
int lmax_orb = -1;
2524
for (int it = 0; it < ntype; it++)
2625
{ lmax_orb = std::max(lmax_orb, orb.Phi[it].getLmax()); }
27-
const double dr = orb.get_dR();
28-
const double dk = orb.get_dk();
29-
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
30-
int Rmesh = static_cast<int>(rmax / dr) + 4;
31-
Rmesh += 1 - Rmesh % 2;
32-
26+
int Lmax;
3327
int Lmax_used;
3428
if(mode==1)
3529
{ Center2_Orb::init_Lmax_3_1(GlobalC::exx_info.info_ri.abfs_Lmax, lmax_orb, Lmax_used, Lmax); }
3630
else
3731
{ throw std::invalid_argument("mode = "+std::to_string(mode)+"in file "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); }
38-
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
39-
dr,
40-
dk,
41-
kmesh,
42-
Rmesh,
43-
psb_);
4432

4533
//=========================================
4634
// (3) make Gaunt coefficients table
@@ -49,7 +37,20 @@ void Matrix_Orbs21::init(const int mode,
4937
// this->MGT.init_Gaunt(2 * Lmax + 1);
5038
Lmax = 2 * Lmax + 1;
5139

40+
const double dr = orb.get_dR();
41+
const double dk = orb.get_dk();
42+
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
43+
int Rmesh = static_cast<int>(rmax / dr) + 4;
44+
Rmesh += 1 - Rmesh % 2;
45+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
46+
dr,
47+
dk,
48+
kmesh,
49+
Rmesh,
50+
psb_);
51+
5252
ModuleBase::timer::tick("Matrix_Orbs21", "init");
53+
return Lmax;
5354
}
5455

5556
void Matrix_Orbs21::init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A1,

source/source_lcao/module_ri/Matrix_Orbs21.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ class Matrix_Orbs21
2222
public:
2323
// mode:
2424
// 1: <jYs lcaos|lcaos> <abfs lcaos|lcaos>
25-
void init(const int mode,
25+
int init(const int mode,
2626
const UnitCell& ucell,
2727
const LCAO_Orbitals& orb,
2828
const double kmesh_times, // extend Kcut, keep dK
29-
const double rmax,
30-
int& Lmax); // extend Rcut, keep dR
29+
const double rmax); // extend Rcut, keep dR
3130

3231
void init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A1,
3332
const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A2,

source/source_lcao/module_ri/Matrix_Orbs22.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,27 @@
99
#include "source_base/tool_title.h"
1010
#include "source_pw/module_pwdft/global.h"
1111

12-
void Matrix_Orbs22::init(const int mode,
12+
int Matrix_Orbs22::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_Orbs22", "init");
2019
ModuleBase::timer::tick("Matrix_Orbs22", "init");
2120

2221
this->lat0 = &ucell.lat0;
22+
2323
const int ntype = orb.get_ntype();
2424
int lmax_orb = -1;
2525
for (int it = 0; it < ntype; it++)
2626
{ lmax_orb = std::max(lmax_orb, orb.Phi[it].getLmax()); }
27-
const double dr = orb.get_dR();
28-
const double dk = orb.get_dk();
29-
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
30-
int Rmesh = static_cast<int>(rmax / dr) + 4;
31-
Rmesh += 1 - Rmesh % 2;
32-
27+
int Lmax;
3328
int Lmax_used;
3429
if(mode==1)
3530
{ Center2_Orb::init_Lmax_4_1(lmax_orb, Lmax_used, Lmax); }
3631
else
3732
{ throw std::invalid_argument("mode = "+std::to_string(mode)+"in file "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); }
38-
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
39-
dr,
40-
dk,
41-
kmesh,
42-
Rmesh,
43-
psb_);
4433

4534
//=========================================
4635
// (3) make Gaunt coefficients table
@@ -49,7 +38,20 @@ void Matrix_Orbs22::init(const int mode,
4938
// this->MGT.init_Gaunt(2 * Lmax + 1);
5039
Lmax = 2 * Lmax + 1;
5140

41+
const double dr = orb.get_dR();
42+
const double dk = orb.get_dk();
43+
const int kmesh = orb.get_kmesh() * kmesh_times + 1;
44+
int Rmesh = static_cast<int>(rmax / dr) + 4;
45+
Rmesh += 1 - Rmesh % 2;
46+
Center2_Orb::init_Table_Spherical_Bessel(Lmax_used,
47+
dr,
48+
dk,
49+
kmesh,
50+
Rmesh,
51+
psb_);
52+
5253
ModuleBase::timer::tick("Matrix_Orbs22", "init");
54+
return Lmax;
5355
}
5456

5557
void Matrix_Orbs22::init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A1,

source/source_lcao/module_ri/Matrix_Orbs22.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ class Matrix_Orbs22
2323
public:
2424
// mode:
2525
// 1: <lcaos lcaos|lcaos lcaos>
26-
void init(const int mode,
26+
int init(const int mode,
2727
const UnitCell& ucell,
2828
const LCAO_Orbitals& orb,
2929
const double kmesh_times, // extend Kcut, keep dK
30-
const double rmax,
31-
int& Lmax); // extend Rcut, keep dR
30+
const double rmax); // extend Rcut, keep dR
3231

3332
void init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A1,
3433
const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A2,

source/source_lcao/module_ri/exx_opt_orb.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ void Exx_Opt_Orb::generate_matrix(
7373
if(judge_orbs_empty(lcaos)) { return {}; }
7474
Matrix_Orbs22 m_lcaoslcaos_lcaoslcaos;
7575
ORB_gaunt_table MGT;
76-
int Lmax;
77-
m_lcaoslcaos_lcaoslcaos.init( 1, ucell,orb, info.kmesh_times, orb.get_Rmax(), Lmax );
76+
const int Lmax = m_lcaoslcaos_lcaoslcaos.init( 1, ucell,orb, info.kmesh_times, orb.get_Rmax() );
7877
MGT.init_Gaunt_CH(Lmax);
7978
MGT.init_Gaunt(Lmax);
8079
m_lcaoslcaos_lcaoslcaos.init_radial( lcaos, lcaos, lcaos, lcaos, MGT );
@@ -93,8 +92,7 @@ void Exx_Opt_Orb::generate_matrix(
9392
if(judge_orbs_empty(jle)) { return {}; }
9493
Matrix_Orbs21 m_jyslcaos_lcaos;
9594
ORB_gaunt_table MGT;
96-
int Lmax;
97-
m_jyslcaos_lcaos.init( 1, ucell , orb, info.kmesh_times, orb.get_Rmax(), Lmax );
95+
const int Lmax = m_jyslcaos_lcaos.init( 1, ucell , orb, info.kmesh_times, orb.get_Rmax() );
9896
MGT.init_Gaunt_CH(Lmax);
9997
MGT.init_Gaunt(Lmax);
10098
m_jyslcaos_lcaos.init_radial( jle, lcaos, lcaos, MGT);
@@ -112,8 +110,7 @@ void Exx_Opt_Orb::generate_matrix(
112110
if(judge_orbs_empty(jle)) { return {}; }
113111
Matrix_Orbs11 m_jys_jys;
114112
ORB_gaunt_table MGT;
115-
int Lmax;
116-
m_jys_jys.init( 2,ucell,orb, info.kmesh_times, orb.get_Rmax(), Lmax );
113+
const int Lmax = m_jys_jys.init( 2,ucell,orb, info.kmesh_times, orb.get_Rmax() );
117114
MGT.init_Gaunt_CH(Lmax);
118115
MGT.init_Gaunt(Lmax);
119116
m_jys_jys.init_radial( jle, jle, MGT );
@@ -131,8 +128,7 @@ void Exx_Opt_Orb::generate_matrix(
131128
if(judge_orbs_empty(abfs)) { return {}; }
132129
Matrix_Orbs11 m_abfs_abfs;
133130
ORB_gaunt_table MGT;
134-
int Lmax;
135-
m_abfs_abfs.init( 2, ucell, orb, info.kmesh_times, orb.get_Rmax(), Lmax );
131+
const int Lmax = m_abfs_abfs.init( 2, ucell, orb, info.kmesh_times, orb.get_Rmax() );
136132
MGT.init_Gaunt_CH(Lmax);
137133
MGT.init_Gaunt(Lmax);
138134
m_abfs_abfs.init_radial( abfs, abfs, MGT );
@@ -151,8 +147,7 @@ void Exx_Opt_Orb::generate_matrix(
151147
if(judge_orbs_empty(abfs)) { return {}; }
152148
Matrix_Orbs21 m_abfslcaos_lcaos;
153149
ORB_gaunt_table MGT;
154-
int Lmax;
155-
m_abfslcaos_lcaos.init( 1, ucell , orb, info.kmesh_times, orb.get_Rmax(), Lmax );
150+
const int Lmax = m_abfslcaos_lcaos.init( 1, ucell , orb, info.kmesh_times, orb.get_Rmax() );
156151
MGT.init_Gaunt_CH(Lmax);
157152
MGT.init_Gaunt(Lmax);
158153
m_abfslcaos_lcaos.init_radial( abfs, lcaos, lcaos, MGT );
@@ -171,8 +166,7 @@ void Exx_Opt_Orb::generate_matrix(
171166
if(judge_orbs_empty(abfs)) { return {}; }
172167
Matrix_Orbs11 m_jys_abfs;
173168
ORB_gaunt_table MGT;
174-
int Lmax;
175-
m_jys_abfs.init( 2, ucell,orb, info.kmesh_times, orb.get_Rmax(), Lmax );
169+
const int Lmax = m_jys_abfs.init( 2, ucell,orb, info.kmesh_times, orb.get_Rmax() );
176170
MGT.init_Gaunt_CH(Lmax);
177171
MGT.init_Gaunt(Lmax);
178172
m_jys_abfs.init_radial( jle, abfs, MGT );

0 commit comments

Comments
 (0)