enable and apply clang-format
This commit is contained in:
215
src/angle.cpp
215
src/angle.cpp
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -14,20 +13,20 @@
|
||||
|
||||
#include "angle.h"
|
||||
#include "atom.h"
|
||||
#include "atom_masks.h"
|
||||
#include "comm.h"
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "math_const.h"
|
||||
#include "suffix.h"
|
||||
#include "atom_masks.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
#include "suffix.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using namespace MathConst;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Angle::Angle(LAMMPS *lmp) : Pointers(lmp)
|
||||
Angle::Angle(LAMMPS *_lmp) : Pointers(_lmp)
|
||||
{
|
||||
energy = 0.0;
|
||||
virial[0] = virial[1] = virial[2] = virial[3] = virial[4] = virial[5] = 0.0;
|
||||
@ -67,10 +66,9 @@ Angle::~Angle()
|
||||
|
||||
void Angle::init()
|
||||
{
|
||||
if (!allocated && atom->nangletypes)
|
||||
error->all(FLERR,"Angle coeffs are not set");
|
||||
if (!allocated && atom->nangletypes) error->all(FLERR, "Angle coeffs are not set");
|
||||
for (int i = 1; i <= atom->nangletypes; i++)
|
||||
if (setflag[i] == 0) error->all(FLERR,"All angle coeffs are not set");
|
||||
if (setflag[i] == 0) error->all(FLERR, "All angle coeffs are not set");
|
||||
|
||||
init_style();
|
||||
}
|
||||
@ -94,7 +92,7 @@ void Angle::init()
|
||||
|
||||
void Angle::ev_setup(int eflag, int vflag, int alloc)
|
||||
{
|
||||
int i,n;
|
||||
int i, n;
|
||||
|
||||
evflag = 1;
|
||||
|
||||
@ -104,11 +102,9 @@ void Angle::ev_setup(int eflag, int vflag, int alloc)
|
||||
|
||||
vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR);
|
||||
vflag_atom = vflag & VIRIAL_ATOM;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL)
|
||||
vflag_atom = 1;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1;
|
||||
cvflag_atom = 0;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL)
|
||||
cvflag_atom = 1;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1;
|
||||
vflag_either = vflag_global || vflag_atom || cvflag_atom;
|
||||
|
||||
// reallocate per-atom arrays if necessary
|
||||
@ -117,28 +113,29 @@ void Angle::ev_setup(int eflag, int vflag, int alloc)
|
||||
maxeatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(eatom);
|
||||
memory->create(eatom,comm->nthreads*maxeatom,"angle:eatom");
|
||||
memory->create(eatom, comm->nthreads * maxeatom, "angle:eatom");
|
||||
}
|
||||
}
|
||||
if (vflag_atom && atom->nmax > maxvatom) {
|
||||
maxvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(vatom);
|
||||
memory->create(vatom,comm->nthreads*maxvatom,6,"angle:vatom");
|
||||
memory->create(vatom, comm->nthreads * maxvatom, 6, "angle:vatom");
|
||||
}
|
||||
}
|
||||
if (cvflag_atom && atom->nmax > maxcvatom) {
|
||||
maxcvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(cvatom);
|
||||
memory->create(cvatom,comm->nthreads*maxcvatom,9,"angle:cvatom");
|
||||
memory->create(cvatom, comm->nthreads * maxcvatom, 9, "angle:cvatom");
|
||||
}
|
||||
}
|
||||
|
||||
// zero accumulators
|
||||
|
||||
if (eflag_global) energy = 0.0;
|
||||
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (vflag_global)
|
||||
for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (eflag_atom && alloc) {
|
||||
n = atom->nlocal;
|
||||
if (force->newton_bond) n += atom->nghost;
|
||||
@ -179,25 +176,25 @@ void Angle::ev_setup(int eflag, int vflag, int alloc)
|
||||
virial = r1F1 + r2F2 + r3F3 = (r1-r2) F1 + (r3-r2) F3 = del1*f1 + del2*f3
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond,
|
||||
double eangle, double *f1, double *f3,
|
||||
double delx1, double dely1, double delz1,
|
||||
double delx2, double dely2, double delz2)
|
||||
void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond, double eangle, double *f1,
|
||||
double *f3, double delx1, double dely1, double delz1, double delx2,
|
||||
double dely2, double delz2)
|
||||
{
|
||||
double eanglethird,v[6];
|
||||
double eanglethird, v[6];
|
||||
|
||||
if (eflag_either) {
|
||||
if (eflag_global) {
|
||||
if (newton_bond) energy += eangle;
|
||||
if (newton_bond)
|
||||
energy += eangle;
|
||||
else {
|
||||
eanglethird = THIRD*eangle;
|
||||
eanglethird = THIRD * eangle;
|
||||
if (i < nlocal) energy += eanglethird;
|
||||
if (j < nlocal) energy += eanglethird;
|
||||
if (k < nlocal) energy += eanglethird;
|
||||
}
|
||||
}
|
||||
if (eflag_atom) {
|
||||
eanglethird = THIRD*eangle;
|
||||
eanglethird = THIRD * eangle;
|
||||
if (newton_bond || i < nlocal) eatom[i] += eanglethird;
|
||||
if (newton_bond || j < nlocal) eatom[j] += eanglethird;
|
||||
if (newton_bond || k < nlocal) eatom[k] += eanglethird;
|
||||
@ -205,12 +202,12 @@ void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond,
|
||||
}
|
||||
|
||||
if (vflag_either) {
|
||||
v[0] = delx1*f1[0] + delx2*f3[0];
|
||||
v[1] = dely1*f1[1] + dely2*f3[1];
|
||||
v[2] = delz1*f1[2] + delz2*f3[2];
|
||||
v[3] = delx1*f1[1] + delx2*f3[1];
|
||||
v[4] = delx1*f1[2] + delx2*f3[2];
|
||||
v[5] = dely1*f1[2] + dely2*f3[2];
|
||||
v[0] = delx1 * f1[0] + delx2 * f3[0];
|
||||
v[1] = dely1 * f1[1] + dely2 * f3[1];
|
||||
v[2] = delz1 * f1[2] + delz2 * f3[2];
|
||||
v[3] = delx1 * f1[1] + delx2 * f3[1];
|
||||
v[4] = delx1 * f1[2] + delx2 * f3[2];
|
||||
v[5] = dely1 * f1[2] + dely2 * f3[2];
|
||||
|
||||
if (vflag_global) {
|
||||
if (newton_bond) {
|
||||
@ -222,56 +219,56 @@ void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond,
|
||||
virial[5] += v[5];
|
||||
} else {
|
||||
if (i < nlocal) {
|
||||
virial[0] += THIRD*v[0];
|
||||
virial[1] += THIRD*v[1];
|
||||
virial[2] += THIRD*v[2];
|
||||
virial[3] += THIRD*v[3];
|
||||
virial[4] += THIRD*v[4];
|
||||
virial[5] += THIRD*v[5];
|
||||
virial[0] += THIRD * v[0];
|
||||
virial[1] += THIRD * v[1];
|
||||
virial[2] += THIRD * v[2];
|
||||
virial[3] += THIRD * v[3];
|
||||
virial[4] += THIRD * v[4];
|
||||
virial[5] += THIRD * v[5];
|
||||
}
|
||||
if (j < nlocal) {
|
||||
virial[0] += THIRD*v[0];
|
||||
virial[1] += THIRD*v[1];
|
||||
virial[2] += THIRD*v[2];
|
||||
virial[3] += THIRD*v[3];
|
||||
virial[4] += THIRD*v[4];
|
||||
virial[5] += THIRD*v[5];
|
||||
virial[0] += THIRD * v[0];
|
||||
virial[1] += THIRD * v[1];
|
||||
virial[2] += THIRD * v[2];
|
||||
virial[3] += THIRD * v[3];
|
||||
virial[4] += THIRD * v[4];
|
||||
virial[5] += THIRD * v[5];
|
||||
}
|
||||
if (k < nlocal) {
|
||||
virial[0] += THIRD*v[0];
|
||||
virial[1] += THIRD*v[1];
|
||||
virial[2] += THIRD*v[2];
|
||||
virial[3] += THIRD*v[3];
|
||||
virial[4] += THIRD*v[4];
|
||||
virial[5] += THIRD*v[5];
|
||||
virial[0] += THIRD * v[0];
|
||||
virial[1] += THIRD * v[1];
|
||||
virial[2] += THIRD * v[2];
|
||||
virial[3] += THIRD * v[3];
|
||||
virial[4] += THIRD * v[4];
|
||||
virial[5] += THIRD * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vflag_atom) {
|
||||
if (newton_bond || i < nlocal) {
|
||||
vatom[i][0] += THIRD*v[0];
|
||||
vatom[i][1] += THIRD*v[1];
|
||||
vatom[i][2] += THIRD*v[2];
|
||||
vatom[i][3] += THIRD*v[3];
|
||||
vatom[i][4] += THIRD*v[4];
|
||||
vatom[i][5] += THIRD*v[5];
|
||||
vatom[i][0] += THIRD * v[0];
|
||||
vatom[i][1] += THIRD * v[1];
|
||||
vatom[i][2] += THIRD * v[2];
|
||||
vatom[i][3] += THIRD * v[3];
|
||||
vatom[i][4] += THIRD * v[4];
|
||||
vatom[i][5] += THIRD * v[5];
|
||||
}
|
||||
if (newton_bond || j < nlocal) {
|
||||
vatom[j][0] += THIRD*v[0];
|
||||
vatom[j][1] += THIRD*v[1];
|
||||
vatom[j][2] += THIRD*v[2];
|
||||
vatom[j][3] += THIRD*v[3];
|
||||
vatom[j][4] += THIRD*v[4];
|
||||
vatom[j][5] += THIRD*v[5];
|
||||
vatom[j][0] += THIRD * v[0];
|
||||
vatom[j][1] += THIRD * v[1];
|
||||
vatom[j][2] += THIRD * v[2];
|
||||
vatom[j][3] += THIRD * v[3];
|
||||
vatom[j][4] += THIRD * v[4];
|
||||
vatom[j][5] += THIRD * v[5];
|
||||
}
|
||||
if (newton_bond || k < nlocal) {
|
||||
vatom[k][0] += THIRD*v[0];
|
||||
vatom[k][1] += THIRD*v[1];
|
||||
vatom[k][2] += THIRD*v[2];
|
||||
vatom[k][3] += THIRD*v[3];
|
||||
vatom[k][4] += THIRD*v[4];
|
||||
vatom[k][5] += THIRD*v[5];
|
||||
vatom[k][0] += THIRD * v[0];
|
||||
vatom[k][1] += THIRD * v[1];
|
||||
vatom[k][2] += THIRD * v[2];
|
||||
vatom[k][3] += THIRD * v[3];
|
||||
vatom[k][4] += THIRD * v[4];
|
||||
vatom[k][5] += THIRD * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -289,60 +286,60 @@ void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond,
|
||||
double a1[3];
|
||||
|
||||
// a1 = r10 = (2*r12 - r32)/3
|
||||
a1[0] = THIRD*(2*delx1-delx2);
|
||||
a1[1] = THIRD*(2*dely1-dely2);
|
||||
a1[2] = THIRD*(2*delz1-delz2);
|
||||
a1[0] = THIRD * (2 * delx1 - delx2);
|
||||
a1[1] = THIRD * (2 * dely1 - dely2);
|
||||
a1[2] = THIRD * (2 * delz1 - delz2);
|
||||
|
||||
cvatom[i][0] += a1[0]*f1[0];
|
||||
cvatom[i][1] += a1[1]*f1[1];
|
||||
cvatom[i][2] += a1[2]*f1[2];
|
||||
cvatom[i][3] += a1[0]*f1[1];
|
||||
cvatom[i][4] += a1[0]*f1[2];
|
||||
cvatom[i][5] += a1[1]*f1[2];
|
||||
cvatom[i][6] += a1[1]*f1[0];
|
||||
cvatom[i][7] += a1[2]*f1[0];
|
||||
cvatom[i][8] += a1[2]*f1[1];
|
||||
cvatom[i][0] += a1[0] * f1[0];
|
||||
cvatom[i][1] += a1[1] * f1[1];
|
||||
cvatom[i][2] += a1[2] * f1[2];
|
||||
cvatom[i][3] += a1[0] * f1[1];
|
||||
cvatom[i][4] += a1[0] * f1[2];
|
||||
cvatom[i][5] += a1[1] * f1[2];
|
||||
cvatom[i][6] += a1[1] * f1[0];
|
||||
cvatom[i][7] += a1[2] * f1[0];
|
||||
cvatom[i][8] += a1[2] * f1[1];
|
||||
}
|
||||
if (newton_bond || j < nlocal) {
|
||||
double a2[3];
|
||||
double f2[3];
|
||||
|
||||
// a2 = r20 = ( -r12 - r32)/3
|
||||
a2[0] = THIRD*(-delx1-delx2);
|
||||
a2[1] = THIRD*(-dely1-dely2);
|
||||
a2[2] = THIRD*(-delz1-delz2);
|
||||
a2[0] = THIRD * (-delx1 - delx2);
|
||||
a2[1] = THIRD * (-dely1 - dely2);
|
||||
a2[2] = THIRD * (-delz1 - delz2);
|
||||
|
||||
f2[0] = - f1[0] - f3[0];
|
||||
f2[1] = - f1[1] - f3[1];
|
||||
f2[2] = - f1[2] - f3[2];
|
||||
f2[0] = -f1[0] - f3[0];
|
||||
f2[1] = -f1[1] - f3[1];
|
||||
f2[2] = -f1[2] - f3[2];
|
||||
|
||||
cvatom[j][0] += a2[0]*f2[0];
|
||||
cvatom[j][1] += a2[1]*f2[1];
|
||||
cvatom[j][2] += a2[2]*f2[2];
|
||||
cvatom[j][3] += a2[0]*f2[1];
|
||||
cvatom[j][4] += a2[0]*f2[2];
|
||||
cvatom[j][5] += a2[1]*f2[2];
|
||||
cvatom[j][6] += a2[1]*f2[0];
|
||||
cvatom[j][7] += a2[2]*f2[0];
|
||||
cvatom[j][8] += a2[2]*f2[1];
|
||||
cvatom[j][0] += a2[0] * f2[0];
|
||||
cvatom[j][1] += a2[1] * f2[1];
|
||||
cvatom[j][2] += a2[2] * f2[2];
|
||||
cvatom[j][3] += a2[0] * f2[1];
|
||||
cvatom[j][4] += a2[0] * f2[2];
|
||||
cvatom[j][5] += a2[1] * f2[2];
|
||||
cvatom[j][6] += a2[1] * f2[0];
|
||||
cvatom[j][7] += a2[2] * f2[0];
|
||||
cvatom[j][8] += a2[2] * f2[1];
|
||||
}
|
||||
if (newton_bond || k < nlocal) {
|
||||
double a3[3];
|
||||
|
||||
// a3 = r30 = ( -r12 + 2*r32)/3
|
||||
a3[0] = THIRD*(-delx1+2*delx2);
|
||||
a3[1] = THIRD*(-dely1+2*dely2);
|
||||
a3[2] = THIRD*(-delz1+2*delz2);
|
||||
a3[0] = THIRD * (-delx1 + 2 * delx2);
|
||||
a3[1] = THIRD * (-dely1 + 2 * dely2);
|
||||
a3[2] = THIRD * (-delz1 + 2 * delz2);
|
||||
|
||||
cvatom[k][0] += a3[0]*f3[0];
|
||||
cvatom[k][1] += a3[1]*f3[1];
|
||||
cvatom[k][2] += a3[2]*f3[2];
|
||||
cvatom[k][3] += a3[0]*f3[1];
|
||||
cvatom[k][4] += a3[0]*f3[2];
|
||||
cvatom[k][5] += a3[1]*f3[2];
|
||||
cvatom[k][6] += a3[1]*f3[0];
|
||||
cvatom[k][7] += a3[2]*f3[0];
|
||||
cvatom[k][8] += a3[2]*f3[1];
|
||||
cvatom[k][0] += a3[0] * f3[0];
|
||||
cvatom[k][1] += a3[1] * f3[1];
|
||||
cvatom[k][2] += a3[2] * f3[2];
|
||||
cvatom[k][3] += a3[0] * f3[1];
|
||||
cvatom[k][4] += a3[0] * f3[2];
|
||||
cvatom[k][5] += a3[1] * f3[2];
|
||||
cvatom[k][6] += a3[1] * f3[0];
|
||||
cvatom[k][7] += a3[2] * f3[0];
|
||||
cvatom[k][8] += a3[2] * f3[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -351,8 +348,8 @@ void Angle::ev_tally(int i, int j, int k, int nlocal, int newton_bond,
|
||||
|
||||
double Angle::memory_usage()
|
||||
{
|
||||
double bytes = (double)comm->nthreads*maxeatom * sizeof(double);
|
||||
bytes += (double)comm->nthreads*maxvatom*6 * sizeof(double);
|
||||
bytes += (double)comm->nthreads*maxcvatom*9 * sizeof(double);
|
||||
double bytes = (double) comm->nthreads * maxeatom * sizeof(double);
|
||||
bytes += (double) comm->nthreads * maxvatom * 6 * sizeof(double);
|
||||
bytes += (double) comm->nthreads * maxcvatom * 9 * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
154
src/bond.cpp
154
src/bond.cpp
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -26,14 +25,14 @@
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
enum{NONE,LINEAR,SPLINE};
|
||||
enum { NONE, LINEAR, SPLINE };
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
set bond contribution to Vdwl energy to 0.0
|
||||
a particular bond style can override this
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Bond::Bond(LAMMPS *lmp) : Pointers(lmp)
|
||||
Bond::Bond(LAMMPS *_lmp) : Pointers(_lmp)
|
||||
{
|
||||
energy = 0.0;
|
||||
virial[0] = virial[1] = virial[2] = virial[3] = virial[4] = virial[5] = 0.0;
|
||||
@ -70,10 +69,9 @@ Bond::~Bond()
|
||||
|
||||
void Bond::init()
|
||||
{
|
||||
if (!allocated && atom->nbondtypes)
|
||||
error->all(FLERR,"Bond coeffs are not set");
|
||||
if (!allocated && atom->nbondtypes) error->all(FLERR, "Bond coeffs are not set");
|
||||
for (int i = 1; i <= atom->nbondtypes; i++)
|
||||
if (setflag[i] == 0) error->all(FLERR,"All bond coeffs are not set");
|
||||
if (setflag[i] == 0) error->all(FLERR, "All bond coeffs are not set");
|
||||
init_style();
|
||||
}
|
||||
|
||||
@ -93,7 +91,7 @@ void Bond::init()
|
||||
|
||||
void Bond::ev_setup(int eflag, int vflag, int alloc)
|
||||
{
|
||||
int i,n;
|
||||
int i, n;
|
||||
|
||||
evflag = 1;
|
||||
|
||||
@ -111,21 +109,22 @@ void Bond::ev_setup(int eflag, int vflag, int alloc)
|
||||
maxeatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(eatom);
|
||||
memory->create(eatom,comm->nthreads*maxeatom,"bond:eatom");
|
||||
memory->create(eatom, comm->nthreads * maxeatom, "bond:eatom");
|
||||
}
|
||||
}
|
||||
if (vflag_atom && atom->nmax > maxvatom) {
|
||||
maxvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(vatom);
|
||||
memory->create(vatom,comm->nthreads*maxvatom,6,"bond:vatom");
|
||||
memory->create(vatom, comm->nthreads * maxvatom, 6, "bond:vatom");
|
||||
}
|
||||
}
|
||||
|
||||
// zero accumulators
|
||||
|
||||
if (eflag_global) energy = 0.0;
|
||||
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (vflag_global)
|
||||
for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (eflag_atom && alloc) {
|
||||
n = atom->nlocal;
|
||||
if (force->newton_bond) n += atom->nghost;
|
||||
@ -149,35 +148,35 @@ void Bond::ev_setup(int eflag, int vflag, int alloc)
|
||||
tally energy and virial into global and per-atom accumulators
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Bond::ev_tally(int i, int j, int nlocal, int newton_bond,
|
||||
double ebond, double fbond,
|
||||
void Bond::ev_tally(int i, int j, int nlocal, int newton_bond, double ebond, double fbond,
|
||||
double delx, double dely, double delz)
|
||||
{
|
||||
double ebondhalf,v[6];
|
||||
double ebondhalf, v[6];
|
||||
|
||||
if (eflag_either) {
|
||||
if (eflag_global) {
|
||||
if (newton_bond) energy += ebond;
|
||||
if (newton_bond)
|
||||
energy += ebond;
|
||||
else {
|
||||
ebondhalf = 0.5*ebond;
|
||||
ebondhalf = 0.5 * ebond;
|
||||
if (i < nlocal) energy += ebondhalf;
|
||||
if (j < nlocal) energy += ebondhalf;
|
||||
}
|
||||
}
|
||||
if (eflag_atom) {
|
||||
ebondhalf = 0.5*ebond;
|
||||
ebondhalf = 0.5 * ebond;
|
||||
if (newton_bond || i < nlocal) eatom[i] += ebondhalf;
|
||||
if (newton_bond || j < nlocal) eatom[j] += ebondhalf;
|
||||
}
|
||||
}
|
||||
|
||||
if (vflag_either) {
|
||||
v[0] = delx*delx*fbond;
|
||||
v[1] = dely*dely*fbond;
|
||||
v[2] = delz*delz*fbond;
|
||||
v[3] = delx*dely*fbond;
|
||||
v[4] = delx*delz*fbond;
|
||||
v[5] = dely*delz*fbond;
|
||||
v[0] = delx * delx * fbond;
|
||||
v[1] = dely * dely * fbond;
|
||||
v[2] = delz * delz * fbond;
|
||||
v[3] = delx * dely * fbond;
|
||||
v[4] = delx * delz * fbond;
|
||||
v[5] = dely * delz * fbond;
|
||||
|
||||
if (vflag_global) {
|
||||
if (newton_bond) {
|
||||
@ -189,40 +188,40 @@ void Bond::ev_tally(int i, int j, int nlocal, int newton_bond,
|
||||
virial[5] += v[5];
|
||||
} else {
|
||||
if (i < nlocal) {
|
||||
virial[0] += 0.5*v[0];
|
||||
virial[1] += 0.5*v[1];
|
||||
virial[2] += 0.5*v[2];
|
||||
virial[3] += 0.5*v[3];
|
||||
virial[4] += 0.5*v[4];
|
||||
virial[5] += 0.5*v[5];
|
||||
virial[0] += 0.5 * v[0];
|
||||
virial[1] += 0.5 * v[1];
|
||||
virial[2] += 0.5 * v[2];
|
||||
virial[3] += 0.5 * v[3];
|
||||
virial[4] += 0.5 * v[4];
|
||||
virial[5] += 0.5 * v[5];
|
||||
}
|
||||
if (j < nlocal) {
|
||||
virial[0] += 0.5*v[0];
|
||||
virial[1] += 0.5*v[1];
|
||||
virial[2] += 0.5*v[2];
|
||||
virial[3] += 0.5*v[3];
|
||||
virial[4] += 0.5*v[4];
|
||||
virial[5] += 0.5*v[5];
|
||||
virial[0] += 0.5 * v[0];
|
||||
virial[1] += 0.5 * v[1];
|
||||
virial[2] += 0.5 * v[2];
|
||||
virial[3] += 0.5 * v[3];
|
||||
virial[4] += 0.5 * v[4];
|
||||
virial[5] += 0.5 * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vflag_atom) {
|
||||
if (newton_bond || i < nlocal) {
|
||||
vatom[i][0] += 0.5*v[0];
|
||||
vatom[i][1] += 0.5*v[1];
|
||||
vatom[i][2] += 0.5*v[2];
|
||||
vatom[i][3] += 0.5*v[3];
|
||||
vatom[i][4] += 0.5*v[4];
|
||||
vatom[i][5] += 0.5*v[5];
|
||||
vatom[i][0] += 0.5 * v[0];
|
||||
vatom[i][1] += 0.5 * v[1];
|
||||
vatom[i][2] += 0.5 * v[2];
|
||||
vatom[i][3] += 0.5 * v[3];
|
||||
vatom[i][4] += 0.5 * v[4];
|
||||
vatom[i][5] += 0.5 * v[5];
|
||||
}
|
||||
if (newton_bond || j < nlocal) {
|
||||
vatom[j][0] += 0.5*v[0];
|
||||
vatom[j][1] += 0.5*v[1];
|
||||
vatom[j][2] += 0.5*v[2];
|
||||
vatom[j][3] += 0.5*v[3];
|
||||
vatom[j][4] += 0.5*v[4];
|
||||
vatom[j][5] += 0.5*v[5];
|
||||
vatom[j][0] += 0.5 * v[0];
|
||||
vatom[j][1] += 0.5 * v[1];
|
||||
vatom[j][2] += 0.5 * v[2];
|
||||
vatom[j][3] += 0.5 * v[3];
|
||||
vatom[j][4] += 0.5 * v[4];
|
||||
vatom[j][5] += 0.5 * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -234,26 +233,25 @@ void Bond::ev_tally(int i, int j, int nlocal, int newton_bond,
|
||||
|
||||
void Bond::write_file(int narg, char **arg)
|
||||
{
|
||||
if (narg != 6 && narg !=8) error->all(FLERR,"Illegal bond_write command");
|
||||
if (narg != 6 && narg != 8) error->all(FLERR, "Illegal bond_write command");
|
||||
|
||||
// parse optional arguments
|
||||
|
||||
int itype = 0;
|
||||
int jtype = 0;
|
||||
if (narg == 8) {
|
||||
itype = utils::inumeric(FLERR,arg[6],false,lmp);
|
||||
jtype = utils::inumeric(FLERR,arg[7],false,lmp);
|
||||
itype = utils::inumeric(FLERR, arg[6], false, lmp);
|
||||
jtype = utils::inumeric(FLERR, arg[7], false, lmp);
|
||||
if (itype < 1 || itype > atom->ntypes || jtype < 1 || jtype > atom->ntypes)
|
||||
error->all(FLERR,"Invalid atom types in bond_write command");
|
||||
error->all(FLERR, "Invalid atom types in bond_write command");
|
||||
}
|
||||
|
||||
int btype = utils::inumeric(FLERR,arg[0],false,lmp);
|
||||
int n = utils::inumeric(FLERR,arg[1],false,lmp);
|
||||
double inner = utils::numeric(FLERR,arg[2],false,lmp);
|
||||
double outer = utils::numeric(FLERR,arg[3],false,lmp);
|
||||
int btype = utils::inumeric(FLERR, arg[0], false, lmp);
|
||||
int n = utils::inumeric(FLERR, arg[1], false, lmp);
|
||||
double inner = utils::numeric(FLERR, arg[2], false, lmp);
|
||||
double outer = utils::numeric(FLERR, arg[3], false, lmp);
|
||||
if (inner <= 0.0 || inner >= outer)
|
||||
error->all(FLERR,"Invalid rlo/rhi values in bond_write command");
|
||||
|
||||
error->all(FLERR, "Invalid rlo/rhi values in bond_write command");
|
||||
|
||||
double r0 = equilibrium_distance(btype);
|
||||
|
||||
@ -271,23 +269,24 @@ void Bond::write_file(int narg, char **arg)
|
||||
// - if the file already exists, print a message about appending
|
||||
// while printing the date and check that units are consistent.
|
||||
if (platform::file_is_readable(table_file)) {
|
||||
std::string units = utils::get_potential_units(table_file,"table");
|
||||
std::string units = utils::get_potential_units(table_file, "table");
|
||||
if (!units.empty() && (units != update->unit_style)) {
|
||||
error->one(FLERR,"Trying to append to a table file with UNITS: {} while units are {}",
|
||||
error->one(FLERR, "Trying to append to a table file with UNITS: {} while units are {}",
|
||||
units, update->unit_style);
|
||||
}
|
||||
std::string date = utils::get_potential_date(table_file,"table");
|
||||
utils::logmesg(lmp,"Appending to table file {} with DATE: {}\n", table_file, date);
|
||||
fp = fopen(table_file.c_str(),"a");
|
||||
std::string date = utils::get_potential_date(table_file, "table");
|
||||
utils::logmesg(lmp, "Appending to table file {} with DATE: {}\n", table_file, date);
|
||||
fp = fopen(table_file.c_str(), "a");
|
||||
} else {
|
||||
utils::logmesg(lmp,"Creating table file {} with DATE: {}\n",
|
||||
table_file, utils::current_date());
|
||||
fp = fopen(table_file.c_str(),"w");
|
||||
if (fp) fmt::print(fp,"# DATE: {} UNITS: {} Created by bond_write\n",
|
||||
utils::current_date(), update->unit_style);
|
||||
utils::logmesg(lmp, "Creating table file {} with DATE: {}\n", table_file,
|
||||
utils::current_date());
|
||||
fp = fopen(table_file.c_str(), "w");
|
||||
if (fp)
|
||||
fmt::print(fp, "# DATE: {} UNITS: {} Created by bond_write\n", utils::current_date(),
|
||||
update->unit_style);
|
||||
}
|
||||
if (fp == nullptr)
|
||||
error->one(FLERR,"Cannot open bond_write file {}: {}", arg[4], utils::getsyserror());
|
||||
error->one(FLERR, "Cannot open bond_write file {}: {}", arg[4], utils::getsyserror());
|
||||
}
|
||||
|
||||
// initialize potentials before evaluating bond potential
|
||||
@ -299,20 +298,20 @@ void Bond::write_file(int narg, char **arg)
|
||||
neighbor->init();
|
||||
|
||||
if (comm->me == 0) {
|
||||
double r,e,f;
|
||||
double r, e, f;
|
||||
|
||||
// evaluate energy and force at each of N distances
|
||||
// note that Bond::single() takes r**2 and returns f/r.
|
||||
|
||||
fprintf(fp,"# Bond potential %s for bond type %d: i,r,energy,force\n",
|
||||
force->bond_style,btype);
|
||||
fprintf(fp,"\n%s\nN %d EQ %.15g\n\n",arg[5],n,r0);
|
||||
fprintf(fp, "# Bond potential %s for bond type %d: i,r,energy,force\n", force->bond_style,
|
||||
btype);
|
||||
fprintf(fp, "\n%s\nN %d EQ %.15g\n\n", arg[5], n, r0);
|
||||
|
||||
const double dr = (outer-inner) / static_cast<double>(n-1);
|
||||
const double dr = (outer - inner) / static_cast<double>(n - 1);
|
||||
for (int i = 0; i < n; i++) {
|
||||
r = inner + dr * static_cast<double>(i);
|
||||
e = single(btype,r*r,itype,jtype,f);
|
||||
fprintf(fp,"%d %.15g %.15g %.15g\n",i+1,r,e,f*r);
|
||||
e = single(btype, r * r, itype, jtype, f);
|
||||
fprintf(fp, "%d %.15g %.15g %.15g\n", i + 1, r, e, f * r);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
@ -322,8 +321,8 @@ void Bond::write_file(int narg, char **arg)
|
||||
|
||||
double Bond::memory_usage()
|
||||
{
|
||||
double bytes = (double)comm->nthreads*maxeatom * sizeof(double);
|
||||
bytes += (double)comm->nthreads*maxvatom*6 * sizeof(double);
|
||||
double bytes = (double) comm->nthreads * maxeatom * sizeof(double);
|
||||
bytes += (double) comm->nthreads * maxvatom * 6 * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@ -332,8 +331,7 @@ double Bond::memory_usage()
|
||||
-------------------------------------------------------------------------- */
|
||||
void Bond::reinit()
|
||||
{
|
||||
if (!reinitflag)
|
||||
error->all(FLERR,"Fix adapt interface to this bond style not supported");
|
||||
if (!reinitflag) error->all(FLERR, "Fix adapt interface to this bond style not supported");
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
288
src/dihedral.cpp
288
src/dihedral.cpp
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -14,11 +13,11 @@
|
||||
|
||||
#include "dihedral.h"
|
||||
#include "atom.h"
|
||||
#include "comm.h"
|
||||
#include "force.h"
|
||||
#include "atom_masks.h"
|
||||
#include "memory.h"
|
||||
#include "comm.h"
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "memory.h"
|
||||
#include "suffix.h"
|
||||
#include "update.h"
|
||||
|
||||
@ -29,7 +28,7 @@ using namespace LAMMPS_NS;
|
||||
DihedralCharmm will override this
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Dihedral::Dihedral(LAMMPS *lmp) : Pointers(lmp)
|
||||
Dihedral::Dihedral(LAMMPS *_lmp) : Pointers(_lmp)
|
||||
{
|
||||
energy = 0.0;
|
||||
writedata = 0;
|
||||
@ -68,10 +67,9 @@ Dihedral::~Dihedral()
|
||||
|
||||
void Dihedral::init()
|
||||
{
|
||||
if (!allocated && atom->ndihedraltypes)
|
||||
error->all(FLERR,"Dihedral coeffs are not set");
|
||||
if (!allocated && atom->ndihedraltypes) error->all(FLERR, "Dihedral coeffs are not set");
|
||||
for (int i = 1; i <= atom->ndihedraltypes; i++)
|
||||
if (setflag[i] == 0) error->all(FLERR,"All dihedral coeffs are not set");
|
||||
if (setflag[i] == 0) error->all(FLERR, "All dihedral coeffs are not set");
|
||||
init_style();
|
||||
}
|
||||
|
||||
@ -94,7 +92,7 @@ void Dihedral::init()
|
||||
|
||||
void Dihedral::ev_setup(int eflag, int vflag, int alloc)
|
||||
{
|
||||
int i,n;
|
||||
int i, n;
|
||||
|
||||
evflag = 1;
|
||||
|
||||
@ -104,11 +102,9 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc)
|
||||
|
||||
vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR);
|
||||
vflag_atom = vflag & VIRIAL_ATOM;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL)
|
||||
vflag_atom = 1;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1;
|
||||
cvflag_atom = 0;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL)
|
||||
cvflag_atom = 1;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1;
|
||||
vflag_either = vflag_global || vflag_atom || cvflag_atom;
|
||||
|
||||
// reallocate per-atom arrays if necessary
|
||||
@ -117,28 +113,29 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc)
|
||||
maxeatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(eatom);
|
||||
memory->create(eatom,comm->nthreads*maxeatom,"dihedral:eatom");
|
||||
memory->create(eatom, comm->nthreads * maxeatom, "dihedral:eatom");
|
||||
}
|
||||
}
|
||||
if (vflag_atom && atom->nmax > maxvatom) {
|
||||
maxvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(vatom);
|
||||
memory->create(vatom,comm->nthreads*maxvatom,6,"dihedral:vatom");
|
||||
memory->create(vatom, comm->nthreads * maxvatom, 6, "dihedral:vatom");
|
||||
}
|
||||
}
|
||||
if (cvflag_atom && atom->nmax > maxcvatom) {
|
||||
maxcvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(cvatom);
|
||||
memory->create(cvatom,comm->nthreads*maxcvatom,9,"dihedral:cvatom");
|
||||
memory->create(cvatom, comm->nthreads * maxcvatom, 9, "dihedral:cvatom");
|
||||
}
|
||||
}
|
||||
|
||||
// zero accumulators
|
||||
|
||||
if (eflag_global) energy = 0.0;
|
||||
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (vflag_global)
|
||||
for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (eflag_atom && alloc) {
|
||||
n = atom->nlocal;
|
||||
if (force->newton_bond) n += atom->nghost;
|
||||
@ -181,20 +178,19 @@ void Dihedral::ev_setup(int eflag, int vflag, int alloc)
|
||||
= vb1*f1 + vb2*f3 + (vb3+vb2)*f4
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
|
||||
int nlocal, int newton_bond,
|
||||
double edihedral, double *f1, double *f3, double *f4,
|
||||
double vb1x, double vb1y, double vb1z,
|
||||
double vb2x, double vb2y, double vb2z,
|
||||
void Dihedral::ev_tally(int i1, int i2, int i3, int i4, int nlocal, int newton_bond,
|
||||
double edihedral, double *f1, double *f3, double *f4, double vb1x,
|
||||
double vb1y, double vb1z, double vb2x, double vb2y, double vb2z,
|
||||
double vb3x, double vb3y, double vb3z)
|
||||
{
|
||||
double edihedralquarter,v[6];
|
||||
double edihedralquarter, v[6];
|
||||
|
||||
if (eflag_either) {
|
||||
if (eflag_global) {
|
||||
if (newton_bond) energy += edihedral;
|
||||
if (newton_bond)
|
||||
energy += edihedral;
|
||||
else {
|
||||
edihedralquarter = 0.25*edihedral;
|
||||
edihedralquarter = 0.25 * edihedral;
|
||||
if (i1 < nlocal) energy += edihedralquarter;
|
||||
if (i2 < nlocal) energy += edihedralquarter;
|
||||
if (i3 < nlocal) energy += edihedralquarter;
|
||||
@ -202,7 +198,7 @@ void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
|
||||
}
|
||||
}
|
||||
if (eflag_atom) {
|
||||
edihedralquarter = 0.25*edihedral;
|
||||
edihedralquarter = 0.25 * edihedral;
|
||||
if (newton_bond || i1 < nlocal) eatom[i1] += edihedralquarter;
|
||||
if (newton_bond || i2 < nlocal) eatom[i2] += edihedralquarter;
|
||||
if (newton_bond || i3 < nlocal) eatom[i3] += edihedralquarter;
|
||||
@ -211,12 +207,12 @@ void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
|
||||
}
|
||||
|
||||
if (vflag_either) {
|
||||
v[0] = vb1x*f1[0] + vb2x*f3[0] + (vb3x+vb2x)*f4[0];
|
||||
v[1] = vb1y*f1[1] + vb2y*f3[1] + (vb3y+vb2y)*f4[1];
|
||||
v[2] = vb1z*f1[2] + vb2z*f3[2] + (vb3z+vb2z)*f4[2];
|
||||
v[3] = vb1x*f1[1] + vb2x*f3[1] + (vb3x+vb2x)*f4[1];
|
||||
v[4] = vb1x*f1[2] + vb2x*f3[2] + (vb3x+vb2x)*f4[2];
|
||||
v[5] = vb1y*f1[2] + vb2y*f3[2] + (vb3y+vb2y)*f4[2];
|
||||
v[0] = vb1x * f1[0] + vb2x * f3[0] + (vb3x + vb2x) * f4[0];
|
||||
v[1] = vb1y * f1[1] + vb2y * f3[1] + (vb3y + vb2y) * f4[1];
|
||||
v[2] = vb1z * f1[2] + vb2z * f3[2] + (vb3z + vb2z) * f4[2];
|
||||
v[3] = vb1x * f1[1] + vb2x * f3[1] + (vb3x + vb2x) * f4[1];
|
||||
v[4] = vb1x * f1[2] + vb2x * f3[2] + (vb3x + vb2x) * f4[2];
|
||||
v[5] = vb1y * f1[2] + vb2y * f3[2] + (vb3y + vb2y) * f4[2];
|
||||
|
||||
if (vflag_global) {
|
||||
if (newton_bond) {
|
||||
@ -228,72 +224,72 @@ void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
|
||||
virial[5] += v[5];
|
||||
} else {
|
||||
if (i1 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
if (i2 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
if (i3 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
if (i4 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vflag_atom) {
|
||||
if (newton_bond || i1 < nlocal) {
|
||||
vatom[i1][0] += 0.25*v[0];
|
||||
vatom[i1][1] += 0.25*v[1];
|
||||
vatom[i1][2] += 0.25*v[2];
|
||||
vatom[i1][3] += 0.25*v[3];
|
||||
vatom[i1][4] += 0.25*v[4];
|
||||
vatom[i1][5] += 0.25*v[5];
|
||||
vatom[i1][0] += 0.25 * v[0];
|
||||
vatom[i1][1] += 0.25 * v[1];
|
||||
vatom[i1][2] += 0.25 * v[2];
|
||||
vatom[i1][3] += 0.25 * v[3];
|
||||
vatom[i1][4] += 0.25 * v[4];
|
||||
vatom[i1][5] += 0.25 * v[5];
|
||||
}
|
||||
if (newton_bond || i2 < nlocal) {
|
||||
vatom[i2][0] += 0.25*v[0];
|
||||
vatom[i2][1] += 0.25*v[1];
|
||||
vatom[i2][2] += 0.25*v[2];
|
||||
vatom[i2][3] += 0.25*v[3];
|
||||
vatom[i2][4] += 0.25*v[4];
|
||||
vatom[i2][5] += 0.25*v[5];
|
||||
vatom[i2][0] += 0.25 * v[0];
|
||||
vatom[i2][1] += 0.25 * v[1];
|
||||
vatom[i2][2] += 0.25 * v[2];
|
||||
vatom[i2][3] += 0.25 * v[3];
|
||||
vatom[i2][4] += 0.25 * v[4];
|
||||
vatom[i2][5] += 0.25 * v[5];
|
||||
}
|
||||
if (newton_bond || i3 < nlocal) {
|
||||
vatom[i3][0] += 0.25*v[0];
|
||||
vatom[i3][1] += 0.25*v[1];
|
||||
vatom[i3][2] += 0.25*v[2];
|
||||
vatom[i3][3] += 0.25*v[3];
|
||||
vatom[i3][4] += 0.25*v[4];
|
||||
vatom[i3][5] += 0.25*v[5];
|
||||
vatom[i3][0] += 0.25 * v[0];
|
||||
vatom[i3][1] += 0.25 * v[1];
|
||||
vatom[i3][2] += 0.25 * v[2];
|
||||
vatom[i3][3] += 0.25 * v[3];
|
||||
vatom[i3][4] += 0.25 * v[4];
|
||||
vatom[i3][5] += 0.25 * v[5];
|
||||
}
|
||||
if (newton_bond || i4 < nlocal) {
|
||||
vatom[i4][0] += 0.25*v[0];
|
||||
vatom[i4][1] += 0.25*v[1];
|
||||
vatom[i4][2] += 0.25*v[2];
|
||||
vatom[i4][3] += 0.25*v[3];
|
||||
vatom[i4][4] += 0.25*v[4];
|
||||
vatom[i4][5] += 0.25*v[5];
|
||||
vatom[i4][0] += 0.25 * v[0];
|
||||
vatom[i4][1] += 0.25 * v[1];
|
||||
vatom[i4][2] += 0.25 * v[2];
|
||||
vatom[i4][3] += 0.25 * v[3];
|
||||
vatom[i4][4] += 0.25 * v[4];
|
||||
vatom[i4][5] += 0.25 * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,99 +308,97 @@ void Dihedral::ev_tally(int i1, int i2, int i3, int i4,
|
||||
double a1[3];
|
||||
|
||||
// a1 = r10 = (3*r12 - 2*r32 - r43)/4
|
||||
a1[0] = 0.25*(3*vb1x - 2*vb2x - vb3x);
|
||||
a1[1] = 0.25*(3*vb1y - 2*vb2y - vb3y);
|
||||
a1[2] = 0.25*(3*vb1z - 2*vb2z - vb3z);
|
||||
a1[0] = 0.25 * (3 * vb1x - 2 * vb2x - vb3x);
|
||||
a1[1] = 0.25 * (3 * vb1y - 2 * vb2y - vb3y);
|
||||
a1[2] = 0.25 * (3 * vb1z - 2 * vb2z - vb3z);
|
||||
|
||||
cvatom[i1][0] += a1[0]*f1[0];
|
||||
cvatom[i1][1] += a1[1]*f1[1];
|
||||
cvatom[i1][2] += a1[2]*f1[2];
|
||||
cvatom[i1][3] += a1[0]*f1[1];
|
||||
cvatom[i1][4] += a1[0]*f1[2];
|
||||
cvatom[i1][5] += a1[1]*f1[2];
|
||||
cvatom[i1][6] += a1[1]*f1[0];
|
||||
cvatom[i1][7] += a1[2]*f1[0];
|
||||
cvatom[i1][8] += a1[2]*f1[1];
|
||||
cvatom[i1][0] += a1[0] * f1[0];
|
||||
cvatom[i1][1] += a1[1] * f1[1];
|
||||
cvatom[i1][2] += a1[2] * f1[2];
|
||||
cvatom[i1][3] += a1[0] * f1[1];
|
||||
cvatom[i1][4] += a1[0] * f1[2];
|
||||
cvatom[i1][5] += a1[1] * f1[2];
|
||||
cvatom[i1][6] += a1[1] * f1[0];
|
||||
cvatom[i1][7] += a1[2] * f1[0];
|
||||
cvatom[i1][8] += a1[2] * f1[1];
|
||||
}
|
||||
if (newton_bond || i2 < nlocal) {
|
||||
double a2[3];
|
||||
double f2[3];
|
||||
|
||||
// a2 = r20 = ( -r12 - 2*r32 - r43)/4
|
||||
a2[0] = 0.25*(-vb1x - 2*vb2x - vb3x);
|
||||
a2[1] = 0.25*(-vb1y - 2*vb2y - vb3y);
|
||||
a2[2] = 0.25*(-vb1z - 2*vb2z - vb3z);
|
||||
a2[0] = 0.25 * (-vb1x - 2 * vb2x - vb3x);
|
||||
a2[1] = 0.25 * (-vb1y - 2 * vb2y - vb3y);
|
||||
a2[2] = 0.25 * (-vb1z - 2 * vb2z - vb3z);
|
||||
|
||||
f2[0] = - f1[0] - f3[0] - f4[0];
|
||||
f2[1] = - f1[1] - f3[1] - f4[1];
|
||||
f2[2] = - f1[2] - f3[2] - f4[2];
|
||||
f2[0] = -f1[0] - f3[0] - f4[0];
|
||||
f2[1] = -f1[1] - f3[1] - f4[1];
|
||||
f2[2] = -f1[2] - f3[2] - f4[2];
|
||||
|
||||
cvatom[i2][0] += a2[0]*f2[0];
|
||||
cvatom[i2][1] += a2[1]*f2[1];
|
||||
cvatom[i2][2] += a2[2]*f2[2];
|
||||
cvatom[i2][3] += a2[0]*f2[1];
|
||||
cvatom[i2][4] += a2[0]*f2[2];
|
||||
cvatom[i2][5] += a2[1]*f2[2];
|
||||
cvatom[i2][6] += a2[1]*f2[0];
|
||||
cvatom[i2][7] += a2[2]*f2[0];
|
||||
cvatom[i2][8] += a2[2]*f2[1];
|
||||
cvatom[i2][0] += a2[0] * f2[0];
|
||||
cvatom[i2][1] += a2[1] * f2[1];
|
||||
cvatom[i2][2] += a2[2] * f2[2];
|
||||
cvatom[i2][3] += a2[0] * f2[1];
|
||||
cvatom[i2][4] += a2[0] * f2[2];
|
||||
cvatom[i2][5] += a2[1] * f2[2];
|
||||
cvatom[i2][6] += a2[1] * f2[0];
|
||||
cvatom[i2][7] += a2[2] * f2[0];
|
||||
cvatom[i2][8] += a2[2] * f2[1];
|
||||
}
|
||||
if (newton_bond || i3 < nlocal) {
|
||||
double a3[3];
|
||||
|
||||
// a3 = r30 = ( -r12 + 2*r32 - r43)/4
|
||||
a3[0] = 0.25*(-vb1x + 2*vb2x - vb3x);
|
||||
a3[1] = 0.25*(-vb1y + 2*vb2y - vb3y);
|
||||
a3[2] = 0.25*(-vb1z + 2*vb2z - vb3z);
|
||||
a3[0] = 0.25 * (-vb1x + 2 * vb2x - vb3x);
|
||||
a3[1] = 0.25 * (-vb1y + 2 * vb2y - vb3y);
|
||||
a3[2] = 0.25 * (-vb1z + 2 * vb2z - vb3z);
|
||||
|
||||
cvatom[i3][0] += a3[0]*f3[0];
|
||||
cvatom[i3][1] += a3[1]*f3[1];
|
||||
cvatom[i3][2] += a3[2]*f3[2];
|
||||
cvatom[i3][3] += a3[0]*f3[1];
|
||||
cvatom[i3][4] += a3[0]*f3[2];
|
||||
cvatom[i3][5] += a3[1]*f3[2];
|
||||
cvatom[i3][6] += a3[1]*f3[0];
|
||||
cvatom[i3][7] += a3[2]*f3[0];
|
||||
cvatom[i3][8] += a3[2]*f3[1];
|
||||
cvatom[i3][0] += a3[0] * f3[0];
|
||||
cvatom[i3][1] += a3[1] * f3[1];
|
||||
cvatom[i3][2] += a3[2] * f3[2];
|
||||
cvatom[i3][3] += a3[0] * f3[1];
|
||||
cvatom[i3][4] += a3[0] * f3[2];
|
||||
cvatom[i3][5] += a3[1] * f3[2];
|
||||
cvatom[i3][6] += a3[1] * f3[0];
|
||||
cvatom[i3][7] += a3[2] * f3[0];
|
||||
cvatom[i3][8] += a3[2] * f3[1];
|
||||
}
|
||||
if (newton_bond || i4 < nlocal) {
|
||||
double a4[3];
|
||||
|
||||
// a4 = r40 = ( -r12 + 2*r32 + 3*r43)/4
|
||||
a4[0] = 0.25*(-vb1x + 2*vb2x + 3*vb3x);
|
||||
a4[1] = 0.25*(-vb1y + 2*vb2y + 3*vb3y);
|
||||
a4[2] = 0.25*(-vb1z + 2*vb2z + 3*vb3z);
|
||||
a4[0] = 0.25 * (-vb1x + 2 * vb2x + 3 * vb3x);
|
||||
a4[1] = 0.25 * (-vb1y + 2 * vb2y + 3 * vb3y);
|
||||
a4[2] = 0.25 * (-vb1z + 2 * vb2z + 3 * vb3z);
|
||||
|
||||
cvatom[i4][0] += a4[0]*f4[0];
|
||||
cvatom[i4][1] += a4[1]*f4[1];
|
||||
cvatom[i4][2] += a4[2]*f4[2];
|
||||
cvatom[i4][3] += a4[0]*f4[1];
|
||||
cvatom[i4][4] += a4[0]*f4[2];
|
||||
cvatom[i4][5] += a4[1]*f4[2];
|
||||
cvatom[i4][6] += a4[1]*f4[0];
|
||||
cvatom[i4][7] += a4[2]*f4[0];
|
||||
cvatom[i4][8] += a4[2]*f4[1];
|
||||
cvatom[i4][0] += a4[0] * f4[0];
|
||||
cvatom[i4][1] += a4[1] * f4[1];
|
||||
cvatom[i4][2] += a4[2] * f4[2];
|
||||
cvatom[i4][3] += a4[0] * f4[1];
|
||||
cvatom[i4][4] += a4[0] * f4[2];
|
||||
cvatom[i4][5] += a4[1] * f4[2];
|
||||
cvatom[i4][6] += a4[1] * f4[0];
|
||||
cvatom[i4][7] += a4[2] * f4[0];
|
||||
cvatom[i4][8] += a4[2] * f4[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void Dihedral::problem(const char *filename, int lineno,
|
||||
int i1, int i2, int i3, int i4)
|
||||
void Dihedral::problem(const char *filename, int lineno, int i1, int i2, int i3, int i4)
|
||||
{
|
||||
const auto x = atom->x;
|
||||
auto warn = fmt::format("Dihedral problem: {} {} {} {} {} {}\n",
|
||||
comm->me, update->ntimestep, atom->tag[i1],
|
||||
atom->tag[i2], atom->tag[i3], atom->tag[i4]);
|
||||
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n",
|
||||
comm->me,x[i1][0],x[i1][1],x[i1][2]);
|
||||
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n",
|
||||
comm->me,x[i2][0],x[i2][1],x[i2][2]);
|
||||
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n",
|
||||
comm->me,x[i3][0],x[i3][1],x[i3][2]);
|
||||
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}",
|
||||
comm->me,x[i4][0],x[i4][1],x[i4][2]);
|
||||
auto warn = fmt::format("Dihedral problem: {} {} {} {} {} {}\n", comm->me, update->ntimestep,
|
||||
atom->tag[i1], atom->tag[i2], atom->tag[i3], atom->tag[i4]);
|
||||
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i1][0], x[i1][1],
|
||||
x[i1][2]);
|
||||
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i2][0], x[i2][1],
|
||||
x[i2][2]);
|
||||
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i3][0], x[i3][1],
|
||||
x[i3][2]);
|
||||
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}", comm->me, x[i4][0], x[i4][1],
|
||||
x[i4][2]);
|
||||
error->warning(filename, lineno, warn);
|
||||
}
|
||||
|
||||
@ -412,8 +406,8 @@ void Dihedral::problem(const char *filename, int lineno,
|
||||
|
||||
double Dihedral::memory_usage()
|
||||
{
|
||||
double bytes = (double)comm->nthreads*maxeatom * sizeof(double);
|
||||
bytes += (double)comm->nthreads*maxvatom*6 * sizeof(double);
|
||||
bytes += (double)comm->nthreads*maxcvatom*9 * sizeof(double);
|
||||
double bytes = (double) comm->nthreads * maxeatom * sizeof(double);
|
||||
bytes += (double) comm->nthreads * maxvatom * 6 * sizeof(double);
|
||||
bytes += (double) comm->nthreads * maxcvatom * 9 * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
281
src/improper.cpp
281
src/improper.cpp
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -27,7 +26,7 @@ using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Improper::Improper(LAMMPS *lmp) : Pointers(lmp)
|
||||
Improper::Improper(LAMMPS *_lmp) : Pointers(_lmp)
|
||||
{
|
||||
energy = 0.0;
|
||||
writedata = 0;
|
||||
@ -66,10 +65,9 @@ Improper::~Improper()
|
||||
|
||||
void Improper::init()
|
||||
{
|
||||
if (!allocated && atom->nimpropertypes)
|
||||
error->all(FLERR,"Improper coeffs are not set");
|
||||
if (!allocated && atom->nimpropertypes) error->all(FLERR, "Improper coeffs are not set");
|
||||
for (int i = 1; i <= atom->nimpropertypes; i++)
|
||||
if (setflag[i] == 0) error->all(FLERR,"All improper coeffs are not set");
|
||||
if (setflag[i] == 0) error->all(FLERR, "All improper coeffs are not set");
|
||||
|
||||
init_style();
|
||||
}
|
||||
@ -93,7 +91,7 @@ void Improper::init()
|
||||
|
||||
void Improper::ev_setup(int eflag, int vflag, int alloc)
|
||||
{
|
||||
int i,n;
|
||||
int i, n;
|
||||
|
||||
evflag = 1;
|
||||
|
||||
@ -103,11 +101,9 @@ void Improper::ev_setup(int eflag, int vflag, int alloc)
|
||||
|
||||
vflag_global = vflag & (VIRIAL_PAIR | VIRIAL_FDOTR);
|
||||
vflag_atom = vflag & VIRIAL_ATOM;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL)
|
||||
vflag_atom = 1;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag != CENTROID_AVAIL) vflag_atom = 1;
|
||||
cvflag_atom = 0;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL)
|
||||
cvflag_atom = 1;
|
||||
if (vflag & VIRIAL_CENTROID && centroidstressflag == CENTROID_AVAIL) cvflag_atom = 1;
|
||||
vflag_either = vflag_global || vflag_atom || cvflag_atom;
|
||||
|
||||
// reallocate per-atom arrays if necessary
|
||||
@ -116,28 +112,29 @@ void Improper::ev_setup(int eflag, int vflag, int alloc)
|
||||
maxeatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(eatom);
|
||||
memory->create(eatom,comm->nthreads*maxeatom,"improper:eatom");
|
||||
memory->create(eatom, comm->nthreads * maxeatom, "improper:eatom");
|
||||
}
|
||||
}
|
||||
if (vflag_atom && atom->nmax > maxvatom) {
|
||||
maxvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(vatom);
|
||||
memory->create(vatom,comm->nthreads*maxvatom,6,"improper:vatom");
|
||||
memory->create(vatom, comm->nthreads * maxvatom, 6, "improper:vatom");
|
||||
}
|
||||
}
|
||||
if (cvflag_atom && atom->nmax > maxcvatom) {
|
||||
maxcvatom = atom->nmax;
|
||||
if (alloc) {
|
||||
memory->destroy(cvatom);
|
||||
memory->create(cvatom,comm->nthreads*maxcvatom,9,"improper:cvatom");
|
||||
memory->create(cvatom, comm->nthreads * maxcvatom, 9, "improper:cvatom");
|
||||
}
|
||||
}
|
||||
|
||||
// zero accumulators
|
||||
|
||||
if (eflag_global) energy = 0.0;
|
||||
if (vflag_global) for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (vflag_global)
|
||||
for (i = 0; i < 6; i++) virial[i] = 0.0;
|
||||
if (eflag_atom && alloc) {
|
||||
n = atom->nlocal;
|
||||
if (force->newton_bond) n += atom->nghost;
|
||||
@ -180,20 +177,19 @@ void Improper::ev_setup(int eflag, int vflag, int alloc)
|
||||
= vb1*f1 + vb2*f3 + (vb3+vb2)*f4
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Improper::ev_tally(int i1, int i2, int i3, int i4,
|
||||
int nlocal, int newton_bond,
|
||||
double eimproper, double *f1, double *f3, double *f4,
|
||||
double vb1x, double vb1y, double vb1z,
|
||||
double vb2x, double vb2y, double vb2z,
|
||||
void Improper::ev_tally(int i1, int i2, int i3, int i4, int nlocal, int newton_bond,
|
||||
double eimproper, double *f1, double *f3, double *f4, double vb1x,
|
||||
double vb1y, double vb1z, double vb2x, double vb2y, double vb2z,
|
||||
double vb3x, double vb3y, double vb3z)
|
||||
{
|
||||
double eimproperquarter,v[6];
|
||||
double eimproperquarter, v[6];
|
||||
|
||||
if (eflag_either) {
|
||||
if (eflag_global) {
|
||||
if (newton_bond) energy += eimproper;
|
||||
if (newton_bond)
|
||||
energy += eimproper;
|
||||
else {
|
||||
eimproperquarter = 0.25*eimproper;
|
||||
eimproperquarter = 0.25 * eimproper;
|
||||
if (i1 < nlocal) energy += eimproperquarter;
|
||||
if (i2 < nlocal) energy += eimproperquarter;
|
||||
if (i3 < nlocal) energy += eimproperquarter;
|
||||
@ -201,7 +197,7 @@ void Improper::ev_tally(int i1, int i2, int i3, int i4,
|
||||
}
|
||||
}
|
||||
if (eflag_atom) {
|
||||
eimproperquarter = 0.25*eimproper;
|
||||
eimproperquarter = 0.25 * eimproper;
|
||||
if (newton_bond || i1 < nlocal) eatom[i1] += eimproperquarter;
|
||||
if (newton_bond || i2 < nlocal) eatom[i2] += eimproperquarter;
|
||||
if (newton_bond || i3 < nlocal) eatom[i3] += eimproperquarter;
|
||||
@ -210,12 +206,12 @@ void Improper::ev_tally(int i1, int i2, int i3, int i4,
|
||||
}
|
||||
|
||||
if (vflag_either) {
|
||||
v[0] = vb1x*f1[0] + vb2x*f3[0] + (vb3x+vb2x)*f4[0];
|
||||
v[1] = vb1y*f1[1] + vb2y*f3[1] + (vb3y+vb2y)*f4[1];
|
||||
v[2] = vb1z*f1[2] + vb2z*f3[2] + (vb3z+vb2z)*f4[2];
|
||||
v[3] = vb1x*f1[1] + vb2x*f3[1] + (vb3x+vb2x)*f4[1];
|
||||
v[4] = vb1x*f1[2] + vb2x*f3[2] + (vb3x+vb2x)*f4[2];
|
||||
v[5] = vb1y*f1[2] + vb2y*f3[2] + (vb3y+vb2y)*f4[2];
|
||||
v[0] = vb1x * f1[0] + vb2x * f3[0] + (vb3x + vb2x) * f4[0];
|
||||
v[1] = vb1y * f1[1] + vb2y * f3[1] + (vb3y + vb2y) * f4[1];
|
||||
v[2] = vb1z * f1[2] + vb2z * f3[2] + (vb3z + vb2z) * f4[2];
|
||||
v[3] = vb1x * f1[1] + vb2x * f3[1] + (vb3x + vb2x) * f4[1];
|
||||
v[4] = vb1x * f1[2] + vb2x * f3[2] + (vb3x + vb2x) * f4[2];
|
||||
v[5] = vb1y * f1[2] + vb2y * f3[2] + (vb3y + vb2y) * f4[2];
|
||||
|
||||
if (vflag_global) {
|
||||
if (newton_bond) {
|
||||
@ -227,72 +223,72 @@ void Improper::ev_tally(int i1, int i2, int i3, int i4,
|
||||
virial[5] += v[5];
|
||||
} else {
|
||||
if (i1 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
if (i2 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
if (i3 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
if (i4 < nlocal) {
|
||||
virial[0] += 0.25*v[0];
|
||||
virial[1] += 0.25*v[1];
|
||||
virial[2] += 0.25*v[2];
|
||||
virial[3] += 0.25*v[3];
|
||||
virial[4] += 0.25*v[4];
|
||||
virial[5] += 0.25*v[5];
|
||||
virial[0] += 0.25 * v[0];
|
||||
virial[1] += 0.25 * v[1];
|
||||
virial[2] += 0.25 * v[2];
|
||||
virial[3] += 0.25 * v[3];
|
||||
virial[4] += 0.25 * v[4];
|
||||
virial[5] += 0.25 * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vflag_atom) {
|
||||
if (newton_bond || i1 < nlocal) {
|
||||
vatom[i1][0] += 0.25*v[0];
|
||||
vatom[i1][1] += 0.25*v[1];
|
||||
vatom[i1][2] += 0.25*v[2];
|
||||
vatom[i1][3] += 0.25*v[3];
|
||||
vatom[i1][4] += 0.25*v[4];
|
||||
vatom[i1][5] += 0.25*v[5];
|
||||
vatom[i1][0] += 0.25 * v[0];
|
||||
vatom[i1][1] += 0.25 * v[1];
|
||||
vatom[i1][2] += 0.25 * v[2];
|
||||
vatom[i1][3] += 0.25 * v[3];
|
||||
vatom[i1][4] += 0.25 * v[4];
|
||||
vatom[i1][5] += 0.25 * v[5];
|
||||
}
|
||||
if (newton_bond || i2 < nlocal) {
|
||||
vatom[i2][0] += 0.25*v[0];
|
||||
vatom[i2][1] += 0.25*v[1];
|
||||
vatom[i2][2] += 0.25*v[2];
|
||||
vatom[i2][3] += 0.25*v[3];
|
||||
vatom[i2][4] += 0.25*v[4];
|
||||
vatom[i2][5] += 0.25*v[5];
|
||||
vatom[i2][0] += 0.25 * v[0];
|
||||
vatom[i2][1] += 0.25 * v[1];
|
||||
vatom[i2][2] += 0.25 * v[2];
|
||||
vatom[i2][3] += 0.25 * v[3];
|
||||
vatom[i2][4] += 0.25 * v[4];
|
||||
vatom[i2][5] += 0.25 * v[5];
|
||||
}
|
||||
if (newton_bond || i3 < nlocal) {
|
||||
vatom[i3][0] += 0.25*v[0];
|
||||
vatom[i3][1] += 0.25*v[1];
|
||||
vatom[i3][2] += 0.25*v[2];
|
||||
vatom[i3][3] += 0.25*v[3];
|
||||
vatom[i3][4] += 0.25*v[4];
|
||||
vatom[i3][5] += 0.25*v[5];
|
||||
vatom[i3][0] += 0.25 * v[0];
|
||||
vatom[i3][1] += 0.25 * v[1];
|
||||
vatom[i3][2] += 0.25 * v[2];
|
||||
vatom[i3][3] += 0.25 * v[3];
|
||||
vatom[i3][4] += 0.25 * v[4];
|
||||
vatom[i3][5] += 0.25 * v[5];
|
||||
}
|
||||
if (newton_bond || i4 < nlocal) {
|
||||
vatom[i4][0] += 0.25*v[0];
|
||||
vatom[i4][1] += 0.25*v[1];
|
||||
vatom[i4][2] += 0.25*v[2];
|
||||
vatom[i4][3] += 0.25*v[3];
|
||||
vatom[i4][4] += 0.25*v[4];
|
||||
vatom[i4][5] += 0.25*v[5];
|
||||
vatom[i4][0] += 0.25 * v[0];
|
||||
vatom[i4][1] += 0.25 * v[1];
|
||||
vatom[i4][2] += 0.25 * v[2];
|
||||
vatom[i4][3] += 0.25 * v[3];
|
||||
vatom[i4][4] += 0.25 * v[4];
|
||||
vatom[i4][5] += 0.25 * v[5];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -311,100 +307,97 @@ void Improper::ev_tally(int i1, int i2, int i3, int i4,
|
||||
double a1[3];
|
||||
|
||||
// a1 = r10 = (3*r12 - 2*r32 - r43)/4
|
||||
a1[0] = 0.25*(3*vb1x - 2*vb2x - vb3x);
|
||||
a1[1] = 0.25*(3*vb1y - 2*vb2y - vb3y);
|
||||
a1[2] = 0.25*(3*vb1z - 2*vb2z - vb3z);
|
||||
a1[0] = 0.25 * (3 * vb1x - 2 * vb2x - vb3x);
|
||||
a1[1] = 0.25 * (3 * vb1y - 2 * vb2y - vb3y);
|
||||
a1[2] = 0.25 * (3 * vb1z - 2 * vb2z - vb3z);
|
||||
|
||||
cvatom[i1][0] += a1[0]*f1[0];
|
||||
cvatom[i1][1] += a1[1]*f1[1];
|
||||
cvatom[i1][2] += a1[2]*f1[2];
|
||||
cvatom[i1][3] += a1[0]*f1[1];
|
||||
cvatom[i1][4] += a1[0]*f1[2];
|
||||
cvatom[i1][5] += a1[1]*f1[2];
|
||||
cvatom[i1][6] += a1[1]*f1[0];
|
||||
cvatom[i1][7] += a1[2]*f1[0];
|
||||
cvatom[i1][8] += a1[2]*f1[1];
|
||||
cvatom[i1][0] += a1[0] * f1[0];
|
||||
cvatom[i1][1] += a1[1] * f1[1];
|
||||
cvatom[i1][2] += a1[2] * f1[2];
|
||||
cvatom[i1][3] += a1[0] * f1[1];
|
||||
cvatom[i1][4] += a1[0] * f1[2];
|
||||
cvatom[i1][5] += a1[1] * f1[2];
|
||||
cvatom[i1][6] += a1[1] * f1[0];
|
||||
cvatom[i1][7] += a1[2] * f1[0];
|
||||
cvatom[i1][8] += a1[2] * f1[1];
|
||||
}
|
||||
if (newton_bond || i2 < nlocal) {
|
||||
double a2[3];
|
||||
double f2[3];
|
||||
|
||||
// a2 = r20 = ( -r12 - 2*r32 - r43)/4
|
||||
a2[0] = 0.25*(-vb1x - 2*vb2x - vb3x);
|
||||
a2[1] = 0.25*(-vb1y - 2*vb2y - vb3y);
|
||||
a2[2] = 0.25*(-vb1z - 2*vb2z - vb3z);
|
||||
a2[0] = 0.25 * (-vb1x - 2 * vb2x - vb3x);
|
||||
a2[1] = 0.25 * (-vb1y - 2 * vb2y - vb3y);
|
||||
a2[2] = 0.25 * (-vb1z - 2 * vb2z - vb3z);
|
||||
|
||||
f2[0] = - f1[0] - f3[0] - f4[0];
|
||||
f2[1] = - f1[1] - f3[1] - f4[1];
|
||||
f2[2] = - f1[2] - f3[2] - f4[2];
|
||||
f2[0] = -f1[0] - f3[0] - f4[0];
|
||||
f2[1] = -f1[1] - f3[1] - f4[1];
|
||||
f2[2] = -f1[2] - f3[2] - f4[2];
|
||||
|
||||
cvatom[i2][0] += a2[0]*f2[0];
|
||||
cvatom[i2][1] += a2[1]*f2[1];
|
||||
cvatom[i2][2] += a2[2]*f2[2];
|
||||
cvatom[i2][3] += a2[0]*f2[1];
|
||||
cvatom[i2][4] += a2[0]*f2[2];
|
||||
cvatom[i2][5] += a2[1]*f2[2];
|
||||
cvatom[i2][6] += a2[1]*f2[0];
|
||||
cvatom[i2][7] += a2[2]*f2[0];
|
||||
cvatom[i2][8] += a2[2]*f2[1];
|
||||
cvatom[i2][0] += a2[0] * f2[0];
|
||||
cvatom[i2][1] += a2[1] * f2[1];
|
||||
cvatom[i2][2] += a2[2] * f2[2];
|
||||
cvatom[i2][3] += a2[0] * f2[1];
|
||||
cvatom[i2][4] += a2[0] * f2[2];
|
||||
cvatom[i2][5] += a2[1] * f2[2];
|
||||
cvatom[i2][6] += a2[1] * f2[0];
|
||||
cvatom[i2][7] += a2[2] * f2[0];
|
||||
cvatom[i2][8] += a2[2] * f2[1];
|
||||
}
|
||||
if (newton_bond || i3 < nlocal) {
|
||||
double a3[3];
|
||||
|
||||
// a3 = r30 = ( -r12 + 2*r32 - r43)/4
|
||||
a3[0] = 0.25*(-vb1x + 2*vb2x - vb3x);
|
||||
a3[1] = 0.25*(-vb1y + 2*vb2y - vb3y);
|
||||
a3[2] = 0.25*(-vb1z + 2*vb2z - vb3z);
|
||||
a3[0] = 0.25 * (-vb1x + 2 * vb2x - vb3x);
|
||||
a3[1] = 0.25 * (-vb1y + 2 * vb2y - vb3y);
|
||||
a3[2] = 0.25 * (-vb1z + 2 * vb2z - vb3z);
|
||||
|
||||
cvatom[i3][0] += a3[0]*f3[0];
|
||||
cvatom[i3][1] += a3[1]*f3[1];
|
||||
cvatom[i3][2] += a3[2]*f3[2];
|
||||
cvatom[i3][3] += a3[0]*f3[1];
|
||||
cvatom[i3][4] += a3[0]*f3[2];
|
||||
cvatom[i3][5] += a3[1]*f3[2];
|
||||
cvatom[i3][6] += a3[1]*f3[0];
|
||||
cvatom[i3][7] += a3[2]*f3[0];
|
||||
cvatom[i3][8] += a3[2]*f3[1];
|
||||
cvatom[i3][0] += a3[0] * f3[0];
|
||||
cvatom[i3][1] += a3[1] * f3[1];
|
||||
cvatom[i3][2] += a3[2] * f3[2];
|
||||
cvatom[i3][3] += a3[0] * f3[1];
|
||||
cvatom[i3][4] += a3[0] * f3[2];
|
||||
cvatom[i3][5] += a3[1] * f3[2];
|
||||
cvatom[i3][6] += a3[1] * f3[0];
|
||||
cvatom[i3][7] += a3[2] * f3[0];
|
||||
cvatom[i3][8] += a3[2] * f3[1];
|
||||
}
|
||||
if (newton_bond || i4 < nlocal) {
|
||||
double a4[3];
|
||||
|
||||
// a4 = r40 = ( -r12 + 2*r32 + 3*r43)/4
|
||||
a4[0] = 0.25*(-vb1x + 2*vb2x + 3*vb3x);
|
||||
a4[1] = 0.25*(-vb1y + 2*vb2y + 3*vb3y);
|
||||
a4[2] = 0.25*(-vb1z + 2*vb2z + 3*vb3z);
|
||||
a4[0] = 0.25 * (-vb1x + 2 * vb2x + 3 * vb3x);
|
||||
a4[1] = 0.25 * (-vb1y + 2 * vb2y + 3 * vb3y);
|
||||
a4[2] = 0.25 * (-vb1z + 2 * vb2z + 3 * vb3z);
|
||||
|
||||
cvatom[i4][0] += a4[0]*f4[0];
|
||||
cvatom[i4][1] += a4[1]*f4[1];
|
||||
cvatom[i4][2] += a4[2]*f4[2];
|
||||
cvatom[i4][3] += a4[0]*f4[1];
|
||||
cvatom[i4][4] += a4[0]*f4[2];
|
||||
cvatom[i4][5] += a4[1]*f4[2];
|
||||
cvatom[i4][6] += a4[1]*f4[0];
|
||||
cvatom[i4][7] += a4[2]*f4[0];
|
||||
cvatom[i4][8] += a4[2]*f4[1];
|
||||
cvatom[i4][0] += a4[0] * f4[0];
|
||||
cvatom[i4][1] += a4[1] * f4[1];
|
||||
cvatom[i4][2] += a4[2] * f4[2];
|
||||
cvatom[i4][3] += a4[0] * f4[1];
|
||||
cvatom[i4][4] += a4[0] * f4[2];
|
||||
cvatom[i4][5] += a4[1] * f4[2];
|
||||
cvatom[i4][6] += a4[1] * f4[0];
|
||||
cvatom[i4][7] += a4[2] * f4[0];
|
||||
cvatom[i4][8] += a4[2] * f4[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
void Improper::problem(const char *filename, int lineno,
|
||||
int i1, int i2, int i3, int i4)
|
||||
void Improper::problem(const char *filename, int lineno, int i1, int i2, int i3, int i4)
|
||||
{
|
||||
const auto x = atom->x;
|
||||
auto warn = fmt::format("Improper problem: {} {} {} {} {} {}\n",
|
||||
comm->me, update->ntimestep, atom->tag[i1],
|
||||
atom->tag[i2], atom->tag[i3], atom->tag[i4]);
|
||||
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n",
|
||||
comm->me,x[i1][0],x[i1][1],x[i1][2]);
|
||||
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n",
|
||||
comm->me,x[i2][0],x[i2][1],x[i2][2]);
|
||||
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n",
|
||||
comm->me,x[i3][0],x[i3][1],x[i3][2]);
|
||||
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}",
|
||||
comm->me,x[i4][0],x[i4][1],x[i4][2]);
|
||||
auto warn = fmt::format("Improper problem: {} {} {} {} {} {}\n", comm->me, update->ntimestep,
|
||||
atom->tag[i1], atom->tag[i2], atom->tag[i3], atom->tag[i4]);
|
||||
warn += fmt::format("WARNING: 1st atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i1][0], x[i1][1],
|
||||
x[i1][2]);
|
||||
warn += fmt::format("WARNING: 2nd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i2][0], x[i2][1],
|
||||
x[i2][2]);
|
||||
warn += fmt::format("WARNING: 3rd atom: {} {:.8} {:.8} {:.8}\n", comm->me, x[i3][0], x[i3][1],
|
||||
x[i3][2]);
|
||||
warn += fmt::format("WARNING: 4th atom: {} {:.8} {:.8} {:.8}", comm->me, x[i4][0], x[i4][1],
|
||||
x[i4][2]);
|
||||
error->warning(filename, lineno, warn);
|
||||
}
|
||||
|
||||
@ -412,7 +405,7 @@ void Improper::problem(const char *filename, int lineno,
|
||||
|
||||
double Improper::memory_usage()
|
||||
{
|
||||
double bytes = (double)comm->nthreads*maxeatom * sizeof(double);
|
||||
bytes += (double)comm->nthreads*maxvatom*6 * sizeof(double);
|
||||
double bytes = (double) comm->nthreads * maxeatom * sizeof(double);
|
||||
bytes += (double) comm->nthreads * maxvatom * 6 * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -22,15 +21,14 @@
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
TableFileReader::TableFileReader(LAMMPS *lmp,
|
||||
const std::string &filename,
|
||||
const std::string &type,
|
||||
TableFileReader::TableFileReader(LAMMPS *lmp, const std::string &filename, const std::string &type,
|
||||
const int auto_convert) :
|
||||
PotentialFileReader(lmp, filename, type + " table", auto_convert)
|
||||
PotentialFileReader(lmp, filename, type + " table", auto_convert)
|
||||
{
|
||||
}
|
||||
|
||||
char *TableFileReader::find_section_start(const std::string &keyword) {
|
||||
char *TableFileReader::find_section_start(const std::string &keyword)
|
||||
{
|
||||
char *line = nullptr;
|
||||
while ((line = reader->next_line())) {
|
||||
ValueTokenizer values(line);
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -24,10 +23,10 @@ using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
Timer::Timer(LAMMPS *lmp) : Pointers(lmp)
|
||||
Timer::Timer(LAMMPS *_lmp) : Pointers(_lmp)
|
||||
{
|
||||
_level = NORMAL;
|
||||
_sync = OFF;
|
||||
_sync = OFF;
|
||||
_timeout = -1;
|
||||
_s_timeout = -1;
|
||||
_checkfreq = 10;
|
||||
@ -49,7 +48,7 @@ void Timer::init()
|
||||
|
||||
void Timer::_stamp(enum ttype which)
|
||||
{
|
||||
double current_cpu=0.0, current_wall=0.0;
|
||||
double current_cpu = 0.0, current_wall = 0.0;
|
||||
|
||||
if (_level > NORMAL) current_cpu = platform::cputime();
|
||||
current_wall = platform::walltime();
|
||||
@ -58,13 +57,13 @@ void Timer::_stamp(enum ttype which)
|
||||
const double delta_cpu = current_cpu - previous_cpu;
|
||||
const double delta_wall = current_wall - previous_wall;
|
||||
|
||||
cpu_array[which] += delta_cpu;
|
||||
cpu_array[which] += delta_cpu;
|
||||
wall_array[which] += delta_wall;
|
||||
cpu_array[ALL] += delta_cpu;
|
||||
wall_array[ALL] += delta_wall;
|
||||
cpu_array[ALL] += delta_cpu;
|
||||
wall_array[ALL] += delta_wall;
|
||||
}
|
||||
|
||||
previous_cpu = current_cpu;
|
||||
previous_cpu = current_cpu;
|
||||
previous_wall = current_wall;
|
||||
|
||||
if (which == RESET) {
|
||||
@ -78,9 +77,9 @@ void Timer::_stamp(enum ttype which)
|
||||
if (_level > NORMAL) current_cpu = platform::cputime();
|
||||
current_wall = platform::walltime();
|
||||
|
||||
cpu_array[SYNC] += current_cpu - previous_cpu;
|
||||
cpu_array[SYNC] += current_cpu - previous_cpu;
|
||||
wall_array[SYNC] += current_wall - previous_wall;
|
||||
previous_cpu = current_cpu;
|
||||
previous_cpu = current_cpu;
|
||||
previous_wall = current_wall;
|
||||
}
|
||||
}
|
||||
@ -89,7 +88,7 @@ void Timer::_stamp(enum ttype which)
|
||||
|
||||
void Timer::barrier_start()
|
||||
{
|
||||
double current_cpu=0.0, current_wall=0.0;
|
||||
double current_cpu = 0.0, current_wall = 0.0;
|
||||
|
||||
MPI_Barrier(world);
|
||||
|
||||
@ -98,9 +97,9 @@ void Timer::barrier_start()
|
||||
current_cpu = platform::cputime();
|
||||
current_wall = platform::walltime();
|
||||
|
||||
cpu_array[TOTAL] = current_cpu;
|
||||
cpu_array[TOTAL] = current_cpu;
|
||||
wall_array[TOTAL] = current_wall;
|
||||
previous_cpu = current_cpu;
|
||||
previous_cpu = current_cpu;
|
||||
previous_wall = current_wall;
|
||||
}
|
||||
|
||||
@ -108,7 +107,7 @@ void Timer::barrier_start()
|
||||
|
||||
void Timer::barrier_stop()
|
||||
{
|
||||
double current_cpu=0.0, current_wall=0.0;
|
||||
double current_cpu = 0.0, current_wall = 0.0;
|
||||
|
||||
MPI_Barrier(world);
|
||||
|
||||
@ -117,7 +116,7 @@ void Timer::barrier_stop()
|
||||
current_cpu = platform::cputime();
|
||||
current_wall = platform::walltime();
|
||||
|
||||
cpu_array[TOTAL] = current_cpu - cpu_array[TOTAL];
|
||||
cpu_array[TOTAL] = current_cpu - cpu_array[TOTAL];
|
||||
wall_array[TOTAL] = current_wall - wall_array[TOTAL];
|
||||
}
|
||||
|
||||
@ -169,14 +168,13 @@ void Timer::print_timeout(FILE *fp)
|
||||
// remaining timeout in seconds
|
||||
int s = _timeout - d;
|
||||
// remaining 1/100ths of seconds
|
||||
const int hs = 100*((_timeout - d) - s);
|
||||
const int hs = 100 * ((_timeout - d) - s);
|
||||
// breaking s down into second/minutes/hours
|
||||
const int seconds = s % 60;
|
||||
s = (s - seconds) / 60;
|
||||
s = (s - seconds) / 60;
|
||||
const int minutes = s % 60;
|
||||
const int hours = (s - minutes) / 60;
|
||||
fprintf(fp," Walltime left : %d:%02d:%02d.%02d\n",
|
||||
hours,minutes,seconds,hs);
|
||||
fprintf(fp, " Walltime left : %d:%02d:%02d.%02d\n", hours, minutes, seconds, hs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,14 +184,13 @@ bool Timer::_check_timeout()
|
||||
{
|
||||
double walltime = platform::walltime() - timeout_start;
|
||||
// broadcast time to insure all ranks act the same.
|
||||
MPI_Bcast(&walltime,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&walltime, 1, MPI_DOUBLE, 0, world);
|
||||
|
||||
if (walltime < _timeout) {
|
||||
_nextcheck += _checkfreq;
|
||||
return false;
|
||||
} else {
|
||||
if (comm->me == 0)
|
||||
error->warning(FLERR,"Wall time limit reached");
|
||||
if (comm->me == 0) error->warning(FLERR, "Wall time limit reached");
|
||||
_timeout = 0.0;
|
||||
return true;
|
||||
}
|
||||
@ -208,38 +205,40 @@ double Timer::get_timeout_remain()
|
||||
/* ----------------------------------------------------------------------
|
||||
modify parameters of the Timer class
|
||||
------------------------------------------------------------------------- */
|
||||
static const char *timer_style[] = { "off", "loop", "normal", "full" };
|
||||
static const char *timer_mode[] = { "nosync", "(dummy)", "sync" };
|
||||
static const char *timer_style[] = {"off", "loop", "normal", "full"};
|
||||
static const char *timer_mode[] = {"nosync", "(dummy)", "sync"};
|
||||
|
||||
void Timer::modify_params(int narg, char **arg)
|
||||
{
|
||||
int iarg = 0;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],timer_style[OFF]) == 0) {
|
||||
if (strcmp(arg[iarg], timer_style[OFF]) == 0) {
|
||||
_level = OFF;
|
||||
} else if (strcmp(arg[iarg],timer_style[LOOP]) == 0) {
|
||||
} else if (strcmp(arg[iarg], timer_style[LOOP]) == 0) {
|
||||
_level = LOOP;
|
||||
} else if (strcmp(arg[iarg],timer_style[NORMAL]) == 0) {
|
||||
} else if (strcmp(arg[iarg], timer_style[NORMAL]) == 0) {
|
||||
_level = NORMAL;
|
||||
} else if (strcmp(arg[iarg],timer_style[FULL]) == 0) {
|
||||
} else if (strcmp(arg[iarg], timer_style[FULL]) == 0) {
|
||||
_level = FULL;
|
||||
} else if (strcmp(arg[iarg],timer_mode[OFF]) == 0) {
|
||||
_sync = OFF;
|
||||
} else if (strcmp(arg[iarg],timer_mode[NORMAL]) == 0) {
|
||||
_sync = NORMAL;
|
||||
} else if (strcmp(arg[iarg],"timeout") == 0) {
|
||||
} else if (strcmp(arg[iarg], timer_mode[OFF]) == 0) {
|
||||
_sync = OFF;
|
||||
} else if (strcmp(arg[iarg], timer_mode[NORMAL]) == 0) {
|
||||
_sync = NORMAL;
|
||||
} else if (strcmp(arg[iarg], "timeout") == 0) {
|
||||
++iarg;
|
||||
if (iarg < narg) {
|
||||
_timeout = utils::timespec2seconds(arg[iarg]);
|
||||
} else error->all(FLERR,"Illegal timer command");
|
||||
} else if (strcmp(arg[iarg],"every") == 0) {
|
||||
} else
|
||||
error->all(FLERR, "Illegal timer command");
|
||||
} else if (strcmp(arg[iarg], "every") == 0) {
|
||||
++iarg;
|
||||
if (iarg < narg) {
|
||||
_checkfreq = utils::inumeric(FLERR,arg[iarg],false,lmp);
|
||||
if (_checkfreq <= 0)
|
||||
error->all(FLERR,"Illegal timer command");
|
||||
} else error->all(FLERR,"Illegal timer command");
|
||||
} else error->all(FLERR,"Illegal timer command");
|
||||
_checkfreq = utils::inumeric(FLERR, arg[iarg], false, lmp);
|
||||
if (_checkfreq <= 0) error->all(FLERR, "Illegal timer command");
|
||||
} else
|
||||
error->all(FLERR, "Illegal timer command");
|
||||
} else
|
||||
error->all(FLERR, "Illegal timer command");
|
||||
++iarg;
|
||||
}
|
||||
|
||||
@ -253,7 +252,7 @@ void Timer::modify_params(int narg, char **arg)
|
||||
timeout = fmt::format("{:%H:%M:%S}", fmt::gmtime(tv));
|
||||
}
|
||||
|
||||
utils::logmesg(lmp,"New timer settings: style={} mode={} timeout={}\n",
|
||||
timer_style[_level],timer_mode[_sync],timeout);
|
||||
utils::logmesg(lmp, "New timer settings: style={} mode={} timeout={}\n", timer_style[_level],
|
||||
timer_mode[_sync], timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -17,19 +16,20 @@
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "tokenizer.h"
|
||||
#include "utils.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
TokenizerException::TokenizerException(const std::string &msg, const std::string &token) {
|
||||
if (token.empty()) {
|
||||
message = msg;
|
||||
} else {
|
||||
message = fmt::format("{}: '{}'", msg, token);
|
||||
}
|
||||
TokenizerException::TokenizerException(const std::string &msg, const std::string &token)
|
||||
{
|
||||
if (token.empty()) {
|
||||
message = msg;
|
||||
} else {
|
||||
message = fmt::format("{}: '{}'", msg, token);
|
||||
}
|
||||
}
|
||||
|
||||
/** Class for splitting text into words
|
||||
@ -52,117 +52,122 @@ TokenizerException::TokenizerException(const std::string &msg, const std::string
|
||||
Tokenizer::Tokenizer(std::string str, std::string _separators) :
|
||||
text(std::move(str)), separators(std::move(_separators)), start(0), ntokens(std::string::npos)
|
||||
{
|
||||
// replace known UTF-8 characters with ASCII equivalents
|
||||
if (utils::has_utf8(text)) text = utils::utf8_subst(text);
|
||||
reset();
|
||||
// replace known UTF-8 characters with ASCII equivalents
|
||||
if (utils::has_utf8(text)) text = utils::utf8_subst(text);
|
||||
reset();
|
||||
}
|
||||
|
||||
Tokenizer::Tokenizer(const Tokenizer &rhs) :
|
||||
text(rhs.text), separators(rhs.separators), ntokens(rhs.ntokens)
|
||||
{
|
||||
reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
Tokenizer::Tokenizer(Tokenizer && rhs) :
|
||||
Tokenizer::Tokenizer(Tokenizer &&rhs) :
|
||||
text(std::move(rhs.text)), separators(std::move(rhs.separators)), ntokens(rhs.ntokens)
|
||||
{
|
||||
reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
Tokenizer& Tokenizer::operator=(const Tokenizer& other)
|
||||
Tokenizer &Tokenizer::operator=(const Tokenizer &other)
|
||||
{
|
||||
Tokenizer tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
Tokenizer tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Tokenizer& Tokenizer::operator=(Tokenizer&& other)
|
||||
Tokenizer &Tokenizer::operator=(Tokenizer &&other)
|
||||
{
|
||||
Tokenizer tmp(std::move(other));
|
||||
swap(tmp);
|
||||
return *this;
|
||||
Tokenizer tmp(std::move(other));
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Tokenizer::swap(Tokenizer& other)
|
||||
void Tokenizer::swap(Tokenizer &other)
|
||||
{
|
||||
std::swap(text, other.text);
|
||||
std::swap(separators, other.separators);
|
||||
std::swap(start, other.start);
|
||||
std::swap(ntokens, other.ntokens);
|
||||
std::swap(text, other.text);
|
||||
std::swap(separators, other.separators);
|
||||
std::swap(start, other.start);
|
||||
std::swap(ntokens, other.ntokens);
|
||||
}
|
||||
|
||||
/*! Re-position the tokenizer state to the first word,
|
||||
* i.e. the first non-separator character */
|
||||
void Tokenizer::reset() {
|
||||
start = text.find_first_not_of(separators);
|
||||
void Tokenizer::reset()
|
||||
{
|
||||
start = text.find_first_not_of(separators);
|
||||
}
|
||||
|
||||
/*! Search the text to be processed for a sub-string.
|
||||
*
|
||||
* \param str string to be searched for
|
||||
* \return true if string was found, false if not */
|
||||
bool Tokenizer::contains(const std::string &str) const {
|
||||
return text.find(str) != std::string::npos;
|
||||
bool Tokenizer::contains(const std::string &str) const
|
||||
{
|
||||
return text.find(str) != std::string::npos;
|
||||
}
|
||||
|
||||
/*! Skip over a given number of tokens
|
||||
*
|
||||
* \param n number of tokens to skip over */
|
||||
void Tokenizer::skip(int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (!has_next()) throw TokenizerException("No more tokens", "");
|
||||
|
||||
size_t end = text.find_first_of(separators, start);
|
||||
|
||||
if (end == std::string::npos) {
|
||||
start = end;
|
||||
} else {
|
||||
start = text.find_first_not_of(separators, end+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*! Indicate whether more tokens are available
|
||||
*
|
||||
* \return true if there are more tokens, false if not */
|
||||
bool Tokenizer::has_next() const {
|
||||
return start != std::string::npos;
|
||||
}
|
||||
|
||||
/*! Retrieve next token.
|
||||
*
|
||||
* \return string with the next token */
|
||||
std::string Tokenizer::next() {
|
||||
void Tokenizer::skip(int n)
|
||||
{
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (!has_next()) throw TokenizerException("No more tokens", "");
|
||||
|
||||
size_t end = text.find_first_of(separators, start);
|
||||
|
||||
if (end == std::string::npos) {
|
||||
std::string token = text.substr(start);
|
||||
start = end;
|
||||
return token;
|
||||
start = end;
|
||||
} else {
|
||||
start = text.find_first_not_of(separators, end + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string token = text.substr(start, end-start);
|
||||
start = text.find_first_not_of(separators, end+1);
|
||||
/*! Indicate whether more tokens are available
|
||||
*
|
||||
* \return true if there are more tokens, false if not */
|
||||
bool Tokenizer::has_next() const
|
||||
{
|
||||
return start != std::string::npos;
|
||||
}
|
||||
|
||||
/*! Retrieve next token.
|
||||
*
|
||||
* \return string with the next token */
|
||||
std::string Tokenizer::next()
|
||||
{
|
||||
if (!has_next()) throw TokenizerException("No more tokens", "");
|
||||
|
||||
size_t end = text.find_first_of(separators, start);
|
||||
|
||||
if (end == std::string::npos) {
|
||||
std::string token = text.substr(start);
|
||||
start = end;
|
||||
return token;
|
||||
}
|
||||
|
||||
std::string token = text.substr(start, end - start);
|
||||
start = text.find_first_not_of(separators, end + 1);
|
||||
return token;
|
||||
}
|
||||
|
||||
/*! Count number of tokens in text.
|
||||
*
|
||||
* \return number of counted tokens */
|
||||
size_t Tokenizer::count() {
|
||||
// lazy evaluation
|
||||
if (ntokens == std::string::npos) {
|
||||
ntokens = utils::count_words(text, separators);
|
||||
}
|
||||
return ntokens;
|
||||
size_t Tokenizer::count()
|
||||
{
|
||||
// lazy evaluation
|
||||
if (ntokens == std::string::npos) { ntokens = utils::count_words(text, separators); }
|
||||
return ntokens;
|
||||
}
|
||||
|
||||
/*! Retrieve the entire text converted to an STL vector of tokens.
|
||||
*
|
||||
* \return The STL vector */
|
||||
std::vector<std::string> Tokenizer::as_vector() {
|
||||
std::vector<std::string> Tokenizer::as_vector()
|
||||
{
|
||||
// store current state
|
||||
size_t current = start;
|
||||
|
||||
@ -171,9 +176,7 @@ std::vector<std::string> Tokenizer::as_vector() {
|
||||
// generate vector
|
||||
std::vector<std::string> tokens;
|
||||
|
||||
while (has_next()) {
|
||||
tokens.emplace_back(next());
|
||||
}
|
||||
while (has_next()) { tokens.emplace_back(next()); }
|
||||
|
||||
// restore state
|
||||
start = current;
|
||||
@ -195,107 +198,109 @@ std::vector<std::string> Tokenizer::as_vector() {
|
||||
*
|
||||
* \see Tokenizer InvalidIntegerException InvalidFloatException */
|
||||
|
||||
ValueTokenizer::ValueTokenizer(const std::string &str, const std::string &separators) : tokens(str, separators) {
|
||||
}
|
||||
|
||||
ValueTokenizer::ValueTokenizer(ValueTokenizer &&rhs) : tokens(std::move(rhs.tokens)) {
|
||||
}
|
||||
|
||||
ValueTokenizer& ValueTokenizer::operator=(const ValueTokenizer& other)
|
||||
ValueTokenizer::ValueTokenizer(const std::string &str, const std::string &separators) :
|
||||
tokens(str, separators)
|
||||
{
|
||||
ValueTokenizer tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ValueTokenizer& ValueTokenizer::operator=(ValueTokenizer&& other)
|
||||
ValueTokenizer::ValueTokenizer(ValueTokenizer &&rhs) : tokens(std::move(rhs.tokens)) {}
|
||||
|
||||
ValueTokenizer &ValueTokenizer::operator=(const ValueTokenizer &other)
|
||||
{
|
||||
ValueTokenizer tmp(std::move(other));
|
||||
swap(tmp);
|
||||
return *this;
|
||||
ValueTokenizer tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ValueTokenizer::swap(ValueTokenizer& other)
|
||||
ValueTokenizer &ValueTokenizer::operator=(ValueTokenizer &&other)
|
||||
{
|
||||
std::swap(tokens, other.tokens);
|
||||
ValueTokenizer tmp(std::move(other));
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ValueTokenizer::swap(ValueTokenizer &other)
|
||||
{
|
||||
std::swap(tokens, other.tokens);
|
||||
}
|
||||
|
||||
/*! Indicate whether more tokens are available
|
||||
*
|
||||
* \return true if there are more tokens, false if not */
|
||||
bool ValueTokenizer::has_next() const {
|
||||
return tokens.has_next();
|
||||
bool ValueTokenizer::has_next() const
|
||||
{
|
||||
return tokens.has_next();
|
||||
}
|
||||
|
||||
/*! Search the text to be processed for a sub-string.
|
||||
*
|
||||
* \param value string with value to be searched for
|
||||
* \return true if string was found, false if not */
|
||||
bool ValueTokenizer::contains(const std::string &value) const {
|
||||
return tokens.contains(value);
|
||||
bool ValueTokenizer::contains(const std::string &value) const
|
||||
{
|
||||
return tokens.contains(value);
|
||||
}
|
||||
|
||||
/*! Retrieve next token
|
||||
*
|
||||
* \return string with next token */
|
||||
std::string ValueTokenizer::next_string() {
|
||||
return tokens.next();
|
||||
std::string ValueTokenizer::next_string()
|
||||
{
|
||||
return tokens.next();
|
||||
}
|
||||
|
||||
/*! Retrieve next token and convert to int
|
||||
*
|
||||
* \return value of next token */
|
||||
int ValueTokenizer::next_int() {
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_integer(current)) {
|
||||
throw InvalidIntegerException(current);
|
||||
}
|
||||
return atoi(current.c_str());
|
||||
int ValueTokenizer::next_int()
|
||||
{
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_integer(current)) { throw InvalidIntegerException(current); }
|
||||
return atoi(current.c_str());
|
||||
}
|
||||
|
||||
/*! Retrieve next token and convert to bigint
|
||||
*
|
||||
* \return value of next token */
|
||||
bigint ValueTokenizer::next_bigint() {
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_integer(current)) {
|
||||
throw InvalidIntegerException(current);
|
||||
}
|
||||
return ATOBIGINT(current.c_str());
|
||||
bigint ValueTokenizer::next_bigint()
|
||||
{
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_integer(current)) { throw InvalidIntegerException(current); }
|
||||
return ATOBIGINT(current.c_str());
|
||||
}
|
||||
|
||||
/*! Retrieve next token and convert to tagint
|
||||
*
|
||||
* \return value of next token */
|
||||
tagint ValueTokenizer::next_tagint() {
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_integer(current)) {
|
||||
throw InvalidIntegerException(current);
|
||||
}
|
||||
return ATOTAGINT(current.c_str());
|
||||
tagint ValueTokenizer::next_tagint()
|
||||
{
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_integer(current)) { throw InvalidIntegerException(current); }
|
||||
return ATOTAGINT(current.c_str());
|
||||
}
|
||||
|
||||
/*! Retrieve next token and convert to double
|
||||
*
|
||||
* \return value of next token */
|
||||
double ValueTokenizer::next_double() {
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_double(current)) {
|
||||
throw InvalidFloatException(current);
|
||||
}
|
||||
return atof(current.c_str());
|
||||
double ValueTokenizer::next_double()
|
||||
{
|
||||
std::string current = tokens.next();
|
||||
if (!utils::is_double(current)) { throw InvalidFloatException(current); }
|
||||
return atof(current.c_str());
|
||||
}
|
||||
|
||||
/*! Skip over a given number of tokens
|
||||
*
|
||||
* \param n number of tokens to skip over */
|
||||
void ValueTokenizer::skip(int n) {
|
||||
tokens.skip(n);
|
||||
void ValueTokenizer::skip(int n)
|
||||
{
|
||||
tokens.skip(n);
|
||||
}
|
||||
|
||||
/*! Count number of tokens in text.
|
||||
*
|
||||
* \return number of counted tokens */
|
||||
size_t ValueTokenizer::count() {
|
||||
return tokens.count();
|
||||
size_t ValueTokenizer::count()
|
||||
{
|
||||
return tokens.count();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user