-
Notifications
You must be signed in to change notification settings - Fork 5
/
compute_position.cpp
executable file
·142 lines (122 loc) · 4.32 KB
/
compute_position.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
/* ----------------------------------------------------------------------
compute position is a child class of "compute", developed based on the
"compute msd", provided by LAMMPS.
This command is distributed under the GNU General Public License.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, 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.
------------------------------------------------------------------------- */
#include "compute_position.h"
#include "atom.h"
#include "update.h"
#include "domain.h"
#include "error.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
ComputePosition::ComputePosition(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
{
if (narg != 3) error->all(FLERR,"Illegal compute position command");
vector_flag = 1;
size_vector = atom->natoms*5;
extvector = 0;
create_attribute = 0;
double **x = atom->x;
int *mask = atom->mask;
imageint *image = atom->image;
int nlocal = atom->nlocal;
MPI_Comm_rank(world, &me); // Assigning the rank of a molecule for each core
MPI_Comm_size(world, &nprocs); // The number of processors
tmprecvcnts = new int[nprocs];
recvcnts = new int[nprocs];
displs = new int[nprocs];
sendbuff = new double[size_vector];
vector = new double[size_vector]; // The output global vector
}
/* ---------------------------------------------------------------------- */
ComputePosition::~ComputePosition()
{
delete [] vector;
delete [] tmprecvcnts;
delete [] recvcnts;
delete [] displs;
delete [] sendbuff;
}
/* ---------------------------------------------------------------------- */
void ComputePosition::init()
{
for (int ii = 0; ii < size_vector; ii++)
{
vector[ii]=-1.0;
}
}
/* ---------------------------------------------------------------------- */
void ComputePosition::compute_vector()
{
invoked_vector = update->ntimestep;
double **x = atom->x;
int *mask = atom->mask;
imageint *image = atom->image;
int nlocal = atom->nlocal;
double *h = domain->h;
double xprd = domain->xprd;
double yprd = domain->yprd;
double zprd = domain->zprd;
int xbox,ybox,zbox;
double xtmp, ytmp, ztmp;
if (domain->triclinic == 0)
{
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit)
{
xbox = (image[i] & IMGMASK) - IMGMAX;
ybox = (image[i] >> IMGBITS & IMGMASK) - IMGMAX;
zbox = (image[i] >> IMG2BITS) - IMGMAX;
xtmp = x[i][0] + xbox*xprd;
ytmp = x[i][1] + ybox*yprd;
ztmp = x[i][2] + zbox*zprd;
sendbuff[5*i] = xtmp;
sendbuff[5*i+1] = ytmp;
sendbuff[5*i+2] = ztmp;
sendbuff[5*i+3] = (double) ((atom->tag[i]) - 1);
sendbuff[5*i+4] = (double) mask[i];
}
} else {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit)
{
xbox = (image[i] & IMGMASK) - IMGMAX;
ybox = (image[i] >> IMGBITS & IMGMASK) - IMGMAX;
zbox = (image[i] >> IMG2BITS) - IMGMAX;
xtmp = x[i][0] + h[0]*xbox + h[5]*ybox + h[4]*zbox;
ytmp = x[i][1] + h[1]*ybox + h[3]*zbox;
ztmp = x[i][2] + h[2]*zbox;
sendbuff[5*i] = xtmp;
sendbuff[5*i+1] = ytmp;
sendbuff[5*i+2] = ztmp;
sendbuff[5*i+3] = (double) ((atom->tag[i]) - 1);
sendbuff[5*i+4] = (double) mask[i];
}
}
// Sending the position of all atoms from all cores (0, 1, ..., n) to all cores
for (int ii = 0; ii < nprocs; ii++)
tmprecvcnts[ii] = (ii == me) ? 5*nlocal : 0 ;
MPI_Allreduce(tmprecvcnts, recvcnts, nprocs, MPI_INT , MPI_SUM, world);
for (int ii = 0; ii < nprocs; ii++)
{
displs[ii] = 0;
}
for (int ii = 1; ii < nprocs; ii++)
for (int jj = ii; jj < nprocs ; jj++)
{
displs[jj] += recvcnts[ii-1];
}
MPI_Allgatherv(sendbuff,5*nlocal, MPI_DOUBLE, vector, recvcnts, displs, MPI_DOUBLE, world);
}