Skip to content

Commit 4a7c116

Browse files
dyzhengdyzheng
andauthored
Refactor: itiaiw2iat interface in UnitCell (#2241)
* Refactor: itiaiw2iat interface in UnitCell * Fix: compiling error in src_ri --------- Co-authored-by: dyzheng <[email protected]>
1 parent 5f7cd08 commit 4a7c116

File tree

6 files changed

+56
-12
lines changed

6 files changed

+56
-12
lines changed

source/module_cell/test/unitcell_test_readpp.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Magnetism::~Magnetism()
6161
* - cal_nwfc(): calcuate the total number of local basis: NSPIN != 4
6262
* - this corresponds to number_of_proj, PP_BETA in pp file, and atoms[it].l_nchi[nw], nw from orb file
6363
* - setup GlobalV::NLOCAL
64+
* - interfaces initialed in this function:
65+
* - itia2iat
66+
* - iat2iwt
67+
* - itiaiw2iwt
68+
* - iwt2iat
69+
* - iwt2iw
6470
* - CalNwfc2
6571
* - cal_nwfc(): calcuate the total number of local basis: NSPIN == 4
6672
* - CheckStructure
@@ -257,6 +263,37 @@ TEST_F(UcellTest,CalNwfc1)
257263
EXPECT_EQ(ucell->atoms[1].nw,9);
258264
EXPECT_EQ(ucell->nwmax,9);
259265
EXPECT_EQ(GlobalV::NLOCAL,3*9);
266+
//check itia2iat
267+
EXPECT_EQ(ucell->itia2iat.getSize(), 4);
268+
EXPECT_EQ(ucell->itia2iat(0,0), 0);
269+
EXPECT_EQ(ucell->itia2iat(0,1), 0);
270+
EXPECT_EQ(ucell->itia2iat(1,0), 1);
271+
EXPECT_EQ(ucell->itia2iat(1,1), 2);
272+
//check iat2iwt
273+
EXPECT_EQ(ucell->iat2iwt.size(), 3);
274+
EXPECT_EQ(ucell->iat2iwt[0], 0);
275+
EXPECT_EQ(ucell->iat2iwt[1], 9);
276+
EXPECT_EQ(ucell->iat2iwt[2], 18);
277+
//check itiaiw2iwt
278+
EXPECT_EQ(ucell->itiaiw2iwt(0, 0, 0), 0);
279+
EXPECT_EQ(ucell->itiaiw2iwt(0, 0, 1), 1);
280+
EXPECT_EQ(ucell->itiaiw2iwt(0, 0, 8), 8);
281+
EXPECT_EQ(ucell->itiaiw2iwt(1, 0, 0), 9);
282+
EXPECT_EQ(ucell->itiaiw2iwt(1, 1, 0), 18);
283+
//check itia2iat
284+
EXPECT_EQ(ucell->itia2iat.getSize(), 4);
285+
EXPECT_EQ(ucell->itia2iat(0, 0), 0);
286+
EXPECT_EQ(ucell->itia2iat(0, 1), 0);
287+
EXPECT_EQ(ucell->itia2iat(1, 0), 1);
288+
EXPECT_EQ(ucell->itia2iat(1, 1), 2);
289+
//check iwt2iat
290+
EXPECT_EQ(ucell->iwt2iat[0], 0);
291+
EXPECT_EQ(ucell->iwt2iat[10], 1);
292+
EXPECT_EQ(ucell->iwt2iat[20], 2);
293+
//check iwt2iw
294+
EXPECT_EQ(ucell->iwt2iw[0], 0);
295+
EXPECT_EQ(ucell->iwt2iw[10], 1);
296+
EXPECT_EQ(ucell->iwt2iw[20], 2);
260297
}
261298

262299
TEST_F(UcellTest,CalNwfc2)

source/module_cell/unitcell.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ UnitCell::UnitCell()
3939

4040
itia2iat.create(1, 1);
4141
lc = new int[3];
42-
itiaiw2iwt.create(1, 1, 1);
4342

4443
latvec = ModuleBase::Matrix3();
4544
latvec_supercell = ModuleBase::Matrix3();
@@ -873,7 +872,8 @@ void UnitCell::cal_nwfc(std::ofstream &log)
873872
this->iwt2iw = new int[GlobalV::NLOCAL];
874873

