diff --git a/src/VORONOI/Install.sh b/src/VORONOI/Install.sh new file mode 100755 index 0000000000000000000000000000000000000000..0942ac6cfbdb6214bdced7cdf5a52077ea316ef7 --- /dev/null +++ b/src/VORONOI/Install.sh @@ -0,0 +1,36 @@ +# Install/unInstall package files in LAMMPS +# edit 2 Makefile.package files to include/exclude package info + +if (test $1 = 1) then + + if (test -e ../Makefile.package) then + sed -i -e 's/[^ \t]*voronoi[^ \t]* //g' ../Makefile.package + sed -i -e 's|^PKG_SYSINC =[ \t]*|&$(voronoi_SYSINC) |' ../Makefile.package + sed -i -e 's|^PKG_SYSLIB =[ \t]*|&$(voronoi_SYSLIB) |' ../Makefile.package + sed -i -e 's|^PKG_SYSPATH =[ \t]*|&$(voronoi_SYSPATH) |' ../Makefile.package + fi + + if (test -e ../Makefile.package.settings) then + sed -i -e '/^include.*VORONOI.*$/d' ../Makefile.package.settings + # multiline form needed for BSD sed on Macs + sed -i -e '4 i \ +include ..\/VORONOI\/Makefile.lammps +' ../Makefile.package.settings + fi + + cp compute_voronoi_atom.h .. + cp compute_voronoi_atom.cpp .. + +elif (test $1 = 0) then + + if (test -e ../Makefile.package) then + sed -i -e 's/[^ \t]*voronoi[^ \t]* //g' ../Makefile.package + fi + + if (test -e ../Makefile.package.settings) then + sed -i -e '/^include.*VORONOI.*$/d' ../Makefile.package.settings + fi + + rm -f ../compute_voronoi_atom.h + rm -f ../compute_voronoi_atom.cpp +fi diff --git a/src/VORONOI/Makefile.lammps b/src/VORONOI/Makefile.lammps new file mode 100644 index 0000000000000000000000000000000000000000..33f33d095d2daf37a212c459452e88a4360a4841 --- /dev/null +++ b/src/VORONOI/Makefile.lammps @@ -0,0 +1,20 @@ +# This file contains the hooks to build and link LAMMPS with the Voro++ +# library so that a LAMMPS input script can calculate a Voronoi tesselation, +# via the compute voronoi/atom command. +# +# See the README in this directory for more info on installing Voro++. +# +# When you build LAMMPS with the VORONOI package installed, it will use the +# 3 settings in this file. They should be set as follows. +# +# voronoi_SYSINC = a path to the Voro++ include files +# voronoi_SYSLIB = the Voro++ library +# voronoi_SYSPATH = a path to the Voro++ library + +# ----------------------------------------------------------- + +# Settings that the LAMMPS build will import when this package is installed + +voronoi_SYSINC = -I/usr/local/include/voro++ +voronoi_SYSLIB = -lvoro++ +voronoi_SYSPATH = -L/usr/local/lib diff --git a/src/VORONOI/README b/src/VORONOI/README new file mode 100644 index 0000000000000000000000000000000000000000..89cf838b4596d48267aea7ab1ce56f9ab8856255 --- /dev/null +++ b/src/VORONOI/README @@ -0,0 +1,37 @@ +The VORONOI package adds a compute voronoi/atom command which +calculates a Voronoi tesselation of the system. + +It uses the Voro++ library, available at http://math.lbl.gov/voro++ to +compute the tesselation locally on each processor. + +== Installation of the Voro++ library == + +1. Download Voro++ at http://math.lbl.gov/voro++/download + which gives instructions for using SVN to check-out the source: + % svn checkout https://codeforge.lbl.gov/anonscm/voro/trunk + +2. compile Voro++ + % make + +3. install Voro++ at the default location (/usr/local) + % sudo make install + +3b. ..or change the PREFIX variable in the config.mk file + to a location that is writable by the user i.e. + PREFIX=/home/maxuser/install/ + +4. In the LAMMPS src directory add the VORONOI package + % make yes-voronoi + +4b. if a different PREFIX than the default was used to install Voro++ + update the paths in the src/VORONOI/Makefile.lammps file + +5. Compile LAMMPS (you should know how that works) + + +== Credits and license == + +This compute was written by Daniel Schwen (daniel@schwen.de) and is +licensed under the GPLv2 license. + +Please contribute changes back to the community. diff --git a/src/VORONOI/compute_voronoi_atom.cpp b/src/VORONOI/compute_voronoi_atom.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d430dea3c74ac2f9762e7ca667b4f4b161157ff --- /dev/null +++ b/src/VORONOI/compute_voronoi_atom.cpp @@ -0,0 +1,143 @@ +/* ---------------------------------------------------------------------- + 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 author: Daniel Schwen +------------------------------------------------------------------------- */ + +#include "math.h" +#include "string.h" +#include "stdlib.h" +#include "compute_voronoi_atom.h" +#include "atom.h" +#include "update.h" +#include "modify.h" +#include "domain.h" +#include "memory.h" +#include "error.h" +#include "comm.h" + +#include <vector> +#include "voro++.hh" + +using namespace LAMMPS_NS; +using namespace voro; + +/* ---------------------------------------------------------------------- */ + +ComputeVoronoi::ComputeVoronoi(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg) +{ + if (narg != 3) error->all(FLERR,"Illegal compute voronoi/atom command"); + + peratom_flag = 1; + size_peratom_cols = 2; + + nmax = 0; + voro = NULL; +} + +/* ---------------------------------------------------------------------- */ + +ComputeVoronoi::~ComputeVoronoi() +{ + memory->destroy(voro); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeVoronoi::init() +{ + if (domain->dimension != 3) + error->all(FLERR,"Compute voronoi/atom not allowed for 2d systems"); + if (domain->triclinic != 0) + error->all(FLERR,"Compute voronoi/atom not allowed for triclinic boxes"); + + int count = 0; + for (int i = 0; i < modify->ncompute; i++) + if (strcmp(modify->compute[i]->style,"voronoi/atom") == 0) count++; + if (count > 1 && comm->me == 0) + error->warning(FLERR,"More than one compute voronoi/atom command"); +} + +/* ---------------------------------------------------------------------- + gather compute vector data from other nodes +------------------------------------------------------------------------- */ + +void ComputeVoronoi::compute_peratom() +{ + int i; + + invoked_peratom = update->ntimestep; + + // grow per atom array if necessary + + int local = atom->nlocal; + if (nlocal > nmax) { + memory->destroy(voro); + nmax = atom->nmax; + memory->create(voro,nmax,size_peratom_cols,"voronoi/atom:voro"); + array_atom = voro; + } + + // n = # of voro++ spatial hash cells + // TODO: make square + + int nall = nlocal + atom->nghost; + int n = int(floor( pow( double(nall)/8.0, 0.333333 ) )); + n = (n==0) ? 1 : n; + + // initialize voro++ container + // preallocates 8 atoms per cell + // voro++ allocates more memory if needed + + double *sublo = domain->sublo; + double *subhi = domain->subhi; + double *cut = comm->cutghost; + + container con(sublo[0]-cut[0],subhi[0]+cut[0], + sublo[1]-cut[1],subhi[1]+cut[1], + sublo[2]-cut[2],subhi[2]+cut[2], + n,n,n,false,false,false,8); + + // pass coordinates for local and ghost atoms to voro++ + + double **x = atom->x; + for (i = 0; i < nall; i++) + con.put(i,x[i][0],x[i][1],x[i][2]); + + // invoke voro++ and fetch results for owned atoms in group + + std::vector<int> neigh; + + voronoicell_neighbor c; + c_loop_all cl(con); + if (cl.start()) do if (con.compute_cell(c,cl)) { + i = cl.pid(); + if (i < nlocal && (mask[i] & groupbit)) { + voro[i][0] = c.volume(); + c.neighbors(neigh); + voro[i][1] = neigh.size(); + } else if (i < nlocal) voro[i][0] = voro[i][1] = 0.0; + } while (cl.inc()); +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based array +------------------------------------------------------------------------- */ + +double ComputeVoronoi::memory_usage() +{ + double bytes = size_peratom_cols * nmax * sizeof(double); + return bytes; +} diff --git a/src/VORONOI/compute_voronoi_atom.h b/src/VORONOI/compute_voronoi_atom.h new file mode 100644 index 0000000000000000000000000000000000000000..d285860e6cd3dec20b2923cf0eac999d1ae3cb28 --- /dev/null +++ b/src/VORONOI/compute_voronoi_atom.h @@ -0,0 +1,53 @@ +/* ---------------------------------------------------------------------- + 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(voronoi/atom,ComputeVoronoi) + +#else + +#ifndef LMP_COMPUTE_VORONOI_H +#define LMP_COMPUTE_VORONOI_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeVoronoi : public Compute { + public: + ComputeVoronoi(class LAMMPS *, int, char **); + ~ComputeVoronoi(); + void init(); + void compute_peratom(); + double memory_usage(); + + private: + int nmax; + double **voro; +}; + +} + +#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. + +*/