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
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
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.
------------------------------------------------------------------------- */
#include "fix_respa.h"
#include <cstring>
#include "atom.h"
#include "force.h"
#include "memory.h"
using namespace LAMMPS_NS;
using namespace FixConst;
/* ---------------------------------------------------------------------- */
FixRespa::FixRespa(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg),
store_torque(0), f_level(NULL), t_level(NULL)
{
// nlevels = # of rRESPA levels
nlevels = force->inumeric(FLERR,arg[3]);
// optional arguments
store_torque = 0;
for (int iarg=4; iarg < narg; ++iarg) {
if (strcmp(arg[iarg],"torque") == 0)
store_torque = 1;
}
// perform initial allocation of atom-based arrays
// register with Atom class
f_level = NULL;
t_level = NULL;
grow_arrays(atom->nmax);
atom->add_callback(0);
}
/* ---------------------------------------------------------------------- */
FixRespa::~FixRespa()
{
// unregister callbacks to this fix from Atom class
atom->delete_callback(id,0);
// delete locally stored arrays
memory->destroy(f_level);
if (store_torque) memory->destroy(t_level);
}
/* ---------------------------------------------------------------------- */
int FixRespa::setmask()
{
return 0;
}
/* ----------------------------------------------------------------------
memory usage of local atom-based arrays
------------------------------------------------------------------------- */
double FixRespa::memory_usage()
{
double bytes = atom->nmax*nlevels*3 * sizeof(double);
if (store_torque) bytes += atom->nmax*nlevels*3 * sizeof(double);
return bytes;
}
/* ----------------------------------------------------------------------
allocate local atom-based arrays
------------------------------------------------------------------------- */
void FixRespa::grow_arrays(int nmax)
{
memory->grow(f_level,nmax,nlevels,3,"fix_respa:f_level");
if (store_torque) memory->grow(t_level,nmax,nlevels,3,"fix_respa:t_level");
}
/* ----------------------------------------------------------------------
copy values within local atom-based arrays
------------------------------------------------------------------------- */
void FixRespa::copy_arrays(int i, int j, int /*delflag*/)
{
for (int k = 0; k < nlevels; k++) {
f_level[j][k][0] = f_level[i][k][0];
f_level[j][k][1] = f_level[i][k][1];
f_level[j][k][2] = f_level[i][k][2];
}
if (store_torque) {
for (int k = 0; k < nlevels; k++) {
t_level[j][k][0] = t_level[i][k][0];
t_level[j][k][1] = t_level[i][k][1];
t_level[j][k][2] = t_level[i][k][2];
}
}
}
/* ----------------------------------------------------------------------
pack values in local atom-based arrays for exchange with another proc
------------------------------------------------------------------------- */
int FixRespa::pack_exchange(int i, double *buf)
{
int m = 0;
for (int k = 0; k < nlevels; k++) {
buf[m++] = f_level[i][k][0];
buf[m++] = f_level[i][k][1];
buf[m++] = f_level[i][k][2];
}
if (store_torque) {
for (int k = 0; k < nlevels; k++) {
buf[m++] = t_level[i][k][0];
buf[m++] = t_level[i][k][1];
buf[m++] = t_level[i][k][2];
}
}
return m;
}
/* ----------------------------------------------------------------------
unpack values in local atom-based arrays from exchange with another proc
------------------------------------------------------------------------- */
int FixRespa::unpack_exchange(int nlocal, double *buf)
{
int m = 0;
for (int k = 0; k < nlevels; k++) {
f_level[nlocal][k][0] = buf[m++];
f_level[nlocal][k][1] = buf[m++];
f_level[nlocal][k][2] = buf[m++];
}
if (store_torque) {
for (int k = 0; k < nlevels; k++) {
t_level[nlocal][k][0] = buf[m++];
t_level[nlocal][k][1] = buf[m++];
t_level[nlocal][k][2] = buf[m++];
}
}
return m;
}