Skip to content

Commit 76629aa

Browse files
committed
add constructors for atom_input
1 parent c7456a0 commit 76629aa

File tree

6 files changed

+47
-91
lines changed

6 files changed

+47
-91
lines changed

source/module_cell/module_neighbor/sltk_atom.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ class FAtom
2929
//==========================================================
3030

3131
FAtom();
32+
FAtom(const double& x_in, const double& y_in, const double& z_in,
33+
const int& type_in, const int& natom_in,
34+
const int& cell_x_in, const int& cell_y_in, const int& cell_z_in)
35+
{
36+
d_x = x_in;
37+
d_y = y_in;
38+
d_z = z_in;
39+
type = type_in;
40+
natom = natom_in;
41+
cell_x = cell_x_in;
42+
cell_y = cell_y_in;
43+
cell_z = cell_z_in;
44+
}
3245
~FAtom();
3346
//2015-05-07
3447
void delete_vector(void);
@@ -64,22 +77,7 @@ class FAtom
6477
const int& getNatom() const { return natom;}
6578
const int& getCellX() const { return cell_x; }
6679
const int& getCellY() const { return cell_y; }
67-
const int& getCellZ() const { return cell_z; }
68-
69-
70-
//==========================================================
71-
// MEMBER FUNCTION :
72-
// EXPLAIN : set value
73-
//==========================================================
74-
void setX(const double& r) { d_x = r; }
75-
void setY(const double& r) { d_y = r; }
76-
void setZ(const double& r) { d_z = r; }
77-
void setType(const int ntype) {type = ntype;}
78-
void setNatom(const int atom) {natom = atom;}
79-
void setCellX(const int nx) {cell_x = nx;}
80-
void setCellY(const int ny) {cell_y = ny;}
81-
void setCellZ(const int nz) {cell_z = nz;}
82-
80+
const int& getCellZ() const { return cell_z; }
8381
};
8482

8583
#endif

source/module_cell/module_neighbor/sltk_atom_input.cpp

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,11 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype)
426426
{
427427
for (int j = 0;j < ucell.atoms[i].na;j++)
428428
{
429-
FAtom fake_atom;
430-
fake_atom.setX(ucell.atoms[i].tau[j].x + vec1[0] * ix + vec2[0] * iy + vec3[0] * iz);
431-
fake_atom.setY(ucell.atoms[i].tau[j].y + vec1[1] * ix + vec2[1] * iy + vec3[1] * iz);
432-
fake_atom.setZ(ucell.atoms[i].tau[j].z + vec1[2] * ix + vec2[2] * iy + vec3[2] * iz);
433-
fake_atom.setType(i);
434-
fake_atom.setNatom(j);
435-
fake_atom.setCellX(ix);
436-
fake_atom.setCellY(iy);
437-
fake_atom.setCellZ(iz);
438-
439-
this->fake_atoms.push_back(fake_atom);
429+
double x = ucell.atoms[i].tau[j].x + vec1[0] * ix + vec2[0] * iy + vec3[0] * iz;
430+
double y = ucell.atoms[i].tau[j].y + vec1[1] * ix + vec2[1] * iy + vec3[1] * iz;
431+
double z = ucell.atoms[i].tau[j].z + vec1[2] * ix + vec2[2] * iy + vec3[2] * iz;
432+
433+
this->fake_atoms.push_back(FAtom(x, y, z, i, j, ix, iy, iz));
440434
}
441435
}
442436
}
@@ -556,42 +550,20 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const
556550
//----------------------------------------------------------
557551
else
558552
{
559-
Load_atom(ucell);
560-
a.setX(x);
561-
a.setY(y);
562-
a.setZ(z);
563-
a.setType(type);
564-
a.setNatom(natom);
565-
// GlobalV::ofs_running<<"\n x = "<<x;
566-
// GlobalV::ofs_running<<"\n y = "<<y;
567-
// GlobalV::ofs_running<<"\n z = "<<z;
568-
// GlobalV::ofs_running<<"\n Type = "<<type;
569-
// GlobalV::ofs_running<<"\n natom = "<<natom;
570-
}
571-
572-
return;
573-
}
574-
575-
void Atom_input::Load_atom(const UnitCell& ucell)const
576-
{
577-
// ModuleBase::TITLE("Atom_input","load_atom");
578-
natom++;
553+
natom++;
579554

580-
if (natom >= ucell.atoms[type].na)
581-
{
582-
type ++;
583-
natom = 0;
555+
if (natom >= ucell.atoms[type].na)
556+
{
557+
type ++;
558+
natom = 0;
559+
}
560+
FAtom temp(ucell.atoms[type].tau[natom].x,
561+
ucell.atoms[type].tau[natom].y,
562+
ucell.atoms[type].tau[natom].z,
563+
type, natom,
564+
0, 0, 0);
565+
a = temp;
584566
}
585567

586-
x = ucell.atoms[type].tau[natom].x;
587-
588-
y = ucell.atoms[type].tau[natom].y;
589-
z = ucell.atoms[type].tau[natom].z;
590-
591-
// std::cout<<" x = "<<ucell.atoms[type].tau[natom].x
592-
// <<" y = "<<ucell.atoms[type].tau[natom].y
593-
// <<" z = "<<ucell.atoms[type].tau[natom].z
594-
// <<" type = "<<type
595-
// <<" natom = "<<natom;
596568
return;
597569
}

