diff --git a/doc/src/Commands_compute.rst b/doc/src/Commands_compute.rst index 755000c976..a2d0fd3823 100644 --- a/doc/src/Commands_compute.rst +++ b/doc/src/Commands_compute.rst @@ -91,6 +91,7 @@ KOKKOS, o = OPENMP, t = OPT. * :doc:`ke/atom/eff ` * :doc:`ke/eff ` * :doc:`ke/rigid ` + * :doc:`local/comp/atom ` * :doc:`mliap ` * :doc:`momentum ` * :doc:`msd ` diff --git a/doc/src/compute.rst b/doc/src/compute.rst index 950487cb72..2862e94b02 100644 --- a/doc/src/compute.rst +++ b/doc/src/compute.rst @@ -245,6 +245,7 @@ The individual style names on the :doc:`Commands compute ` pag * :doc:`ke/atom/eff ` - per-atom translational and radial kinetic energy in the electron force field model * :doc:`ke/eff ` - kinetic energy of a group of nuclei and electrons in the electron force field model * :doc:`ke/rigid ` - translational kinetic energy of rigid bodies +* :doc:`local/comp/atom ` - local composition for each atom * :doc:`mliap ` - gradients of energy and forces with respect to model parameters and related quantities for training machine learning interatomic potentials * :doc:`momentum ` - translational momentum * :doc:`msd ` - mean-squared displacement of group of atoms diff --git a/doc/src/compute_local_composition_atom.rst b/doc/src/compute_local_comp_atom.rst similarity index 72% rename from doc/src/compute_local_composition_atom.rst rename to doc/src/compute_local_comp_atom.rst index 96e422122b..ad9331895e 100644 --- a/doc/src/compute_local_composition_atom.rst +++ b/doc/src/compute_local_comp_atom.rst @@ -1,20 +1,17 @@ -.. index:: compute ave/sphere/atom -.. index:: compute local_composition/atom/kk +.. index:: compute local/comp/atom -compute local_composition/atom command -================================ - -Accelerator Variants: *local_composition/atom/kk* +compute local/comp/atom command +====================================== Syntax """""" .. code-block:: LAMMPS - compute ID group-ID local_composition/atom keyword values ... + compute ID group-ID local/comp/atom keyword values ... * ID, group-ID are documented in :doc:`compute ` command -* local_composition/atom = style name of this compute command +* local/comp/atom = style name of this compute command * one or more keyword/value pairs may be appended .. parsed-literal:: @@ -27,9 +24,9 @@ Examples .. code-block:: LAMMPS - compute 1 all local_composition/atom + compute 1 all local/comp/atom - compute 1 all local_composition/atom cutoff 9.0 + compute 1 all local/comp/atom cutoff 9.0 comm_modify cutoff 9.0 @@ -38,12 +35,11 @@ Description .. versionadded:: 24May2023 -Define a computation that calculates the local composition of atom types for a -central atom based on its neighbors inside a spherical cutoff. For a simulation with -:math:`N` atom types and an atom with :math:`M` neighbors within the cutoff, the -fraction of each atom type is counted and divided by the total number of atoms in the -sphere, including the central atom (:math:`M+1`). The sum of all fractions will -always add to one. +Define a computation that calculates a local composition vector for each +atom. For a central atom with :math:`M` neighbors within the neighbor cutoff sphere, +composition is defined as the number of atoms of a given type +(including the central atom) divided by (:math:`M+1`). For a given central atom, +the sum of all compositions equals one. .. note:: @@ -89,16 +85,13 @@ too frequently. ---------- - -.. include:: accel_styles.rst - - ----------- - Output info """"""""""" -This compute calculates a per-atom array with :math:`1 + N` columns, where :math:`N` is the number of atom types. The first column is a count of the number of atoms used to calcuate composition (including the central atom), and each subsequent column indicates the fraction of that atom type detected within the cutoff range. +This compute calculates a per-atom array with :math:`1 + N` columns, where :math:`N` +is the number of atom types. The first column is a count of the number of atoms +used to calculate composition (including the central atom), and each subsequent +column indicates the fraction of that atom type within the cutoff sphere. These values can be accessed by any command that uses per-atom values from a compute as input. See the :doc:`Howto output ` diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index d2d15633af..6c53226332 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3611,6 +3611,7 @@ Tk Tkin tloop tlsph +tm tmax Tmax tmd @@ -3736,6 +3737,7 @@ Umin un unary uncomment +uncommented uncompress uncompute underprediction diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp similarity index 71% rename from src/EXTRA-COMPUTE/compute_local_composition_atom.cpp rename to src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index ba3e40d8c8..50ad3ce72c 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -15,7 +15,7 @@ Contributing author: Stan Moore (SNL) ------------------------------------------------------------------------- */ -#include "compute_local_composition_atom.h" +#include "compute_local_comp_atom.h" #include "atom.h" #include "comm.h" @@ -37,40 +37,24 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -ComputeLocalCompositionAtom::ComputeLocalCompositionAtom(LAMMPS *lmp, int narg, char **arg) : +ComputeLocalCompAtom::ComputeLocalCompAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), result(nullptr) { - if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute local_composition/atom command"); - - // get nelements and ntypes + if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute local/comp/atom command"); int ntypes = atom->ntypes; - // memory->create(map, ntypes + 1, "compute_sna_grid:map"); - // nelements = utils::inumeric(FLERR, 0, false, lmp); // !!!!!!!! what is 2nd arg in inumeric? - // for (int i = 0; i < ntypes; i++) { - // int jelem = utils::inumeric(FLERR, i, false, lmp); - // if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); - // map[i + 1] = jelem; - // printf("mapp[x] %d jelem %d \n", map[i + 1], jelem); - // } - - // printf("ntypes %d \n", ntypes); - // printf("elements %d \n", nelements); - - // process optional args - cutoff = 0.0; int iarg = 3; while (iarg < narg) { if (strcmp(arg[iarg], "cutoff") == 0) { - if (iarg + 2 > narg) error->all(FLERR, "Illegal compute local_composition/atom command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute local/comp/atom command"); cutoff = utils::numeric(FLERR, arg[iarg + 1], false, lmp); - if (cutoff <= 0.0) error->all(FLERR, "Illegal compute local_composition/atom command"); + if (cutoff <= 0.0) error->all(FLERR, "Illegal compute local/comp/atom command"); iarg += 2; } else - error->all(FLERR, "Illegal compute local_composition/atom command"); + error->all(FLERR, "Illegal compute local/comp/atom command"); } peratom_flag = 1; @@ -82,21 +66,20 @@ ComputeLocalCompositionAtom::ComputeLocalCompositionAtom(LAMMPS *lmp, int narg, /* ---------------------------------------------------------------------- */ -ComputeLocalCompositionAtom::~ComputeLocalCompositionAtom() +ComputeLocalCompAtom::~ComputeLocalCompAtom() { if (copymode) return; memory->destroy(result); - // memory->destroy(map); } /* ---------------------------------------------------------------------- */ -void ComputeLocalCompositionAtom::init() +void ComputeLocalCompAtom::init() { if (!force->pair && cutoff == 0.0) error->all(FLERR, - "Compute local_composition/atom requires a cutoff be specified " + "Compute local/comp/atom requires a cutoff be specified " "or a pair style be defined"); double skin = neighbor->skin; @@ -109,7 +92,7 @@ void ComputeLocalCompositionAtom::init() if (cutoff > cutghost) error->all(FLERR, - "Compute local_composition/atom cutoff exceeds ghost atom range - " + "Compute local/comp/atom cutoff exceeds ghost atom range - " "use comm_modify cutoff command"); } @@ -120,10 +103,6 @@ void ComputeLocalCompositionAtom::init() } cutsq = cutoff * cutoff; - if (domain->dimension == 3) - volume = 4.0 / 3.0 * MY_PI * cutsq * cutoff; - else - volume = MY_PI * cutsq; // need an occasional full neighbor list @@ -133,19 +112,19 @@ void ComputeLocalCompositionAtom::init() /* ---------------------------------------------------------------------- */ -void ComputeLocalCompositionAtom::init_list(int /*id*/, NeighList *ptr) +void ComputeLocalCompAtom::init_list(int /*id*/, NeighList *ptr) { list = ptr; } /* ---------------------------------------------------------------------- */ -void ComputeLocalCompositionAtom::compute_peratom() +void ComputeLocalCompAtom::compute_peratom() { int i, j, ii, jj, inum, jnum; double xtmp, ytmp, ztmp, delx, dely, delz, rsq; int *ilist, *jlist, *numneigh, **firstneigh; - int count; + int count, itype, jtype; invoked_peratom = update->ntimestep; @@ -154,7 +133,7 @@ void ComputeLocalCompositionAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(result); nmax = atom->nmax; - memory->create(result, nmax, size_peratom_cols, "local_composition/atom:result"); + memory->create(result, nmax, size_peratom_cols, "local/comp/atom:result"); array_atom = result; } @@ -176,11 +155,9 @@ void ComputeLocalCompositionAtom::compute_peratom() int typeone_i, typeone_j; - // TODO continue to implement map (nelements instead of ntypes) - int ntypes = atom->ntypes; - double lcomp[ntypes]; + int lcomp[ntypes]; // get per-atom local compositions @@ -202,14 +179,14 @@ void ComputeLocalCompositionAtom::compute_peratom() count = 1; - typeone_i = type[i]; - lcomp[typeone_i - 1]++; + itype = type[i]; + lcomp[itype-1]++; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; - typeone_j = type[j]; + jtype = type[j]; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; @@ -217,7 +194,7 @@ void ComputeLocalCompositionAtom::compute_peratom() rsq = delx * delx + dely * dely + delz * delz; if (rsq < cutsq) { count++; - lcomp[typeone_j-1]++; + lcomp[jtype-1]++; } } @@ -225,10 +202,12 @@ void ComputeLocalCompositionAtom::compute_peratom() result[i][0] = count; - // local composition fractions per element - for (int n = 0; n < ntypes; n++) { - result[i][n + 1] = lcomp[n] / count; - } + // local comp fractions per element + + double lfac = 1.0 / count; + for (int n = 0; n < ntypes; n++) + result[i][n+1] = lcomp[n] * lfac; + } } } @@ -237,7 +216,7 @@ void ComputeLocalCompositionAtom::compute_peratom() memory usage of local atom-based array ------------------------------------------------------------------------- */ -double ComputeLocalCompositionAtom::memory_usage() +double ComputeLocalCompAtom::memory_usage() { double bytes = (double) 2 * nmax * sizeof(double); return bytes; diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.h b/src/EXTRA-COMPUTE/compute_local_comp_atom.h similarity index 71% rename from src/EXTRA-COMPUTE/compute_local_composition_atom.h rename to src/EXTRA-COMPUTE/compute_local_comp_atom.h index 64498b6640..22e40edab9 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.h +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.h @@ -13,21 +13,21 @@ #ifdef COMPUTE_CLASS // clang-format off -ComputeStyle(local_composition/atom,ComputeLocalCompositionAtom); +ComputeStyle(local/comp/atom,ComputeLocalCompAtom); // clang-format on #else -#ifndef LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_H -#define LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_H +#ifndef LMP_COMPUTE_LOCAL_COMP_ATOM_H +#define LMP_COMPUTE_LOCAL_COMP_ATOM_H #include "compute.h" namespace LAMMPS_NS { -class ComputeLocalCompositionAtom : public Compute { +class ComputeLocalCompAtom : public Compute { public: - ComputeLocalCompositionAtom(class LAMMPS *, int, char **); - ~ComputeLocalCompositionAtom() override; + ComputeLocalCompAtom(class LAMMPS *, int, char **); + ~ComputeLocalCompAtom() override; void init() override; void init_list(int, class NeighList *) override; void compute_peratom() override; @@ -37,9 +37,6 @@ class ComputeLocalCompositionAtom : public Compute { int nmax; double cutoff; // global cutoff distance double cutsq; // cutoff**2 - double volume; // local volume - double nelements; // number of elements - int *map; // map types to [0,nelements) class NeighList *list; // neighbor list double **result; // peratom array of local compositions diff --git a/src/KOKKOS/compute_local_composition_atom.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp similarity index 77% rename from src/KOKKOS/compute_local_composition_atom.cpp rename to src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 1c52d6c948..7ee63eafea 100644 --- a/src/KOKKOS/compute_local_composition_atom.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -12,10 +12,10 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Stan Moore (SNL) + Contributing author: Stan Moore (SNL), Megan McCarthy (SNL) ------------------------------------------------------------------------- */ -#include "compute_local_composition_kokkos.h" +#include "compute_local_comp_atom_kokkos.h" #include "atom_kokkos.h" #include "atom_masks.h" @@ -39,8 +39,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ template -ComputeLocalCompositionKokkos::ComputeLocalCompositionKokkos(LAMMPS *lmp, int narg, char **arg) : - ComputeLocalComposition(lmp, narg, arg) +ComputeLocalCompAtomKokkos::ComputeLocalCompAtomKokkos(LAMMPS *lmp, int narg, char **arg) : + ComputeLocalCompAtom(lmp, narg, arg) { kokkosable = 1; atomKK = (AtomKokkos *) atom; @@ -52,7 +52,7 @@ ComputeLocalCompositionKokkos::ComputeLocalCompositionKokkos(LAMMPS /* ---------------------------------------------------------------------- */ template -ComputeLocalCompositionKokkos::~ComputeLocalCompositionKokkos() +ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() { if (copymode) return; @@ -62,9 +62,9 @@ ComputeLocalCompositionKokkos::~ComputeLocalCompositionKokkos() /* ---------------------------------------------------------------------- */ template -void ComputeLocalCompositionKokkos::init() +void ComputeLocalCompAtomKokkos::init() { - ComputeLocalComposition::init(); + ComputeLocalCompAtom::init(); // adjust neighbor list request for KOKKOS @@ -77,7 +77,7 @@ void ComputeLocalCompositionKokkos::init() /* ---------------------------------------------------------------------- */ template -void ComputeLocalCompositionKokkos::compute_peratom() +void ComputeLocalCompAtomKokkos::compute_peratom() { invoked_peratom = update->ntimestep; @@ -86,17 +86,11 @@ void ComputeLocalCompositionKokkos::compute_peratom() if (atom->nmax > nmax) { memoryKK->destroy_kokkos(k_result,result); nmax = atom->nmax; - memoryKK->create_kokkos(k_result,result,nmax,2,"local_composition/atom:result"); + memoryKK->create_kokkos(k_result,result,nmax,2,"local/comp/atom:result"); d_result = k_result.view(); array_atom = result; } - // // need velocities of ghost atoms - - // atomKK->sync(Host,V_MASK); - // comm->forward_comm(this); - // atomKK->modified(Host,V_MASK); - // invoke full neighbor list (will copy or build if necessary) neighbor->build_one(list); @@ -119,8 +113,8 @@ void ComputeLocalCompositionKokkos::compute_peratom() Kokkos::deep_copy(d_result,0.0); copymode = 1; - typename Kokkos::RangePolicy policy(0,inum); - Kokkos::parallel_for("ComputeLocalComposition",policy,*this); + typename Kokkos::RangePolicy policy(0,inum); + Kokkos::parallel_for("ComputeLocalComp",policy,*this); copymode = 0; k_result.modify(); @@ -129,13 +123,11 @@ void ComputeLocalCompositionKokkos::compute_peratom() template KOKKOS_INLINE_FUNCTION -void ComputeLocalCompositionKokkos::operator()(TagComputeLocalComposition, const int &ii) const +void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalComp, const int &ii) const { double typeone_i, typeone_j; - // TODO continue to implement map (nelements instead of ntypes) - - double lcomp[ntypes]; + int lcomp[ntypes]; // get per-atom local compositions @@ -156,13 +148,13 @@ void ComputeLocalCompositionKokkos::operator()(TagComputeLocalCompos int count = 1; - typeone_i = type[i]; + itype = type[i]; for (int jj = 0; jj < jnum; jj++) { int j = d_neighbors(i,jj); j &= NEIGHMASK; - typeone_j = type[j]; + jtype = type[j]; const F_FLOAT delx = x(j,0) - xtmp; const F_FLOAT dely = x(j,1) - ytmp; @@ -170,7 +162,7 @@ void ComputeLocalCompositionKokkos::operator()(TagComputeLocalCompos const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; if (rsq < cutsq) { count++; - lcomp[typeone_j]++; + lcomp[jtype]++; } } for (int n = 0 n < 4; n++) { @@ -181,8 +173,8 @@ void ComputeLocalCompositionKokkos::operator()(TagComputeLocalCompos } namespace LAMMPS_NS { -template class ComputeLocalCompositionKokkos; +template class ComputeLocalCompAtomKokkos; #ifdef LMP_KOKKOS_GPU -template class ComputeLocalCompositionKokkos; +template class ComputeLocalCompAtomKokkos; #endif } diff --git a/src/KOKKOS/compute_local_composition_atom.h b/src/KOKKOS/compute_local_comp_atom_kokkos.h similarity index 60% rename from src/KOKKOS/compute_local_composition_atom.h rename to src/KOKKOS/compute_local_comp_atom_kokkos.h index fb0c914b36..5f9baa2af0 100644 --- a/src/KOKKOS/compute_local_composition_atom.h +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.h @@ -13,45 +13,42 @@ #ifdef COMPUTE_CLASS // clang-format off -ComputeStyle(local_composition/atom/kk,ComputeLocalCompositionAtomKokkos); -ComputeStyle(local_composition/atom/kk/device,ComputeLocalCompositionAtomKokkos); -ComputeStyle(local_composition/atom/kk/host,ComputeLocalCompositionAtomKokkos); +ComputeStyle(local/comp/atom/kk,ComputeLocalCompAtomKokkos); +ComputeStyle(local/comp/atom/kk/device,ComputeLocalCompAtomKokkos); +ComputeStyle(local/comp/atom/kk/host,ComputeLocalCompAtomKokkos); // clang-format on #else -#ifndef LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_KOKKOS_H -#define LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_KOKKOS_H +#ifndef LMP_COMPUTE_LOCAL_COMP_ATOM_KOKKOS_H +#define LMP_COMPUTE_LOCAL_COMP_ATOM_KOKKOS_H -#include "compute_local_composition_atom.h" +#include "compute_local_comp_atom.h" #include "kokkos_type.h" namespace LAMMPS_NS { // clang-format off -struct TagComputeLocalCompositionAtom {}; +struct TagComputeLocalCompAtom {}; // clang-format on -template class ComputeLocalCompositionAtomKokkos : public ComputeLocalCompositionAtom { +template class ComputeLocalCompAtomKokkos : public ComputeLocalCompAtom { public: typedef DeviceType device_type; typedef ArrayTypes AT; - ComputeLocalCompositionAtomKokkos(class LAMMPS *, int, char **); - ~ComputeLocalCompositionAtomKokkos() override; + ComputeLocalCompAtomKokkos(class LAMMPS *, int, char **); + ~ComputeLocalCompAtomKokkos() override; void init() override; void compute_peratom() override; KOKKOS_INLINE_FUNCTION - void operator()(TagComputeLocalCompositionAtom, const int &) const; + void operator()(TagComputeLocalCompAtom, const int &) const; private: - double adof, mvv2e, mv2d, boltz; typename AT::t_x_array x; typename AT::t_v_array v; - typename ArrayTypes::t_float_1d rmass; - typename ArrayTypes::t_float_1d mass; typename ArrayTypes::t_int_1d type; typename ArrayTypes::t_int_1d mask;