Loading...
Searching...
No Matches
ParticleSystemData.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_PARTICLE_SYSTEM_DATA_HPP
12#define CUBBYFLOW_PARTICLE_SYSTEM_DATA_HPP
13
14#include <Core/Array/Array.hpp>
17
18#ifndef CUBBYFLOW_DOXYGEN
19
20namespace flatbuffers
21{
22class FlatBufferBuilder;
23template <typename T>
24struct Offset;
25} // namespace flatbuffers
26
27namespace CubbyFlow
28{
29namespace fbs
30{
33} // namespace fbs
34} // namespace CubbyFlow
35
36#endif
37
38namespace CubbyFlow
39{
47template <size_t N>
49{
50 public:
53
56
59
62
64 ~ParticleSystemData() override = default;
65
68
71
74
77
90
92 [[nodiscard]] size_t NumberOfParticles() const;
93
102 [[nodiscard]] size_t AddScalarData(double initialVal = 0.0);
103
114
116 [[nodiscard]] double Radius() const;
117
119 virtual void SetRadius(double newRadius);
120
122 [[nodiscard]] double Mass() const;
123
125 virtual void SetMass(double newMass);
126
129
132
135
138
141
144
147
150
153 size_t idx) const;
154
157
175
194
203 [[nodiscard]] const std::shared_ptr<PointNeighborSearcher<N>>&
205
208 const std::shared_ptr<PointNeighborSearcher<N>>& newNeighborSearcher);
209
220
223
226
228 void Serialize(std::vector<uint8_t>* buffer) const override;
229
231 void Deserialize(const std::vector<uint8_t>& buffer) override;
232
235
236 protected:
237 template <size_t M = N>
238 static std::enable_if_t<M == 2, void> Serialize(
240 flatbuffers::FlatBufferBuilder* builder,
241 flatbuffers::Offset<fbs::ParticleSystemData2>* fbsParticleSystemData);
242
243 template <size_t M = N>
244 static std::enable_if_t<M == 3, void> Serialize(
246 flatbuffers::FlatBufferBuilder* builder,
247 flatbuffers::Offset<fbs::ParticleSystemData3>* fbsParticleSystemData);
248
249 template <size_t M = N>
250 static std::enable_if_t<M == 2, void> Deserialize(
251 const fbs::ParticleSystemData2* fbsParticleSystemData,
253
254 template <size_t M = N>
255 static std::enable_if_t<M == 3, void> Deserialize(
256 const fbs::ParticleSystemData3* fbsParticleSystemData,
258
259 private:
260 double m_radius = 1e-3;
261 double m_mass = 1e-3;
262 size_t m_numberOfParticles = 0;
263 size_t m_positionIdx = 0;
264 size_t m_velocityIdx = 0;
265 size_t m_forceIdx = 0;
266
267 Array1<ScalarData> m_scalarDataList;
268 Array1<VectorData> m_vectorDataList;
269
270 std::shared_ptr<PointNeighborSearcher<N>> m_neighborSearcher;
271 Array1<Array1<size_t>> m_neighborLists;
272};
273
276
279
281using ParticleSystemData2Ptr = std::shared_ptr<ParticleSystemData2>;
282
284using ParticleSystemData3Ptr = std::shared_ptr<ParticleSystemData3>;
285} // namespace CubbyFlow
286
287#endif
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
Definition Matrix.hpp:30
N-D particle system data.
Definition ParticleSystemData.hpp:49
static std::enable_if_t< M==2, void > Serialize(const ParticleSystemData< 2 > &particles, flatbuffers::FlatBufferBuilder *builder, flatbuffers::Offset< fbs::ParticleSystemData2 > *fbsParticleSystemData)
void AddParticle(const Vector< double, N > &newPosition, const Vector< double, N > &newVelocity=Vector< double, N >(), const Vector< double, N > &newForce=Vector< double, N >())
Adds a particle to the data structure.
void Resize(size_t newNumberOfParticles)
Resizes the number of particles of the container.
void Set(const ParticleSystemData &other)
Copies from other particle system data.
double Radius() const
Returns the radius of the particles.
ArrayView1< Vector< double, N > > Forces()
Returns the force array (mutable).
const std::shared_ptr< PointNeighborSearcher< N > > & NeighborSearcher() const
Returns neighbor searcher.
static std::enable_if_t< M==3, void > Serialize(const ParticleSystemData< 3 > &particles, flatbuffers::FlatBufferBuilder *builder, flatbuffers::Offset< fbs::ParticleSystemData3 > *fbsParticleSystemData)
void AddParticles(const ConstArrayView1< Vector< double, N > > &newPositions, const ConstArrayView1< Vector< double, N > > &newVelocities=ConstArrayView1< Vector< double, N > >(), const ConstArrayView1< Vector< double, N > > &newForces=ConstArrayView1< Vector< double, N > >())
Adds particles to the data structure.
ConstArrayView1< Vector< double, N > > Velocities() const
Returns the velocity array (immutable).
ConstArrayView1< Vector< double, N > > Positions() const
Returns the position array (immutable).
ParticleSystemData(const ParticleSystemData &other)
Copy constructor.
void SetNeighborSearcher(const std::shared_ptr< PointNeighborSearcher< N > > &newNeighborSearcher)
Sets neighbor searcher.
ParticleSystemData & operator=(const ParticleSystemData &other)
Copy assignment operator.
ParticleSystemData()
Default constructor.
static std::enable_if_t< M==3, void > Deserialize(const fbs::ParticleSystemData3 *fbsParticleSystemData, ParticleSystemData< 3 > &particles)
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes this particle system data from the buffer.
virtual void SetRadius(double newRadius)
Sets the radius of the particles.
ArrayView1< Vector< double, N > > VectorDataAt(size_t idx)
Returns custom vector data layer at given index (mutable).
virtual void SetMass(double newMass)
Sets the mass of the particles.
size_t AddVectorData(const Vector< double, N > &initialVal=Vector< double, N >{})
Adds a vector data layer and returns its index.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes this particle system data to the buffer.
ConstArrayView1< double > ScalarDataAt(size_t idx) const
Returns custom scalar data layer at given index (immutable).
const Array1< Array1< size_t > > & NeighborLists() const
Returns neighbor lists.
size_t AddScalarData(double initialVal=0.0)
Adds a scalar data layer and returns its index.
void BuildNeighborSearcher(double maxSearchRadius)
Builds neighbor searcher with given search radius.
double Mass() const
Returns the mass of the particles.
ParticleSystemData(ParticleSystemData &&other) noexcept
Move constructor.
static std::enable_if_t< M==2, void > Deserialize(const fbs::ParticleSystemData2 *fbsParticleSystemData, ParticleSystemData< 2 > &particles)
size_t NumberOfParticles() const
Returns the number of particles.
ConstArrayView1< Vector< double, N > > VectorDataAt(size_t idx) const
Returns custom vector data layer at given index (immutable).
ArrayView1< Vector< double, N > > Velocities()
Returns the velocity array (mutable).
ArrayView1< Vector< double, N > > Positions()
Returns the position array (mutable).
ArrayView1< double > ScalarDataAt(size_t idx)
Returns custom scalar data layer at given index (mutable).
ParticleSystemData(size_t numberOfParticles)
Constructs particle system data with given number of particles.
~ParticleSystemData() override=default
Default virtual destructor.
ConstArrayView1< Vector< double, N > > Forces() const
Returns the force array (immutable).
ParticleSystemData & operator=(ParticleSystemData &&other) noexcept
Move assignment operator.
void BuildNeighborLists(double maxSearchRadius)
Builds neighbor lists with given search radius.
Abstract base class for any serializable class.
Definition Serialization.hpp:22
Definition pybind11Utils.hpp:21
std::shared_ptr< ParticleSystemData3 > ParticleSystemData3Ptr
Shared pointer type of ParticleSystemData3.
Definition ParticleSystemData.hpp:284
ParticleSystemData< 2 > ParticleSystemData2
2-D ParticleSystemData type.
Definition ParticleSystemData.hpp:275
ParticleSystemData< 3 > ParticleSystemData3
3-D ParticleSystemData type.
Definition ParticleSystemData.hpp:278
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition ParticleSystemData.hpp:281