@@ -58,17 +58,20 @@ void Center2_Orb::Orb11::init_radial_table(const std::set<size_t>& radials)
5858 const size_t rmesh = Center2_Orb::get_rmesh (this ->nA .getRcut (), this ->nB .getRcut (), dr_);
5959
6060 std::set<size_t > radials_used;
61- for (const size_t & ir: radials) {
62- if (ir < rmesh) {
61+ for (const size_t & ir: radials)
62+ {
63+ if (ir < rmesh)
64+ {
6365 radials_used.insert (ir);
64- }
65- }
66+ }
67+ }
6668
6769 for (int LAB = std::abs (LA - LB); LAB <= LA + LB; ++LAB)
6870 {
69- if ((LAB - std::abs (LA - LB)) % 2 == 1 ) { // if LA+LB-LAB == odd, then Gaunt_Coefficients = 0
71+ if ((LAB - std::abs (LA - LB)) % 2 == 1 ) // if LA+LB-LAB == odd, then Gaunt_Coefficients = 0
72+ {
7073 continue ;
71- }
74+ }
7275
7376 this ->Table_r [LAB].resize (rmesh, 0 );
7477 this ->Table_dr [LAB].resize (rmesh, 0 );
@@ -97,9 +100,10 @@ double Center2_Orb::Orb11::cal_overlap(const ModuleBase::Vector3<double>& RA,
97100 const double distance = (distance_true >= tiny1) ? distance_true : distance_true + tiny1;
98101 const double RcutA = this ->nA .getRcut ();
99102 const double RcutB = this ->nB .getRcut ();
100- if (distance > (RcutA + RcutB)) {
103+ if (distance > (RcutA + RcutB))
104+ {
101105 return 0.0 ;
102- }
106+ }
103107
104108 const int LA = this ->nA .getL ();
105109 const int LB = this ->nB .getL ();
@@ -112,6 +116,9 @@ double Center2_Orb::Orb11::cal_overlap(const ModuleBase::Vector3<double>& RA,
112116 rly);
113117
114118 double overlap = 0.0 ;
119+ const int idx1 = this ->MGT .get_lm_index (LA, mA );
120+ const int idx2 = this ->MGT .get_lm_index (LB, mB );
121+ const double * Gaunt_Coefficients_ptr = &(this ->MGT .Gaunt_Coefficients (idx1, idx2, 0 ));
115122
116123 for (const auto & tb_r: this ->Table_r )
117124 {
@@ -120,17 +127,18 @@ double Center2_Orb::Orb11::cal_overlap(const ModuleBase::Vector3<double>& RA,
120127 for (int mAB = 0 ; mAB != 2 * LAB + 1 ; ++mAB )
121128 // const int mAB = mA + mB;
122129 {
123- const double Gaunt_real_A_B_AB = this ->MGT .Gaunt_Coefficients ( this -> MGT . get_lm_index (LA, mA ),
124- this -> MGT . get_lm_index (LB, mB ),
125- this -> MGT . get_lm_index (LAB, mAB ));
126- if ( 0 == Gaunt_real_A_B_AB) {
130+ const int idx3 = this ->MGT .get_lm_index (LAB, mAB );
131+ const double Gaunt_real_A_B_AB = *(Gaunt_Coefficients_ptr + idx3);
132+ if ( 0 == Gaunt_real_A_B_AB)
133+ {
127134 continue ;
128- }
135+ }
129136
130- const double ylm_solid = rly[this ->MGT .get_lm_index (LAB, mAB )];
131- if (0 == ylm_solid) {
137+ const double ylm_solid = rly[idx3];
138+ if (0 == ylm_solid)
139+ {
132140 continue ;
133- }
141+ }
134142 const double ylm_real = (distance > tiny2) ? ylm_solid / pow (distance, LAB) : ylm_solid;
135143
136144 const double i_exp = std::pow (-1.0 , (LA - LB - LAB) / 2 );
@@ -166,18 +174,23 @@ ModuleBase::Vector3<double> Center2_Orb::Orb11::cal_grad_overlap( // caoyu add 2
166174 const double distance = (distance_true >= tiny1) ? distance_true : distance_true + tiny1;
167175 const double RcutA = this ->nA .getRcut ();
168176 const double RcutB = this ->nB .getRcut ();
169- if (distance > (RcutA + RcutB)) {
177+ if (distance > (RcutA + RcutB))
178+ {
170179 return ModuleBase::Vector3<double >(0.0 , 0.0 , 0.0 );
171- }
180+ }
172181
173182 const int LA = this ->nA .getL ();
174183 const int LB = this ->nB .getL ();
184+ const int idx1 = this ->MGT .get_lm_index (LA, mA );
185+ const int idx2 = this ->MGT .get_lm_index (LB, mB );
186+ const double * Gaunt_Coefficients_ptr = &(this ->MGT .Gaunt_Coefficients (idx1, idx2, 0 ));
175187
176- std::vector<double > rly ((LA + LB + 1 ) * (LA + LB + 1 ));
188+ const int LAB2 = (LA + LB + 1 ) * (LA + LB + 1 );
189+ std::vector<double > rly (LAB2);
177190 std::vector<ModuleBase::Vector3<double >> grly;
178- ModuleBase::Array_Pool<double > tmp_grly ((LA + LB + 1 ) * (LA + LB + 1 ) , 3 );
191+ ModuleBase::Array_Pool<double > tmp_grly (LAB2 , 3 );
179192 ModuleBase::Ylm::grad_rl_sph_harm (LA + LB, delta_R.x , delta_R.y , delta_R.z , rly.data (), tmp_grly.get_ptr_2D ());
180- for (int i=0 ; i<(LA + LB + 1 ) * (LA + LB + 1 ) ; ++i)
193+ for (int i=0 ; i<LAB2 ; ++i)
181194 {
182195 ModuleBase::Vector3<double > ele (tmp_grly[i][0 ], tmp_grly[i][1 ], tmp_grly[i][2 ]);
183196 grly.push_back (ele);
@@ -191,17 +204,17 @@ ModuleBase::Vector3<double> Center2_Orb::Orb11::cal_grad_overlap( // caoyu add 2
191204 for (int mAB = 0 ; mAB != 2 * LAB + 1 ; ++mAB )
192205 // const int mAB = mA + mB;
193206 {
194- const double Gaunt_real_A_B_AB = this ->MGT .Gaunt_Coefficients ( this -> MGT . get_lm_index (LA, mA ),
195- this -> MGT . get_lm_index (LB, mB ),
196- this -> MGT . get_lm_index (LAB, mAB ));
197- if ( 0 == Gaunt_real_A_B_AB) {
207+ const int idx3 = this ->MGT .get_lm_index (LAB, mAB );
208+ const double Gaunt_real_A_B_AB = *(Gaunt_Coefficients_ptr + idx3);
209+ if ( 0 == Gaunt_real_A_B_AB)
210+ {
198211 continue ;
199- }
212+ }
200213
201- const double ylm_solid = rly[this -> MGT . get_lm_index (LAB, mAB ) ];
214+ const double ylm_solid = rly[idx3 ];
202215 const double ylm_real = (distance > tiny2) ? ylm_solid / pow (distance, LAB) : ylm_solid;
203216
204- const ModuleBase::Vector3<double > gylm_solid = grly[this -> MGT . get_lm_index (LAB, mAB ) ];
217+ const ModuleBase::Vector3<double > gylm_solid = grly[idx3 ];
205218 const ModuleBase::Vector3<double > gylm_real
206219 = (distance > tiny2) ? gylm_solid / pow (distance, LAB) : gylm_solid;
207220
0 commit comments