CUDASPHSolverBase2.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_SPH_SOLVER_BASE2_HPP
12 #define CUBBYFLOW_CUDA_PARTICLE_SPH_SOLVER_BASE2_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
19 
20 namespace CubbyFlow
21 {
25 class CUDASPHSolverBase2 : public CUDAParticleSystemSolverBase2
26 {
27  public:
29  CUDASPHSolverBase2();
30 
32  CUDASPHSolverBase2(const CUDASPHSolverBase2&) = delete;
33 
35  CUDASPHSolverBase2(CUDASPHSolverBase2&&) noexcept = delete;
36 
38  ~CUDASPHSolverBase2() override = default;
39 
41  CUDASPHSolverBase2& operator=(const CUDASPHSolverBase2&) = delete;
42 
44  CUDASPHSolverBase2& operator=(CUDASPHSolverBase2&&) noexcept = delete;
45 
51  float NegativePressureScale() const;
52 
61  void SetNegativePressureScale(float newNegativePressureScale);
62 
64  float ViscosityCoefficient() const;
65 
67  void SetViscosityCoefficient(float newViscosityCoefficient);
68 
75  float PseudoViscosityCoefficient() const;
76 
78  void SetPseudoViscosityCoefficient(float newPseudoViscosityCoefficient);
79 
87  float SpeedOfSound() const;
88 
90  void SetSpeedOfSound(float newSpeedOfSound);
91 
99  float TimeStepLimitScale() const;
100 
102  void SetTimeStepLimitScale(float newScale);
103 
110  const BoundingBox2F& Container() const;
111 
113  void SetContainer(const BoundingBox2F& cont);
114 
121  CUDAParticleSystemData2* ParticleSystemData() override;
122 
129  const CUDAParticleSystemData2* ParticleSystemData() const override;
130 
137  CUDASPHSystemData2* SPHSystemData();
138 
145  const CUDASPHSystemData2* SPHSystemData() const;
146 
147  protected:
149  unsigned int GetNumberOfSubTimeSteps(
150  double timeIntervalInSeconds) const override;
151 
152  CUDAArrayView1<float2> Forces() const;
153 
154  CUDAArrayView1<float2> SmoothedVelocities() const;
155 
156  private:
157  // Basic SPH solver properties
158  size_t m_forcesIdx;
159  size_t m_smoothedVelIdx;
160  float m_negativePressureScale = 0.0f;
161  float m_viscosityCoefficient = 0.01f;
162  float m_pseudoViscosityCoefficient = 10.0f;
163  float m_speedOfSound = 100.0f;
164  float m_timeStepLimitScale = 1.0f;
165  BoundingBox2F m_container{ Vector2F{ -1000.0f, -1000.0f },
166  Vector2F{ 1000.0f, 1000.0f } };
167 
168  // Data model
169  CUDASPHSystemData2Ptr m_sphSystemData;
170 };
171 
173 using CUDASPHSolverBase2Ptr = std::shared_ptr<CUDASPHSolverBase2>;
174 
178 template <typename DerivedBuilder>
179 class CUDASPHSolverBuilderBase2
180  : public CUDAParticleSystemSolverBuilderBase2<DerivedBuilder>
181 {
182  public:
184  DerivedBuilder& WithTargetDensity(float targetDensity);
185 
187  DerivedBuilder& WithTargetSpacing(float targetSpacing);
188 
190  DerivedBuilder& WithRelativeKernelRadius(float relativeKernelRadius);
191 
193  DerivedBuilder& WithNegativePressureScale(float negativePressureScale);
194 
196  DerivedBuilder& WithViscosityCoefficient(float viscosityCoefficient);
197 
199  DerivedBuilder& WithPseudoViscosityCoefficient(
200  float pseudoViscosityCoefficient);
201 
202  protected:
203  float m_targetDensity = WATER_DENSITY_FLOAT;
204  float m_targetSpacing = 0.1f;
205  float m_relativeKernelRadius = 1.8f;
206  float m_negativePressureScale = 0.0f;
207  float m_viscosityCoefficient = 0.01f;
208  float m_pseudoViscosityCoefficient = 10.0f;
209 };
210 
211 template <typename T>
212 T& CUDASPHSolverBuilderBase2<T>::WithTargetDensity(float targetDensity)
213 {
214  m_targetDensity = targetDensity;
215  return static_cast<T&>(*this);
216 }
217 
218 template <typename T>
219 T& CUDASPHSolverBuilderBase2<T>::WithTargetSpacing(float targetSpacing)
220 {
221  m_targetSpacing = targetSpacing;
222  return static_cast<T&>(*this);
223 }
224 
225 template <typename T>
226 T& CUDASPHSolverBuilderBase2<T>::WithRelativeKernelRadius(
227  float relativeKernelRadius)
228 {
229  m_relativeKernelRadius = relativeKernelRadius;
230  return static_cast<T&>(*this);
231 }
232 
233 template <typename T>
234 T& CUDASPHSolverBuilderBase2<T>::WithNegativePressureScale(
235  float negativePressureScale)
236 {
237  m_negativePressureScale = negativePressureScale;
238  return static_cast<T&>(*this);
239 }
240 
241 template <typename T>
242 T& CUDASPHSolverBuilderBase2<T>::WithViscosityCoefficient(
243  float viscosityCoefficient)
244 {
245  m_viscosityCoefficient = viscosityCoefficient;
246  return static_cast<T&>(*this);
247 }
248 
249 template <typename T>
250 T& CUDASPHSolverBuilderBase2<T>::WithPseudoViscosityCoefficient(
251  float pseudoViscosityCoefficient)
252 {
253  m_pseudoViscosityCoefficient = pseudoViscosityCoefficient;
254  return static_cast<T&>(*this);
255 }
256 } // namespace CubbyFlow
257 
258 #endif
259 
260 #endif
BoundingBox2< float > BoundingBox2F
Definition: BoundingBox.hpp:157
constexpr float WATER_DENSITY_FLOAT
Water density.
Definition: Constants.hpp:302
Definition: pybind11Utils.hpp:20
Vector2< float > Vector2F
Definition: Matrix.hpp:773