MPS-Basic
Loading...
Searching...
No Matches
bucket.cpp
Go to the documentation of this file.
1#include "bucket.hpp"
2
3using std::cerr;
4using std::endl;
5
6void Bucket::generate(const int& particleNum) {
7 next.resize(particleNum);
8}
9
10Bucket::Bucket(const double& reMax, const Domain& domain, const size_t& particleSize) {
11 this->length = reMax;
12 this->domain = domain;
13
14 this->numX = (int) (domain.xLength / length) + 3;
15 this->numY = (int) (domain.yLength / length) + 3;
16 this->numZ = (int) (domain.zLength / length) + 3;
17 this->num = numX * numY * numZ;
18
19 this->first.resize(num);
20 this->last.resize(num);
21 this->next.resize(particleSize);
22}
23
25
26#pragma omp parallel for
27 for (int i = 0; i < num; i++) {
28 first[i] = -1;
29 last[i] = -1;
30 }
31#pragma omp parallel for
32 for (int i = 0; i < particles.size(); i++) {
33 next[i] = -1;
34 }
35
36 for (auto& p : particles) {
37 if (p.type == ParticleType::Ghost)
38 continue;
39
40 bool isInDomain = true;
41 if (p.position.x() < domain.xMin || domain.xMax < p.position.x())
42 isInDomain = false;
43 if (p.position.y() < domain.yMin || domain.yMax < p.position.y())
44 isInDomain = false;
45 if (p.position.z() < domain.zMin || domain.zMax < p.position.z())
46 isInDomain = false;
47 if (!isInDomain) {
48 cerr << "WARNING: particle " << p.id << " is out of domain." << endl;
49 cerr << "x = " << p.position.x() << " ";
50 cerr << "y = " << p.position.y() << " ";
51 cerr << "z = " << p.position.z() << endl;
52 p.type = ParticleType::Ghost;
53 continue;
54 // std::exit(-1);
55 }
56
57 int ix = (int) ((p.position.x() - domain.xMin) / length) + 1;
58 int iy = (int) ((p.position.y() - domain.yMin) / length) + 1;
59 int iz = (int) ((p.position.z() - domain.zMin) / length) + 1;
60 int iBucket = ix + iy * numX + iz * numX * numY;
61
62 if (last[iBucket] == -1)
63 first[iBucket] = p.id;
64 else
65 next[last[iBucket]] = p.id;
66 last[iBucket] = p.id;
67 }
68}
Bucket()=default
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
int num
Definition bucket.hpp:20
std::vector< int > last
Definition bucket.hpp:23
int numZ
Definition bucket.hpp:20
double length
Definition bucket.hpp:21
std::vector< int > first
Definition bucket.hpp:23
void generate(const int &particleNum)
Definition bucket.cpp:6
int numX
Definition bucket.hpp:20
Domain domain
Definition bucket.hpp:22
represents the domain of the simulation
Definition domain.hpp:8
double xMax
maximum x coordinate of the domain
Definition domain.hpp:12
double zMin
minimum z coordinate of the domain
Definition domain.hpp:15
double zMax
maximum z coordinate of the domain
Definition domain.hpp:16
double xMin
minimum x coordinate of the domain
Definition domain.hpp:11
double yMin
minimum y coordinate of the domain
Definition domain.hpp:13
double zLength
Definition domain.hpp:17
double yLength
Definition domain.hpp:17
double yMax
maximum y coordinate of the domain
Definition domain.hpp:14
double xLength
Definition domain.hpp:17
A collection of particles.
Definition particles.hpp:10
int size() const
Get the number of particles.
Definition particles.cpp:21
@ Ghost
Ghost particle (outside of the domain, not used for calculation)