diff --git a/source/module_cell/module_neighbor/sltk_atom.h b/source/module_cell/module_neighbor/sltk_atom.h index 187238e0d7..1c9ed519cb 100644 --- a/source/module_cell/module_neighbor/sltk_atom.h +++ b/source/module_cell/module_neighbor/sltk_atom.h @@ -20,15 +20,31 @@ class FAtom int type; int natom; + int cell_x; + int cell_y; + int cell_z; public: //========================================================== // Default Constructor and deconstructor //========================================================== FAtom(); + FAtom(const double& x_in, const double& y_in, const double& z_in, + const int& type_in, const int& natom_in, + const int& cell_x_in, const int& cell_y_in, const int& cell_z_in) + { + d_x = x_in; + d_y = y_in; + d_z = z_in; + type = type_in; + natom = natom_in; + cell_x = cell_x_in; + cell_y = cell_y_in; + cell_z = cell_z_in; + } ~FAtom(); //2015-05-07 - void delete_vector(void); + void delete_vector(); // static int count1; // static int count2; @@ -47,7 +63,7 @@ class FAtom std::shared_ptr getAdjacentSet() const { return this->as; } - void allocate_AdjacentSet(void) + void allocate_AdjacentSet() { this->as = std::make_shared(); } //========================================================== @@ -59,16 +75,9 @@ class FAtom const double& z() const { return d_z; } const int& getType() const { return type;} const int& getNatom() const { return natom;} - -//========================================================== -// MEMBER FUNCTION : -// EXPLAIN : set value -//========================================================== - void setX(const double& r) { d_x = r; } - void setY(const double& r) { d_y = r; } - void setZ(const double& r) { d_z = r; } - void setType(const int ntype) {type = ntype;} - void setNatom(const int atom) {natom = atom;} + const int& getCellX() const { return cell_x; } + const int& getCellY() const { return cell_y; } + const int& getCellZ() const { return cell_z; } }; #endif diff --git a/source/module_cell/module_neighbor/sltk_atom_input.cpp b/source/module_cell/module_neighbor/sltk_atom_input.cpp index 2f1f127766..7991bb142c 100644 --- a/source/module_cell/module_neighbor/sltk_atom_input.cpp +++ b/source/module_cell/module_neighbor/sltk_atom_input.cpp @@ -188,14 +188,6 @@ Atom_input::Atom_input Atom_input::~Atom_input() { - if (expand_flag) - { - delete [] store_x; - delete [] store_y; - delete [] store_z; - delete [] store_type; - delete [] store_natom; - } } //============================================ @@ -409,27 +401,6 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype) GlobalV::ofs_running << " Good luck! " << std::endl; } - double *x_old = new double[d_amount]; - double *y_old = new double[d_amount]; - double *z_old = new double[d_amount]; - - int *type_old = new int[d_amount]; - int *natom_old = new int[d_amount]; - - int ia = 0; - for (int i = 0;i < ntype;i++) - { - for (int j = 0;j < ucell.atoms[i].na;j++) - { - x_old[ia] = ucell.atoms[i].tau[j].x; - y_old[ia] = ucell.atoms[i].tau[j].y; - z_old[ia] = ucell.atoms[i].tau[j].z; - type_old[ia] = i; - natom_old[ia] = j; - ia++; - } - } - // how many copys we need now. const int gcopy = (glayerX + glayerX_minus) * @@ -443,23 +414,7 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype) if(test_atom_input)ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Atom_number_now",d_amount_expand); // store new atom positions. - this->store_x = new double[d_amount_expand]; - this->store_y = new double[d_amount_expand]; - this->store_z = new double[d_amount_expand]; - - ModuleBase::Memory::record("SLTK::Epd_Atom",sizeof(double) * d_amount_expand*3); - - // store which grid the atom is in. - store_cell_x = new int[d_amount_expand]; - store_cell_y = new int[d_amount_expand]; - store_cell_z = new int[d_amount_expand]; - - this->store_type = new int[d_amount_expand]; - this->store_natom = new int[d_amount_expand]; - ModuleBase::Memory::record("SLTK::Epd_atom_info",sizeof(int) * d_amount_expand*5); - - int ia_all = 0; for (int ix = -glayerX_minus; ix < glayerX; ix++) { @@ -467,48 +422,23 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype) { for (int iz = -glayerZ_minus; iz < glayerZ; iz++) { - for (int ia = 0; ia < d_amount; ia++) + for (int i = 0;i < ntype;i++) { - store_x[ia_all] = x_old[ia] + vec1[0] * ix + vec2[0] * iy + vec3[0] * iz; - store_y[ia_all] = y_old[ia] + vec1[1] * ix + vec2[1] * iy + vec3[1] * iz; - store_z[ia_all] = z_old[ia] + vec1[2] * ix + vec2[2] * iy + vec3[2] * iz; - store_type[ia_all] = type_old[ia]; - store_natom[ia_all] = natom_old[ia]; - - // notice '0' is not the origin unitcell. - store_cell_x[ia_all] = ix + glayerX_minus; - store_cell_y[ia_all] = iy + glayerY_minus; - store_cell_z[ia_all] = iz + glayerZ_minus; - - if (test_atom_input > 1) + for (int j = 0;j < ucell.atoms[i].na;j++) { - if (d_amount_expand < 1000) - { - GlobalV::ofs_running << "\n" << std::setw(6) << ia_all - << std::setw(10) << x_old[ia] - << std::setw(10) << y_old[ia] - << std::setw(10) << z_old[ia] - << std::setw(10) << store_x[ia_all] - << std::setw(10) << store_y[ia_all] - << std::setw(10) << store_z[ia_all] - << std::setw(6) << store_cell_x[ia_all] - << std::setw(6) << store_cell_y[ia_all] - << std::setw(6) << store_cell_z[ia_all]; - } - } + double x = ucell.atoms[i].tau[j].x + vec1[0] * ix + vec2[0] * iy + vec3[0] * iz; + double y = ucell.atoms[i].tau[j].y + vec1[1] * ix + vec2[1] * iy + vec3[1] * iz; + double z = ucell.atoms[i].tau[j].z + vec1[2] * ix + vec2[2] * iy + vec3[2] * iz; - ia_all++; + this->fake_atoms.push_back(FAtom(x, y, z, i, j, ix, iy, iz)); + } } } } } - // mohan fix bug 2012-04-02 by valgrind. - delete[] store_cell_x; - delete[] store_cell_y; - delete[] store_cell_z; - assert(ia_all == d_amount_expand); + assert(this->fake_atoms.size() == d_amount_expand); // becareful! now the cell is not the origin cell, // it's unitcell in expand case! so don't add @@ -554,12 +484,6 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype) << " Ymax=" << y_max_expand << " Zmax=" << z_max_expand << std::endl; } - - delete[] x_old; - delete[] y_old; - delete[] z_old; - delete[] type_old; - delete[] natom_old; return; } @@ -614,11 +538,7 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const //---------------------------------------------------------- if (expand_flag) { - a.setX(store_x[d_current]); - a.setY(store_y[d_current]); - a.setZ(store_z[d_current]); - a.setType(store_type[d_current]); - a.setNatom(store_natom[d_current]); + a = fake_atoms[d_current]; ++ d_current; } @@ -630,44 +550,20 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const //---------------------------------------------------------- else { - Load_atom(ucell - - ); - a.setX(x); - a.setY(y); - a.setZ(z); - a.setType(type); - a.setNatom(natom); -// GlobalV::ofs_running<<"\n x = "<= ucell.atoms[type].na) - { - type ++; - natom = 0; + if (natom >= ucell.atoms[type].na) + { + type ++; + natom = 0; + } + FAtom temp(ucell.atoms[type].tau[natom].x, + ucell.atoms[type].tau[natom].y, + ucell.atoms[type].tau[natom].z, + type, natom, + 0, 0, 0); + a = temp; } - x = ucell.atoms[type].tau[natom].x; - - y = ucell.atoms[type].tau[natom].y; - z = ucell.atoms[type].tau[natom].z; - -// std::cout<<" x = "<( (directx - this->d_minX) )=" << static_cast( (directy - this->d_minY) ) << std::endl; - std::cout << std::endl; - int ok; - cin >> ok; - } - */ + a = atom.getCellX() - this->d_minX; + b = atom.getCellY() - this->d_minY; + c = atom.getCellZ() - this->d_minZ; } else { @@ -500,7 +460,7 @@ void Grid::Build_Hash_Table(const UnitCell &ucell, AtomLink* const pointCache) Hash_one_hit = 0; // mohan add 2010-06-25 for (; current < end; ++ current) { - AtomLink* const hashTarget = this->getHashCode(ucell, current->fatom); + AtomLink* const hashTarget = this->getHashCode(ucell, current->fatom); //================================================ // Find a new position diff --git a/source/module_cell/module_neighbor/sltk_grid.h b/source/module_cell/module_neighbor/sltk_grid.h index e081ac57d5..18f3470d6c 100644 --- a/source/module_cell/module_neighbor/sltk_grid.h +++ b/source/module_cell/module_neighbor/sltk_grid.h @@ -22,11 +22,8 @@ struct AtomLink AtomLink* next_p; // Constructors and destructor - AtomLink - ( - const FAtom& atom = FAtom(), - AtomLink* const pointNext = NULL //mohan fix bug 2011/09/26, from NullPtr->NULL - ); + AtomLink(const FAtom& atom = FAtom(), AtomLink* const pointNext = NULL); + //mohan fix bug 2011/09/26, from NullPtr->NULL }; diff --git a/source/module_cell/module_neighbor/sltk_grid_driver.cpp b/source/module_cell/module_neighbor/sltk_grid_driver.cpp index e7b6e65238..798c4b33ca 100644 --- a/source/module_cell/module_neighbor/sltk_grid_driver.cpp +++ b/source/module_cell/module_neighbor/sltk_grid_driver.cpp @@ -70,19 +70,13 @@ int Grid_Driver::Locate_offset( //---------------------------------------------------------- // EXPLAIN : Create an AtomLink object //---------------------------------------------------------- - AtomLink temp; - - temp.fatom.setX(cartesian_pos.x); - temp.fatom.setY(cartesian_pos.y); - temp.fatom.setZ(cartesian_pos.z); - temp.fatom.setType(ntype); - temp.fatom.setNatom(nnumber); + FAtom temp(cartesian_pos.x, cartesian_pos.y, cartesian_pos.z, ntype, nnumber, 0, 0, 0); //---------------------------------------------------------- // EXPLAIN : Find the Hash number of this atom position //---------------------------------------------------------- - AtomLink* Search = this->getHashCode(ucell, temp.fatom); - + AtomLink* Search = this->getHashCode(ucell, temp); + //---------------------------------------------------------- // EXPLAIN : If we don't get the index for one Hash try, // we need to search in array. @@ -196,28 +190,6 @@ void Grid_Driver::Find_adjacent_atom(const int offset, std::shared_ptr &adjacent_site)const -{ - const double dx = a1.fatom.x() - adjacent_site.x; - const double dy = a1.fatom.y() - adjacent_site.y; - const double dz = a1.fatom.z() - adjacent_site.z; - return sqrt(dx*dx + dy*dy + dz*dz); -} - ModuleBase::Vector3 Grid_Driver::Calculate_adjacent_site ( @@ -241,30 +213,6 @@ ModuleBase::Vector3 Grid_Driver::Calculate_adjacent_site return adjacent_site; } -AdjacentAtomInfo Grid_Driver::get_adjs(const UnitCell& ucell_in, const size_t &iat) -{ - const int it = ucell_in.iat2it[iat]; - const int ia = ucell_in.iat2ia[iat]; - const ModuleBase::Vector3 &tau = ucell_in.atoms[it].tau[ia]; - - AdjacentAtomInfo adjs; - this->Find_atom(ucell_in, tau, it, ia, &adjs); - return adjs; -} - -std::vector Grid_Driver::get_adjs(const UnitCell& ucell_in) -{ - std::vector adjs(ucell_in.nat); -#ifdef _OPENMP -#pragma omp parallel for -#endif - for(size_t iat = 0; iat < ucell_in.nat; iat++) - { - adjs[iat] = Grid_Driver::get_adjs(ucell_in, iat); - } - return adjs; -} - // filter_adjs delete not adjacent atoms in adjs void filter_adjs(const std::vector& is_adj, AdjacentAtomInfo& adjs) { diff --git a/source/module_cell/module_neighbor/sltk_grid_driver.h b/source/module_cell/module_neighbor/sltk_grid_driver.h index e501cb8940..61216665bb 100644 --- a/source/module_cell/module_neighbor/sltk_grid_driver.h +++ b/source/module_cell/module_neighbor/sltk_grid_driver.h @@ -77,13 +77,6 @@ class Grid_Driver : public Grid const ModuleBase::Vector3& getAdjacentTau(const int i) const { return adj_info.adjacent_tau[i]; } const ModuleBase::Vector3& getBox(const int i) const {return adj_info.box[i];} - //========================================================== - // get_adjs will not store results in Grid_Driver::adj_info, - // but return the AdjacentAtomInfo object instead - //========================================================== - AdjacentAtomInfo get_adjs(const UnitCell& ucell_in, const size_t &iat); - std::vector get_adjs(const UnitCell& ucell_in); - private: mutable AdjacentAtomInfo adj_info; @@ -107,9 +100,6 @@ class Grid_Driver : public Grid std::shared_ptr as, AdjacentAtomInfo &adjs)const; - double Distance(const AtomLink& a1, const ModuleBase::Vector3 &adjacent_site)const; - double Distance(const AtomLink& a1, const AtomLink& a2)const; - //========================================================== // MEMBER FUNCTIONS : // NAME : Calculate_adjacent_site diff --git a/source/module_cell/module_neighbor/test/sltk_atom_test.cpp b/source/module_cell/module_neighbor/test/sltk_atom_test.cpp index 6a8488f4e1..11307b269e 100644 --- a/source/module_cell/module_neighbor/test/sltk_atom_test.cpp +++ b/source/module_cell/module_neighbor/test/sltk_atom_test.cpp @@ -44,16 +44,17 @@ TEST_F(SltkAtomTest, AllocateAdjacentSet) EXPECT_EQ(b->box.size(), 0); } + TEST_F(SltkAtomTest, SetterGetters) { - test.setX(1.0); - test.setY(2.0); - test.setZ(3.0); - test.setType(4); - test.setNatom(5); - EXPECT_DOUBLE_EQ(test.x(), 1.0); - EXPECT_DOUBLE_EQ(test.y(), 2.0); - EXPECT_DOUBLE_EQ(test.z(), 3.0); - EXPECT_EQ(test.getType(), 4); - EXPECT_EQ(test.getNatom(), 5); + FAtom test_temp(1.0, 2.0, 3.0, 4, 5, 0, 1, 2); + + EXPECT_DOUBLE_EQ(test_temp.x(), 1.0); + EXPECT_DOUBLE_EQ(test_temp.y(), 2.0); + EXPECT_DOUBLE_EQ(test_temp.z(), 3.0); + EXPECT_EQ(test_temp.getType(), 4); + EXPECT_EQ(test_temp.getNatom(), 5); + EXPECT_EQ(test_temp.getCellX(), 0); + EXPECT_EQ(test_temp.getCellY(), 1); + EXPECT_EQ(test_temp.getCellZ(), 2); }