Skip to content

Commit 89a629e

Browse files
Refactor: Remove LCAO_Matrix.cpp (#4602)
* add set_mat2d into LCAO_domain.h * delete set_mat2d & set_HSgamma from LM * replace lm.set_HSgamma by LCAO_domain::set_mat2d * remove LCAO_matrix.cpp * avoid redefinition of LM in test * avoid redefinition of LM in test
1 parent 2f8c540 commit 89a629e

File tree

10 files changed

+75
-92
lines changed

10 files changed

+75
-92
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,13 @@ OBJS_LCAO=DM_gamma.o\
525525
spar_hsr.o\
526526
spar_st.o\
527527
spar_u.o\
528-
LCAO_matrix.o\
529528
LCAO_set_fs.o\
530529
LCAO_set_st.o\
531530
LCAO_nl_mu.o\
532531
LCAO_nnr.o\
533532
LCAO_set_zero.o\
534533
LCAO_allocate.o\
534+
LCAO_set_mat2d.o\
535535
center2_orb.o\
536536
center2_orb-orb11.o\
537537
center2_orb-orb21.o\

source/module_hamilt_lcao/hamilt_lcaodft/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ if(ENABLE_LCAO)
3232
spar_hsr.cpp
3333
spar_st.cpp
3434
spar_u.cpp
35-
LCAO_matrix.cpp
3635
LCAO_nnr.cpp
3736
LCAO_set_fs.cpp
3837
LCAO_set_st.cpp
3938
LCAO_nl_mu.cpp
4039
LCAO_set_zero.cpp
4140
LCAO_allocate.cpp
41+
LCAO_set_mat2d.cpp
4242
record_adj.cpp
4343
center2_orb.cpp
4444
center2_orb-orb11.cpp

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ void zeros_HSR(const char& mtype, LCAO_HS_Arrays& HS_arrays);
165165

166166
void divide_HS_in_frag(LCAO_Matrix& lm, const bool isGamma, Parallel_Orbitals& pv, const int& nks);
167167

168+
template <typename T>
169+
void set_mat2d(const int& global_ir,
170+
const int& global_ic,
171+
const T& v,
172+
const Parallel_Orbitals& pv,
173+
T* mat);
174+
168175
} // namespace LCAO_domain
169176

