@@ -20,51 +20,49 @@ double Ions_Move_Basic::best_xxx = 1.0;
2020
2121int Ions_Move_Basic::out_stru=0 ;
2222
23- void Ions_Move_Basic::setup_gradient (double *grad, const ModuleBase::matrix &force)
23+ void Ions_Move_Basic::setup_gradient (double * pos, double *grad, const ModuleBase::matrix &force)
2424{
2525 ModuleBase::TITLE (" Ions_Move_Basic" ," setup_gradient" );
2626
2727 assert (GlobalC::ucell.ntype >0 );
28+ assert (pos!=NULL );
2829 assert (grad!=NULL );
2930 assert (dim == 3 *GlobalC::ucell.nat );
3031
32+ ModuleBase::GlobalFunc::ZEROS (pos, dim);
3133 ModuleBase::GlobalFunc::ZEROS (grad, dim);
3234
3335 // (1) init gradient
36+ // the unit of pos: Bohr.
3437 // the unit of force: Ry/Bohr.
3538 // the unit of gradient:
3639 int iat=0 ;
3740 for (int it = 0 ;it < GlobalC::ucell.ntype ;it++)
3841 {
3942 Atom* atom = &GlobalC::ucell.atoms [it];
4043 for (int ia =0 ;ia< GlobalC::ucell.atoms [it].na ;ia++)
41- {
42- if (atom->mbl [ia].x == 1 )
43- {
44- grad[3 *iat ] = -force (iat, 0 )*GlobalC::ucell.lat0 ;
45- // this->grad[3*iat ] = -force(iat, 0);
46- }
47- if (atom->mbl [ia].y == 1 )
48- {
49- grad[3 *iat+1 ] = -force (iat, 1 )*GlobalC::ucell.lat0 ;
50- }
51- if (atom->mbl [ia].z == 1 )
52- {
53- grad[3 *iat+2 ] = -force (iat, 2 )*GlobalC::ucell.lat0 ;
54- // std::cout << " grad=" << grad[3*iat+2] << std::endl;
55- }
44+ {
45+ for ( int ik = 0 ; ik < 3 ; ++ik)
46+ {
47+ pos[3 *iat + ik] = atom->tau [ia][ik] * GlobalC::ucell.lat0 ;
48+ if (atom->mbl [ia][ik])
49+ {
50+ grad[3 *iat + ik] = - force (iat, ik) * GlobalC::ucell.lat0 ;
51+ }
52+ }
5653 ++iat;
5754 }
5855 }
5956
6057 return ;
6158}
6259
63- void Ions_Move_Basic::move_atoms (double *move)
60+ void Ions_Move_Basic::move_atoms (double *move, double *pos )
6461{
6562 ModuleBase::TITLE (" Ions_Move_Basic" ," move_atoms" );
6663
6764 assert (move!=NULL );
65+ assert (pos!=NULL );
6866
6967 // ------------------------
7068 // for test only
@@ -91,31 +89,16 @@ void Ions_Move_Basic::move_atoms(double *move)
9189 assert ( iat == GlobalC::ucell.nat );
9290 }
9391
94- int iat = 0 ;
95- const double move_threshold = 1.0e-10 ;
96- ModuleBase::Vector3<double > *move_ion = new ModuleBase::Vector3<double > [GlobalC::ucell.nat ];
97- for (int it = 0 ; it < GlobalC::ucell.ntype ; it++)
98- {
99- Atom* atom = &GlobalC::ucell.atoms [it];
100- for (int ia = 0 ; ia < atom->na ; ia++)
101- {
102- for (int k = 0 ; k < 3 ; ++k)
103- {
104- if ( abs (move[3 *iat + k]) > move_threshold && atom->mbl [ia][k])
105- {
106- move_ion[iat][k] = move[3 *iat + k] / GlobalC::ucell.lat0 ;
107- }
108- else
109- {
110- move_ion[iat][k] = 0 ;
111- }
112- }
113- move_ion[iat] = move_ion[iat] * GlobalC::ucell.GT ;
114- iat++;
115- }
116- }
117- assert ( iat == GlobalC::ucell.nat );
118- GlobalC::ucell.update_pos_taud (move_ion);
92+ const double move_threshold = 1.0e-10 ;
93+ const int total_freedom = GlobalC::ucell.nat * 3 ;
94+ for (int i =0 ;i<total_freedom;i++)
95+ {
96+ if ( abs (move[i]) > move_threshold )
97+ {
98+ pos[i] += move[i];
99+ }
100+ }
101+ GlobalC::ucell.update_pos_tau (pos);
119102
120103 // --------------------------------------------
121104 // Print out the structure file.
@@ -128,7 +111,6 @@ void Ions_Move_Basic::move_atoms(double *move)
128111 {
129112 GlobalC::ucell.print_cell_cif (" STRU_NOW.cif" );
130113 }
131- delete[] move_ion;
132114 return ;
133115}
134116
0 commit comments