forked from lammps/lammps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_langevin_spin.cpp
173 lines (134 loc) · 4.86 KB
/
fix_langevin_spin.cpp
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, [email protected]
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------
Contributing authors: Julien Tranchida (SNL)
Aidan Thompson (SNL)
Please cite the related publication:
Tranchida, J., Plimpton, S. J., Thibaudeau, P., & Thompson, A. P. (2018).
Massively parallel symplectic algorithm for coupled magnetic spin dynamics
and molecular dynamics. Journal of Computational Physics.
------------------------------------------------------------------------- */
#include "fix_langevin_spin.h"
#include "atom.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "math_const.h"
#include "modify.h"
#include "random_mars.h"
#include "respa.h"
#include "update.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
/* ---------------------------------------------------------------------- */
FixLangevinSpin::FixLangevinSpin(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg), random(nullptr)
{
if (narg != 6) error->all(FLERR,"Illegal langevin/spin command");
temp = utils::numeric(FLERR,arg[3],false,lmp);
alpha_t = utils::numeric(FLERR,arg[4],false,lmp);
seed = utils::inumeric(FLERR,arg[5],false,lmp);
if (alpha_t < 0.0) {
error->all(FLERR,"Illegal langevin/spin command");
} else if (alpha_t == 0.0) {
tdamp_flag = 0;
} else {
tdamp_flag = 1;
}
if (temp < 0.0) {
error->all(FLERR,"Illegal langevin/spin command");
} else if (temp == 0.0) {
temp_flag = 0;
} else {
temp_flag = 1;
}
// initialize Marsaglia RNG with processor-unique seed
// random = new RanPark(lmp,seed + comm->me);
random = new RanMars(lmp,seed + comm->me);
}
/* ---------------------------------------------------------------------- */
FixLangevinSpin::~FixLangevinSpin()
{
delete random;
}
/* ---------------------------------------------------------------------- */
int FixLangevinSpin::setmask()
{
int mask = 0;
return mask;
}
/* ---------------------------------------------------------------------- */
void FixLangevinSpin::init()
{
// fix_langevin_spin has to be the last defined fix
int flag_force = 0;
int flag_lang = 0;
for (int i = 0; i < modify->nfix; i++) {
if (strcmp("precession/spin",modify->fix[i]->style)==0) flag_force = MAX(flag_force,i);
if (strcmp("langevin/spin",modify->fix[i]->style)==0) flag_lang = i;
}
if (flag_force >= flag_lang) error->all(FLERR,"Fix langevin/spin has to come after all other spin fixes");
gil_factor = 1.0/(1.0+(alpha_t)*(alpha_t));
dts = 0.25 * update->dt;
double hbar = force->hplanck/MY_2PI; // eV/(rad.THz)
double kb = force->boltz; // eV/K
D = (alpha_t*gil_factor*kb*temp);
D /= (hbar*dts);
sigma = sqrt(2.0*D);
}
/* ---------------------------------------------------------------------- */
void FixLangevinSpin::setup(int vflag)
{
if (utils::strmatch(update->integrate_style,"^respa")) {
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
post_force_respa(vflag,nlevels_respa-1,0);
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
} else post_force(vflag);
}
/* ---------------------------------------------------------------------- */
void FixLangevinSpin::add_tdamping(double spi[3], double fmi[3])
{
double cpx = fmi[1]*spi[2] - fmi[2]*spi[1];
double cpy = fmi[2]*spi[0] - fmi[0]*spi[2];
double cpz = fmi[0]*spi[1] - fmi[1]*spi[0];
// adding the transverse damping
fmi[0] -= alpha_t*cpx;
fmi[1] -= alpha_t*cpy;
fmi[2] -= alpha_t*cpz;
}
/* ---------------------------------------------------------------------- */
void FixLangevinSpin::add_temperature(double fmi[3])
{
double rx = sigma*random->gaussian();
double ry = sigma*random->gaussian();
double rz = sigma*random->gaussian();
// adding the random field
fmi[0] += rx;
fmi[1] += ry;
fmi[2] += rz;
// adding gilbert's prefactor
fmi[0] *= gil_factor;
fmi[1] *= gil_factor;
fmi[2] *= gil_factor;
}
/* ---------------------------------------------------------------------- */
void FixLangevinSpin::compute_single_langevin(int i, double spi[3], double fmi[3])
{
int *mask = atom->mask;
if (mask[i] & groupbit) {
if (tdamp_flag) add_tdamping(spi,fmi);
if (temp_flag) add_temperature(fmi);
}
}