170177
#endif

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
class LCAO_Matrix {
1818
public:
19-
LCAO_Matrix();
20-
~LCAO_Matrix();
19+
LCAO_Matrix(){};
20+
~LCAO_Matrix(){};
2121

2222
Parallel_Orbitals* ParaV;
2323

@@ -40,20 +40,6 @@ class LCAO_Matrix {
4040
// Records the R direct coordinates of HR and SR output, This variable will
4141
// be filled with data when HR and SR files are output.
4242
std::set<Abfs::Vector3_Order<int>> output_R_coor;
43-
44-
template <typename T>
45-
static void set_mat2d(const int& global_ir,
46-
const int& global_ic,
47-
const T& v,
48-
const Parallel_Orbitals& pv,
49-
T* mat);
50-
51-
void set_HSgamma(const int& iw1_all,
52-
const int& iw2_all,
53-
const double& v,
54-
double* HSloc);
5543
};
5644

57-
#include "LCAO_matrix.hpp"
58-
5945
#endif

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_nl_mu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,10 @@ void build_Nonlocal_mu_new(LCAO_Matrix& lm,
344344
// mohan add 2010-12-20
345345
if (nlm_tmp != 0.0)
346346
{
347-
lm.set_HSgamma(iw1_all,
347+
LCAO_domain::set_mat2d(iw1_all,
348348
iw2_all,
349349
nlm_tmp,
350+
*lm.ParaV,
350351
NLloc); // N stands for nonlocal.
351352
}
352353
}

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.hpp renamed to source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_mat2d.cpp

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,58 @@
1-
#ifndef LCAO_MATRIX_HPP
2-
#define LCAO_MATRIX_HPP
3-
4-
#include "LCAO_matrix.h"
5-
6-
//------------------------------------------------------
7-
// DESCRIPTION:
8-
// set 'dtype' matrix element (iw1_all, iw2_all) with
9-
// an input value 'v'
10-
//------------------------------------------------------
11-
template<typename T>
12-
void LCAO_Matrix::set_mat2d(
13-
const int& global_ir, // index i for atomic orbital (row)
14-
const int& global_ic, // index j for atomic orbital (column)
15-
const T& v, // value for matrix element (i,j)
16-
const Parallel_Orbitals& pv,
17-
T* HSloc) //input pointer for store the matrix
18-
{
19-
// use iw1_all and iw2_all to set Hloc
20-
// becareful! The ir and ic may be < 0 !!!
21-
const int ir = pv.global2local_row(global_ir);
22-
const int ic = pv.global2local_col(global_ic);
23-
24-
const long index =
25-
ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()
26-
? ic * static_cast<long>(pv.nrow) + ir
27-
: ir * static_cast<long>(pv.ncol) + ic;
28-
29-
if (index >= pv.nloc)
30-
{
31-
std::cout << " iw1_all = " << global_ir << std::endl;
32-
std::cout << " iw2_all = " << global_ic << std::endl;
33-
std::cout << " ir = " << ir << std::endl;
34-
std::cout << " ic = " << ic << std::endl;
35-
std::cout << " index = " << index << std::endl;
36-
std::cout << " ParaV->nloc = " << pv.nloc << std::endl;
37-
ModuleBase::WARNING_QUIT("LCAO_Matrix", "set_mat2d");
38-
}
39-
40-
//using input pointer HSloc
41-
HSloc[index] += v;
42-
}
43-
44-
#endif
1+
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"
2+
3+
namespace LCAO_domain
4+
{
5+
6+
//------------------------------------------------------
7+
// DESCRIPTION:
8+
// set 'dtype' matrix element (iw1_all, iw2_all) with
9+
// an input value 'v'
10+
//------------------------------------------------------
11+
template<typename T>
12+
void set_mat2d(
13+
const int& global_ir, // index i for atomic orbital (row)
14+
const int& global_ic, // index j for atomic orbital (column)
15+
const T& v, // value for matrix element (i,j)
16+
const Parallel_Orbitals& pv,
17+
T* HSloc) //input pointer for store the matrix
18+
{
19+
// use iw1_all and iw2_all to set Hloc
20+
// becareful! The ir and ic may be < 0 !!!
21+
const int ir = pv.global2local_row(global_ir);
22+
const int ic = pv.global2local_col(global_ic);
23+
24+
const long index =
25+
ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()
26+
? ic * static_cast<long>(pv.nrow) + ir
27+
: ir * static_cast<long>(pv.ncol) + ic;
28+
29+
if (index >= pv.nloc)
30+
{
31+
std::cout << " iw1_all = " << global_ir << std::endl;
32+
std::cout << " iw2_all = " << global_ic << std::endl;
33+
std::cout << " ir = " << ir << std::endl;
34+
std::cout << " ic = " << ic << std::endl;
35+
std::cout << " index = " << index << std::endl;
36+
std::cout << " ParaV->nloc = " << pv.nloc << std::endl;
37+
ModuleBase::WARNING_QUIT("LCAO_Matrix", "set_mat2d");
38+
}
39+
40+
//using input pointer HSloc
41+
HSloc[index] += v;
42+
}
43+
44+
template void set_mat2d<double>(
45+
const int& global_ir,
46+
const int& global_ic,
47+
const double& v,
48+
const Parallel_Orbitals& pv,
49+
double* HSloc);
50+
51+
template void set_mat2d<std::complex<double>>(
52+
const int& global_ir,
53+
const int& global_ic,
54+
const std::complex<double>& v,
55+
const Parallel_Orbitals& pv,
56+
std::complex<double>* HSloc);
57+
58+
} // namespace LCAO_domain

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_set_st.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void single_overlap(LCAO_Matrix& lm,
272272
// according to global2local_row and global2local_col
273273
// the last paramete: 1 for Sloc, 2 for Hloc
274274
// and 3 for Hloc_fixed.
275-
lm.set_HSgamma(iw1_all, iw2_all, olm[0], HSloc);
275+
LCAO_domain::set_mat2d(iw1_all, iw2_all, olm[0], *lm.ParaV, HSloc);
276276
}
277277
else // condition 7, multiple k-points algorithm
278278
{

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/test/test_sc_lambda_lcao.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ void hamilt::OperatorLCAO<double, double>::contributeHk(const int ik_in)
5555
* -
5656
*/
5757

58-
LCAO_Matrix::LCAO_Matrix()
59-
{
60-
}
61-
62-
LCAO_Matrix::~LCAO_Matrix()
63-
{
64-
}
65-
6658
class ScLambdaLCAOTest : public ::testing::Test
6759
{
6860
protected:

source/module_ri/RI_2D_Comm.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "module_hamilt_pw/hamilt_pwdft/global.h"
1212
#include "module_base/tool_title.h"
1313
#include "module_base/timer.h"
14+
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"
1415

1516
#include <RI/global/Global_Func-2.h>
1617

@@ -145,7 +146,7 @@ void RI_2D_Comm::add_Hexx(
145146
if (pv.global2local_col(iwt1) < 0) {
146147
continue;
147148
}
148-
LCAO_Matrix::set_mat2d(iwt0, iwt1, RI::Global_Func::convert<TK>(H(iw0_b, iw1_b)) * RI::Global_Func::convert<TK>(frac), pv, hk);
149+
LCAO_domain::set_mat2d(iwt0, iwt1, RI::Global_Func::convert<TK>(H(iw0_b, iw1_b)) * RI::Global_Func::convert<TK>(frac), pv, hk);
149150
}
150151
}
151152
}
@@ -227,7 +228,7 @@ void RI_2D_Comm::add_HexxR(
227228
{
228229
ModuleBase::TITLE("RI_2D_Comm", "add_HexxR");
229230
ModuleBase::timer::tick("RI_2D_Comm", "add_HexxR");
230-
for (const auto& Hs_tmpA : Hs[GlobalV::NSPIN == 2 ? current_spin : 0])
231+
for (const auto& Hs_tmpA : Hs[GlobalV::NSPIN == 2 ? current_spin : 0])
231232
{
232233
const TA& iat0 = Hs_tmpA.first;
233234
for (const auto& Hs_tmpB : Hs_tmpA.second)

0 commit comments

Comments
 (0)