Skip to content

Commit c4676b0

Browse files
committed
update the update_pos_taud
1 parent c53f445 commit c4676b0

File tree

10 files changed

+610
-377
lines changed

10 files changed

+610
-377
lines changed

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ bool UnitCell::read_atom_positions(std::ifstream& ifpos,
3333
std::ofstream& ofs_warning) {
3434
return true;
3535
}
36-
void UnitCell::update_pos_taud(double* posd_in) {}
3736
void UnitCell::update_pos_taud(const ModuleBase::Vector3<double>* posd_in) {}
3837
void UnitCell::update_vel(const ModuleBase::Vector3<double>* vel_in) {}
3938
void UnitCell::bcast_atoms_tau() {}

source/module_cell/test/unitcell_test_para.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ TEST_F(UcellTest, UpdatePosTaud)
167167
ucell->iat2iait(iat, &ia, &it);
168168
tmp[iat] = ucell->atoms[it].taud[ia];
169169
}
170-
ucell->update_pos_taud(pos_in);
170+
unitcell::update_pos_taud(ucell->lat,pos_in,ucell->ntype,
171+
ucell->nat,ucell->atoms);
171172
for (int iat = 0; iat < ucell->nat; ++iat)
172173
{
173174
int it, ia;

source/module_cell/unitcell.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,6 @@ std::vector<ModuleBase::Vector3<int>> UnitCell::get_constrain() const
314314
return constrain;
315315
}
316316

