Commit 4553881f authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #28 from timattox/new-neighbor

New neighbor, USER-DPD updates
parents c9c2ae6c 81fcbcd9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
/*_tally.cpp
/*_rx.h
/*_rx.cpp
/*_ssa.h
/*_ssa.cpp

/kokkos.cpp
/kokkos.h
+129 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   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:
   James Larentzos (ARL) and Timothy I. Mattox (Engility Corporation)
------------------------------------------------------------------------- */

#include "nbin_ssa.h"
#include "atom.h"
#include "group.h"
#include "memory.h"
#include "error.h"

using namespace LAMMPS_NS;

/* ---------------------------------------------------------------------- */

NBinSSA::NBinSSA(LAMMPS *lmp) : NBinStandard(lmp)
{
  maxbin_ssa = 0;
  bins_ssa = NULL;
  maxhead_ssa = 0;
  binhead_ssa = NULL;
  gbinhead_ssa = NULL;
}

NBinSSA::~NBinSSA()
{
  memory->destroy(bins_ssa);
  memory->destroy(binhead_ssa);
  memory->destroy(gbinhead_ssa);
}

/* ----------------------------------------------------------------------
   bin owned and ghost atoms for the Shardlow Splitting Algorithm (SSA)
   local atoms are in distinct bins (binhead_ssa) from the ghosts
   ghost atoms are in distinct bins (gbinhead_ssa) from the locals
     ghosts which are not in an Active Interaction Region (AIR) are skipped
------------------------------------------------------------------------- */

void NBinSSA::bin_atoms()
{
  int i,ibin;
  int nlocal = atom->nlocal;
  int nall = nlocal + atom->nghost;
  if (includegroup) nlocal = atom->nfirst;
  double **x = atom->x;
  int *mask = atom->mask;
  int *ssaAIR = atom->ssaAIR;

  for (i = 0; i < mbins; i++) {
    gbinhead_ssa[i] = -1;
    binhead_ssa[i] = -1;
  }

  // bin in reverse order so linked list will be in forward order

  if (includegroup) {
    int bitmask = group->bitmask[includegroup];
    int nowned = atom->nlocal; // NOTE: nlocal was set to atom->nfirst above
    for (i = nall-1; i >= nowned; i--) {
      if (ssaAIR[i] < 2) continue; // skip ghost atoms not in AIR
      if (mask[i] & bitmask) {
        ibin = coord2bin(x[i]);
        bins_ssa[i] = gbinhead_ssa[ibin];
        gbinhead_ssa[ibin] = i;
      }
    }
  } else {
    for (i = nall-1; i >= nlocal; i--) {
      if (ssaAIR[i] < 2) continue; // skip ghost atoms not in AIR
      ibin = coord2bin(x[i]);
      bins_ssa[i] = gbinhead_ssa[ibin];
      gbinhead_ssa[ibin] = i;
    }
  }
  for (i = nlocal-1; i >= 0; i--) {
    ibin = coord2bin(x[i]);
    bins_ssa[i] = binhead_ssa[ibin];
    binhead_ssa[ibin] = i;
  }
}

/* ---------------------------------------------------------------------- */

void NBinSSA::bin_atoms_setup(int nall)
{
  NBinStandard::bin_atoms_setup(nall); // Setup the parent class's data too

  if (mbins > maxhead_ssa) {
    maxhead_ssa = mbins;
    memory->destroy(gbinhead_ssa);
    memory->destroy(binhead_ssa);
    memory->create(binhead_ssa,maxhead_ssa,"binhead_ssa");
    memory->create(gbinhead_ssa,maxhead_ssa,"gbinhead_ssa");
  }

  if (nall > maxbin_ssa) {
    maxbin_ssa = nall;
    memory->destroy(bins_ssa);
    memory->create(bins_ssa,maxbin_ssa,"bins_ssa");
  }
}

/* ---------------------------------------------------------------------- */

