Skip to content

Commit 5d9836c

Browse files
committed
rewrite module neighbour to parition atom into boxes
1 parent 5b97b61 commit 5d9836c

File tree

9 files changed

+191
-862
lines changed

9 files changed

+191
-862
lines changed

source/module_cell/module_neighbor/sltk_atom_arrange.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ void atom_arrange::search(const bool pbc_flag,
7070
ModuleBase::TITLE("atom_arrange", "search");
7171
ModuleBase::timer::tick("atom_arrange", "search");
7272

73-
assert(search_radius_bohr > 0.0);
73+
if (search_radius_bohr < 0.0)
74+
{
75+
ModuleBase::WARNING_QUIT("atom_arrange::search", " search_radius_bohr < 0,forbidden");
76+
}
7477

7578
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius is (Bohr))", search_radius_bohr);
7679
ModuleBase::GlobalFunc::OUT(ofs_in, "searching radius unit is (Bohr))", ucell.lat0);
@@ -82,7 +85,7 @@ void atom_arrange::search(const bool pbc_flag,
8285

8386
const double radius_lat0unit = search_radius_bohr / ucell.lat0;
8487

85-
88+
8689
Atom_input at(ofs_in, ucell, pbc_flag, radius_lat0unit, test_atom_in);
8790

8891
grid_d.init(ofs_in, ucell, at);
@@ -138,5 +141,5 @@ void atom_arrange::delete_vector(std::ofstream& ofs_in,
138141

139142
grid_d.delete_vector(at2.getGrid_layerX_minus(), at2.getGrid_layerY_minus(), at2.getGrid_layerZ_minus());
140143

141-
grid_d.delete_Cell();
144+
grid_d.clear_atoms();
142145
}

source/module_cell/module_neighbor/sltk_atom_input.cpp

Lines changed: 7 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ Atom_input::Atom_input(std::ofstream& ofs_in,
1212
const bool boundary_in,
1313
const double radius_in,
1414
const int& test_atom_in)
15-
: periodic_boundary(boundary_in), radius(radius_in), expand_flag(false), glayerX(1), glayerX_minus(0), glayerY(1),
16-
glayerY_minus(0), glayerZ(1), glayerZ_minus(0), test_atom_input(test_atom_in)
15+
: periodic_boundary(boundary_in), radius(radius_in),
16+
glayerX(1), glayerX_minus(0), glayerY(1),
17+
glayerY_minus(0), glayerZ(1), glayerZ_minus(0),
18+
test_atom_input(test_atom_in)
1719
{
1820
ModuleBase::TITLE("Atom_input", "Atom_input");
1921

@@ -23,70 +25,13 @@ Atom_input::Atom_input(std::ofstream& ofs_in,
2325
ModuleBase::GlobalFunc::OUT(ofs_in, "Searching radius(lat0)", radius);
2426
}
2527

26-
if (radius < 0.0)
27-
{
28-
ModuleBase::WARNING_QUIT("atom_arrange::init", " search radius < 0,forbidden");
29-
}
30-
// random selection, in order to estimate again.
31-
this->x_min = ucell.atoms[0].tau[0].x;
32-
this->y_min = ucell.atoms[0].tau[0].y;
33-
this->z_min = ucell.atoms[0].tau[0].z;
34-
this->x_max = ucell.atoms[0].tau[0].x;
35-
this->y_max = ucell.atoms[0].tau[0].y;
36-
this->z_max = ucell.atoms[0].tau[0].z;
37-
38-
// calculate min & max value
39-
for (int i = 0; i < ucell.ntype; i++)
40-
{
41-
for (int j = 0; j < ucell.atoms[i].na; j++)
42-
{
43-
x_min = std::min(x_min, ucell.atoms[i].tau[j].x);
44-
x_max = std::max(x_max, ucell.atoms[i].tau[j].x);
45-
y_min = std::min(y_min, ucell.atoms[i].tau[j].y);
46-
y_max = std::max(y_max, ucell.atoms[i].tau[j].y);
47-
z_min = std::min(z_min, ucell.atoms[i].tau[j].z);
48-
z_max = std::max(z_max, ucell.atoms[i].tau[j].z);
49-
}
50-
}
51-
52-
if (test_atom_input)
53-
{
54-
ModuleBase::GlobalFunc::OUT(ofs_in, "Find the coordinate range of the input atom(unit:lat0).");
55-
ModuleBase::GlobalFunc::OUT(ofs_in, "min_tau", x_min, y_min, z_min);
56-
ModuleBase::GlobalFunc::OUT(ofs_in, "max_tau", x_max, y_max, z_max);
57-
}
58-
59-
//----------------------------------------------------------
60-
// CALL MEMBER FUNCTION :
61-
// NAME : Check_Expand_Condition(check if swe need to
62-
// expand grid,and generate 6 MEMBER VARIABLE(number of
63-
// layers for 6 dimension)
64-
// initial value for "glayerX,Y,Z" : 1
65-
// (if > 2 ,expand flag = 1)
66-
// initial value for "glayerX,Y,Z_minus" : 0
67-
// ( if > 1 ,expand flag = 1)
68-
//----------------------------------------------------------
69-
7028
this->Check_Expand_Condition(ucell);
7129

7230
if (test_atom_input)
7331
{
7432
ModuleBase::GlobalFunc::OUT(ofs_in, "glayer+", glayerX, glayerY, glayerZ);
7533
ModuleBase::GlobalFunc::OUT(ofs_in, "glayer-", glayerX_minus, glayerY_minus, glayerZ_minus);
76-
ModuleBase::GlobalFunc::OUT(ofs_in, "expand_flag", expand_flag);
77-
}
78-
79-
//----------------------------------------------------------
80-
// CALL MEMBER FUNCTION :
81-
// NAME : calculate_cells
82-
// Calculate how many cells we need in each direction.
83-
//----------------------------------------------------------
84-
this->calculate_cells();
85-
if (test_atom_input)
86-
{
87-
ModuleBase::GlobalFunc::OUT(ofs_in, "CellDim", cell_nx, cell_ny, cell_nz);
8834
}
89-
return;
9035
}
9136

9237
Atom_input::~Atom_input()
@@ -180,143 +125,28 @@ void Atom_input::Check_Expand_Condition(const UnitCell& ucell)
180125
double a23_norm = sqrt(a23_1 * a23_1 + a23_2 * a23_2 + a23_3 * a23_3);
181126
double extend_v = a23_norm * radius;
182127
double extend_d1 = extend_v / ucell.omega * ucell.lat0 * ucell.lat0 * ucell.lat0;
183-
int extend_d11 = static_cast<int>(extend_d1);
184-
// 2016-09-05, LiuXh
185-
if (extend_d1 - extend_d11 > 0.0)
186-
{
187-
extend_d11 += 1;
188-
}
128+
int extend_d11 = std::ceil(extend_d1);
189129

190130
double a31_1 = ucell.latvec.e32 * ucell.latvec.e13 - ucell.latvec.e33 * ucell.latvec.e12;
191131
double a31_2 = ucell.latvec.e31 * ucell.latvec.e13 - ucell.latvec.e33 * ucell.latvec.e11;
192132
double a31_3 = ucell.latvec.e31 * ucell.latvec.e12 - ucell.latvec.e32 * ucell.latvec.e11;
193133
double a31_norm = sqrt(a31_1 * a31_1 + a31_2 * a31_2 + a31_3 * a31_3);
194134
double extend_d2 = a31_norm * radius / ucell.omega * ucell.lat0 * ucell.lat0 * ucell.lat0;
195-
int extend_d22 = static_cast<int>(extend_d2);
196-
// 2016-09-05, LiuXh
197-
if (extend_d2 - extend_d22 > 0.0)
198-
{
199-
extend_d22 += 1;
200-
}
135+
int extend_d22 = std::ceil(extend_d2);
201136

202137
double a12_1 = ucell.latvec.e12 * ucell.latvec.e23 - ucell.latvec.e13 * ucell.latvec.e22;
203138
double a12_2 = ucell.latvec.e11 * ucell.latvec.e23 - ucell.latvec.e13 * ucell.latvec.e21;
204139
double a12_3 = ucell.latvec.e11 * ucell.latvec.e22 - ucell.latvec.e12 * ucell.latvec.e21;
205140
double a12_norm = sqrt(a12_1 * a12_1 + a12_2 * a12_2 + a12_3 * a12_3);
206141
double extend_d3 = a12_norm * radius / ucell.omega * ucell.lat0 * ucell.lat0 * ucell.lat0;
207-
int extend_d33 = static_cast<int>(extend_d3);
142+
int extend_d33 = std::ceil(extend_d3);
208143
// 2016-09-05, LiuXh
209-
if (extend_d3 - extend_d33 > 0.0)
210-
{
211-
extend_d33 += 1;
212-
}
213144

214145
glayerX = extend_d11 + 1;
215146
glayerY = extend_d22 + 1;
216147
glayerZ = extend_d33 + 1;
217-
// Begin, 2016-09-05, LiuXh
218-
// glayerX_minus = extend_d11 +1;
219-
// glayerY_minus = extend_d22 +1;
220-
// glayerZ_minus = extend_d33 +1;
221148
glayerX_minus = extend_d11;
222149
glayerY_minus = extend_d22;
223150
glayerZ_minus = extend_d33;
224151
// End, 2016-09-05, LiuXh
225-
226-
if (glayerX == 1)
227-
{
228-
glayerX++;
229-
}
230-
if (glayerY == 1)
231-
{
232-
glayerY++;
233-
}
234-
if (glayerZ == 1)
235-
{
236-
glayerZ++;
237-
}
238-
if (glayerX_minus == 1)
239-
{
240-
glayerX_minus++;
241-
}
242-
if (glayerY_minus == 1)
243-
{
244-
glayerY_minus++;
245-
}
246-
if (glayerZ_minus == 1)
247-
{
248-
glayerZ_minus++;
249-
}
250-
// End, 2016-07-19, LiuXh
251-
/*
252-
if(test_atom_input)
253-
{
254-
GlobalV::ofs_running << " Extend distance from the (minX,minY,minZ) direct position in this unitcell: " <<
255-
std::endl;
256-
}
257-
258-
if(test_atom_input)OUT(GlobalV::ofs_running,"ExtentDim-",extent_1DX_minus,extent_1DY_minus,extent_1DZ_minus);
259-
*/
260-
//----------------------------------------------------------
261-
// EXPLAIN : if extent don't satisfty the searching
262-
// requiment, we must expand one more layer
263-
//----------------------------------------------------------
264-
265-
if (glayerX > 2 || glayerY > 2 || glayerZ > 2)
266-
{
267-
this->expand_flag = true;
268-
}
269-
else if (glayerX_minus > 1 || glayerX_minus > 1 || glayerX_minus > 1)
270-
{
271-
this->expand_flag = true;
272-
}
273-
else
274-
{
275-
this->expand_flag = false;
276-
}
277-
return;
278-
}
279-
280-
void Atom_input::calculate_cells()
281-
{
282-
ModuleBase::TITLE("Atom_input", "calculate_cells");
283-
//----------------------------------------------------------
284-
// EXPLAIN :
285-
// Expand_Case : Simple , we already know the cell numbres,
286-
// all the trouble is only to construct adjacentset using all
287-
// the cells.
288-
// Not_Expand_Case : Using searching radius to construct
289-
// the cells , trouble here,but is the convenience of searching
290-
// time , we then only need to search 27-adjacent cell for each cell.
291-
//----------------------------------------------------------
292-
if (expand_flag)
293-
{
294-
cell_nx = glayerX + glayerX_minus;
295-
cell_ny = glayerY + glayerY_minus;
296-
cell_nz = glayerZ + glayerZ_minus;
297-
}
298-
else
299-
{
300-
// maybe a bug, if we don't use direct
301-
// coordinates, mohan note 2011-04-14
302-
double real_nx, real_ny, real_nz;
303-
real_nx = (x_max - x_min) / radius;
304-
real_ny = (y_max - y_min) / radius;
305-
real_nz = (z_max - z_min) / radius;
306-
cell_nx = static_cast<int>(real_nx) + 1;
307-
cell_ny = static_cast<int>(real_ny) + 1;
308-
cell_nz = static_cast<int>(real_nz) + 1;
309-
}
310-
311-
//================
312-
// Wrong !
313-
//================
314-
// if(int_nx != real_nx) this->cell_nx++;
315-
// if(int_ny != real_ny) this->cell_ny++;
316-
// if(int_nz != real_nz) this->cell_nz++;
317-
//=======================================
318-
// Not need because if int_nx = real_nx,
319-
// the position belong to the next cell
320-
//=======================================
321-
return;
322152
}

