MPS-Basic
Loading...
Searching...
No Matches
Bucket Class Reference

Class for bucket for neighbor search. More...

#include <bucket.hpp>

Collaboration diagram for Bucket:

Public Member Functions

 Bucket ()=default
 
 Bucket (const double &reMax, const Domain &domain, const size_t &particleSize)
 
void generate (const int &particleNum)
 
void storeParticles (Particles &particles)
 store particles in the bucket
 

Public Attributes

int num {}
 
int numX {}
 
int numY {}
 
int numZ {}
 
double length {}
 
Domain domain {}
 
std::vector< int > next
 
std::vector< int > first
 
std::vector< int > last
 

Detailed Description

Class for bucket for neighbor search.

This class is used for neighbor search in particle method. In particle method, neighbor search is required for calculating interaction between particles. Each particle is stored in the bucket, bucket is used for searching neighbor particles.

Definition at line 17 of file bucket.hpp.

Constructor & Destructor Documentation

◆ Bucket() [1/2]

Bucket::Bucket ( )
default

◆ Bucket() [2/2]

Bucket::Bucket ( const double & reMax,
const Domain & domain,
const size_t & particleSize )

Definition at line 10 of file bucket.cpp.

10 {
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}
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
int numX
Definition bucket.hpp:20
Domain domain
Definition bucket.hpp:22
double zLength
Definition domain.hpp:17
double yLength
Definition domain.hpp:17
double xLength
Definition domain.hpp:17

Member Function Documentation

◆ generate()

void Bucket::generate ( const int & particleNum)

Definition at line 6 of file bucket.cpp.

6 {
7 next.resize(particleNum);
8}

◆ storeParticles()

void Bucket::storeParticles ( Particles & particles)

store particles in the bucket

Parameters
particlesparticles to be stored
domaindomain of the simulation

Definition at line 24 of file bucket.cpp.

24 {
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}
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 yMax
maximum y coordinate of the domain
Definition domain.hpp:14
int size() const
Get the number of particles.
Definition particles.cpp:21
@ Ghost
Ghost particle (outside of the domain, not used for calculation)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ num

int Bucket::num {}

Definition at line 20 of file bucket.hpp.

20{}, numX{}, numY{}, numZ{};

◆ numX

int Bucket::numX {}

Definition at line 20 of file bucket.hpp.

20{}, numX{}, numY{}, numZ{};

◆ numY

int Bucket::numY {}

Definition at line 20 of file bucket.hpp.

20{}, numX{}, numY{}, numZ{};

◆ numZ

int Bucket::numZ {}

Definition at line 20 of file bucket.hpp.

20{}, numX{}, numY{}, numZ{};

◆ length

double Bucket::length {}

Definition at line 21 of file bucket.hpp.

21{};

◆ domain

Domain Bucket::domain {}

Definition at line 22 of file bucket.hpp.

22{};

◆ next

std::vector<int> Bucket::next

Definition at line 23 of file bucket.hpp.

◆ first

std::vector<int> Bucket::first

Definition at line 23 of file bucket.hpp.

◆ last

std::vector<int> Bucket::last

Definition at line 23 of file bucket.hpp.


The documentation for this class was generated from the following files: