Skip to content

Commit d00f3af

Browse files
author
Fei Yang
committed
Remove legacy UnitCell velocity initialization
1 parent b7552ee commit d00f3af

3 files changed

Lines changed: 15 additions & 176 deletions

File tree

source/source_md/md_func.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -227,67 +227,6 @@ void rand_vel(const int& natom,
227227
return;
228228
}
229229

230-
void init_vel(const UnitCell& unit_in,
231-
const int& my_rank,
232-
const bool& restart,
233-
double& temperature,
234-
double* allmass,
235-
int& frozen_freedom,
236-
ModuleBase::Vector3<int>* ionmbl,
237-
ModuleBase::Vector3<double>* vel)
238-
{
239-
ModuleBase::Vector3<int> frozen;
240-
get_mass_mbl(unit_in, allmass, frozen, ionmbl);
241-
frozen_freedom = frozen.x + frozen.y + frozen.z;
242-
if (frozen.x == 0)
243-
{
244-
++frozen_freedom;
245-
}
246-
if (frozen.y == 0)
247-
{
248-
++frozen_freedom;
249-
}
250-
if (frozen.z == 0)
251-
{
252-
++frozen_freedom;
253-
}
254-
255-
if (unit_in.init_vel)
256-
{
257-
std::cout << " Reading velocities from STRU file" << std::endl;
258-
read_vel(unit_in, vel);
259-
double kinetic = 0.0;
260-
double t_current = MD_func::current_temp(kinetic, unit_in.nat, frozen_freedom, allmass, vel);
261-
if (restart)
262-
{
263-
std::cout << " Restart MD, current temperature is " << t_current * ModuleBase::Hartree_to_K << " K"
264-
<< std::endl;
265-
}
266-
else if (temperature < 0)
267-
{
268-
std::cout << " Autoset the initial tempearture to " << t_current * ModuleBase::Hartree_to_K << " K"
269-
<< std::endl;
270-
temperature = t_current;
271-
}
272-
else
273-
{
274-
std::cout << " Initial temeprature from INPUT is " << temperature * ModuleBase::Hartree_to_K << " K"
275-
<< std::endl;
276-
std::cout << " Reading temperature from STRU is " << t_current * ModuleBase::Hartree_to_K << " K"
277-
<< std::endl;
278-
std::cout << " Rescale velocties to initial temperature" << std::endl;
279-
rescale_vel(unit_in.nat, temperature, allmass, frozen_freedom, vel);
280-
}
281-
}
282-
else
283-
{
284-
std::cout << " Random velocities according to initial temperature "
285-
<< temperature * ModuleBase::Hartree_to_K << " K"
286-
<< std::endl;
287-
rand_vel(unit_in.nat, temperature, allmass, frozen_freedom, frozen, ionmbl, my_rank, vel);
288-
}
289-
}
290-
291230
void init_vel(MDCell& mdcell,
292231
const bool& init_vel,
293232
const bool& restart,

source/source_md/md_func.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ namespace MD_func
2727
*/
2828
double gaussrand();
2929

30-
/**
31-
* @brief initialize the atomic velocities
32-
*
33-
* @param unit_in unitcell information
34-
* @param my_rank MPI rank of the processor
35-
* @param restart whether restart the md
36-
* @param temperature ion temperature
37-
* @param allmass atomic mass
38-
* @param frozen_freedom the fixed freedom
39-
* @param ionmbl determine whether the atomic freedom is fixed
40-
* @param vel the genarated atomic velocities
41-
*/
42-
void init_vel(const UnitCell& unit_in,
43-
const int& my_rank,
44-
const bool& restart,
45-
double& temperature,
46-
double* allmass,
47-
int& frozen_freedom,
48-
ModuleBase::Vector3<int>* ionmbl,
49-
ModuleBase::Vector3<double>* vel);
5030
void init_vel(MDCell& mdcell,
5131
const bool& init_vel,
5232
const bool& restart,

source/source_md/test/md_func_test.cpp

Lines changed: 15 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
* - MD_func::read_vel
2828
* - read atomic velocity from STRU
2929
*
30-
* - MD_func::init_vel
31-
* - initialize the atomic velocities
32-
*
3330
* - MD_func::rescale_vel
3431
* - rescale the velocity to the target temperature
3532
*
@@ -60,43 +57,6 @@ TEST_F(MD_func_test, gaussrand)
6057
EXPECT_DOUBLE_EQ(MD_func::gaussrand(), 0.60805637857480721);
6158
}
6259

63-
TEST_F(MD_func_test, randomvel)
64-
{
65-
ucell.init_vel = 0;
66-
temperature = 300 / ModuleBase::Hartree_to_K;
67-
MD_func::init_vel(ucell, GlobalV::MY_RANK, false, temperature, allmass, frozen_freedom, ionmbl, vel);
68-
69-
EXPECT_NEAR(vel[0].x, 9.9105892783200826e-06, doublethreshold);
70-
EXPECT_NEAR(vel[0].y, -3.343699576563167e-05, doublethreshold);
71-
EXPECT_NEAR(vel[0].z, 9.385130426808701e-05, doublethreshold);
72-
EXPECT_NEAR(vel[1].x, -0.00017919300771203808, doublethreshold);
73-
EXPECT_NEAR(vel[1].y, 5.7074002254799079e-05, doublethreshold);
74-
EXPECT_NEAR(vel[1].z, -3.1088136026582953e-05, doublethreshold);
75-
EXPECT_NEAR(vel[2].x, 0.000141316492668737, doublethreshold);
76-
EXPECT_NEAR(vel[2].y, -0.00015841124290501442, doublethreshold);
77-
EXPECT_NEAR(vel[2].z, 1.900921882689748e-05, doublethreshold);
78-
EXPECT_NEAR(vel[3].x, 2.7965925764981002e-05, doublethreshold);
79-
EXPECT_NEAR(vel[3].y, 0.00013477423641584702, doublethreshold);
80-
EXPECT_NEAR(vel[3].z, -8.177238706840153e-05, doublethreshold);
81-
}
82-
83-
TEST_F(MD_func_test, getmassmbl)
84-
{
85-
ucell.init_vel = 0;
86-
temperature = 300 / ModuleBase::Hartree_to_K;
87-
MD_func::init_vel(ucell, GlobalV::MY_RANK, false, temperature, allmass, frozen_freedom, ionmbl, vel);
88-
89-
for (int i = 0; i < natom; ++i)
90-
{
91-
EXPECT_DOUBLE_EQ(allmass[i], 39.948 / ModuleBase::AU_to_MASS);
92-
EXPECT_TRUE(ionmbl[i].x == 1);
93-
EXPECT_TRUE(ionmbl[i].y == 1);
94-
EXPECT_TRUE(ionmbl[i].z == 1);
95-
}
96-
97-
EXPECT_TRUE(frozen_freedom == 3);
98-
}
99-
10060
TEST_F(MD_func_test, readvel)
10161
{
10262
MD_func::read_vel(ucell, vel);
@@ -142,64 +102,24 @@ TEST_F(MD_func_test, RescaleVel)
142102
EXPECT_DOUBLE_EQ(vel[3].z, 0.00013737032325207373);
143103
}
144104

145-
TEST_F(MD_func_test, InitVelCase1)
146-
{
147-
ucell.init_vel = 1;
148-
temperature = -1.0;
149-
MD_func::init_vel(ucell, GlobalV::MY_RANK, false, temperature, allmass, frozen_freedom, ionmbl, vel);
150-
151-
EXPECT_NEAR(temperature, 300.0 / ModuleBase::Hartree_to_K, doublethreshold);
152-
}
153-
154-
TEST_F(MD_func_test, InitVelCase2)
155-
{
156-
ucell.init_vel = 1;
157-
temperature = 300.0 / ModuleBase::Hartree_to_K;
158-
MD_func::init_vel(ucell, GlobalV::MY_RANK, false, temperature, allmass, frozen_freedom, ionmbl, vel);
159-
160-
EXPECT_DOUBLE_EQ(temperature, 300.0 / ModuleBase::Hartree_to_K);
161-
}
162-
163-
TEST_F(MD_func_test, InitVelCase3)
164-
{
165-
ucell.init_vel = 1;
166-
temperature = 310.0 / ModuleBase::Hartree_to_K;
167-
168-
EXPECT_DOUBLE_EQ(temperature, 310.0 / ModuleBase::Hartree_to_K);
169-
}
170-
171-
TEST_F(MD_func_test, InitVelCase4)
172-
{
173-
ucell.init_vel = 0;
174-
temperature = 300.0 / ModuleBase::Hartree_to_K;
175-
MD_func::init_vel(ucell, GlobalV::MY_RANK, false, temperature, allmass, frozen_freedom, ionmbl, vel);
176-
177-
EXPECT_DOUBLE_EQ(temperature, 300.0 / ModuleBase::Hartree_to_K);
178-
}
179-
180-
TEST_F(MD_func_test, InitVelCase5)
181-
{
182-
ucell.init_vel = 1;
183-
temperature = 330.0 / ModuleBase::Hartree_to_K;
184-
MD_func::init_vel(ucell, GlobalV::MY_RANK, true, temperature, allmass, frozen_freedom, ionmbl, vel);
185-
186-
EXPECT_DOUBLE_EQ(temperature, 330.0 / ModuleBase::Hartree_to_K);
187-
}
188-
189105
TEST_F(MD_func_test, compute_stress)
190106
{
191-
temperature = 300.0 / ModuleBase::Hartree_to_K;
192-
MD_func::init_vel(ucell, GlobalV::MY_RANK, false, temperature, allmass, frozen_freedom, ionmbl, vel);
107+
const ModuleBase::Vector3<double> test_velocity(0.1, 0.2, 0.3);
108+
for (int i = 0; i < natom; ++i)
109+
{
110+
allmass[i] = 39.948 / ModuleBase::AU_to_MASS;
111+
vel[i] = test_velocity;
112+
}
193113
MD_func::compute_stress(ucell, vel, allmass, true, virial, stress);
194-
EXPECT_DOUBLE_EQ(stress(0, 0), 5.2064533063674207e-06);
195-
EXPECT_DOUBLE_EQ(stress(0, 1), -1.6467487572445666e-06);
196-
EXPECT_DOUBLE_EQ(stress(0, 2), 1.5039983732220917e-06);
197-
EXPECT_DOUBLE_EQ(stress(1, 0), -1.6467487572445661e-06);
198-
EXPECT_DOUBLE_EQ(stress(1, 1), 2.380646437613151e-06);
199-
EXPECT_DOUBLE_EQ(stress(1, 2), -1.2514149065904968e-06);
200-
EXPECT_DOUBLE_EQ(stress(2, 0), 1.5039983732220917e-06);
201-
EXPECT_DOUBLE_EQ(stress(2, 1), -1.2514149065904968e-06);
202-
EXPECT_DOUBLE_EQ(stress(2, 2), 9.6330189688583664e-07);
114+
EXPECT_DOUBLE_EQ(stress(0, 0), 2.9128300667662788);
115+
EXPECT_DOUBLE_EQ(stress(0, 1), 5.8256601335325575);
116+
EXPECT_DOUBLE_EQ(stress(0, 2), 8.7384902002988341);
117+
EXPECT_DOUBLE_EQ(stress(1, 0), 5.8256601335325575);
118+
EXPECT_DOUBLE_EQ(stress(1, 1), 11.651320267065115);
119+
EXPECT_DOUBLE_EQ(stress(1, 2), 17.476980400597668);
120+
EXPECT_DOUBLE_EQ(stress(2, 0), 8.7384902002988358);
121+
EXPECT_DOUBLE_EQ(stress(2, 1), 17.476980400597672);
122+
EXPECT_DOUBLE_EQ(stress(2, 2), 26.215470600896506);
203123
}
204124

205125
TEST_F(MD_func_test, dump_info)

0 commit comments

Comments
 (0)