CUDASPHSolverBase3.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_BASE3_HPP
12 #define CUBBYFLOW_CUDA_PARTICLE_SPH_SOLVER_BASE3_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
19 
20 namespace CubbyFlow
21 {
25 class CUDASPHSolverBase3 : public CUDAParticleSystemSolverBase3
26 {
27  public:
29  CUDASPHSolverBase3();
30 
32  CUDASPHSolverBase3(const CUDASPHSolverBase3&) = delete;
33 
35  CUDASPHSolverBase3(CUDASPHSolverBase3&&) noexcept = delete;
36 
38  ~CUDASPHSolverBase3() override = default;
39 
41  CUDASPHSolverBase3& operator=(const CUDASPHSolverBase3&) = delete;
42 
44  CUDASPHSolverBase3& operator=(CUDASPHSolverBase3&&) 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 BoundingBox3F& Container() const;
111 
113  void SetContainer(const BoundingBox3F& cont);
114 
121  CUDAParticleSystemData3* ParticleSystemData() override;
122 
129  const CUDAParticleSystemData3* ParticleSystemData() const override;
130 
137  CUDASPHSystemData3* SPHSystemData();
138 
145  const CUDASPHSystemData3* SPHSystemData() const;
146 
147  protected:
149  unsigned int GetNumberOfSubTimeSteps(
150  double timeIntervalInSeconds) const override;
151 
152  CUDAArrayView1<float4> Forces() const;
153 
154  CUDAArrayView1<float4> 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  BoundingBox3F m_container;
166 
167  // Data model
168  CUDASPHSystemData3Ptr m_sphSystemData;
169 };
170 
172 using CUDASPHSolverBase3Ptr = std::shared_ptr<CUDASPHSolverBase3>;
173 
177 template <typename DerivedBuilder>
178 class CUDASPHSolverBuilderBase3
179  : public CUDAParticleSystemSolverBuilderBase3<DerivedBuilder>
180 {
181  public:
183  DerivedBuilder& WithTargetDensity(float targetDensity);
184 
186  DerivedBuilder& WithTargetSpacing(float targetSpacing);
187 
189  DerivedBuilder& WithRelativeKernelRadius(float relativeKernelRadius);
190 
192  DerivedBuilder& WithNegativePressureScale(float negativePressureScale);
193 
195  DerivedBuilder& WithViscosityCoefficient(float viscosityCoefficient);
196 
198  DerivedBuilder& WithPseudoViscosityCoefficient(
199  float pseudoViscosityCoefficient);
200 
201  protected:
202  float m_targetDensity = WATER_DENSITY_FLOAT;
203  float m_targetSpacing = 0.1f;
204  float m_relativeKernelRadius = 1.8f;
205  float m_negativePressureScale = 0.0f;
206  float m_viscosityCoefficient = 0.01f;
207  float m_pseudoViscosityCoefficient = 10.0f;
208 };
209 
210 template <typename T>
211 T& CUDASPHSolverBuilderBase3<T>::WithTargetDensity(float targetDensity)
212 {
213  m_targetDensity = targetDensity;
214  return static_cast<T&>(*this);
215 }
216 
217 template <typename T>
218 T& CUDASPHSolverBuilderBase3<T>::WithTargetSpacing(float targetSpacing)
219 {
220  m_targetSpacing = targetSpacing;
221  return static_cast<T&>(*this);
222 }
223 
224 template <typename T>
225 T& CUDASPHSolverBuilderBase3<T>::WithRelativeKernelRadius(
226  float relativeKernelRadius)
227 {
228  m_relativeKernelRadius = relativeKernelRadius;
229  return static_cast<T&>(*this);
230 }
231 
232 template <typename T>
233 T& CUDASPHSolverBuilderBase3<T>::WithNegativePressureScale(
234  float negativePressureScale)
235 {
236  m_negativePressureScale = negativePressureScale;
237  return static_cast<T&>(*this);
238 }
239 
240 template <typename T>
241 T& CUDASPHSolverBuilderBase3<T>::WithViscosityCoefficient(
242  float viscosityCoefficient)
243 {
244  m_viscosityCoefficient = viscosityCoefficient;
245  return static_cast<T&>(*this);
246 }
247 
248 template <typename T>
249 T& CUDASPHSolverBuilderBase3<T>::WithPseudoViscosityCoefficient(
250  float pseudoViscosityCoefficient)
251 {
252  m_pseudoViscosityCoefficient = pseudoViscosityCoefficient;
253  return static_cast<T&>(*this);
254 }
255 } // namespace CubbyFlow
256 
257 #endif
258 
259 #endif
BoundingBox3< float > BoundingBox3F
Definition: BoundingBox.hpp:161
constexpr float WATER_DENSITY_FLOAT
Water density.
Definition: Constants.hpp:302
Definition: pybind11Utils.hpp:20