@@ -188,14 +188,6 @@ Atom_input::Atom_input
188188
189189Atom_input::~Atom_input ()
190190{
191- if (expand_flag)
192- {
193- delete [] store_x;
194- delete [] store_y;
195- delete [] store_z;
196- delete [] store_type;
197- delete [] store_natom;
198- }
199191}
200192
201193// ============================================
@@ -409,27 +401,6 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype)
409401 GlobalV::ofs_running << " Good luck! " << std::endl;
410402 }
411403
412- double *x_old = new double [d_amount];
413- double *y_old = new double [d_amount];
414- double *z_old = new double [d_amount];
415-
416- int *type_old = new int [d_amount];
417- int *natom_old = new int [d_amount];
418-
419- int ia = 0 ;
420- for (int i = 0 ;i < ntype;i++)
421- {
422- for (int j = 0 ;j < ucell.atoms [i].na ;j++)
423- {
424- x_old[ia] = ucell.atoms [i].tau [j].x ;
425- y_old[ia] = ucell.atoms [i].tau [j].y ;
426- z_old[ia] = ucell.atoms [i].tau [j].z ;
427- type_old[ia] = i;
428- natom_old[ia] = j;
429- ia++;
430- }
431- }
432-
433404 // how many copys we need now.
434405 const int gcopy =
435406 (glayerX + glayerX_minus) *
@@ -443,72 +414,37 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype)
443414 if (test_atom_input)ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running," Atom_number_now" ,d_amount_expand);
444415
445416 // store new atom positions.
446- this ->store_x = new double [d_amount_expand];
447- this ->store_y = new double [d_amount_expand];
448- this ->store_z = new double [d_amount_expand];
449-
450- ModuleBase::Memory::record (" SLTK::Epd_Atom" ,sizeof (double ) * d_amount_expand*3 );
451-
452- // store which grid the atom is in.
453- store_cell_x = new int [d_amount_expand];
454- store_cell_y = new int [d_amount_expand];
455- store_cell_z = new int [d_amount_expand];
456-
457- this ->store_type = new int [d_amount_expand];
458- this ->store_natom = new int [d_amount_expand];
459417
460- ModuleBase::Memory::record (" SLTK::Epd_atom_info" ,sizeof (int ) * d_amount_expand*5 );
461-
462- int ia_all = 0 ;
463418
464419 for (int ix = -glayerX_minus; ix < glayerX; ix++)
465420 {
466421 for (int iy = -glayerY_minus; iy < glayerY; iy++)
467422 {
468423 for (int iz = -glayerZ_minus; iz < glayerZ; iz++)
469424 {
470- for (int ia = 0 ; ia < d_amount; ia ++)
425+ for (int i = 0 ;i < ntype;i ++)
471426 {
472- store_x[ia_all] = x_old[ia] + vec1[0 ] * ix + vec2[0 ] * iy + vec3[0 ] * iz;
473- store_y[ia_all] = y_old[ia] + vec1[1 ] * ix + vec2[1 ] * iy + vec3[1 ] * iz;
474- store_z[ia_all] = z_old[ia] + vec1[2 ] * ix + vec2[2 ] * iy + vec3[2 ] * iz;
475- store_type[ia_all] = type_old[ia];
476- store_natom[ia_all] = natom_old[ia];
477-
478- // notice '0' is not the origin unitcell.
479- store_cell_x[ia_all] = ix + glayerX_minus;
480- store_cell_y[ia_all] = iy + glayerY_minus;
481- store_cell_z[ia_all] = iz + glayerZ_minus;
482-
483- if (test_atom_input > 1 )
427+ for (int j = 0 ;j < ucell.atoms [i].na ;j++)
484428 {
485- if (d_amount_expand < 1000 )
486- {
487- GlobalV::ofs_running << " \n " << std::setw (6 ) << ia_all
488- << std::setw (10 ) << x_old[ia]
489- << std::setw (10 ) << y_old[ia]
490- << std::setw (10 ) << z_old[ia]
491- << std::setw (10 ) << store_x[ia_all]
492- << std::setw (10 ) << store_y[ia_all]
493- << std::setw (10 ) << store_z[ia_all]
494- << std::setw (6 ) << store_cell_x[ia_all]
495- << std::setw (6 ) << store_cell_y[ia_all]
496- << std::setw (6 ) << store_cell_z[ia_all];
497- }
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);
498440 }
499-
500- ia_all++;
501441 }
502442 }
503443 }
504444 }
505445
506- // mohan fix bug 2012-04-02 by valgrind.
507- delete[] store_cell_x;
508- delete[] store_cell_y;
509- delete[] store_cell_z;
510446
511- assert (ia_all == d_amount_expand);
447+ assert (this -> fake_atoms . size () == d_amount_expand);
512448
513449 // becareful! now the cell is not the origin cell,
514450 // it's unitcell in expand case! so don't add
@@ -554,12 +490,6 @@ void Atom_input::Expand_Grid(const UnitCell &ucell, const int ntype)
554490 << " Ymax=" << y_max_expand
555491 << " Zmax=" << z_max_expand << std::endl;
556492 }
557-
558- delete[] x_old;
559- delete[] y_old;
560- delete[] z_old;
561- delete[] type_old;
562- delete[] natom_old;
563493 return ;
564494}
565495
@@ -614,11 +544,7 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const
614544// ----------------------------------------------------------
615545 if (expand_flag)
616546 {
617- a.setX (store_x[d_current]);
618- a.setY (store_y[d_current]);
619- a.setZ (store_z[d_current]);
620- a.setType (store_type[d_current]);
621- a.setNatom (store_natom[d_current]);
547+ a = fake_atoms[d_current];
622548 ++ d_current;
623549 }
624550
@@ -630,9 +556,7 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const
630556// ----------------------------------------------------------
631557 else
632558 {
633- Load_atom (ucell
634-
635- );
559+ Load_atom (ucell);
636560 a.setX (x);
637561 a.setY (y);
638562 a.setZ (z);
0 commit comments