fix memory leaks and reformat
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -24,18 +23,18 @@
|
||||
|
||||
#include "fix_pimd.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#include "universe.h"
|
||||
#include "comm.h"
|
||||
#include "force.h"
|
||||
#include "atom.h"
|
||||
#include "comm.h"
|
||||
#include "domain.h"
|
||||
#include "update.h"
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "math_const.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
#include "universe.h"
|
||||
#include "update.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using namespace FixConst;
|
||||
@ -47,46 +46,6 @@ enum{PIMD,NMPIMD,CMD};
|
||||
|
||||
FixPIMD::FixPIMD(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
{
|
||||
method = PIMD;
|
||||
fmass = 1.0;
|
||||
nhc_temp = 298.15;
|
||||
nhc_nchain = 2;
|
||||
sp = 1.0;
|
||||
|
||||
for (int i=3; i<narg-1; i+=2)
|
||||
{
|
||||
if (strcmp(arg[i],"method")==0)
|
||||
{
|
||||
if (strcmp(arg[i+1],"pimd")==0) method=PIMD;
|
||||
else if (strcmp(arg[i+1],"nmpimd")==0) method=NMPIMD;
|
||||
else if (strcmp(arg[i+1],"cmd")==0) method=CMD;
|
||||
else error->universe_all(FLERR,"Unknown method parameter for fix pimd");
|
||||
}
|
||||
else if (strcmp(arg[i],"fmass")==0)
|
||||
{
|
||||
fmass = atof(arg[i+1]);
|
||||
if (fmass<0.0 || fmass>1.0) error->universe_all(FLERR,"Invalid fmass value for fix pimd");
|
||||
}
|
||||
else if (strcmp(arg[i],"sp")==0)
|
||||
{
|
||||
sp = atof(arg[i+1]);
|
||||
if (fmass<0.0) error->universe_all(FLERR,"Invalid sp value for fix pimd");
|
||||
}
|
||||
else if (strcmp(arg[i],"temp")==0)
|
||||
{
|
||||
nhc_temp = atof(arg[i+1]);
|
||||
if (nhc_temp<0.0) error->universe_all(FLERR,"Invalid temp value for fix pimd");
|
||||
}
|
||||
else if (strcmp(arg[i],"nhc")==0)
|
||||
{
|
||||
nhc_nchain = atoi(arg[i+1]);
|
||||
if (nhc_nchain<2) error->universe_all(FLERR,"Invalid nhc value for fix pimd");
|
||||
}
|
||||
else error->universe_all(arg[i],i+1,"Unknown keyword for fix pimd");
|
||||
}
|
||||
|
||||
/* Initiation */
|
||||
|
||||
max_nsend = 0;
|
||||
tag_send = nullptr;
|
||||
buf_send = nullptr;
|
||||
@ -110,6 +69,41 @@ FixPIMD::FixPIMD(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
nhc_eta_dotdot = nullptr;
|
||||
nhc_eta_mass = nullptr;
|
||||
|
||||
method = PIMD;
|
||||
fmass = 1.0;
|
||||
nhc_temp = 298.15;
|
||||
nhc_nchain = 2;
|
||||
sp = 1.0;
|
||||
|
||||
for (int i = 3; i < narg - 1; i += 2) {
|
||||
if (strcmp(arg[i], "method") == 0) {
|
||||
if (strcmp(arg[i + 1], "pimd") == 0)
|
||||
method = PIMD;
|
||||
else if (strcmp(arg[i + 1], "nmpimd") == 0)
|
||||
method = NMPIMD;
|
||||
else if (strcmp(arg[i + 1], "cmd") == 0)
|
||||
method = CMD;
|
||||
else
|
||||
error->universe_all(FLERR, "Unknown method parameter for fix pimd");
|
||||
} else if (strcmp(arg[i], "fmass") == 0) {
|
||||
fmass = utils::numeric(FLERR, arg[i + 1], false, lmp);
|
||||
if (fmass < 0.0 || fmass > 1.0)
|
||||
error->universe_all(FLERR, "Invalid fmass value for fix pimd");
|
||||
} else if (strcmp(arg[i], "sp") == 0) {
|
||||
sp = utils::numeric(FLERR, arg[i + 1], false, lmp);
|
||||
if (fmass < 0.0) error->universe_all(FLERR, "Invalid sp value for fix pimd");
|
||||
} else if (strcmp(arg[i], "temp") == 0) {
|
||||
nhc_temp = utils::numeric(FLERR, arg[i + 1], false, lmp);
|
||||
if (nhc_temp < 0.0) error->universe_all(FLERR, "Invalid temp value for fix pimd");
|
||||
} else if (strcmp(arg[i], "nhc") == 0) {
|
||||
nhc_nchain = utils::inumeric(FLERR, arg[i + 1], false, lmp);
|
||||
if (nhc_nchain < 2) error->universe_all(FLERR, "Invalid nhc value for fix pimd");
|
||||
} else
|
||||
error->universe_all(FLERR, fmt::format("Unknown keyword {} for fix pimd", arg[i]));
|
||||
}
|
||||
|
||||
/* Initiation */
|
||||
|
||||
size_peratom_cols = 12 * nhc_nchain + 3;
|
||||
|
||||
nhc_offset_one_1 = 3 * nhc_nchain;
|
||||
@ -138,7 +132,37 @@ FixPIMD::FixPIMD(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
FixPIMD::~FixPIMD()
|
||||
{
|
||||
delete[] mass;
|
||||
atom->delete_callback(id, Atom::GROW);
|
||||
atom->delete_callback(id, Atom::RESTART);
|
||||
|
||||
memory->destroy(M_x2xp);
|
||||
memory->destroy(M_xp2x);
|
||||
memory->destroy(M_f2fp);
|
||||
memory->destroy(M_fp2f);
|
||||
memory->sfree(lam);
|
||||
|
||||
if (buf_beads)
|
||||
for (int i = 0; i < np; i++) memory->sfree(buf_beads[i]);
|
||||
delete[] buf_beads;
|
||||
delete[] plan_send;
|
||||
delete[] plan_recv;
|
||||
delete[] mode_index;
|
||||
|
||||
memory->sfree(tag_send);
|
||||
memory->sfree(buf_send);
|
||||
memory->sfree(buf_recv);
|
||||
|
||||
memory->destroy(array_atom);
|
||||
memory->destroy(nhc_eta);
|
||||
memory->destroy(nhc_eta_dot);
|
||||
memory->destroy(nhc_eta_dotdot);
|
||||
memory->destroy(nhc_eta_mass);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int FixPIMD::setmask()
|
||||
{
|
||||
int mask = 0;
|
||||
@ -155,7 +179,8 @@ void FixPIMD::init()
|
||||
if (atom->map_style == Atom::MAP_NONE)
|
||||
error->all(FLERR, "Fix pimd requires an atom map, see atom_modify");
|
||||
|
||||
if (universe->me==0 && screen) fprintf(screen,"Fix pimd initializing Path-Integral ...\n");
|
||||
if (universe->me == 0 && universe->uscreen)
|
||||
fprintf(universe->uscreen, "Fix pimd initializing Path-Integral ...\n");
|
||||
|
||||
// prepare the constants
|
||||
|
||||
@ -200,8 +225,10 @@ void FixPIMD::init()
|
||||
|
||||
mass = new double[atom->ntypes + 1];
|
||||
|
||||
if (method==CMD || method==NMPIMD) nmpimd_init();
|
||||
else for (int i=1; i<=atom->ntypes; i++) mass[i] = atom->mass[i] / np * fmass;
|
||||
if (method == CMD || method == NMPIMD)
|
||||
nmpimd_init();
|
||||
else
|
||||
for (int i = 1; i <= atom->ntypes; i++) mass[i] = atom->mass[i] / np * fmass;
|
||||
|
||||
if (!nhc_ready) nhc_init();
|
||||
}
|
||||
@ -210,7 +237,8 @@ void FixPIMD::init()
|
||||
|
||||
void FixPIMD::setup(int vflag)
|
||||
{
|
||||
if (universe->me==0 && screen) fprintf(screen,"Setting up Path-Integral ...\n");
|
||||
if (universe->me == 0 && universe->uscreen)
|
||||
fprintf(universe->uscreen, "Setting up Path-Integral ...\n");
|
||||
|
||||
post_force(vflag);
|
||||
}
|
||||
@ -234,13 +262,13 @@ void FixPIMD::final_integrate()
|
||||
|
||||
void FixPIMD::post_force(int /*flag*/)
|
||||
{
|
||||
for (int i=0; i<atom->nlocal; i++) for(int j=0; j<3; j++) atom->f[i][j] /= np;
|
||||
for (int i = 0; i < atom->nlocal; i++)
|
||||
for (int j = 0; j < 3; j++) atom->f[i][j] /= np;
|
||||
|
||||
comm_exec(atom->x);
|
||||
spring_force();
|
||||
|
||||
if (method==CMD || method==NMPIMD)
|
||||
{
|
||||
if (method == CMD || method == NMPIMD) {
|
||||
/* forward comm for the force on ghost atoms */
|
||||
|
||||
nmpimd_fill(atom->f);
|
||||
@ -267,28 +295,32 @@ void FixPIMD::nhc_init()
|
||||
double mass0 = KT * tau * tau;
|
||||
int max = 3 * atom->nlocal;
|
||||
|
||||
for (int i=0; i<max; i++)
|
||||
{
|
||||
for (int ichain=0; ichain<nhc_nchain; ichain++)
|
||||
{
|
||||
for (int i = 0; i < max; i++) {
|
||||
for (int ichain = 0; ichain < nhc_nchain; ichain++) {
|
||||
nhc_eta[i][ichain] = 0.0;
|
||||
nhc_eta_dot[i][ichain] = 0.0;
|
||||
nhc_eta_dot[i][ichain] = 0.0;
|
||||
nhc_eta_dotdot[i][ichain] = 0.0;
|
||||
nhc_eta_mass[i][ichain] = mass0;
|
||||
if ((method==CMD || method==NMPIMD) && universe->iworld==0) ; else nhc_eta_mass[i][ichain] *= fmass;
|
||||
if ((method == CMD || method == NMPIMD) && universe->iworld == 0)
|
||||
;
|
||||
else
|
||||
nhc_eta_mass[i][ichain] *= fmass;
|
||||
}
|
||||
|
||||
nhc_eta_dot[i][nhc_nchain] = 0.0;
|
||||
|
||||
for (int ichain = 1; ichain < nhc_nchain; ichain++)
|
||||
nhc_eta_dotdot[i][ichain] = (nhc_eta_mass[i][ichain-1] * nhc_eta_dot[i][ichain-1]
|
||||
* nhc_eta_dot[i][ichain-1] * force->mvv2e - KT) / nhc_eta_mass[i][ichain];
|
||||
nhc_eta_dotdot[i][ichain] = (nhc_eta_mass[i][ichain - 1] * nhc_eta_dot[i][ichain - 1] *
|
||||
nhc_eta_dot[i][ichain - 1] * force->mvv2e -
|
||||
KT) /
|
||||
nhc_eta_mass[i][ichain];
|
||||
}
|
||||
|
||||
// Zero NH acceleration for CMD
|
||||
|
||||
if (method==CMD && universe->iworld==0) for (int i=0; i<max; i++)
|
||||
if (method == CMD && universe->iworld == 0)
|
||||
for (int i = 0; i < max; i++)
|
||||
for (int ichain = 0; ichain < nhc_nchain; ichain++) nhc_eta_dotdot[i][ichain] = 0.0;
|
||||
|
||||
nhc_ready = true;
|
||||
@ -302,8 +334,7 @@ void FixPIMD::nhc_update_x()
|
||||
double **x = atom->x;
|
||||
double **v = atom->v;
|
||||
|
||||
if (method==CMD || method==NMPIMD)
|
||||
{
|
||||
if (method == CMD || method == NMPIMD) {
|
||||
nmpimd_fill(atom->v);
|
||||
comm_exec(atom->v);
|
||||
|
||||
@ -313,8 +344,7 @@ void FixPIMD::nhc_update_x()
|
||||
nmpimd_transform(buf_beads, v, M_xp2x[universe->iworld]);
|
||||
}
|
||||
|
||||
for (int i=0; i<n; i++)
|
||||
{
|
||||
for (int i = 0; i < n; i++) {
|
||||
x[i][0] += dtv * v[i][0];
|
||||
x[i][1] += dtv * v[i][1];
|
||||
x[i][2] += dtv * v[i][2];
|
||||
@ -330,8 +360,7 @@ void FixPIMD::nhc_update_v()
|
||||
double **v = atom->v;
|
||||
double **f = atom->f;
|
||||
|
||||
for (int i=0; i<n; i++)
|
||||
{
|
||||
for (int i = 0; i < n; i++) {
|
||||
double dtfm = dtf / mass[type[i]];
|
||||
v[i][0] += dtfm * f[i][0];
|
||||
v[i][1] += dtfm * f[i][1];
|
||||
@ -350,8 +379,7 @@ void FixPIMD::nhc_update_v()
|
||||
double dt4 = 0.25 * update->dt;
|
||||
double dt8 = 0.125 * update->dt;
|
||||
|
||||
for (int i=0; i<nmax; i++)
|
||||
{
|
||||
for (int i = 0; i < nmax; i++) {
|
||||
int iatm = i / 3;
|
||||
int idim = i % 3;
|
||||
|
||||
@ -366,8 +394,7 @@ void FixPIMD::nhc_update_v()
|
||||
|
||||
eta_dotdot[0] = (kecurrent - KT) / nhc_eta_mass[i][0];
|
||||
|
||||
for (int ichain=nhc_nchain-1; ichain>0; ichain--)
|
||||
{
|
||||
for (int ichain = nhc_nchain - 1; ichain > 0; ichain--) {
|
||||
expfac = exp(-dt8 * eta_dot[ichain + 1]);
|
||||
eta_dot[ichain] *= expfac;
|
||||
eta_dot[ichain] += eta_dotdot[ichain] * dt4;
|
||||
@ -388,19 +415,18 @@ void FixPIMD::nhc_update_v()
|
||||
kecurrent = force->boltz * t_current;
|
||||
eta_dotdot[0] = (kecurrent - KT) / nhc_eta_mass[i][0];
|
||||
|
||||
for (int ichain=0; ichain<nhc_nchain; ichain++)
|
||||
eta[ichain] += dthalf * eta_dot[ichain];
|
||||
for (int ichain = 0; ichain < nhc_nchain; ichain++) eta[ichain] += dthalf * eta_dot[ichain];
|
||||
|
||||
eta_dot[0] *= expfac;
|
||||
eta_dot[0] += eta_dotdot[0] * dt4;
|
||||
eta_dot[0] *= expfac;
|
||||
|
||||
for (int ichain=1; ichain<nhc_nchain; ichain++)
|
||||
{
|
||||
for (int ichain = 1; ichain < nhc_nchain; ichain++) {
|
||||
expfac = exp(-dt8 * eta_dot[ichain + 1]);
|
||||
eta_dot[ichain] *= expfac;
|
||||
eta_dotdot[ichain] = (nhc_eta_mass[i][ichain-1] * eta_dot[ichain-1] * eta_dot[ichain-1]
|
||||
- KT) / nhc_eta_mass[i][ichain];
|
||||
eta_dotdot[ichain] =
|
||||
(nhc_eta_mass[i][ichain - 1] * eta_dot[ichain - 1] * eta_dot[ichain - 1] - KT) /
|
||||
nhc_eta_mass[i][ichain];
|
||||
eta_dot[ichain] += eta_dotdot[ichain] * dt4;
|
||||
eta_dot[ichain] *= expfac;
|
||||
}
|
||||
@ -429,23 +455,21 @@ void FixPIMD::nmpimd_init()
|
||||
lam[0] = 0.0;
|
||||
if (np % 2 == 0) lam[np - 1] = 4.0 * np;
|
||||
|
||||
for (int i=2; i<=np/2; i++)
|
||||
{
|
||||
for (int i = 2; i <= np / 2; i++) {
|
||||
lam[2 * i - 3] = lam[2 * i - 2] = 2.0 * np * (1.0 - 1.0 * cos(2.0 * MY_PI * (i - 1) / np));
|
||||
}
|
||||
|
||||
// Set up eigenvectors for non-degenerated modes
|
||||
|
||||
for (int i=0; i<np; i++)
|
||||
{
|
||||
for (int i = 0; i < np; i++) {
|
||||
M_x2xp[0][i] = 1.0 / np;
|
||||
if (np % 2 == 0) M_x2xp[np - 1][i] = 1.0 / np * pow(-1.0, i);
|
||||
}
|
||||
|
||||
// Set up eigenvectors for degenerated modes
|
||||
|
||||
for (int i=0; i<(np-1)/2; i++) for(int j=0; j<np; j++)
|
||||
{
|
||||
for (int i = 0; i < (np - 1) / 2; i++)
|
||||
for (int j = 0; j < np; j++) {
|
||||
M_x2xp[2 * i + 1][j] = sqrt(2.0) * cos(2.0 * MY_PI * (i + 1) * j / np) / np;
|
||||
M_x2xp[2 * i + 2][j] = -sqrt(2.0) * sin(2.0 * MY_PI * (i + 1) * j / np) / np;
|
||||
}
|
||||
@ -453,8 +477,7 @@ void FixPIMD::nmpimd_init()
|
||||
// Set up Ut
|
||||
|
||||
for (int i = 0; i < np; i++)
|
||||
for (int j=0; j<np; j++)
|
||||
{
|
||||
for (int j = 0; j < np; j++) {
|
||||
M_xp2x[i][j] = M_x2xp[j][i] * np;
|
||||
M_f2fp[i][j] = M_x2xp[i][j] * np;
|
||||
M_fp2f[i][j] = M_xp2x[i][j];
|
||||
@ -464,12 +487,10 @@ void FixPIMD::nmpimd_init()
|
||||
|
||||
int iworld = universe->iworld;
|
||||
|
||||
for (int i=1; i<=atom->ntypes; i++)
|
||||
{
|
||||
for (int i = 1; i <= atom->ntypes; i++) {
|
||||
mass[i] = atom->mass[i];
|
||||
|
||||
if (iworld)
|
||||
{
|
||||
if (iworld) {
|
||||
mass[i] *= lam[iworld];
|
||||
mass[i] *= fmass;
|
||||
}
|
||||
@ -491,8 +512,8 @@ void FixPIMD::nmpimd_transform(double** src, double** des, double *vector)
|
||||
int n = atom->nlocal;
|
||||
int m = 0;
|
||||
|
||||
for (int i=0; i<n; i++) for(int d=0; d<3; d++)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
for (int d = 0; d < 3; d++) {
|
||||
des[i][d] = 0.0;
|
||||
for (int j = 0; j < np; j++) { des[i][d] += (src[j][m] * vector[j]); }
|
||||
m++;
|
||||
@ -514,8 +535,7 @@ void FixPIMD::spring_force()
|
||||
double *xlast = buf_beads[x_last];
|
||||
double *xnext = buf_beads[x_next];
|
||||
|
||||
for (int i=0; i<nlocal; i++)
|
||||
{
|
||||
for (int i = 0; i < nlocal; i++) {
|
||||
double delx1 = xlast[0] - x[i][0];
|
||||
double dely1 = xlast[1] - x[i][1];
|
||||
double delz1 = xlast[2] - x[i][2];
|
||||
@ -548,14 +568,12 @@ void FixPIMD::spring_force()
|
||||
|
||||
void FixPIMD::comm_init()
|
||||
{
|
||||
if (size_plan)
|
||||
{
|
||||
if (size_plan) {
|
||||
delete[] plan_send;
|
||||
delete[] plan_recv;
|
||||
}
|
||||
|
||||
if (method == PIMD)
|
||||
{
|
||||
if (method == PIMD) {
|
||||
size_plan = 2;
|
||||
plan_send = new int[2];
|
||||
plan_recv = new int[2];
|
||||
@ -566,21 +584,22 @@ void FixPIMD::comm_init()
|
||||
if (rank_last < 0) rank_last += universe->nprocs;
|
||||
if (rank_next >= universe->nprocs) rank_next -= universe->nprocs;
|
||||
|
||||
plan_send[0] = rank_next; plan_send[1] = rank_last;
|
||||
plan_recv[0] = rank_last; plan_recv[1] = rank_next;
|
||||
plan_send[0] = rank_next;
|
||||
plan_send[1] = rank_last;
|
||||
plan_recv[0] = rank_last;
|
||||
plan_recv[1] = rank_next;
|
||||
|
||||
mode_index[0] = 0; mode_index[1] = 1;
|
||||
x_last = 1; x_next = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode_index[0] = 0;
|
||||
mode_index[1] = 1;
|
||||
x_last = 1;
|
||||
x_next = 0;
|
||||
} else {
|
||||
size_plan = np - 1;
|
||||
plan_send = new int[size_plan];
|
||||
plan_recv = new int[size_plan];
|
||||
mode_index = new int[size_plan];
|
||||
|
||||
for (int i=0; i<size_plan; i++)
|
||||
{
|
||||
for (int i = 0; i < size_plan; i++) {
|
||||
plan_send[i] = universe->me + comm->nprocs * (i + 1);
|
||||
if (plan_send[i] >= universe->nprocs) plan_send[i] -= universe->nprocs;
|
||||
|
||||
@ -594,9 +613,9 @@ void FixPIMD::comm_init()
|
||||
x_last = (universe->iworld - 1 + universe->nworlds) % (universe->nworlds);
|
||||
}
|
||||
|
||||
if (buf_beads)
|
||||
{
|
||||
for (int i=0; i<np; i++) if (buf_beads[i]) delete [] buf_beads[i];
|
||||
if (buf_beads) {
|
||||
for (int i = 0; i < np; i++)
|
||||
if (buf_beads[i]) delete[] buf_beads[i];
|
||||
delete[] buf_beads;
|
||||
}
|
||||
|
||||
@ -610,8 +629,7 @@ void FixPIMD::comm_exec(double **ptr)
|
||||
{
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
if (nlocal > max_nlocal)
|
||||
{
|
||||
if (nlocal > max_nlocal) {
|
||||
max_nlocal = nlocal + 200;
|
||||
int size = sizeof(double) * max_nlocal * 3;
|
||||
buf_recv = (double *) memory->srealloc(buf_recv, size, "FixPIMD:x_recv");
|
||||
@ -626,47 +644,46 @@ void FixPIMD::comm_exec(double **ptr)
|
||||
|
||||
// go over comm plans
|
||||
|
||||
for (int iplan = 0; iplan<size_plan; iplan++)
|
||||
{
|
||||
for (int iplan = 0; iplan < size_plan; iplan++) {
|
||||
// sendrecv nlocal
|
||||
|
||||
int nsend;
|
||||
|
||||
MPI_Sendrecv( &(nlocal), 1, MPI_INT, plan_send[iplan], 0,
|
||||
&(nsend), 1, MPI_INT, plan_recv[iplan], 0, universe->uworld, MPI_STATUS_IGNORE);
|
||||
MPI_Sendrecv(&(nlocal), 1, MPI_INT, plan_send[iplan], 0, &(nsend), 1, MPI_INT, plan_recv[iplan],
|
||||
0, universe->uworld, MPI_STATUS_IGNORE);
|
||||
|
||||
// allocate arrays
|
||||
|
||||
if (nsend > max_nsend)
|
||||
{
|
||||
if (nsend > max_nsend) {
|
||||
max_nsend = nsend + 200;
|
||||
tag_send = (tagint*) memory->srealloc(tag_send, sizeof(tagint)*max_nsend, "FixPIMD:tag_send");
|
||||
buf_send = (double*) memory->srealloc(buf_send, sizeof(double)*max_nsend*3, "FixPIMD:x_send");
|
||||
tag_send =
|
||||
(tagint *) memory->srealloc(tag_send, sizeof(tagint) * max_nsend, "FixPIMD:tag_send");
|
||||
buf_send =
|
||||
(double *) memory->srealloc(buf_send, sizeof(double) * max_nsend * 3, "FixPIMD:x_send");
|
||||
}
|
||||
|
||||
// send tags
|
||||
|
||||
MPI_Sendrecv( atom->tag, nlocal, MPI_LMP_TAGINT, plan_send[iplan], 0,
|
||||
tag_send, nsend, MPI_LMP_TAGINT, plan_recv[iplan], 0, universe->uworld, MPI_STATUS_IGNORE);
|
||||
MPI_Sendrecv(atom->tag, nlocal, MPI_LMP_TAGINT, plan_send[iplan], 0, tag_send, nsend,
|
||||
MPI_LMP_TAGINT, plan_recv[iplan], 0, universe->uworld, MPI_STATUS_IGNORE);
|
||||
|
||||
// wrap positions
|
||||
|
||||
double *wrap_ptr = buf_send;
|
||||
int ncpy = sizeof(double) * 3;
|
||||
|
||||
for (int i=0; i<nsend; i++)
|
||||
{
|
||||
for (int i = 0; i < nsend; i++) {
|
||||
int index = atom->map(tag_send[i]);
|
||||
|
||||
if (index<0)
|
||||
{
|
||||
if (index < 0) {
|
||||
char error_line[256];
|
||||
|
||||
sprintf(error_line, "Atom " TAGINT_FORMAT " is missing at world [%d] "
|
||||
"rank [%d] required by rank [%d] (" TAGINT_FORMAT ", "
|
||||
TAGINT_FORMAT ", " TAGINT_FORMAT ").\n", tag_send[i],
|
||||
universe->iworld, comm->me, plan_recv[iplan],
|
||||
atom->tag[0], atom->tag[1], atom->tag[2]);
|
||||
sprintf(error_line,
|
||||
"Atom " TAGINT_FORMAT " is missing at world [%d] "
|
||||
"rank [%d] required by rank [%d] (" TAGINT_FORMAT ", " TAGINT_FORMAT
|
||||
", " TAGINT_FORMAT ").\n",
|
||||
tag_send[i], universe->iworld, comm->me, plan_recv[iplan], atom->tag[0],
|
||||
atom->tag[1], atom->tag[2]);
|
||||
|
||||
error->universe_one(FLERR, error_line);
|
||||
}
|
||||
@ -677,8 +694,8 @@ void FixPIMD::comm_exec(double **ptr)
|
||||
|
||||
// sendrecv x
|
||||
|
||||
MPI_Sendrecv( buf_send, nsend*3, MPI_DOUBLE, plan_recv[iplan], 0,
|
||||
buf_recv, nlocal*3, MPI_DOUBLE, plan_send[iplan], 0, universe->uworld, MPI_STATUS_IGNORE);
|
||||
MPI_Sendrecv(buf_send, nsend * 3, MPI_DOUBLE, plan_recv[iplan], 0, buf_recv, nlocal * 3,
|
||||
MPI_DOUBLE, plan_send[iplan], 0, universe->uworld, MPI_STATUS_IGNORE);
|
||||
|
||||
// copy x
|
||||
|
||||
@ -688,8 +705,7 @@ void FixPIMD::comm_exec(double **ptr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int FixPIMD::pack_forward_comm(int n, int *list, double *buf,
|
||||
int /*pbc_flag*/, int * /*pbc*/)
|
||||
int FixPIMD::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/)
|
||||
{
|
||||
int i, j, m;
|
||||
|
||||
@ -763,10 +779,14 @@ int FixPIMD::pack_exchange(int i, double *buf)
|
||||
int offset = 0;
|
||||
int pos = i * 3;
|
||||
|
||||
memcpy(buf+offset, nhc_eta[pos], nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(buf+offset, nhc_eta_dot[pos], nhc_size_one_2); offset += nhc_offset_one_2;
|
||||
memcpy(buf+offset, nhc_eta_dotdot[pos], nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(buf+offset, nhc_eta_mass[pos], nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(buf + offset, nhc_eta[pos], nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
memcpy(buf + offset, nhc_eta_dot[pos], nhc_size_one_2);
|
||||
offset += nhc_offset_one_2;
|
||||
memcpy(buf + offset, nhc_eta_dotdot[pos], nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
memcpy(buf + offset, nhc_eta_mass[pos], nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
|
||||
return size_peratom_cols;
|
||||
}
|
||||
@ -778,10 +798,14 @@ int FixPIMD::unpack_exchange(int nlocal, double *buf)
|
||||
int offset = 0;
|
||||
int pos = nlocal * 3;
|
||||
|
||||
memcpy(nhc_eta[pos], buf+offset, nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_dot[pos], buf+offset, nhc_size_one_2); offset += nhc_offset_one_2;
|
||||
memcpy(nhc_eta_dotdot[pos], buf+offset, nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_mass[pos], buf+offset, nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(nhc_eta[pos], buf + offset, nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_dot[pos], buf + offset, nhc_size_one_2);
|
||||
offset += nhc_offset_one_2;
|
||||
memcpy(nhc_eta_dotdot[pos], buf + offset, nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_mass[pos], buf + offset, nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
|
||||
return size_peratom_cols;
|
||||
}
|
||||
@ -795,10 +819,14 @@ int FixPIMD::pack_restart(int i, double *buf)
|
||||
// pack buf[0] this way because other fixes unpack it
|
||||
buf[offset++] = size_peratom_cols + 1;
|
||||
|
||||
memcpy(buf+offset, nhc_eta[pos], nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(buf+offset, nhc_eta_dot[pos], nhc_size_one_2); offset += nhc_offset_one_2;
|
||||
memcpy(buf+offset, nhc_eta_dotdot[pos], nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(buf+offset, nhc_eta_mass[pos], nhc_size_one_1); offset += nhc_offset_one_1;
|
||||
memcpy(buf + offset, nhc_eta[pos], nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
memcpy(buf + offset, nhc_eta_dot[pos], nhc_size_one_2);
|
||||
offset += nhc_offset_one_2;
|
||||
memcpy(buf + offset, nhc_eta_dotdot[pos], nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
memcpy(buf + offset, nhc_eta_mass[pos], nhc_size_one_1);
|
||||
offset += nhc_offset_one_1;
|
||||
|
||||
return size_peratom_cols + 1;
|
||||
}
|
||||
@ -818,10 +846,14 @@ void FixPIMD::unpack_restart(int nlocal, int nth)
|
||||
|
||||
int pos = nlocal * 3;
|
||||
|
||||
memcpy(nhc_eta[pos], extra[nlocal]+m, nhc_size_one_1); m += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_dot[pos], extra[nlocal]+m, nhc_size_one_2); m += nhc_offset_one_2;
|
||||
memcpy(nhc_eta_dotdot[pos], extra[nlocal]+m, nhc_size_one_1); m += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_mass[pos], extra[nlocal]+m, nhc_size_one_1); m += nhc_offset_one_1;
|
||||
memcpy(nhc_eta[pos], extra[nlocal] + m, nhc_size_one_1);
|
||||
m += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_dot[pos], extra[nlocal] + m, nhc_size_one_2);
|
||||
m += nhc_offset_one_2;
|
||||
memcpy(nhc_eta_dotdot[pos], extra[nlocal] + m, nhc_size_one_1);
|
||||
m += nhc_offset_one_1;
|
||||
memcpy(nhc_eta_mass[pos], extra[nlocal] + m, nhc_size_one_1);
|
||||
m += nhc_offset_one_1;
|
||||
|
||||
nhc_ready = true;
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ namespace LAMMPS_NS {
|
||||
class FixPIMD : public Fix {
|
||||
public:
|
||||
FixPIMD(class LAMMPS *, int, char **);
|
||||
virtual ~FixPIMD();
|
||||
|
||||
int setmask();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user