Skip to content

Commit bf2ff91

Browse files
linpeizePeizeLin
andauthored
Refactor: change cal_proj() to cal_mul() in Exx_Opt_Orb (#6506)
Co-authored-by: linpz <[email protected]>
1 parent 10a9c41 commit bf2ff91

File tree

2 files changed

+51
-57
lines changed

2 files changed

+51
-57
lines changed

source/source_lcao/module_ri/exx_opt_orb.cpp

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,19 @@ void Exx_Opt_Orb::generate_matrix(
174174
const std::vector<std::vector<RI::Tensor<double>>> ms_abfs_abfs_I = cal_I( ms_abfs_abfs, T,I,T,I );
175175
// < lcaos lcaos | lcaos lcaos > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | lcaos lcaos >
176176
const RI::Tensor<double> m_lcaoslcaos_lcaoslcaos_proj =
177-
cal_proj_22(
178-
ms_lcaoslcaos_lcaoslcaos.at(T).at(I).at(T).at(I),
177+
ms_lcaoslcaos_lcaoslcaos.at(T).at(I).at(T).at(I) - cal_mul_22(
179178
ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I),
180179
ms_abfs_abfs_I,
181180
ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I));
182181
// < lcaos lcaos | jys > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | jys >
183182
const std::vector<RI::Tensor<double>> m_lcaoslcaos_jys_proj =
184-
{cal_proj_21(
185-
ms_lcaoslcaos_jys.at(T).at(I).at(T).at(I)[0],
183+
{ms_lcaoslcaos_jys.at(T).at(I).at(T).at(I)[0] - cal_mul_21(
186184
ms_lcaoslcaos_abfs.at(T).at(I).at(T).at(I),
187185
ms_abfs_abfs_I,
188186
{ms_jys_abfs.at(T).at(I).at(T).at(I)})};
189187
// < jys | jys > - < jys | abfs > * < abfs | abfs >.I * < abfs | jys >
190188
const std::vector<std::vector<RI::Tensor<double>>> m_jys_jys_proj =
191-
{{cal_proj_11(
192-
ms_jys_jys.at(T).at(I).at(T).at(I),
189+
{{ms_jys_jys.at(T).at(I).at(T).at(I) - cal_mul_11(
193190
{ms_jys_abfs.at(T).at(I).at(T).at(I)},
194191
ms_abfs_abfs_I,
195192
{ms_jys_abfs.at(T).at(I).at(T).at(I)})}};
@@ -228,42 +225,35 @@ void Exx_Opt_Orb::generate_matrix(
228225
const std::vector<std::vector<RI::Tensor<double>>> ms_abfs_abfs_I = cal_I( ms_abfs_abfs, TA,IA,TB,IB );
229226
// < lcaos lcaos | lcaos lcaos > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | lcaos lcaos >
230227
const RI::Tensor<double> m_lcaoslcaos_lcaoslcaos_proj =
231-
cal_proj_22(
232-
ms_lcaoslcaos_lcaoslcaos.at(TA).at(IA).at(TB).at(IB),
228+
ms_lcaoslcaos_lcaoslcaos.at(TA).at(IA).at(TB).at(IB) - cal_mul_22(
233229
ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB),
234230
ms_abfs_abfs_I,
235231
ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB));
236232
// < lcaos lcaos | jys > - < lcaos lcaos | abfs > * < abfs | abfs >.I * < abfs | jys >
237233
const std::vector<RI::Tensor<double>> m_lcaoslcaos_jys_proj =
238-
{cal_proj_21(
239-
ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[0],
234+
{ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[0] - cal_mul_21(
240235
ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB),
241236
ms_abfs_abfs_I,
242237
{ ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }),
243-
cal_proj_21(
244-
ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[1],
238+
ms_lcaoslcaos_jys.at(TA).at(IA).at(TB).at(IB)[1] - cal_mul_21(
245239
ms_lcaoslcaos_abfs.at(TA).at(IA).at(TB).at(IB),
246240
ms_abfs_abfs_I,
247241
{ ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) })};
248242
// < jys | jys > - < jys | abfs > * < abfs | abfs >.I * < abfs | jys >
249243
const std::vector<std::vector<RI::Tensor<double>>> m_jys_jys_proj =
250-
{{cal_proj_11(
251-
ms_jys_jys.at(TA).at(IA).at(TA).at(IA),
244+
{{ms_jys_jys.at(TA).at(IA).at(TA).at(IA) - cal_mul_11(
252245
{ ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) },
253246
ms_abfs_abfs_I,
254247
{ ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }),
255-
cal_proj_11(
256-
ms_jys_jys.at(TA).at(IA).at(TB).at(IB),
248+
ms_jys_jys.at(TA).at(IA).at(TB).at(IB) - cal_mul_11(
257249
{ ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) },
258250
ms_abfs_abfs_I,
259251
{ ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }) },
260-
{cal_proj_11(
261-
ms_jys_jys.at(TB).at(IB).at(TA).at(IA),
252+
{ms_jys_jys.at(TB).at(IB).at(TA).at(IA) - cal_mul_11(
262253
{ ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) },
263254
ms_abfs_abfs_I,
264255
{ ms_jys_abfs.at(TA).at(IA).at(TA).at(IA), ms_jys_abfs.at(TA).at(IA).at(TB).at(IB) }),
265-
cal_proj_11(
266-
ms_jys_jys.at(TB).at(IB).at(TB).at(IB),
256+
ms_jys_jys.at(TB).at(IB).at(TB).at(IB) - cal_mul_11(
267257
{ ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) },
268258
ms_abfs_abfs_I,
269259
{ ms_jys_abfs.at(TB).at(IB).at(TA).at(IA), ms_jys_abfs.at(TB).at(IB).at(TB).at(IB) }) }};
@@ -301,86 +291,94 @@ void Exx_Opt_Orb::generate_matrix(
301291
}
302292
}
303293

304-
// m_big - m_left * m_middle * m_right.T
305-
RI::Tensor<double> Exx_Opt_Orb::cal_proj_22(
306-
const RI::Tensor<double> & m_big,
294+
// m_left * m_middle * m_right.T
295+
RI::Tensor<double> Exx_Opt_Orb::cal_mul_22(
307296
const std::vector<RI::Tensor<double>> & m_left,
308297
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
309298
const std::vector<RI::Tensor<double>> & m_right ) const
310299
{
311-
ModuleBase::TITLE("Exx_Opt_Orb::cal_proj_22");
312-
RI::Tensor<double> m_proj = m_big.copy();
300+
ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_22");
301+
RI::Tensor<double> m_mul;
313302
for( size_t il=0; il!=m_left.size(); ++il )
314303
{
315304
for( size_t ir=0; ir!=m_right.size(); ++ir )
316305
{
317-
// m_proj = m_proj - m_left[il] * m_middle[il][ir] * m_right[ir].T;
306+
// m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T;
318307
const RI::Tensor<double> m_lm = RI::Tensor_Multiply::x0x1y1_x0x1a_ay1(m_left[il], m_middle[il][ir]);
319308
const RI::Tensor<double> m_lmr = RI::Tensor_Multiply::x0x1y0y1_x0x1a_y0y1a(m_lm, m_right[ir]);
320-
m_proj -= m_lmr;
309+
if(m_mul.empty())
310+
{ m_mul = std::move(m_lmr); }
311+
else
312+
{ m_mul += m_lmr; }
321313
}
322314
}
323-
return m_proj;
315+
return m_mul;
324316
}
325-
RI::Tensor<double> Exx_Opt_Orb::cal_proj_21(
326-
const RI::Tensor<double> & m_big,
317+
RI::Tensor<double> Exx_Opt_Orb::cal_mul_21(
327318
const std::vector<RI::Tensor<double>> & m_left,
328319
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
329320
const std::vector<RI::Tensor<double>> & m_right ) const
330321
{
331-
ModuleBase::TITLE("Exx_Opt_Orb::cal_proj_21");
332-
RI::Tensor<double> m_proj = m_big.copy();
322+
ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_21");
323+
RI::Tensor<double> m_mul;
333324
for( size_t il=0; il!=m_left.size(); ++il )
334325
{
335326
for( size_t ir=0; ir!=m_right.size(); ++ir )
336327
{
337-
// m_proj = m_proj - m_left[il] * m_middle[il][ir] * m_right[ir].T;
328+
// m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T;
338329
const RI::Tensor<double> m_lm = RI::Tensor_Multiply::x0x1y1_x0x1a_ay1(m_left[il], m_middle[il][ir]);
339330
const RI::Tensor<double> m_lmr = RI::Tensor_Multiply::x0x1y0_x0x1a_y0a(m_lm, m_right[ir]);
340-
m_proj -= m_lmr;
331+
if(m_mul.empty())
332+
{ m_mul = std::move(m_lmr); }
333+
else
334+
{ m_mul += m_lmr; }
341335
}
342336
}
343-
return m_proj;
337+
return m_mul;
344338
}
345-
RI::Tensor<double> Exx_Opt_Orb::cal_proj_12(
346-
const RI::Tensor<double> & m_big,
339+
RI::Tensor<double> Exx_Opt_Orb::cal_mul_12(
347340
const std::vector<RI::Tensor<double>> & m_left,
348341
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
349342
const std::vector<RI::Tensor<double>> & m_right ) const
350343
{
351-
ModuleBase::TITLE("Exx_Opt_Orb::cal_proj_12");
352-
RI::Tensor<double> m_proj = m_big.copy();
344+
ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_12");
345+
RI::Tensor<double> m_mul;
353346
for( size_t il=0; il!=m_left.size(); ++il )
354347
{
355348
for( size_t ir=0; ir!=m_right.size(); ++ir )
356349
{
357-
// m_proj = m_proj - m_left[il] * m_middle[il][ir] * m_right[ir].T;
350+
// m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T;
358351
const RI::Tensor<double> m_lm = RI::Tensor_Multiply::x0y1_x0a_ay1(m_left[il], m_middle[il][ir]);
359352
const RI::Tensor<double> m_lmr = RI::Tensor_Multiply::x0y0y1_x0a_y0y1a(m_lm, m_right[ir]);
360-
m_proj -= m_lmr;
353+
if(m_mul.empty())
354+
{ m_mul = std::move(m_lmr); }
355+
else
356+
{ m_mul += m_lmr; }
361357
}
362358
}
363-
return m_proj;
359+
return m_mul;
364360
}
365-
RI::Tensor<double> Exx_Opt_Orb::cal_proj_11(
366-
const RI::Tensor<double> & m_big,
361+
RI::Tensor<double> Exx_Opt_Orb::cal_mul_11(
367362
const std::vector<RI::Tensor<double>> & m_left,
368363
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
369364
const std::vector<RI::Tensor<double>> & m_right ) const
370365
{
371-
ModuleBase::TITLE("Exx_Opt_Orb::cal_proj_11");
372-
RI::Tensor<double> m_proj = m_big.copy();
366+
ModuleBase::TITLE("Exx_Opt_Orb::cal_mul_11");
367+
RI::Tensor<double> m_mul;
373368
for( size_t il=0; il!=m_left.size(); ++il )
374369
{
375370
for( size_t ir=0; ir!=m_right.size(); ++ir )
376371
{
377-
// m_proj = m_proj - m_left[il] * m_middle[il][ir] * m_right[ir].T;
372+
// m_mul += m_left[il] * m_middle[il][ir] * m_right[ir].T;
378373
const RI::Tensor<double> m_lm = RI::Tensor_Multiply::x0y1_x0a_ay1(m_left[il], m_middle[il][ir]);
379374
const RI::Tensor<double> m_lmr = RI::Tensor_Multiply::x0y0_x0a_y0a(m_lm, m_right[ir]);
380-
m_proj -= m_lmr;
375+
if(m_mul.empty())
376+
{ m_mul = std::move(m_lmr); }
377+
else
378+
{ m_mul += m_lmr; }
381379
}
382380
}
383-
return m_proj;
381+
return m_mul;
384382
}
385383

386384
std::vector<std::vector<RI::Tensor<double>>> Exx_Opt_Orb::cal_I(

source/source_lcao/module_ri/exx_opt_orb.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,19 @@ class Exx_Opt_Orb
2323
std::vector<std::vector<RI::Tensor<double>>> cal_I(
2424
const std::map<size_t,std::map<size_t,std::map<size_t,std::map<size_t,RI::Tensor<double>>>>> &ms,
2525
const size_t TA, const size_t IA, const size_t TB, const size_t IB ) const;
26-
RI::Tensor<double> cal_proj_22(
27-
const RI::Tensor<double> & m_big,
26+
RI::Tensor<double> cal_mul_22(
2827
const std::vector<RI::Tensor<double>> & m_left,
2928
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
3029
const std::vector<RI::Tensor<double>> & m_right ) const;
31-
RI::Tensor<double> cal_proj_21(
32-
const RI::Tensor<double> & m_big,
30+
RI::Tensor<double> cal_mul_21(
3331
const std::vector<RI::Tensor<double>> & m_left,
3432
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
3533
const std::vector<RI::Tensor<double>> & m_right ) const;
36-
RI::Tensor<double> cal_proj_12(
37-
const RI::Tensor<double> & m_big,
34+
RI::Tensor<double> cal_mul_12(
3835
const std::vector<RI::Tensor<double>> & m_left,
3936
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
4037
const std::vector<RI::Tensor<double>> & m_right ) const;
41-
RI::Tensor<double> cal_proj_11(
42-
const RI::Tensor<double> & m_big,
38+
RI::Tensor<double> cal_mul_11(
4339
const std::vector<RI::Tensor<double>> & m_left,
4440
const std::vector<std::vector<RI::Tensor<double>>> & m_middle,
4541
const std::vector<RI::Tensor<double>> & m_right ) const;

0 commit comments

Comments
 (0)