Files
lammps/src/pair_zero.cpp
Axel Kohlmeyer 01a54723d7 more iwyu updates
2022-12-11 23:40:31 -05:00

262 lines
7.7 KiB
C++

/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Carsten Svaneborg (SDU)
------------------------------------------------------------------------- */
#include "pair_zero.h"
#include "atom.h"
#include "comm.h"
#include "error.h"
#include "memory.h"
#include "neighbor.h"
#include <cstring>
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
PairZero::PairZero(LAMMPS *lmp) : Pair(lmp)
{
coeffflag = 1;
writedata = 1;
single_enable = 1;
respa_enable = 1;
fullneighflag = 0;
}
/* ---------------------------------------------------------------------- */
PairZero::~PairZero()
{
if (allocated) {
memory->destroy(setflag);
memory->destroy(cutsq);
memory->destroy(cut);
}
}
/* ---------------------------------------------------------------------- */
void PairZero::compute(int eflag, int vflag)
{
ev_init(eflag, vflag);
if (vflag_fdotr) virial_fdotr_compute();
}
/* ---------------------------------------------------------------------- */
void PairZero::compute_outer(int eflag, int vflag)
{
ev_init(eflag, vflag);
}
/* ----------------------------------------------------------------------
allocate all arrays
------------------------------------------------------------------------- */
void PairZero::allocate()
{
allocated = 1;
int np1 = atom->ntypes + 1;
memory->create(setflag, np1, np1, "pair:setflag");
for (int i = 1; i < np1; i++)
for (int j = i; j < np1; j++) setflag[i][j] = 0;
memory->create(cutsq, np1, np1, "pair:cutsq");
memory->create(cut, np1, np1, "pair:cut");
}
/* ----------------------------------------------------------------------
global settings
------------------------------------------------------------------------- */
void PairZero::settings(int narg, char **arg)
{
if (narg < 1) utils::missing_cmd_args(FLERR, "pair_style zero", error);
cut_global = utils::numeric(FLERR, arg[0], false, lmp);
// reset to defaults
coeffflag = 1;
fullneighflag = 0;
int iarg = 1;
while (iarg < narg) {
if (strcmp("nocoeff", arg[iarg]) == 0) {
coeffflag = 0;
++iarg;
} else if (strcmp("full", arg[iarg]) == 0) {
fullneighflag = 1;
++iarg;
} else
error->all(FLERR, "Unknown pair style zero option {}", arg[iarg]);
}
// reset cutoffs that have been explicitly set
if (allocated) {
int i, j;
for (i = 1; i <= atom->ntypes; i++)
for (j = i + 1; j <= atom->ntypes; j++) cut[i][j] = cut_global;
}
}
/* ----------------------------------------------------------------------
set coeffs for one or more type pairs
------------------------------------------------------------------------- */
void PairZero::coeff(int narg, char **arg)
{
if ((narg < 2) || (coeffflag && narg > 3))
error->all(FLERR, "Incorrect args for pair coefficients");
if (!allocated) allocate();
int ilo, ihi, jlo, jhi;
utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error);
utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error);
double cut_one = cut_global;
if (coeffflag && (narg == 3)) cut_one = utils::numeric(FLERR, arg[2], false, lmp);
int count = 0;
for (int i = ilo; i <= ihi; i++) {
for (int j = MAX(jlo, i); j <= jhi; j++) {
cut[i][j] = cut_one;
setflag[i][j] = 1;
count++;
}
}
if (count == 0) error->all(FLERR, "Incorrect args for pair coefficients");
}
/* ----------------------------------------------------------------------
init specific to this pair style
------------------------------------------------------------------------- */
void PairZero::init_style()
{
if (fullneighflag)
neighbor->add_request(this, NeighConst::REQ_FULL);
else
neighbor->add_request(this, NeighConst::REQ_DEFAULT);
}
/* ----------------------------------------------------------------------
init for one type pair i,j and corresponding j,i
------------------------------------------------------------------------- */
double PairZero::init_one(int i, int j)
{
if (setflag[i][j] == 0) { cut[i][j] = mix_distance(cut[i][i], cut[j][j]); }
return cut[i][j];
}
/* ----------------------------------------------------------------------
proc 0 writes to restart file
------------------------------------------------------------------------- */
void PairZero::write_restart(FILE *fp)
{
write_restart_settings(fp);
int i, j;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
fwrite(&setflag[i][j], sizeof(int), 1, fp);
if (setflag[i][j]) { fwrite(&cut[i][j], sizeof(double), 1, fp); }
}
}
/* ----------------------------------------------------------------------
proc 0 reads from restart file, bcasts
------------------------------------------------------------------------- */
void PairZero::read_restart(FILE *fp)
{
read_restart_settings(fp);
allocate();
int i, j;
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) utils::sfread(FLERR, &setflag[i][j], sizeof(int), 1, fp, nullptr, error);
MPI_Bcast(&setflag[i][j], 1, MPI_INT, 0, world);
if (setflag[i][j]) {
if (me == 0) { utils::sfread(FLERR, &cut[i][j], sizeof(double), 1, fp, nullptr, error); }
MPI_Bcast(&cut[i][j], 1, MPI_DOUBLE, 0, world);
}
}
}
/* ----------------------------------------------------------------------
proc 0 writes to restart file
------------------------------------------------------------------------- */
void PairZero::write_restart_settings(FILE *fp)
{
fwrite(&cut_global, sizeof(double), 1, fp);
fwrite(&coeffflag, sizeof(int), 1, fp);
}
/* ----------------------------------------------------------------------
proc 0 reads from restart file, bcasts
------------------------------------------------------------------------- */
void PairZero::read_restart_settings(FILE *fp)
{
int me = comm->me;
if (me == 0) {
utils::sfread(FLERR, &cut_global, sizeof(double), 1, fp, nullptr, error);
utils::sfread(FLERR, &coeffflag, sizeof(int), 1, fp, nullptr, error);
}
MPI_Bcast(&cut_global, 1, MPI_DOUBLE, 0, world);
MPI_Bcast(&coeffflag, 1, MPI_INT, 0, world);
}
/* ----------------------------------------------------------------------
proc 0 writes to data file
------------------------------------------------------------------------- */
void PairZero::write_data(FILE *fp)
{
for (int i = 1; i <= atom->ntypes; i++) fprintf(fp, "%d\n", i);
}
/* ----------------------------------------------------------------------
proc 0 writes all pairs to data file
------------------------------------------------------------------------- */
void PairZero::write_data_all(FILE *fp)
{
for (int i = 1; i <= atom->ntypes; i++)
for (int j = i; j <= atom->ntypes; j++) fprintf(fp, "%d %d %g\n", i, j, cut[i][j]);
}
/* ---------------------------------------------------------------------- */
double PairZero::single(int /*i*/, int /*j*/, int /* itype */, int /* jtype */, double /* rsq */,
double /*factor_coul*/, double /* factor_lj */, double &fforce)
{
fforce = 0.0;
return 0.0;
}