Jet  v1.3.3
particle_system_data2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_PARTICLE_SYSTEM_DATA2_H_
8 #define INCLUDE_JET_PARTICLE_SYSTEM_DATA2_H_
9 
10 #include <jet/array1.h>
12 #include <jet/serialization.h>
13 
14 #include <memory>
15 #include <vector>
16 
17 #ifndef JET_DOXYGEN
18 
19 namespace flatbuffers {
20 
21 class FlatBufferBuilder;
22 template<typename T> struct Offset;
23 
24 }
25 
26 namespace jet {
27 namespace fbs {
28 
29 struct ParticleSystemData2;
30 
31 }
32 }
33 
34 #endif // JET_DOXYGEN
35 
36 namespace jet {
37 
46  public:
49 
52 
55 
58 
61 
64 
76  void resize(size_t newNumberOfParticles);
77 
79  size_t numberOfParticles() const;
80 
89  size_t addScalarData(double initialVal = 0.0);
90 
99  size_t addVectorData(const Vector2D& initialVal = Vector2D());
100 
102  double radius() const;
103 
105  virtual void setRadius(double newRadius);
106 
108  double mass() const;
109 
111  virtual void setMass(double newMass);
112 
115 
118 
121 
124 
127 
130 
133 
136 
139 
142 
158  const Vector2D& newPosition,
159  const Vector2D& newVelocity = Vector2D(),
160  const Vector2D& newForce = Vector2D());
161 
176  const ConstArrayAccessor1<Vector2D>& newPositions,
177  const ConstArrayAccessor1<Vector2D>& newVelocities
179  const ConstArrayAccessor1<Vector2D>& newForces
181 
191 
194  const PointNeighborSearcher2Ptr& newNeighborSearcher);
195 
205  const std::vector<std::vector<size_t>>& neighborLists() const;
206 
208  void buildNeighborSearcher(double maxSearchRadius);
209 
211  void buildNeighborLists(double maxSearchRadius);
212 
214  void serialize(std::vector<uint8_t>* buffer) const override;
215 
217  void deserialize(const std::vector<uint8_t>& buffer) override;
218 
220  void set(const ParticleSystemData2& other);
221 
224 
225  protected:
227  flatbuffers::FlatBufferBuilder* builder,
228  flatbuffers::Offset<fbs::ParticleSystemData2>* fbsParticleSystemData)
229  const;
230 
232  const fbs::ParticleSystemData2* fbsParticleSystemData);
233 
234  private:
235  double _radius = 1e-3;
236  double _mass = 1e-3;
237  size_t _numberOfParticles = 0;
238  size_t _positionIdx;
239  size_t _velocityIdx;
240  size_t _forceIdx;
241 
242  std::vector<ScalarData> _scalarDataList;
243  std::vector<VectorData> _vectorDataList;
244 
245  PointNeighborSearcher2Ptr _neighborSearcher;
246  std::vector<std::vector<size_t>> _neighborLists;
247 };
248 
250 typedef std::shared_ptr<ParticleSystemData2> ParticleSystemData2Ptr;
251 
252 } // namespace jet
253 
254 #endif // INCLUDE_JET_PARTICLE_SYSTEM_DATA2_H_
jet::Array< T, 1 >
1-D array class.
Definition: array1.h:31
jet::ParticleSystemData2::ParticleSystemData2
ParticleSystemData2(size_t numberOfParticles)
Constructs particle system data with given number of particles.
jet::ParticleSystemData2::velocities
ArrayAccessor1< Vector2D > velocities()
Returns the velocity array (mutable).
jet::ParticleSystemData2::resize
void resize(size_t newNumberOfParticles)
Resizes the number of particles of the container.
jet::ParticleSystemData2::ParticleSystemData2
ParticleSystemData2(const ParticleSystemData2 &other)
Copy constructor.
jet::ParticleSystemData2::setRadius
virtual void setRadius(double newRadius)
Sets the radius of the particles.
jet::ParticleSystemData2::~ParticleSystemData2
virtual ~ParticleSystemData2()
Destructor.
jet::ParticleSystemData2::positions
ConstArrayAccessor1< Vector2D > positions() const
Returns the position array (immutable).
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
jet::ParticleSystemData2::setMass
virtual void setMass(double newMass)
Sets the mass of the particles.
jet::Vector2D
Vector2< double > Vector2D
Double-type 2D vector.
Definition: vector2.h:340
point_neighbor_searcher2.h
jet::PointNeighborSearcher2Ptr
std::shared_ptr< PointNeighborSearcher2 > PointNeighborSearcher2Ptr
Shared pointer for the PointNeighborSearcher2 type.
Definition: point_neighbor_searcher2.h:82
jet::ParticleSystemData2::scalarDataAt
ArrayAccessor1< double > scalarDataAt(size_t idx)
Returns custom scalar data layer at given index (mutable).
jet::ParticleSystemData2::forces
ConstArrayAccessor1< Vector2D > forces() const
Returns the force array (immutable).
jet::ParticleSystemData2::addParticle
void addParticle(const Vector2D &newPosition, const Vector2D &newVelocity=Vector2D(), const Vector2D &newForce=Vector2D())
Adds a particle to the data structure.
jet::ParticleSystemData2::vectorDataAt
ConstArrayAccessor1< Vector2D > vectorDataAt(size_t idx) const
Returns custom vector data layer at given index (immutable).
jet::ParticleSystemData2::buildNeighborLists
void buildNeighborLists(double maxSearchRadius)
Builds neighbor lists with given search radius.
jet::ParticleSystemData2::operator=
ParticleSystemData2 & operator=(const ParticleSystemData2 &other)
Copies from other particle system data.
jet::ParticleSystemData2::mass
double mass() const
Returns the mass of the particles.
jet::ParticleSystemData2::ScalarData
Array1< double > ScalarData
Scalar data chunk.
Definition: particle_system_data2.h:48
jet::ParticleSystemData2::radius
double radius() const
Returns the radius of the particles.
jet
Definition: advection_solver2.h:18
jet::ParticleSystemData2::neighborLists
const std::vector< std::vector< size_t > > & neighborLists() const
Returns neighbor lists.
jet::ParticleSystemData2::neighborSearcher
const PointNeighborSearcher2Ptr & neighborSearcher() const
Returns neighbor searcher.
jet::ParticleSystemData2::numberOfParticles
size_t numberOfParticles() const
Returns the number of particles.
jet::ParticleSystemData2::scalarDataAt
ConstArrayAccessor1< double > scalarDataAt(size_t idx) const
Returns custom scalar data layer at given index (immutable).
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::ParticleSystemData2::buildNeighborSearcher
void buildNeighborSearcher(double maxSearchRadius)
Builds neighbor searcher with given search radius.
jet::ParticleSystemData2::positions
ArrayAccessor1< Vector2D > positions()
Returns the position array (mutable).
jet::ParticleSystemData2::addParticles
void addParticles(const ConstArrayAccessor1< Vector2D > &newPositions, const ConstArrayAccessor1< Vector2D > &newVelocities=ConstArrayAccessor1< Vector2D >(), const ConstArrayAccessor1< Vector2D > &newForces=ConstArrayAccessor1< Vector2D >())
Adds particles to the data structure.
jet::ParticleSystemData2::velocities
ConstArrayAccessor1< Vector2D > velocities() const
Returns the velocity array (immutable).
jet::ParticleSystemData2::forces
ArrayAccessor1< Vector2D > forces()
Returns the force array (mutable).
jet::ParticleSystemData2::setNeighborSearcher
void setNeighborSearcher(const PointNeighborSearcher2Ptr &newNeighborSearcher)
Sets neighbor searcher.
jet::ParticleSystemData2::deserializeParticleSystemData
void deserializeParticleSystemData(const fbs::ParticleSystemData2 *fbsParticleSystemData)
jet::ParticleSystemData2::addVectorData
size_t addVectorData(const Vector2D &initialVal=Vector2D())
Adds a vector data layer and returns its index.
jet::Serializable
Abstract base class for any serializable class.
Definition: serialization.h:17
jet::ParticleSystemData2Ptr
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: particle_system_data2.h:250
jet::ParticleSystemData2::deserialize
void deserialize(const std::vector< uint8_t > &buffer) override
Deserializes this particle system data from the buffer.
jet::ParticleSystemData2::set
void set(const ParticleSystemData2 &other)
Copies from other particle system data.
serialization.h
jet::ParticleSystemData2::ParticleSystemData2
ParticleSystemData2()
Default constructor.
jet::ParticleSystemData2::vectorDataAt
ArrayAccessor1< Vector2D > vectorDataAt(size_t idx)
Returns custom vector data layer at given index (mutable).
jet::ParticleSystemData2::serialize
void serialize(std::vector< uint8_t > *buffer) const override
Serializes this particle system data to the buffer.
jet::ParticleSystemData2::addScalarData
size_t addScalarData(double initialVal=0.0)
Adds a scalar data layer and returns its index.
jet::ArrayAccessor< T, 1 >
1-D array accessor class.
Definition: array_accessor1.h:27
array1.h
jet::ParticleSystemData2::serializeParticleSystemData
void serializeParticleSystemData(flatbuffers::FlatBufferBuilder *builder, flatbuffers::Offset< fbs::ParticleSystemData2 > *fbsParticleSystemData) const
jet::ParticleSystemData2::VectorData
Array1< Vector2D > VectorData
Vector data chunk.
Definition: particle_system_data2.h:51
jet::ParticleSystemData2
2-D particle system data.
Definition: particle_system_data2.h:45