875874
this->itia2iat.create(ntype, namax);
876-
this->itiaiw2iwt.create(ntype, namax, nwmax*GlobalV::NPOL);
875+
//this->itiaiw2iwt.create(ntype, namax, nwmax*GlobalV::NPOL);
876+
this->iat2iwt.resize(nat);
877877
int iat=0;
878878
int iwt=0;
879879
for(int it = 0;it < ntype;it++)
@@ -882,9 +882,10 @@ void UnitCell::cal_nwfc(std::ofstream &log)
882882
{
883883
this->itia2iat(it, ia) = iat;
884884
//this->iat2ia[iat] = ia;
885+
this->iat2iwt[iat] = iwt;
885886
for(int iw=0; iw<atoms[it].nw * GlobalV::NPOL; iw++)
886887
{
887-
this->itiaiw2iwt(it, ia, iw) = iwt;
888+
//this->itiaiw2iwt(it, ia, iw) = iwt;
888889
this->iwt2iat[iwt] = iat;
889890
this->iwt2iw[iwt] = iw;
890891
++iwt;

source/module_cell/unitcell.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ class UnitCell
6767
int *iwt2iat; // iwt ==> iat.
6868
int *iwt2iw; // iwt ==> iw, Peize Lin add 2018-07-02
6969
ModuleBase::IntArray itia2iat;//(it, ia)==>iat, the index in nat, add 2009-3-2 by mohan
70-
ModuleBase::IntArray itiaiw2iwt;//(it, ia, iw)==>iwt, the index in nwfc, add 2009-3-2 by mohan
70+
//atom index iat to the first global index for orbital of this atom
71+
std::vector<int> iat2iwt;
72+
// indexing tool for find orbital global index from it,ia,iw
73+
template<typename Tiait>
74+
inline Tiait itiaiw2iwt(const Tiait &it, const Tiait &ia, const Tiait &iw) const
75+
{
76+
return Tiait(this->iat2iwt[this->itia2iat(it, ia)] + iw);
77+
}
7178

7279
//========================================================
7380
// indexing tools for ia and it

source/module_io/test/for_testing_input_conv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ UnitCell::UnitCell(){
111111

112112
itia2iat.create(1, 1);
113113
lc = new int[3];
114-
itiaiw2iwt.create(1, 1, 1);
115114

116115
latvec = ModuleBase::Matrix3();
117116
latvec_supercell = ModuleBase::Matrix3();

source/src_ri/exx_abfs-parallel-communicate-hexx-template.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ Tmatrix Exx_Abfs::Parallel::Communicate::Hexx::Ra2D_to_Km2D(const Parallel_Orbit
8383
{
8484
for(auto & HR_a2D_A : HR_a2D[is])
8585
{
86-
const size_t iat1 = HR_a2D_A.first;
87-
const size_t it1 = GlobalC::ucell.iat2it[iat1];
88-
const size_t ia1 = GlobalC::ucell.iat2ia[iat1];
86+
const int iat1 = HR_a2D_A.first;
87+
const int it1 = GlobalC::ucell.iat2it[iat1];
88+
const int ia1 = GlobalC::ucell.iat2ia[iat1];
8989
for(auto & HR_a2D_B : HR_a2D_A.second)
9090
{
91-
const size_t iat2 = HR_a2D_B.first;
92-
const size_t it2 = GlobalC::ucell.iat2it[iat2];
93-
const size_t ia2 = GlobalC::ucell.iat2ia[iat2];
91+
const int iat2 = HR_a2D_B.first;
92+
const int it2 = GlobalC::ucell.iat2it[iat2];
93+
const int ia2 = GlobalC::ucell.iat2ia[iat2];
9494

9595
Tmatrix HK_a2D;
9696
for(auto & HR_a2D_C : HR_a2D_B.second)

source/src_ri/exx_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ ofs_mpi.close();
10261026
if(GlobalV::GAMMA_ONLY_LOCAL)
10271027
{
10281028
std::ofstream ofs("LOC.DM.dat",std::ofstream::app);
1029-
const int it1=0, it2=0;
1029+
const size_t it1=0, it2=0;
10301030
for( size_t ia1=0; ia1!=GlobalC::ucell.atoms[it1].na; ++ia1 )
10311031
for( size_t ia2=0; ia2!=GlobalC::ucell.atoms[it2].na; ++ia2 )
10321032
for( size_t is=0; is!=GlobalV::NSPIN; ++is )

0 commit comments

Comments
 (0)