source/module_cell/module_neighbor/sltk_atom_input.h

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class Atom_input
1919
~Atom_input();
2020

2121
public:
22-
bool getExpandFlag() const
23-
{
24-
return expand_flag;
25-
}
26-
2722
int getBoundary() const
2823
{
2924
return periodic_boundary;
@@ -34,45 +29,6 @@ class Atom_input
3429
return radius;
3530
}
3631

37-
//==========================================================
38-
//
39-
//==========================================================
40-
double minX() const
41-
{
42-
return x_min;
43-
}
44-
45-
double minY() const
46-
{
47-
return y_min;
48-
}
49-
50-
double minZ() const
51-
{
52-
return z_min;
53-
}
54-
55-
//==========================================================
56-
//
57-
//==========================================================
58-
int getCell_nX() const
59-
{
60-
return cell_nx;
61-
}
62-
63-
int getCell_nY() const
64-
{
65-
return cell_ny;
66-
}
67-
68-
int getCell_nZ() const
69-
{
70-
return cell_nz;
71-
}
72-
73-
//==========================================================
74-
//
75-
//==========================================================
7632
int getGrid_layerX() const
7733
{
7834
return glayerX;
@@ -106,36 +62,15 @@ class Atom_input
10662
private:
10763
int test_atom_input; // caoyu reconst 2021-05-24
10864
bool periodic_boundary;
109-
11065
double radius;
11166

112-
double x_min;
113-
double y_min;
114-
double z_min;
115-
double x_max;
116-
double y_max;
117-
double z_max;
118-
//==========================================================
119-
// MEMBRE FUNCTION :
120-
// NAME : Check_Expand_Condition
121-
//==========================================================
12267
void Check_Expand_Condition(const UnitCell& ucell);
123-
bool expand_flag;
12468
int glayerX;
12569
int glayerX_minus;
12670
int glayerY;
12771
int glayerY_minus;
12872
int glayerZ;
12973
int glayerZ_minus;
130-
131-
//==========================================================
132-
// MEMBRE FUNCTION :
133-
// NAME : Expand_Grid
134-
//==========================================================
135-
void calculate_cells();
136-
int cell_nx;
137-
int cell_ny;
138-
int cell_nz;
13974
};
14075

14176
#endif

0 commit comments

Comments
 (0)