PeriDyno 1.0.0
Loading...
Searching...
No Matches
GridHash.h
Go to the documentation of this file.
1#pragma once
2#include "Algorithm/Scan.h"
4
5namespace dyno{
6
7 #define INVALID -1
8 #define BUCKETS 8
9 #define CAPACITY 16
10
11 template<typename TDataType>
13 {
14 public:
15 typedef typename TDataType::Real Real;
16 typedef typename TDataType::Coord Coord;
17
20
21 void setSpace(Real _h, Coord _lo, Coord _hi);
22
23 void construct(const DArray<Coord>& pos);
24
25 void clear();
26
27 void release();
28
29 GPU_FUNC inline int getIndex(int i, int j, int k)
30 {
31 if (i < 0 || i >= nx) return INVALID;
32 if (j < 0 || j >= ny) return INVALID;
33 if (k < 0 || k >= nz) return INVALID;
34
35 return i + j*nx + k*nx*ny;
36 }
37
38 GPU_FUNC inline int getIndex(Coord pos) {
39 int i = (int)floor((pos[0] - lo[0]) / ds);
40 int j = (int)floor((pos[1] - lo[1]) / ds);
41 int k = (int)floor((pos[2] - lo[2]) / ds);
42
43 return getIndex(i, j, k);
44 }
45
46 GPU_FUNC inline int3 getIndex3(Coord pos) {
47 int i = (int)floor((pos[0] - lo[0]) / ds);
48 int j = (int)floor((pos[1] - lo[1]) / ds);
49 int k = (int)floor((pos[2] - lo[2]) / ds);
50
51 return make_int3(i, j, k);
52 }
53
54 GPU_FUNC inline int getCounter(int gId) {
55 if (gId >= num - 1) {
56 return particle_num - index[gId];
57 }
58
59 return index[gId + 1] - index[gId];
60 }
61
62 GPU_FUNC inline int getParticleId(int gId, int n) {
63 return ids[index[gId] + n];
64 }
65
66 public:
67 int num;
68 int nx, ny, nz;
69
70 int particle_num = 0;
71
73
76
77 //int npMax; //maximum particle number for each cell
78
79 int* ids = nullptr;
80 int* counter = nullptr;
81 int* index = nullptr;
82
83 Scan<int>* m_scan = nullptr;
85 };
86}
#define INVALID
Definition STLMacro.h:8
void setSpace(Real _h, Coord _lo, Coord _hi)
GPU_FUNC int3 getIndex3(Coord pos)
Definition GridHash.h:46
int * counter
Definition GridHash.h:80
TDataType::Real Real
Definition GridHash.h:15
Reduction< int > * m_reduce
Definition GridHash.h:84
TDataType::Coord Coord
Definition GridHash.h:16
GPU_FUNC int getIndex(Coord pos)
Definition GridHash.h:38
void construct(const DArray< Coord > &pos)
Scan< int > * m_scan
Definition GridHash.h:83
GPU_FUNC int getCounter(int gId)
Definition GridHash.h:54
GPU_FUNC int getParticleId(int gId, int n)
Definition GridHash.h:62
GPU_FUNC int getIndex(int i, int j, int k)
Definition GridHash.h:29
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89