bigint NBinSSA::memory_usage()
{
  bigint bytes = NBinStandard::memory_usage(); // Count the parent's usage too

  if (maxbin_ssa) bytes += memory->usage(bins_ssa,maxbin_ssa);
  if (maxhead_ssa) {
    bytes += memory->usage(binhead_ssa,maxhead_ssa);
    bytes += memory->usage(gbinhead_ssa,maxhead_ssa);
  }
  return bytes;
}
+54 −0
Original line number Diff line number Diff line
/* -*- 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 NBIN_CLASS

NBinStyle(ssa,
          NBinSSA,
          NB_SSA)

#else

#ifndef LMP_NBIN_SSA_H
#define LMP_NBIN_SSA_H

#include "nbin_standard.h"

namespace LAMMPS_NS {

class NBinSSA : public NBinStandard {
 public:

  int *bins_ssa;             // index of next atom in each bin
  int maxbin_ssa;            // size of bins_ssa array
  int *binhead_ssa;          // index of 1st local atom in each bin
  int *gbinhead_ssa;         // index of 1st ghost atom in each bin
  int maxhead_ssa;           // size of binhead_ssa and gbinhead_ssa arrays

  NBinSSA(class LAMMPS *);
  ~NBinSSA();

  void bin_atoms_setup(int);
  void bin_atoms();

  bigint memory_usage();
};

}

#endif
#endif

/* ERROR/WARNING messages:

*/
+19 −70
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#include "npair_half_bin_newton_ssa.h"
#include "neighbor.h"
#include "nstencil_ssa.h"
#include "nbin_ssa.h"
#include "neigh_list.h"
#include "atom.h"
#include "atom_vec.h"
@@ -78,71 +80,18 @@ void NPairHalfBinNewtonSSA::build(NeighList *list)
  int **firstneigh = list->firstneigh;
  MyPage<int> *ipage = list->ipage;

  int inum = 0;

  // bin owned and ghost atoms for use by Shardlow Splitting Algorithm
  // exclude ghost atoms that are not in the Active Interaction Regions (AIR)

  // NOTE to Tim: this binatomflag no longer exists
  //   the logic up higher assures that binning has been done
  //     before this build() method is called
  //   maybe this code below needs to be in a new NBinShardlow class?
  // this class also inherits NPair::nb from its parent
  //   which points to the NBin class that did the binning
  //   there are last_step variables stored there which indicate
  //   the last time binning was done
  // the basic question is what data is created/stored by SSA binning
  //   and in what class should it live?
  //   if it is created by the binning operation, then I think
  //     it should be in a new NBinShardlow class

  if (true /* binatomflag */) { // only false in Neighbor::build_one

    if (mbins > list->maxhead_ssa) {
      list->maxhead_ssa = mbins;
      memory->destroy(list->gbinhead_ssa);
      memory->destroy(list->binhead_ssa);
      memory->create(list->binhead_ssa,list->maxhead_ssa,"binhead_ssa");
      memory->create(list->gbinhead_ssa,list->maxhead_ssa,"gbinhead_ssa");
    }
    for (i = 0; i < mbins; i++) {
      list->gbinhead_ssa[i] = -1;
      list->binhead_ssa[i] = -1;
    }
  NStencilSSA *ns_ssa = dynamic_cast<NStencilSSA*>(ns);
  if (!ns_ssa) error->one(FLERR, "NStencil wasn't a NStencilSSA object");
  int nstencil_half = ns_ssa->nstencil_half;
  int nstencil_full = ns_ssa->nstencil;

    if (nall > list->maxbin_ssa) {
      list->maxbin_ssa = nall;
      memory->destroy(list->bins_ssa);
      memory->create(list->bins_ssa,list->maxbin_ssa,"bins_ssa");
    }

    // bin in reverse order so linked list will be in forward order
  NBinSSA *nb_ssa = dynamic_cast<NBinSSA*>(nb);
  if (!nb_ssa) error->one(FLERR, "NBin wasn't a NBinSSA object");
  int *bins_ssa = nb_ssa->bins_ssa;
  int *binhead_ssa = nb_ssa->binhead_ssa;
  int *gbinhead_ssa = nb_ssa->gbinhead_ssa;

    if (includegroup) {
      int bitmask = group->bitmask[includegroup];
      int nowned = atom->nlocal; // NOTE: nlocal was set to atom->nfirst above
      for (i = nall-1; i >= nowned; i--) {
        if (ssaAIR[i] < 2) continue; // skip ghost atoms not in AIR
        if (mask[i] & bitmask) {
          ibin = coord2bin(x[i]);
          list->bins_ssa[i] = list->gbinhead_ssa[ibin];
          list->gbinhead_ssa[ibin] = i;
        }
      }
    } else {
      for (i = nall-1; i >= nlocal; i--) {
        if (ssaAIR[i] < 2) continue; // skip ghost atoms not in AIR
        ibin = coord2bin(x[i]);
        list->bins_ssa[i] = list->gbinhead_ssa[ibin];
        list->gbinhead_ssa[ibin] = i;
      }
    }
    for (i = nlocal-1; i >= 0; i--) {
      ibin = coord2bin(x[i]);
      list->bins_ssa[i] = list->binhead_ssa[ibin];
      list->binhead_ssa[ibin] = i;
    }
  }  // else reuse previous binning. See Neighbor::build_one comment
  int inum = 0;

  ipage->reset();

@@ -166,7 +115,7 @@ void NPairHalfBinNewtonSSA::build(NeighList *list)
    // loop over rest of local atoms in i's bin
    // just store them, since j is beyond i in linked list

    for (j = list->bins_ssa[i]; j >= 0; j = list->bins_ssa[j]) {
    for (j = bins_ssa[i]; j >= 0; j = bins_ssa[j]) {

      jtype = type[j];
      if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
@@ -197,9 +146,9 @@ void NPairHalfBinNewtonSSA::build(NeighList *list)

    // loop over all local atoms in other bins in "half" stencil

    for (k = 0; k < nstencil; k++) {
      for (j = list->binhead_ssa[ibin+stencil[k]]; j >= 0; 
           j = list->bins_ssa[j]) {
    for (k = 0; k < nstencil_half; k++) {
      for (j = binhead_ssa[ibin+stencil[k]]; j >= 0; 
           j = bins_ssa[j]) {

        jtype = type[j];
        if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
@@ -233,9 +182,9 @@ void NPairHalfBinNewtonSSA::build(NeighList *list)
    // That is a significant time savings because of the "full" stencil
    // Note2: only non-pure locals can have ghosts as neighbors

    if (ssaAIR[i] == 1) for (k = 0; k < nstencil_ssa; k++) {
      for (j = list->gbinhead_ssa[ibin+stencil[k]]; j >= 0; 
           j = list->bins_ssa[j]) {
    if (ssaAIR[i] == 1) for (k = 0; k < nstencil_full; k++) {
      for (j = gbinhead_ssa[ibin+stencil[k]]; j >= 0; 
           j = bins_ssa[j]) {

        jtype = type[j];
        if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@

NPairStyle(half/bin/newton/ssa,
           NPairHalfBinNewtonSSA,
           NP_BIN | NP_NEWTON | NP_ORTHO | NP_SSA)
           NP_HALF | NP_BIN | NP_NEWTON | NP_ORTHO | NP_SSA)

#else

Loading