lammps/src/fix_add_force.cpp

100 lines
2.6 KiB
C++

/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
www.cs.sandia.gov/~sjplimp/lammps.html
Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "string.h"
#include "stdlib.h"
#include "fix_add_force.h"
#include "atom.h"
#include "update.h"
#include "respa.h"
#include "error.h"
/* ---------------------------------------------------------------------- */
FixAddForce::FixAddForce(int narg, char **arg) : Fix(narg, arg)
{
if (narg != 6) error->all("Illegal fix addforce command");
xvalue = atof(arg[3]);
yvalue = atof(arg[4]);
zvalue = atof(arg[5]);
}
/* ---------------------------------------------------------------------- */
int FixAddForce::setmask()
{
int mask = 0;
mask |= POST_FORCE;
mask |= POST_FORCE_RESPA;
mask |= MIN_POST_FORCE;
return mask;
}
/* ---------------------------------------------------------------------- */
void FixAddForce::init()
{
if (strcmp(update->integrate_style,"respa") == 0)
nlevels_respa = ((Respa *) update->integrate)->nlevels;
}
/* ---------------------------------------------------------------------- */
void FixAddForce::setup()
{
if (strcmp(update->integrate_style,"verlet") == 0)
post_force(1);
else {
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
post_force_respa(1,nlevels_respa-1,0);
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
}
}
/* ---------------------------------------------------------------------- */
void FixAddForce::min_setup()
{
post_force(1);
}
/* ---------------------------------------------------------------------- */
void FixAddForce::post_force(int vflag)
{
double **f = atom->f;
int *mask = atom->mask;
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
f[i][0] += xvalue;
f[i][1] += yvalue;
f[i][2] += zvalue;
}
}
/* ---------------------------------------------------------------------- */
void FixAddForce::post_force_respa(int vflag, int ilevel, int iloop)
{
if (ilevel == nlevels_respa-1) post_force(vflag);
}
/* ---------------------------------------------------------------------- */
void FixAddForce::min_post_force(int vflag)
{
post_force(vflag);
}