/* ---------------------------------------------------------------------- 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 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 authors: German Samolyuk (ORNL) and Mario Pinto (Computational Research Lab, Pune, India) ------------------------------------------------------------------------- */ #include "math.h" #include "string.h" #include "compute_charge_flux.h" #include "atom.h" #include "update.h" #include "modify.h" #include "velocity.h" #include "group.h" #include "error.h" using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ ComputeChargeFlux::ComputeChargeFlux(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg) { if (narg < 3) error->all(FLERR,"Illegal compute charge/flux command"); vector_flag = 1; size_vector = 3; extvector = 1; vector = new double[3]; } /* ---------------------------------------------------------------------- */ ComputeChargeFlux::~ComputeChargeFlux() { delete [] vector; } /* ---------------------------------------------------------------------- */ void ComputeChargeFlux::init() { } /* ---------------------------------------------------------------------- */ void ComputeChargeFlux::compute_vector() { invoked_vector = update->ntimestep; double **v = atom->v; double *q = atom->q; int *mask = atom->mask; int nlocal = atom->nlocal; double qi,vx,vy,vz; double je[3]; je[0] = je[1] = je[2]=0.0; for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { qi = q[i]; vx = v[i][0]; vy = v[i][1]; vz = v[i][2]; je[0] += qi * vx; je[1] += qi * vy; je[2] += qi * vz; } } // sum across all procs // 1st 3 terms are total charge flux MPI_Allreduce(je,vector,3,MPI_DOUBLE,MPI_SUM,world); }