@@ -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,31 @@ 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- }
498- }
429+ double x = ucell.atoms [i].tau [j].x + vec1[0 ] * ix + vec2[0 ] * iy + vec3[0 ] * iz;
430+ double y = ucell.atoms [i].tau [j].y + vec1[1 ] * ix + vec2[1 ] * iy + vec3[1 ] * iz;
431+ double z = ucell.atoms [i].tau [j].z + vec1[2 ] * ix + vec2[2 ] * iy + vec3[2 ] * iz;
499432
500- ia_all++;
433+ this ->fake_atoms .push_back (FAtom (x, y, z, i, j, ix, iy, iz));
434+ }
501435 }
502436 }
503437 }
504438 }
505439
506- // mohan fix bug 2012-04-02 by valgrind.
507- delete[] store_cell_x;
508- delete[] store_cell_y;
509- delete[] store_cell_z;
510440
511- assert (ia_all == d_amount_expand);
441+ assert (this -> fake_atoms . size () == d_amount_expand);
512442
513443 // becareful! now the cell is not the origin cell,
514444 // 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)
554484 << " Ymax=" << y_max_expand
555485 << " Zmax=" << z_max_expand << std::endl;
556486 }
557-
558- delete[] x_old;
559- delete[] y_old;
560- delete[] z_old;
561- delete[] type_old;
562- delete[] natom_old;
563487 return ;
564488}
565489
@@ -614,11 +538,7 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const
614538// ----------------------------------------------------------
615539 if (expand_flag)
616540 {
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]);
541+ a = fake_atoms[d_current];
622542 ++ d_current;
623543 }
624544
@@ -630,44 +550,20 @@ void Atom_input::set_FAtom(const UnitCell &ucell, FAtom &a)const
630550// ----------------------------------------------------------
631551 else
632552 {
633- Load_atom (ucell
634-
635- );
636- a.setX (x);
637- a.setY (y);
638- a.setZ (z);
639- a.setType (type);
640- a.setNatom (natom);
641- // GlobalV::ofs_running<<"\n x = "<<x;
642- // GlobalV::ofs_running<<"\n y = "<<y;
643- // GlobalV::ofs_running<<"\n z = "<<z;
644- // GlobalV::ofs_running<<"\n Type = "<<type;
645- // GlobalV::ofs_running<<"\n natom = "<<natom;
646- }
647-
648- return ;
649- }
553+ natom++;
650554
651- void Atom_input::Load_atom (const UnitCell& ucell)const
652- {
653- // ModuleBase::TITLE("Atom_input","load_atom");
654- natom++;
655-
656- if (natom >= ucell.atoms [type].na )
657- {
658- type ++;
659- natom = 0 ;
555+ if (natom >= ucell.atoms [type].na )
556+ {
557+ type ++;
558+ natom = 0 ;
559+ }
560+ FAtom temp (ucell.atoms [type].tau [natom].x ,
561+ ucell.atoms [type].tau [natom].y ,
562+ ucell.atoms [type].tau [natom].z ,
563+ type, natom,
564+ 0 , 0 , 0 );
565+ a = temp;
660566 }
661567
662- x = ucell.atoms [type].tau [natom].x ;
663-
664- y = ucell.atoms [type].tau [natom].y ;
665- z = ucell.atoms [type].tau [natom].z ;
666-
667- // std::cout<<" x = "<<ucell.atoms[type].tau[natom].x
668- // <<" y = "<<ucell.atoms[type].tau[natom].y
669- // <<" z = "<<ucell.atoms[type].tau[natom].z
670- // <<" type = "<<type
671- // <<" natom = "<<natom;
672568 return ;
673569}
0 commit comments