diff --git a/src/compute_force_molecule.cpp b/src/compute_force_molecule.cpp new file mode 100644 index 0000000000..d05b162e3f --- /dev/null +++ b/src/compute_force_molecule.cpp @@ -0,0 +1,106 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "compute_force_molecule.h" +#include "atom.h" +#include "update.h" +#include "domain.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +ComputeForceMolecule::ComputeForceMolecule(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg) +{ + if (narg != 3) error->all(FLERR,"Illegal compute force/molecule command"); + + if (atom->molecular == 0) + error->all(FLERR,"Compute force/molecule requires molecular atom style"); + + array_flag = 1; + size_array_cols = 3; + extarray = 0; + + // setup molecule-based data + + nmolecules = molecules_in_group(idlo,idhi); + size_array_rows = nmolecules; + + memory->create(force,nmolecules,3,"force/molecule:force"); + memory->create(forceall,nmolecules,3,"force/molecule:forceall"); + array = forceall; +} + +/* ---------------------------------------------------------------------- */ + +ComputeForceMolecule::~ComputeForceMolecule() +{ + memory->destroy(force); + memory->destroy(forceall); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeForceMolecule::init() +{ + int ntmp = molecules_in_group(idlo,idhi); + if (ntmp != nmolecules) + error->all(FLERR,"Molecule count changed in compute force/molecule"); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeForceMolecule::compute_array() +{ + tagint imol; + double massone; + double unwrap[3]; + + invoked_array = update->ntimestep; + + for (int i = 0; i < nmolecules; i++) + force[i][0] = force[i][1] = force[i][2] = 0.0; + + double **f = atom->f; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + imol = molecule[i]; + if (molmap) imol = molmap[imol-idlo]; + else imol--; + force[imol][0] += f[i][0]; + force[imol][1] += f[i][1]; + force[imol][2] += f[i][2]; + } + + MPI_Allreduce(&force[0][0],&forceall[0][0],3*nmolecules, + MPI_DOUBLE,MPI_SUM,world); +} + +/* ---------------------------------------------------------------------- + memory usage of local data +------------------------------------------------------------------------- */ + +double ComputeForceMolecule::memory_usage() +{ + double bytes = 0; + if (molmap) bytes += (idhi-idlo+1) * sizeof(int); + bytes += (bigint) nmolecules * 2*3 * sizeof(double); + return bytes; +} diff --git a/src/compute_force_molecule.h b/src/compute_force_molecule.h new file mode 100644 index 0000000000..ec90e3c9fe --- /dev/null +++ b/src/compute_force_molecule.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- ---------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#ifdef COMPUTE_CLASS + +ComputeStyle(force/molecule,ComputeForceMolecule) + +#else + +#ifndef LMP_COMPUTE_FORCE_MOLECULE_H +#define LMP_COMPUTE_FORCE_MOLECULE_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeForceMolecule : public Compute { + public: + ComputeForceMolecule(class LAMMPS *, int, char **); + ~ComputeForceMolecule(); + void init(); + void compute_array(); + double memory_usage(); + + private: + int nmolecules; + tagint idlo,idhi; + + double **force,**forceall; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Compute force/molecule requires molecular atom style + +Self-explanatory. + +E: Molecule count changed in compute force/molecule + +Number of molecules must remain constant over time. + +*/ diff --git a/src/compute_vcm_molecule.cpp b/src/compute_vcm_molecule.cpp new file mode 100644 index 0000000000..ab86d2ee0a --- /dev/null +++ b/src/compute_vcm_molecule.cpp @@ -0,0 +1,147 @@ +/* ---------------------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#include "compute_vcm_molecule.h" +#include "atom.h" +#include "update.h" +#include "domain.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +ComputeVCMMolecule::ComputeVCMMolecule(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg) +{ + if (narg != 3) error->all(FLERR,"Illegal compute vcm/molecule command"); + + if (atom->molecular == 0) + error->all(FLERR,"Compute vcm/molecule requires molecular atom style"); + + array_flag = 1; + size_array_cols = 3; + extarray = 0; + + // setup molecule-based data + + nmolecules = molecules_in_group(idlo,idhi); + size_array_rows = nmolecules; + + memory->create(massproc,nmolecules,"vcm/molecule:massproc"); + memory->create(masstotal,nmolecules,"vcm/molecule:masstotal"); + memory->create(vcm,nmolecules,3,"vcm/molecule:vcm"); + memory->create(vcmall,nmolecules,3,"vcm/molecule:vcmall"); + array = vcmall; + + // compute masstotal for each molecule + + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int *type = atom->type; + double *mass = atom->mass; + double *rmass = atom->rmass; + int nlocal = atom->nlocal; + + tagint imol; + double massone; + + for (int i = 0; i < nmolecules; i++) massproc[i] = 0.0; + + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + if (rmass) massone = rmass[i]; + else massone = mass[type[i]]; + imol = molecule[i]; + if (molmap) imol = molmap[imol-idlo]; + else imol--; + massproc[imol] += massone; + } + + MPI_Allreduce(massproc,masstotal,nmolecules,MPI_DOUBLE,MPI_SUM,world); +} + +/* ---------------------------------------------------------------------- */ + +ComputeVCMMolecule::~ComputeVCMMolecule() +{ + memory->destroy(massproc); + memory->destroy(masstotal); + memory->destroy(vcm); + memory->destroy(vcmall); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeVCMMolecule::init() +{ + int ntmp = molecules_in_group(idlo,idhi); + if (ntmp != nmolecules) + error->all(FLERR,"Molecule count changed in compute vcm/molecule"); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeVCMMolecule::compute_array() +{ + tagint imol; + double massone; + double unwrap[3]; + + invoked_array = update->ntimestep; + + for (int i = 0; i < nmolecules; i++) + vcm[i][0] = vcm[i][1] = vcm[i][2] = 0.0; + + double **v = atom->v; + int *mask = atom->mask; + tagint *molecule = atom->molecule; + int *type = atom->type; + imageint *image = atom->image; + double *mass = atom->mass; + double *rmass = atom->rmass; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + if (rmass) massone = rmass[i]; + else massone = mass[type[i]]; + imol = molecule[i]; + if (molmap) imol = molmap[imol-idlo]; + else imol--; + vcm[imol][0] += v[i][0] * massone; + vcm[imol][1] += v[i][1] * massone; + vcm[imol][2] += v[i][2] * massone; + } + + MPI_Allreduce(&vcm[0][0],&vcmall[0][0],3*nmolecules, + MPI_DOUBLE,MPI_SUM,world); + for (int i = 0; i < nmolecules; i++) { + vcmall[i][0] /= masstotal[i]; + vcmall[i][1] /= masstotal[i]; + vcmall[i][2] /= masstotal[i]; + } +} + +/* ---------------------------------------------------------------------- + memory usage of local data +------------------------------------------------------------------------- */ + +double ComputeVCMMolecule::memory_usage() +{ + double bytes = (bigint) nmolecules * 2 * sizeof(double); + if (molmap) bytes += (idhi-idlo+1) * sizeof(int); + bytes += (bigint) nmolecules * 2*3 * sizeof(double); + return bytes; +} diff --git a/src/compute_vcm_molecule.h b/src/compute_vcm_molecule.h new file mode 100644 index 0000000000..b5bce320ca --- /dev/null +++ b/src/compute_vcm_molecule.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- ---------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#ifdef COMPUTE_CLASS + +ComputeStyle(vcm/molecule,ComputeVCMMolecule) + +#else + +#ifndef LMP_COMPUTE_VCM_MOLECULE_H +#define LMP_COMPUTE_VCM_MOLECULE_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeVCMMolecule : public Compute { + public: + ComputeVCMMolecule(class LAMMPS *, int, char **); + ~ComputeVCMMolecule(); + void init(); + void compute_array(); + double memory_usage(); + + private: + int nmolecules; + tagint idlo,idhi; + + double *massproc,*masstotal; + double **vcm,**vcmall; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Compute vcm/molecule requires molecular atom style + +Self-explanatory. + +E: Molecule count changed in compute vcm/molecule + +Number of molecules must remain constant over time. + +*/