SPHSystemData2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: SPHSystemData2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D SPH particle system data.
6 > Created Time: 2017/05/31
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SPH_SYSTEM_DATA2_H
10 #define CUBBYFLOW_SPH_SYSTEM_DATA2_H
11 
13 
14 namespace CubbyFlow
15 {
24  {
25  public:
28 
30  explicit SPHSystemData2(size_t numberOfParticles);
31 
33  SPHSystemData2(const SPHSystemData2& other);
34 
36  virtual ~SPHSystemData2();
37 
44  void SetRadius(double newRadius) override;
45 
53  void SetMass(double newMass) override;
54 
57 
60 
63 
66 
76  void UpdateDensities();
77 
79  void SetTargetDensity(double targetDensity);
80 
82  double GetTargetDensity() const;
83 
90  void SetTargetSpacing(double spacing);
91 
93  double GetTargetSpacing() const;
94 
103  void SetRelativeKernelRadius(double relativeRadius);
104 
111  double GetRelativeKernelRadius() const;
112 
121  void SetKernelRadius(double kernelRadius);
122 
124  double GetKernelRadius() const;
125 
127  double SumOfKernelNearby(const Vector2D& position) const;
128 
140  double Interpolate(const Vector2D& origin, const ConstArrayAccessor1<double>& values) const;
141 
153  Vector2D Interpolate(const Vector2D& origin, const ConstArrayAccessor1<Vector2D>& values) const;
154 
161  Vector2D GradientAt(size_t i, const ConstArrayAccessor1<double>& values) const;
162 
169  double LaplacianAt(size_t i, const ConstArrayAccessor1<double>& values) const;
170 
177  Vector2D LaplacianAt(size_t i, const ConstArrayAccessor1<Vector2D>& values) const;
178 
180  void BuildNeighborSearcher();
181 
183  void BuildNeighborLists();
184 
186  void Serialize(std::vector<uint8_t>* buffer) const override;
187 
189  void Deserialize(const std::vector<uint8_t>& buffer) override;
190 
192  void Set(const SPHSystemData2& other);
193 
195  SPHSystemData2& operator=(const SPHSystemData2& other);
196 
197  private:
199  double m_targetDensity = WATER_DENSITY;
200 
202  double m_targetSpacing = 0.1;
203 
206  double m_kernelRadiusOverTargetSpacing = 1.8;
207 
209  double m_kernelRadius;
210 
211  size_t m_pressureIdx;
212 
213  size_t m_densityIdx;
214 
216  void ComputeMass();
217  };
218 
220  using SPHSystemData2Ptr = std::shared_ptr<SPHSystemData2>;
221 }
222 
223 #endif
constexpr double WATER_DENSITY
Water density.
Definition: Constants.h:159
void SetRadius(double newRadius) override
Sets the radius.
double Interpolate(const Vector2D &origin, const ConstArrayAccessor1< double > &values) const
Returns interpolated value at given origin point.
2-D particle system data.
Definition: ParticleSystemData2.h:47
double GetTargetSpacing() const
Returns the target particle spacing in meters.
ConstArrayAccessor1< double > GetDensities() const
Returns the density array accessor (immutable).
Vector2D GradientAt(size_t i, const ConstArrayAccessor1< double > &values) const
void SetTargetDensity(double targetDensity)
Sets the target density of this particle system.
void SetMass(double newMass) override
Sets the mass of a particle.
void BuildNeighborLists()
Builds neighbor lists with kernel radius.
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
void Set(const SPHSystemData2 &other)
Copies from other SPH system data.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes this SPH system data from the buffer.
Definition: pybind11Utils.h:24
double GetRelativeKernelRadius() const
Returns the relative kernel radius.
void SetRelativeKernelRadius(double relativeRadius)
Sets the relative kernel radius.
void SetTargetSpacing(double spacing)
Sets the target particle spacing in meters.
void BuildNeighborSearcher()
Builds neighbor searcher with kernel radius.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes this SPH system data to the buffer.
ConstArrayAccessor1< double > GetPressures() const
Returns the pressure array accessor (immutable).
double GetKernelRadius() const
Returns the kernel radius in meters unit.
1-D array accessor class.
Definition: ArrayAccessor1.h:28
2-D SPH particle system data.
Definition: SPHSystemData2.h:23
virtual ~SPHSystemData2()
Destructor.
double LaplacianAt(size_t i, const ConstArrayAccessor1< double > &values) const
std::shared_ptr< SPHSystemData2 > SPHSystemData2Ptr
Shared pointer for the SPHSystemData2 type.
Definition: SPHSystemData2.h:220
2-D vector class.
Definition: Vector2.h:26
SPHSystemData2()
Constructs empty SPH system.
SPHSystemData2 & operator=(const SPHSystemData2 &other)
Copies from other SPH system data.
double GetTargetDensity() const
Returns the target density of this particle system.
void UpdateDensities()
Updates the density array with the latest particle positions.
double SumOfKernelNearby(const Vector2D &position) const
Returns sum of kernel function evaluation for each nearby particle.
void SetKernelRadius(double kernelRadius)
Sets the absolute kernel radius.