add new APIs for creating and manipulating neighbor list requests

also add a few new (delegating) constructors to simplify code
This commit is contained in:
Axel Kohlmeyer
2022-03-02 19:12:00 -05:00
parent f7514ce358
commit d4272815a3
4 changed files with 168 additions and 37 deletions

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -13,14 +12,17 @@
------------------------------------------------------------------------- */
#include "neigh_request.h"
#include "atom.h"
#include "memory.h"
#include "neighbor.h"
using namespace LAMMPS_NS;
using namespace NeighConst;
/* ---------------------------------------------------------------------- */
NeighRequest::NeighRequest(LAMMPS *lmp) : Pointers(lmp)
NeighRequest::NeighRequest(LAMMPS *_lmp) : Pointers(_lmp)
{
// default ID = 0
@ -96,9 +98,27 @@ NeighRequest::NeighRequest(LAMMPS *lmp) : Pointers(lmp)
/* ---------------------------------------------------------------------- */
NeighRequest::NeighRequest(LAMMPS *_lmp, int idx, void *ptr, int num)
: NeighRequest(_lmp)
{
index = idx;
requestor = ptr;
requestor_instance = num;
}
/* ---------------------------------------------------------------------- */
NeighRequest::NeighRequest(NeighRequest *old)
: NeighRequest(old->lmp)
{
copy_request(old,1);
}
/* ---------------------------------------------------------------------- */
NeighRequest::~NeighRequest()
{
delete [] iskip;
delete[] iskip;
memory->destroy(ijskip);
}
@ -165,15 +185,13 @@ int NeighRequest::identical(NeighRequest *other)
int NeighRequest::same_skip(NeighRequest *other)
{
int i,j;
int ntypes = atom->ntypes;
const int ntypes = atom->ntypes;
int same = 1;
for (i = 1; i <= ntypes; i++)
for (int i = 1; i <= ntypes; i++)
if (iskip[i] != other->iskip[i]) same = 0;
for (i = 1; i <= ntypes; i++)
for (j = 1; j <= ntypes; j++)
for (int i = 1; i <= ntypes; i++)
for (int j = 1; j <= ntypes; j++)
if (ijskip[i][j] != other->ijskip[i][j]) same = 0;
return same;
@ -206,7 +224,7 @@ void NeighRequest::copy_request(NeighRequest *other, int skipflag)
size = other->size;
history = other->history;
granonesided = other->granonesided;
respainner = other->respainner;
respainner = other->respainner;
respamiddle = other->respamiddle;
respaouter = other->respaouter;
bond = other->bond;
@ -223,22 +241,47 @@ void NeighRequest::copy_request(NeighRequest *other, int skipflag)
if (!skipflag) return;
int i,j;
int i, j;
int ntypes = atom->ntypes;
skip = other->skip;
if (other->iskip) {
iskip = new int[ntypes+1];
for (i = 1; i <= ntypes; i++)
iskip[i] = other->iskip[i];
iskip = new int[ntypes + 1];
for (i = 1; i <= ntypes; i++) iskip[i] = other->iskip[i];
}
if (other->ijskip) {
memory->create(ijskip,ntypes+1,ntypes+1,"neigh_request:ijskip");
memory->create(ijskip, ntypes + 1, ntypes + 1, "neigh_request:ijskip");
for (i = 1; i <= ntypes; i++)
for (j = 1; j <= ntypes; j++)
ijskip[i][j] = other->ijskip[i][j];
for (j = 1; j <= ntypes; j++) ijskip[i][j] = other->ijskip[i][j];
}
}
/* ---------------------------------------------------------------------- */
void NeighRequest::apply_flags(int flags)
{
if (flags & REQ_FULL) {
half = 0;
full = 1;
}
if (flags & REQ_GHOST) { ghost = 1; }
if (flags & REQ_SIZE) { size = 1; }
if (flags & REQ_HISTORY) { history = 1; }
if (flags & REQ_OCCASIONAL) { occasional = 1; }
if (flags & REQ_RESPA_INOUT) { respainner = respaouter = 1; }
if (flags & REQ_RESPA_ALL) { respainner = respamiddle = respaouter = 1; }
}
/* ---------------------------------------------------------------------- */
void NeighRequest::set_id(int _id) {
id = _id;
}
void NeighRequest::set_cutoff(double _cutoff)
{
cut = 1;
cutoff = _cutoff;
}