317-
318-
319-
void UnitCell::update_pos_taud(double* posd_in) {
320-
int iat = 0;
321-
for (int it = 0; it < this->ntype; it++) {
322-
Atom* atom = &this->atoms[it];
323-
for (int ia = 0; ia < atom->na; ia++) {
324-
for (int ik = 0; ik < 3; ++ik) {
325-
atom->taud[ia][ik] += posd_in[3 * iat + ik];
326-
atom->dis[ia][ik] = posd_in[3 * iat + ik];
327-
}
328-
iat++;
329-
}
330-
}
331-
assert(iat == this->nat);
332-
unitcell::periodic_boundary_adjustment(this->atoms,this->latvec, this->ntype);
333-
this->bcast_atoms_tau();
334-
}
335-
336317
// posd_in is atomic displacements here liuyu 2023-03-22
337318
void UnitCell::update_pos_taud(const ModuleBase::Vector3<double>* posd_in) {
338319
int iat = 0;

source/module_cell/unitcell.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class UnitCell {
201201
void print_cell_xyz(const std::string& fn) const;
202202

203203
void update_pos_taud(const ModuleBase::Vector3<double>* posd_in);
204-
void update_pos_taud(double* posd_in);
205204
void update_vel(const ModuleBase::Vector3<double>* vel_in);
206205
void bcast_atoms_tau();
207206
bool judge_big_cell() const;

source/module_cell/update_cell.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,32 @@ void update_pos_tau(const Lattice& lat,
374374
bcast_atoms_tau(atoms, ntype);
375375
}
376376

377+
void update_pos_taud(const Lattice& lat,
378+
const double* posd_in,
379+
const int ntype,
380+
const int nat,
381+
Atom* atoms)
382+
{
383+
int iat = 0;
384+
for (int it = 0; it < ntype; it++)
385+
{
386+
Atom* atom = &atoms[it];
387+
for (int ia = 0; ia < atom->na; ia++)
388+
{
389+
for (int ik = 0; ik < 3; ++ik)
390+
{
391+
atom->taud[ia][ik] += posd_in[3 * iat + ik];
392+
atom->dis[ia][ik] = posd_in[3 * iat + ik];
393+
}
394+
iat++;
395+
}
396+
}
397+
assert(iat == nat);
398+
periodic_boundary_adjustment(atoms,lat.latvec,ntype);
399+
bcast_atoms_tau(atoms, ntype);
400+
}
401+
402+
377403
void periodic_boundary_adjustment(Atom* atoms,
378404
const ModuleBase::Matrix3& latvec,
379405
const int ntype)
@@ -384,12 +410,6 @@ void periodic_boundary_adjustment(Atom* atoms,
384410
// first adjust direct coordinates,
385411
// then update them into cartesian coordinates,
386412
//----------------------------------------------
387-
for (int i=0;i<ntype;i++) {
388-
Atom* atom = &atoms[i];
389-
for (int j=0;j<atom->na;j++) {
390-
printf("the taud is %f %f %f\n",atom->taud[j].x,atom->taud[j].y,atom->taud[j].z);
391-
}
392-
}
393413
for (int it = 0; it < ntype; it++) {
394414
Atom* atom = &atoms[it];
395415
for (int ia = 0; ia < atom->na; ia++) {

source/module_cell/update_cell.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ namespace unitcell
4848
const int ntype,
4949
const int nat,
5050
Atom* atoms);
51+
52+
/**
53+
* @brief update the position and tau of the atoms
54+
*
55+
* @param lat: the lattice of the atoms [in]
56+
* @param pos_in: the position of the atoms in direct coordinate system [in]
57+
* @param ntype: the number of types of the atoms [in]
58+
* @param nat: the number of atoms [in]
59+
* @param atoms: the atoms to be updated [out]
60+
*/
61+
void update_pos_taud(const Lattice& lat,
62+
const double* posd_in,
63+
const int ntype,
64+
const int nat,
65+
Atom* atoms);
66+
/**
67+
* @brief update the velocity of the atoms
68+
*
69+
* @param lat: the lattice of the atoms [in]
70+
* @param pos_in: the position of the atoms in direct coordinate system
71+
* in ModuleBase::Vector3 version [in]
72+
* @param ntype: the number of types of the atoms [in]
73+
* @param nat: the number of atoms [in]
74+
* @param atoms: the atoms to be updated [out]
75+
*/
5176
}
5277
//
5378
#endif // UPDATE_CELL_H

source/module_relax/relax_new/relax.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void Relax::move_cell_ions(UnitCell& ucell, const bool is_new_dir)
633633
ucell.symm.symmetrize_vec3_nat(move_ion);
634634
}
635635

636-
ucell.update_pos_taud(move_ion);
636+
unitcell::update_pos_taud(ucell.lat,move_ion,ucell.ntype,ucell.nat,ucell.atoms);
637637

638638
// Print the structure file.
639639
ucell.print_tau();

source/module_relax/relax_new/test/relax_test.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "gtest/gtest.h"
2+
#include <iomanip>
23
#define private public
34
#include "module_parameter/parameter.h"
45
#undef private
@@ -27,13 +28,13 @@ class Test_SETGRAD : public testing::Test
2728
force_in.create(nat,3);
2829
stress_in.create(3,3);
2930

30-
force_in(0,0) = 1; force_in(0,1) = 2; force_in(0,2)= 3;
31-
force_in(1,0) = 4; force_in(1,1) = 5; force_in(1,2)= 6;
32-
force_in(2,0) = 7; force_in(2,1) = 8; force_in(2,2)= 9;
31+
force_in(0,0) = 0.1; force_in(0,1) = 0.1; force_in(0,2)= 0.1;
32+
force_in(1,0) = 0; force_in(1,1) = 0.1; force_in(1,2)= 0.1;
33+
force_in(2,0) = 0; force_in(2,1) = 0; force_in(2,2)= 0.1;
3334

34-
stress_in(0,0) = 1; stress_in(0,1) = 2; stress_in(0,2)= 3;
35-
stress_in(1,0) = 4; stress_in(1,1) = 5; stress_in(1,2)= 6;
36-
stress_in(2,0) = 7; stress_in(2,1) = 8; stress_in(2,2)= 9;
35+
stress_in(0,0) = 1; stress_in(0,1) = 1; stress_in(0,2)= 1;
36+
stress_in(1,0) = 0; stress_in(1,1) = 1; stress_in(1,2)= 1;
37+
stress_in(2,0) = 0; stress_in(2,1) = 0; stress_in(2,2)= 1;
3738

3839
ucell.ntype = 1;
3940
ucell.nat = nat;
@@ -46,6 +47,8 @@ class Test_SETGRAD : public testing::Test
4647
ucell.iat2ia = new int[nat];
4748
ucell.atoms[0].mbl.resize(nat);
4849
ucell.atoms[0].taud.resize(nat);
50+
ucell.atoms[0].tau.resize(nat);
51+
ucell.atoms[0].dis.resize(nat);
4952
ucell.lc = new int[3];
5053

5154
ucell.iat2it[0] = 0;
@@ -136,14 +139,25 @@ TEST_F(Test_SETGRAD, relax_new)
136139
{
137140
std::vector<double> result_ref =
138141
{
139-
0,0,0.1709672056,0,0.2849453427,0,0.3989234797,0,0,1.005319517,
140-
0.01063903455,0.01595855183,0.0212780691,1.026597586,0.03191710366,
141-
0.03723662093,0.04255613821,1.047875655,1.059181731,0,0,0,1.059181731,
142-
0,0,0,1.059181731,1.034363264,0.01301504537,0.01952256806,
143-
0.02603009074,1.060393355,0.03904513611,0.0455526588,0.05206018148,
144-
1.086423445,1,0,0,0,1,0,0,0,1
142+
0, 0, 0.24293434145,
143+
0, 0.242934341453, 0,
144+
0, 0, 0,
145+
//paramter for taud
146+
1.2267616333,0.2267616333,0.22676163333,
147+
0, 1.2267616333 ,0.2267616333,
148+
0, 0, 1.22676163333,
149+
// paramter for fisrt time after relaxation
150+
1.3677603495, 0, 0,
151+
0, 1.36776034956, 0,
152+
0, 0, 1.36776034956,
153+
// paramter for second time after relaxation
154+
1.3677603495 ,0.3633367476,0.36333674766,
155+
0, 1.3677603495 ,0.36333674766,
156+
0, 0, 1.3677603495 ,
157+
// paramter for third time after relaxation
158+
1,0,0,0,1,0,0,0,1
159+
// paramter for fourth time after relaxation
145160
};
146-
147161
for(int i=0;i<result.size();i++)
148162
{
149163
EXPECT_NEAR(result[i],result_ref[i],1e-8);
@@ -258,6 +272,7 @@ class Test_RELAX : public testing::Test
258272
ucell.atoms[i].mbl.resize(na);
259273
ucell.atoms[i].taud.resize(na);
260274
ucell.atoms[i].tau.resize(na);
275+
ucell.atoms[i].dis.resize(na);
261276
for (int j=0;j<na;j++)
262277
{
263278
ucell.atoms[i].mbl[j] = {1,1,1};
@@ -291,7 +306,6 @@ TEST_F(Test_RELAX, relax_new)
291306
int size = 1584;
292307
double tmp;
293308
std::ifstream result_ref("./support/result_ref.txt");
294-
295309
for(int i=0;i<size;i++)
296310
{
297311
result_ref >> tmp;

source/module_relax/relax_new/test/relax_test.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,13 @@
22

33
namespace GlobalC
44
{
5-
UnitCell ucell;
65
Structure_Factor sf;
76
ModulePW::PW_Basis* rhopw;
87
}
98

109
UnitCell::UnitCell(){};
1110
UnitCell::~UnitCell(){};
1211

13-
void UnitCell::update_pos_taud(double* posd_in)
14-
{
15-
int iat = 0;
16-
for (int it = 0; it < this->ntype; it++)
17-
{
18-
Atom* atom = &this->atoms[it];
19-
for (int ia = 0; ia < atom->na; ia++)
20-
{
21-
this->atoms[it].taud[ia].x += posd_in[iat*3];
22-
this->atoms[it].taud[ia].y += posd_in[iat*3 + 1];
23-
this->atoms[it].taud[ia].z += posd_in[iat*3 + 2];
24-
iat++;
25-
}
26-
}
27-
assert(iat == this->nat);
28-
}
2912

3013
void UnitCell::print_stru_file(const std::string& fn,
3114
const int& nspin,

0 commit comments

Comments
 (0)