2007-12-01 08:01:24 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
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
|
2012-06-07 06:47:51 +08:00
|
|
|
certain rights in this software. This software is distributed under
|
2007-12-01 08:01:24 +08:00
|
|
|
the GNU General Public License.
|
|
|
|
|
|
|
|
See the README file in the top-level LAMMPS directory.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2015-10-31 04:04:06 +08:00
|
|
|
#include <string.h>
|
2007-12-01 08:01:24 +08:00
|
|
|
#include "compute_pe_atom.h"
|
|
|
|
#include "atom.h"
|
2009-01-06 06:26:08 +08:00
|
|
|
#include "update.h"
|
2007-12-01 08:01:24 +08:00
|
|
|
#include "comm.h"
|
|
|
|
#include "force.h"
|
|
|
|
#include "pair.h"
|
|
|
|
#include "bond.h"
|
|
|
|
#include "angle.h"
|
|
|
|
#include "dihedral.h"
|
|
|
|
#include "improper.h"
|
2012-02-15 04:14:03 +08:00
|
|
|
#include "kspace.h"
|
2016-07-13 06:40:29 +08:00
|
|
|
#include "modify.h"
|
|
|
|
#include "fix.h"
|
2007-12-01 08:01:24 +08:00
|
|
|
#include "memory.h"
|
|
|
|
#include "error.h"
|
|
|
|
|
|
|
|
using namespace LAMMPS_NS;
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2012-06-07 06:47:51 +08:00
|
|
|
ComputePEAtom::ComputePEAtom(LAMMPS *lmp, int narg, char **arg) :
|
2016-08-30 06:52:03 +08:00
|
|
|
Compute(lmp, narg, arg),
|
|
|
|
energy(NULL)
|
2007-12-01 08:01:24 +08:00
|
|
|
{
|
2011-09-24 02:06:55 +08:00
|
|
|
if (narg < 3) error->all(FLERR,"Illegal compute pe/atom command");
|
2007-12-01 08:01:24 +08:00
|
|
|
|
|
|
|
peratom_flag = 1;
|
2009-12-05 05:03:54 +08:00
|
|
|
size_peratom_cols = 0;
|
2007-12-01 08:01:24 +08:00
|
|
|
peatomflag = 1;
|
|
|
|
timeflag = 1;
|
|
|
|
comm_reverse = 1;
|
|
|
|
|
|
|
|
if (narg == 3) {
|
|
|
|
pairflag = 1;
|
|
|
|
bondflag = angleflag = dihedralflag = improperflag = 1;
|
2012-02-15 04:14:03 +08:00
|
|
|
kspaceflag = 1;
|
2016-07-13 06:40:29 +08:00
|
|
|
fixflag = 1;
|
2007-12-01 08:01:24 +08:00
|
|
|
} else {
|
|
|
|
pairflag = 0;
|
|
|
|
bondflag = angleflag = dihedralflag = improperflag = 0;
|
2012-02-15 04:14:03 +08:00
|
|
|
kspaceflag = 0;
|
2016-07-13 06:40:29 +08:00
|
|
|
fixflag = 0;
|
2007-12-01 08:01:24 +08:00
|
|
|
int iarg = 3;
|
|
|
|
while (iarg < narg) {
|
|
|
|
if (strcmp(arg[iarg],"pair") == 0) pairflag = 1;
|
|
|
|
else if (strcmp(arg[iarg],"bond") == 0) bondflag = 1;
|
|
|
|
else if (strcmp(arg[iarg],"angle") == 0) angleflag = 1;
|
|
|
|
else if (strcmp(arg[iarg],"dihedral") == 0) dihedralflag = 1;
|
|
|
|
else if (strcmp(arg[iarg],"improper") == 0) improperflag = 1;
|
2012-02-15 04:14:03 +08:00
|
|
|
else if (strcmp(arg[iarg],"kspace") == 0) kspaceflag = 1;
|
2016-07-13 06:40:29 +08:00
|
|
|
else if (strcmp(arg[iarg],"fix") == 0) fixflag = 1;
|
2011-09-24 02:06:55 +08:00
|
|
|
else error->all(FLERR,"Illegal compute pe/atom command");
|
2007-12-01 08:01:24 +08:00
|
|
|
iarg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nmax = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
ComputePEAtom::~ComputePEAtom()
|
|
|
|
{
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->destroy(energy);
|
2007-12-01 08:01:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void ComputePEAtom::compute_peratom()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-01-06 06:26:08 +08:00
|
|
|
invoked_peratom = update->ntimestep;
|
|
|
|
if (update->eflag_atom != invoked_peratom)
|
2011-09-24 02:06:55 +08:00
|
|
|
error->all(FLERR,"Per-atom energy was not tallied on needed timestep");
|
2007-12-01 08:01:24 +08:00
|
|
|
|
|
|
|
// grow local energy array if necessary
|
2009-03-19 01:37:46 +08:00
|
|
|
// needs to be atom->nmax in length
|
2007-12-01 08:01:24 +08:00
|
|
|
|
|
|
|
if (atom->nmax > nmax) {
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->destroy(energy);
|
2007-12-01 08:01:24 +08:00
|
|
|
nmax = atom->nmax;
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->create(energy,nmax,"pe/atom:energy");
|
2009-12-05 05:03:54 +08:00
|
|
|
vector_atom = energy;
|
2007-12-01 08:01:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// npair includes ghosts if either newton flag is set
|
|
|
|
// b/c some bonds/dihedrals call pair::ev_tally with pairwise info
|
|
|
|
// nbond includes ghosts if newton_bond is set
|
|
|
|
// ntotal includes ghosts if either newton flag is set
|
2013-06-04 22:55:56 +08:00
|
|
|
// KSpace includes ghosts if tip4pflag is set
|
2007-12-01 08:01:24 +08:00
|
|
|
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
int npair = nlocal;
|
|
|
|
int nbond = nlocal;
|
|
|
|
int ntotal = nlocal;
|
2013-06-04 22:55:56 +08:00
|
|
|
int nkspace = nlocal;
|
2007-12-01 08:01:24 +08:00
|
|
|
if (force->newton) npair += atom->nghost;
|
|
|
|
if (force->newton_bond) nbond += atom->nghost;
|
|
|
|
if (force->newton) ntotal += atom->nghost;
|
2013-06-05 21:41:11 +08:00
|
|
|
if (force->kspace && force->kspace->tip4pflag) nkspace += atom->nghost;
|
2007-12-01 08:01:24 +08:00
|
|
|
|
|
|
|
// clear local energy array
|
|
|
|
|
|
|
|
for (i = 0; i < ntotal; i++) energy[i] = 0.0;
|
|
|
|
|
|
|
|
// add in per-atom contributions from each force
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2007-12-01 08:01:24 +08:00
|
|
|
if (pairflag && force->pair) {
|
|
|
|
double *eatom = force->pair->eatom;
|
|
|
|
for (i = 0; i < npair; i++) energy[i] += eatom[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bondflag && force->bond) {
|
|
|
|
double *eatom = force->bond->eatom;
|
|
|
|
for (i = 0; i < nbond; i++) energy[i] += eatom[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (angleflag && force->angle) {
|
|
|
|
double *eatom = force->angle->eatom;
|
|
|
|
for (i = 0; i < nbond; i++) energy[i] += eatom[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dihedralflag && force->dihedral) {
|
|
|
|
double *eatom = force->dihedral->eatom;
|
|
|
|
for (i = 0; i < nbond; i++) energy[i] += eatom[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (improperflag && force->improper) {
|
|
|
|
double *eatom = force->improper->eatom;
|
|
|
|
for (i = 0; i < nbond; i++) energy[i] += eatom[i];
|
|
|
|
}
|
|
|
|
|
2012-02-15 04:14:03 +08:00
|
|
|
if (kspaceflag && force->kspace) {
|
|
|
|
double *eatom = force->kspace->eatom;
|
2013-06-04 22:55:56 +08:00
|
|
|
for (i = 0; i < nkspace; i++) energy[i] += eatom[i];
|
2012-02-15 04:14:03 +08:00
|
|
|
}
|
|
|
|
|
2016-07-13 06:40:29 +08:00
|
|
|
// add in per-atom contributions from relevant fixes
|
|
|
|
// always only for owned atoms, not ghost
|
|
|
|
|
2018-03-17 00:37:27 +08:00
|
|
|
if (fixflag && modify->n_thermo_energy_atom)
|
2016-07-13 06:40:29 +08:00
|
|
|
modify->thermo_energy_atom(nlocal,energy);
|
|
|
|
|
2013-06-04 22:55:56 +08:00
|
|
|
// communicate ghost energy between neighbor procs
|
|
|
|
|
2013-09-18 22:10:31 +08:00
|
|
|
if (force->newton || (force->kspace && force->kspace->tip4pflag))
|
2013-06-04 22:55:56 +08:00
|
|
|
comm->reverse_comm_compute(this);
|
|
|
|
|
2007-12-01 08:01:24 +08:00
|
|
|
// zero energy of atoms not in group
|
|
|
|
// only do this after comm since ghost contributions must be included
|
|
|
|
|
|
|
|
int *mask = atom->mask;
|
|
|
|
|
|
|
|
for (i = 0; i < nlocal; i++)
|
|
|
|
if (!(mask[i] & groupbit)) energy[i] = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int ComputePEAtom::pack_reverse_comm(int n, int first, double *buf)
|
|
|
|
{
|
|
|
|
int i,m,last;
|
|
|
|
|
|
|
|
m = 0;
|
|
|
|
last = first + n;
|
|
|
|
for (i = first; i < last; i++) buf[m++] = energy[i];
|
2014-08-07 00:16:32 +08:00
|
|
|
return m;
|
2007-12-01 08:01:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void ComputePEAtom::unpack_reverse_comm(int n, int *list, double *buf)
|
|
|
|
{
|
|
|
|
int i,j,m;
|
|
|
|
|
|
|
|
m = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
j = list[i];
|
|
|
|
energy[j] += buf[m++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
memory usage of local atom-based array
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double ComputePEAtom::memory_usage()
|
|
|
|
{
|
|
|
|
double bytes = nmax * sizeof(double);
|
|
|
|
return bytes;
|
|
|
|
}
|