CUDAParticleSystemSolverBase2.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_SOLVER_BASE2_HPP
12 #define CUBBYFLOW_CUDA_PARTICLE_SYSTEM_SOLVER_BASE2_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
18 #include <Core/Matrix/Matrix.hpp>
19 #include <Core/Utils/Constants.hpp>
20 
21 namespace CubbyFlow
22 {
29 class CUDAParticleSystemSolverBase2 : public PhysicsAnimation
30 {
31  public:
33  CUDAParticleSystemSolverBase2();
34 
36  CUDAParticleSystemSolverBase2(const CUDAParticleSystemSolverBase2&) =
37  delete;
38 
40  CUDAParticleSystemSolverBase2(CUDAParticleSystemSolverBase2&&) noexcept =
41  delete;
42 
44  ~CUDAParticleSystemSolverBase2() override = default;
45 
47  CUDAParticleSystemSolverBase2& operator=(
48  const CUDAParticleSystemSolverBase2&) = delete;
49 
51  CUDAParticleSystemSolverBase2& operator=(
52  CUDAParticleSystemSolverBase2&&) noexcept = delete;
53 
55  float DragCoefficient() const;
56 
64  void SetDragCoefficient(float newDragCoefficient);
65 
73  float RestitutionCoefficient() const;
74 
83  void SetRestitutionCoefficient(float newRestitutionCoefficient);
84 
86  const Vector2F& Gravity() const;
87 
89  void SetGravity(const Vector2F& newGravity);
90 
97  virtual CUDAParticleSystemData2* ParticleSystemData();
98 
105  virtual const CUDAParticleSystemData2* ParticleSystemData() const;
106 
107  protected:
109  void OnInitialize() override;
110 
111  void UpdateCollider(double timeStepInSeconds);
112 
113  void UpdateEmitter(double timeStepInSeconds);
114 
115  private:
116  float m_dragCoefficient = 1e-4f;
117  float m_restitutionCoefficient = 0.0f;
118  Vector2F m_gravity{ 0.0f, GRAVITY_FLOAT };
119  CUDAParticleSystemData2Ptr m_particleSystemData;
120 };
121 
123 using CUDAParticleSystemSolverBase2Ptr =
124  std::shared_ptr<CUDAParticleSystemSolverBase2>;
125 
129 template <typename DerivedBuilder>
130 class CUDAParticleSystemSolverBuilderBase2
131 {
132  public:
134  DerivedBuilder& WithDragCoefficient(float coeff);
135 
137  DerivedBuilder& WithRestitutionCoefficient(float coeff);
138 
140  DerivedBuilder& WithGravity(const Vector2F& gravity);
141 
142  protected:
143  float m_dragCoefficient = 1e-4f;
144  float m_restitutionCoefficient = 0.0f;
145  Vector2F m_gravity{ 0.0f, GRAVITY_FLOAT };
146 };
147 
148 template <typename T>
149 T& CUDAParticleSystemSolverBuilderBase2<T>::WithDragCoefficient(float coeff)
150 {
151  m_dragCoefficient = coeff;
152  return static_cast<T&>(*this);
153 }
154 
155 template <typename T>
156 T& CUDAParticleSystemSolverBuilderBase2<T>::WithRestitutionCoefficient(
157  float coeff)
158 {
159  m_restitutionCoefficient = coeff;
160  return static_cast<T&>(*this);
161 }
162 
163 template <typename T>
164 T& CUDAParticleSystemSolverBuilderBase2<T>::WithGravity(const Vector2F& gravity)
165 {
166  m_gravity = gravity;
167  return static_cast<T&>(*this);
168 }
169 } // namespace CubbyFlow
170 
171 #endif
172 
173 #endif
Definition: pybind11Utils.hpp:20
Vector2< float > Vector2F
Definition: Matrix.hpp:773
constexpr float GRAVITY_FLOAT
Gravity.
Definition: Constants.hpp:298