Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions source/module_cell/module_neighbor/sltk_atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +63,7 @@ class FAtom
std::shared_ptr<AdjacentSet> getAdjacentSet() const
{ return this->as; }

void allocate_AdjacentSet(void)
void allocate_AdjacentSet()
{ this->as = std::make_shared<AdjacentSet>(); }

//==========================================================
Expand All @@ -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
146 changes: 21 additions & 125 deletions source/module_cell/module_neighbor/sltk_atom_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

//============================================
Expand Down Expand Up @@ -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) *
Expand All @@ -443,72 +414,31 @@ 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++)
{
for (int iy = -glayerY_minus; iy < glayerY; iy++)
{
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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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 = "<<x;
// GlobalV::ofs_running<<"\n y = "<<y;
// GlobalV::ofs_running<<"\n z = "<<z;
// GlobalV::ofs_running<<"\n Type = "<<type;
// GlobalV::ofs_running<<"\n natom = "<<natom;
}

return;
}
natom++;

void Atom_input::Load_atom(const UnitCell& ucell)const
{
// ModuleBase::TITLE("Atom_input","load_atom");
natom++;

if (natom >= 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 = "<<ucell.atoms[type].tau[natom].x
// <<" y = "<<ucell.atoms[type].tau[natom].y
// <<" z = "<<ucell.atoms[type].tau[natom].z
// <<" type = "<<type
// <<" natom = "<<natom;
return;
}
Loading
Loading