CUDAParticleSystemData3.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_CUDA_PARTICLE_SYSTEM_DATA3_HPP
12 #define CUBBYFLOW_CUDA_PARTICLE_SYSTEM_DATA3_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 #include <Core/Array/ArrayView.hpp>
17 #include <Core/CUDA/CUDAArray.hpp>
19 #include <Core/Matrix/Matrix.hpp>
20 
21 #include <cuda_runtime.h>
22 
23 namespace CubbyFlow
24 {
25 class CUDAParticleSystemData3
26 {
27  public:
29  using IntData = CUDAArray1<int>;
30 
32  using FloatData = CUDAArray1<float>;
33 
35  using VectorData = CUDAArray1<float4>;
36 
38  CUDAParticleSystemData3();
39 
41  explicit CUDAParticleSystemData3(size_t numberOfParticles);
42 
44  virtual ~CUDAParticleSystemData3() = default;
45 
47  CUDAParticleSystemData3(const CUDAParticleSystemData3& other);
48 
50  CUDAParticleSystemData3(CUDAParticleSystemData3&& other) noexcept;
51 
53  CUDAParticleSystemData3& operator=(const CUDAParticleSystemData3& other);
54 
56  CUDAParticleSystemData3& operator=(
57  CUDAParticleSystemData3&& other) noexcept;
58 
64  void Resize(size_t newNumberOfParticles);
65 
67  size_t NumberOfParticles() const;
68 
74  size_t AddIntData(int initialVal = 0);
75 
81  size_t AddFloatData(float initialVal = 0.0f);
82 
88  size_t AddVectorData(const Vector4F& initialVal = Vector4F{});
89 
91  size_t NumberOfIntData() const;
92 
94  size_t NumberOfFloatData() const;
95 
97  size_t NumberOfVectorData() const;
98 
100  ConstCUDAArrayView1<float4> Positions() const;
101 
103  CUDAArrayView1<float4> Positions();
104 
106  ConstCUDAArrayView1<float4> Velocities() const;
107 
109  CUDAArrayView1<float4> Velocities();
110 
112  ConstCUDAArrayView1<int> IntDataAt(size_t idx) const;
113 
115  CUDAArrayView1<int> IntDataAt(size_t idx);
116 
118  ConstCUDAArrayView1<float> FloatDataAt(size_t idx) const;
119 
121  CUDAArrayView1<float> FloatDataAt(size_t idx);
122 
124  ConstCUDAArrayView1<float4> VectorDataAt(size_t idx) const;
125 
127  CUDAArrayView1<float4> VectorDataAt(size_t idx);
128 
135  void AddParticle(const Vector4F& newPosition,
136  const Vector4F& newVelocity = Vector4F{});
137 
144  void AddParticles(
145  ConstArrayView1<Vector4F> newPositions,
146  ConstArrayView1<Vector4F> newVelocities = ArrayView1<Vector4F>{});
147 
154  void AddParticles(
155  ConstCUDAArrayView1<float4> newPositions,
156  ConstCUDAArrayView1<float4> newVelocities = CUDAArrayView1<float4>{});
157 
159  ConstCUDAArrayView1<uint32_t> NeighborStarts() const;
160 
162  ConstCUDAArrayView1<uint32_t> NeighborEnds() const;
163 
169  const CUDAPointHashGridSearcher3* NeighborSearcher() const;
170 
176  ConstCUDAArrayView1<uint32_t> NeighborLists() const;
177 
179  void BuildNeighborSearcher(float maxSearchRadius);
180 
182  void BuildNeighborLists(float maxSearchRadius);
183 
185  void Set(const CUDAParticleSystemData3& other);
186 
187  protected:
188  CUDAPointHashGridSearcher3Ptr m_neighborSearcher;
189  CUDAArray1<uint32_t> m_neighborStarts;
190  CUDAArray1<uint32_t> m_neighborEnds;
191  CUDAArray1<uint32_t> m_neighborLists;
192 
193  private:
194  size_t m_numberOfParticles = 0;
195  size_t m_positionIdx;
196  size_t m_velocityIdx;
197 
198  std::vector<IntData> m_intDataList;
199  std::vector<FloatData> m_floatDataList;
200  std::vector<VectorData> m_vectorDataList;
201 };
202 
204 using CUDAParticleSystemData3Ptr = std::shared_ptr<CUDAParticleSystemData3>;
205 } // namespace CubbyFlow
206 
207 #endif
208 
209 #endif
Vector4< float > Vector4F
Definition: Matrix.hpp:799
Definition: pybind11Utils.hpp:20