forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverlet.cpp
More file actions
147 lines (120 loc) · 3.58 KB
/
verlet.cpp
File metadata and controls
147 lines (120 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "verlet.h"
#include "md_func.h"
#include "source_base/timer.h"
Verlet::Verlet(const Parameter& param_in, UnitCell& unit_in) : MD_base(param_in, unit_in)
{
}
Verlet::~Verlet()
{
}
void Verlet::setup(ModuleESolver::ESolver* p_esolver, const std::string& global_readin_dir)
{
ModuleBase::TITLE("Verlet", "setup");
ModuleBase::timer::start("Verlet", "setup");
MD_base::setup(p_esolver, global_readin_dir);
ModuleBase::timer::end("Verlet", "setup");
}
void Verlet::first_half(std::ofstream& ofs)
{
ModuleBase::TITLE("Verlet", "first_half");
ModuleBase::timer::start("Verlet", "first_half");
MD_base::update_vel(force);
MD_base::update_pos();
ModuleBase::timer::end("Verlet", "first_half");
}
void Verlet::second_half()
{
ModuleBase::TITLE("Verlet", "second_half");
ModuleBase::timer::start("Verlet", "second_half");
MD_base::update_vel(force);
apply_thermostat();
ModuleBase::timer::end("Verlet", "second_half");
}
void Verlet::apply_thermostat(void)
{
double t_target = 0.0;
t_current = MD_func::current_temp(kinetic, ucell.nat, frozen_freedom_, allmass, vel);
if (mdp.md_type == "nve")
{
}
else if (mdp.md_thermostat == "rescaling")
{
t_target = MD_func::target_temp(step_ + step_rst_, mdp.md_nstep, md_tfirst, md_tlast);
if (std::abs(t_target - t_current) * ModuleBase::Hartree_to_K > mdp.md_tolerance)
{
thermalize(0, t_current, t_target);
}
}
else if (mdp.md_thermostat == "rescale_v")
{
if ((step_ + step_rst_) % mdp.md_nraise == 0)
{
t_target = MD_func::target_temp(step_ + step_rst_, mdp.md_nstep, md_tfirst, md_tlast);
thermalize(0, t_current, t_target);
}
}
else if (mdp.md_thermostat == "anderson")
{
if (my_rank == 0)
{
double deviation = 0.0;
for (int i = 0; i < ucell.nat; ++i)
{
if (static_cast<double>(std::rand()) / RAND_MAX <= 1.0 / mdp.md_nraise)
{
deviation = sqrt(md_tlast / allmass[i]);
for (int k = 0; k < 3; ++k)
{
if (ionmbl[i][k])
{
vel[i][k] = deviation * MD_func::gaussrand();
}
}
}
}
}
#ifdef __MPI
MPI_Bcast(vel, ucell.nat * 3, MPI_DOUBLE, 0, MPI_COMM_WORLD);
#endif
}
else if (mdp.md_thermostat == "berendsen")
{
t_target = MD_func::target_temp(step_ + step_rst_, mdp.md_nstep, md_tfirst, md_tlast);
thermalize(mdp.md_nraise, t_current, t_target);
}
else
{
ModuleBase::WARNING_QUIT("Verlet", "No such thermostat!");
}
}
void Verlet::thermalize(const int& nraise, const double& current_temp, const double& target_temp)
{
double fac = 0.0;
if (nraise > 0 && current_temp > 0 && target_temp > 0)
{
fac = sqrt(1 + (target_temp / current_temp - 1) / nraise);
}
else if (nraise == 0 && current_temp > 0 && target_temp > 0)
{
fac = sqrt(target_temp / current_temp);
}
for (int i = 0; i < ucell.nat; ++i)
{
vel[i] *= fac;
}
}
void Verlet::print_md(std::ofstream& ofs, const bool& cal_stress)
{
MD_base::print_md(ofs, cal_stress);
return;
}
void Verlet::write_restart(const std::string& global_out_dir)
{
MD_base::write_restart(global_out_dir);
return;
}
void Verlet::restart(const std::string& global_readin_dir)
{
MD_base::restart(global_readin_dir);
return;
}