source/module_cell/module_neighbor/sltk_atom_input.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ class Atom_input
177177
// MEMBRE FUNCTION :
178178
// NAME : Load_atom
179179
//==========================================================
180-
void Load_atom(const UnitCell& ucell)const;
180+
181181
mutable int d_current;
182-
mutable double x;
183-
mutable double y;
184-
mutable double z;
185182
mutable int type;
186183
mutable int natom;
187184
};

source/module_cell/module_neighbor/sltk_grid.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ struct AtomLink
2222
AtomLink* next_p;
2323

2424
// Constructors and destructor
25-
AtomLink
26-
(
27-
const FAtom& atom = FAtom(),
28-
AtomLink* const pointNext = NULL //mohan fix bug 2011/09/26, from NullPtr->NULL
29-
);
25+
AtomLink(const FAtom& atom = FAtom(), AtomLink* const pointNext = NULL);
26+
//mohan fix bug 2011/09/26, from NullPtr->NULL
3027

3128
};
3229

source/module_cell/module_neighbor/sltk_grid_driver.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,12 @@ int Grid_Driver::Locate_offset(
7070
//----------------------------------------------------------
7171
// EXPLAIN : Create an AtomLink object
7272
//----------------------------------------------------------
73-
AtomLink temp;
74-
75-
temp.fatom.setX(cartesian_pos.x);
76-
temp.fatom.setY(cartesian_pos.y);
77-
temp.fatom.setZ(cartesian_pos.z);
78-
temp.fatom.setCellX(0);
79-
temp.fatom.setCellY(0);
80-
temp.fatom.setCellZ(0);
81-
temp.fatom.setType(ntype);
82-
temp.fatom.setNatom(nnumber);
73+
FAtom temp(cartesian_pos.x, cartesian_pos.y, cartesian_pos.z, ntype, nnumber, 0, 0, 0);
8374

8475
//----------------------------------------------------------
8576
// EXPLAIN : Find the Hash number of this atom position
8677
//----------------------------------------------------------
87-
AtomLink* Search = this->getHashCode(ucell, temp.fatom);
78+
AtomLink* Search = this->getHashCode(ucell, temp);
8879

8980
//----------------------------------------------------------
9081
// EXPLAIN : If we don't get the index for one Hash try,

source/module_cell/module_neighbor/test/sltk_atom_test.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ TEST_F(SltkAtomTest, AllocateAdjacentSet)
4444
EXPECT_EQ(b->box.size(), 0);
4545
}
4646

47+
4748
TEST_F(SltkAtomTest, SetterGetters)
4849
{
49-
test.setX(1.0);
50-
test.setY(2.0);
51-
test.setZ(3.0);
52-
test.setType(4);
53-
test.setNatom(5);
54-
EXPECT_DOUBLE_EQ(test.x(), 1.0);
55-
EXPECT_DOUBLE_EQ(test.y(), 2.0);
56-
EXPECT_DOUBLE_EQ(test.z(), 3.0);
57-
EXPECT_EQ(test.getType(), 4);
58-
EXPECT_EQ(test.getNatom(), 5);
50+
FAtom test_temp(1.0, 2.0, 3.0, 4, 5, 0, 1, 2);
51+
52+
EXPECT_DOUBLE_EQ(test_temp.x(), 1.0);
53+
EXPECT_DOUBLE_EQ(test_temp.y(), 2.0);
54+
EXPECT_DOUBLE_EQ(test_temp.z(), 3.0);
55+
EXPECT_EQ(test_temp.getType(), 4);
56+
EXPECT_EQ(test_temp.getNatom(), 5);
57+
EXPECT_EQ(test_temp.getCellX(), 0);
58+
EXPECT_EQ(test_temp.getCellY(), 1);
59+
EXPECT_EQ(test_temp.getCellZ(), 2);
5960
}

0 commit comments

Comments
 (0)