29 const std::vector<Atom> & atoms,
36 domainSize = 2.0f*glm::vec3(
r,
r,
r);
43 minPoint =
min(atoms);
44 length =
max(atoms)-minPoint;
49 nx = length.x / domainSize.x;
50 ny = length.y / domainSize.y;
51 nz = length.z / domainSize.z;
63 void build(
const std::vector<Atom> & atoms)
65 domainAssignments = std::vector<uint64_t>(atoms.size(),
NULL_INDEX);
68 domainAssignments[
i] = std::min(hash(atoms[
i].position),
uint64_t(domains.size()-1));
69 domains[domainAssignments[
i]].push_back(
i);
81 domains = std::vector<std::vector<uint64_t>>(nx*ny*nz);
82 for (
auto &
domain : domains)
84 domain.reserve(2*std::ceil(domainSize.x*domainSize.y*domainSize.z*0.74048));
86 domainAssignments = std::vector<uint64_t>(domainAssignments.size(),
NULL_INDEX);
110 const std::vector<Atom> & atoms,
117 std::map<uint64_t, float> n;
119 auto wrap = [](
int i,
int m){
return ((
i %
m) +
m) %
m; };
121 auto coords = domainCoords(position);
123 float halfWidth = 0.5f*std::min(std::min(length.x, length.y), length.z);
129 cutoff = std::min(
cutoff, std::max(std::max(length.x, length.y), length.z));
136 for (
int i = -
sx;
i <=
sx;
i++)
139 for (
int j = -
sy;
j <=
sy;
j++)
142 for (
int k = -
sz;
k <=
sz;
k++)
145 if (
w > domains.size()) {
continue; }
146 for (
const auto & index : domains[
w])
148 if (index > atoms.size()) {
break; }
149 glm::vec3
r = position-atoms[index].position;
152 for (
uint8_t c = 0; c < 3; c++)
154 if (
r[c] > length[c]*0.5f) {
r[c] =
r[c]-length[c]; }
155 if (
r[c] <= -length[c]*0.5f) {
r[c] =
r[c]+length[c]; }
158 float d2 = glm::dot(
r,
r);
161 n.insert({index, std::sqrt(
d2)});
167 std::vector<std::pair<uint64_t, float>>
nd(n.begin(), n.end());
174 const std::pair<uint64_t, float> & a,
175 const std::pair<uint64_t, float> & b
176 ) { return a.second == b.second ? a.first < b.first : a.second < b.second; }
196 const std::vector<Atom> & atoms,
206 glm::vec3
r = position-atoms[
i].position;
209 for (
uint8_t c = 0; c < 3; c++)
211 if (
r[c] > length[c]*0.5f) {
r[c] =
r[c]-length[c]; }
212 if (
r[c] <= -length[c]*0.5f) {
r[c] =
r[c]+length[c]; }
215 float d2 = glm::dot(
r,
r);
227 const std::pair<uint64_t, float> & a,
228 const std::pair<uint64_t, float> & b
229 ) { return a.second == b.second ? a.first < b.first : a.second < b.second; }
240 glm::vec3 domainSize;
242 std::vector<std::vector<uint64_t>> domains;
243 std::vector<uint64_t> domainAssignments;
245 inline glm::vec<3, uint64_t, glm::packed_highp> domainCoords(
const glm::vec3 & position)
const
247 return glm::floor((position-minPoint)/domainSize);
250 inline uint64_t hash(
const glm::vec3 & position)
const
252 auto c = domainCoords(position);
253 return c.x*ny*nz+c.y*nz+c.z;
glm::vec3 max(const std::vector< Atom > &atoms)
Calculate the maximum positions of some Atoms.
Definition atom.h:176
glm::vec3 min(const std::vector< Atom > &atoms)
Calculate the minimum positions of some Atoms.
Definition atom.h:157
float largest(const std::vector< Atom > &atoms)
Calculate the largest Atom.
Definition atom.h:232
Calculate neighbour lists.
Definition neighbours.h:18
std::vector< std::pair< uint64_t, float > > neighboursDirect(const std::vector< Atom > &atoms, glm::vec3 position, float cutoff, bool nearestImage=true) const
Get the neighbours to a position within a cutoff by a direct evaluation.
Definition neighbours.h:195
Neighbours(const std::vector< Atom > &atoms, float domainSideLength=-1.0)
Construct a Neighbour list from some Atoms.
Definition neighbours.h:28
std::vector< std::pair< uint64_t, float > > neighbours(const std::vector< Atom > &atoms, glm::vec3 position, float cutoff, bool noDirect=false, bool nearestImage=true) const
Get the neighbours to a position within a cutoff using the spatial domains.
Definition neighbours.h:109
void build(const std::vector< Atom > &atoms)
Build the neighbour list from some Atoms.
Definition neighbours.h:63
void clear()
Reset the spatial domains.
Definition neighbours.h:77
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
constexpr uint64_t NULL_INDEX
An index reserved for a NULL value.
Definition constants.h:11