Loading...
Searching...
No Matches
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
20namespace CubbyFlow
21{
26{
27 public:
30
33
36
39
42
45
52
61 void SetNegativePressureScale(float newNegativePressureScale);
62
65
67 void SetViscosityCoefficient(float newViscosityCoefficient);
68
76
78 void SetPseudoViscosityCoefficient(float newPseudoViscosityCoefficient);
79
87 float SpeedOfSound() const;
88
90 void SetSpeedOfSound(float newSpeedOfSound);
91
100
102 void SetTimeStepLimitScale(float newScale);
103
111
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
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
170};
171
173using CUDASPHSolverBase2Ptr = std::shared_ptr<CUDASPHSolverBase2>;
174
178template <typename DerivedBuilder>
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
194
197
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
211template <typename T>
212T& CUDASPHSolverBuilderBase2<T>::WithTargetDensity(float targetDensity)
213{
214 m_targetDensity = targetDensity;
215 return static_cast<T&>(*this);
216}
217
218template <typename T>
219T& CUDASPHSolverBuilderBase2<T>::WithTargetSpacing(float targetSpacing)
220{
221 m_targetSpacing = targetSpacing;
222 return static_cast<T&>(*this);
223}
224
225template <typename T>
226T& CUDASPHSolverBuilderBase2<T>::WithRelativeKernelRadius(
228{
229 m_relativeKernelRadius = relativeKernelRadius;
230 return static_cast<T&>(*this);
231}
232
233template <typename T>
234T& CUDASPHSolverBuilderBase2<T>::WithNegativePressureScale(
236{
237 m_negativePressureScale = negativePressureScale;
238 return static_cast<T&>(*this);
239}
240
241template <typename T>
242T& CUDASPHSolverBuilderBase2<T>::WithViscosityCoefficient(
244{
245 m_viscosityCoefficient = viscosityCoefficient;
246 return static_cast<T&>(*this);
247}
248
249template <typename T>
250T& CUDASPHSolverBuilderBase2<T>::WithPseudoViscosityCoefficient(
252{
253 m_pseudoViscosityCoefficient = pseudoViscosityCoefficient;
254 return static_cast<T&>(*this);
255}
256} // namespace CubbyFlow
257
258#endif
259
260#endif
Definition pybind11Utils.hpp:21
BoundingBox2< float > BoundingBox2F
Definition BoundingBox.hpp:157
Vector2< float > Vector2F
Definition Matrix.hpp:773
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
constexpr float WATER_DENSITY_FLOAT
Water density.
Definition Constants.hpp:302