Repository navigation
Expand file tree
/
Copy pathlangevin.cpp
More file actions
107 lines (79 loc) · 2.43 KB
/
Copy pathlangevin.cpp
File metadata and controls
107 lines (79 loc) · 2.43 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
#include "langevin.h"
#include "md_func.h"
#include "source_base/parallel_common.h"
#include "source_base/timer.h"
Langevin::Langevin(const Parameter& param_in, UnitCell& unit_in) : MD_base(param_in, unit_in)
{
/// convert to a.u. unit
assert(ModuleBase::AU_to_FS!=0.0);
md_damp = mdp.md_damp / ModuleBase::AU_to_FS;
assert(ucell.nat>0);
total_force = new ModuleBase::Vector3<double>[ucell.nat];
}
Langevin::~Langevin()
{
delete[] total_force;
}
void Langevin::setup(ModuleESolver::ESolver* p_esolver, const std::string& global_readin_dir)
{
ModuleBase::TITLE("Langevin", "setup");
ModuleBase::timer::tick("Langevin", "setup");
MD_base::setup(p_esolver, global_readin_dir);
post_force();
ModuleBase::timer::tick("Langevin", "setup");
return;
}
void Langevin::first_half(std::ofstream& ofs)
{
ModuleBase::TITLE("Langevin", "first_half");
ModuleBase::timer::tick("Langevin", "first_half");
MD_base::update_vel(total_force);
MD_base::update_pos();
ModuleBase::timer::tick("Langevin", "first_half");
return;
}
void Langevin::second_half()
{
ModuleBase::TITLE("Langevin", "second_half");
ModuleBase::timer::tick("Langevin", "second_half");
post_force();
MD_base::update_vel(total_force);
ModuleBase::timer::tick("Langevin", "second_half");
return;
}
void Langevin::print_md(std::ofstream& ofs, const bool& cal_stress)
{
MD_base::print_md(ofs, cal_stress);
return;
}
void Langevin::write_restart(const std::string& global_out_dir)
{
MD_base::write_restart(global_out_dir);
return;
}
void Langevin::restart(const std::string& global_readin_dir)
{
MD_base::restart(global_readin_dir);
return;
}
void Langevin::post_force()
{
if (my_rank == 0)
{
double t_target = MD_func::target_temp(step_ + step_rst_, mdp.md_nstep, md_tfirst, md_tlast);
ModuleBase::Vector3<double> fictitious_force;
for (int i = 0; i < ucell.nat; ++i)
{
fictitious_force = -allmass[i] * vel[i] / md_damp;
for (int j = 0; j < 3; ++j)
{
fictitious_force[j] += sqrt(24.0 * t_target * allmass[i] / md_damp / md_dt)
* (static_cast<double>(std::rand()) / RAND_MAX - 0.5);
}
total_force[i] = force[i] + fictitious_force;
}
}
#ifdef __MPI
MPI_Bcast(total_force, ucell.nat * 3, MPI_DOUBLE, 0, MPI_COMM_WORLD);
#endif
}