MPS-Basic
Loading...
Searching...
No Matches
neighbor_searcher.cpp
Go to the documentation of this file.
2
3#include "bucket.hpp"
4
5NeighborSearcher::NeighborSearcher(const double& re, const Domain& domain, const size_t& particleSize) {
6 this->re = re;
7 this->domain = domain;
8 this->bucket = Bucket(re, domain, particleSize);
9}
10
12 bucket.storeParticles(particles);
13
14#pragma omp parallel for
15 for (auto& pi : particles) {
16 if (pi.type == ParticleType::Ghost)
17 continue;
18
19 pi.neighbors.clear();
20
21 int ix = (int) ((pi.position.x() - domain.xMin) / bucket.length) + 1;
22 int iy = (int) ((pi.position.y() - domain.yMin) / bucket.length) + 1;
23 int iz = (int) ((pi.position.z() - domain.zMin) / bucket.length) + 1;
24
25 for (int jx = ix - 1; jx <= ix + 1; jx++) {
26 for (int jy = iy - 1; jy <= iy + 1; jy++) {
27 for (int jz = iz - 1; jz <= iz + 1; jz++) {
28 int jBucket = jx + jy * bucket.numX + jz * bucket.numX * bucket.numY;
29 int j = bucket.first[jBucket];
30
31 while (j != -1) {
32 Particle& pj = particles[j];
33
34 double dist = (pj.position - pi.position).norm();
35 if (j != pi.id && dist < re) {
36 pi.neighbors.emplace_back(j, dist);
37 }
38
39 j = bucket.next[j];
40 }
41 }
42 }
43 }
44 }
45}
Class for bucket for neighbor search.
Definition bucket.hpp:17
void storeParticles(Particles &particles)
store particles in the bucket
Definition bucket.cpp:24
std::vector< int > next
Definition bucket.hpp:23
int numY
Definition bucket.hpp:20
double length
Definition bucket.hpp:21
std::vector< int > first
Definition bucket.hpp:23
int numX
Definition bucket.hpp:20
represents the domain of the simulation
Definition domain.hpp:8
double zMin
minimum z coordinate of the domain
Definition domain.hpp:15
double xMin
minimum x coordinate of the domain
Definition domain.hpp:11
double yMin
minimum y coordinate of the domain
Definition domain.hpp:13
NeighborSearcher()=default
void setNeighbors(Particles &particles)
Class for particle in MPS method.
Definition particle.hpp:47
Eigen::Vector3d position
position of the particle
Definition particle.hpp:55
A collection of particles.
Definition particles.hpp:10
@ Ghost
Ghost particle (outside of the domain, not used for calculation)