@@ -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
9237Atom_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}
0 commit comments