CUDASPHKernels3-Impl.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_SPH_KERNELS3_IMPL_HPP
12 #define CUBBYFLOW_CUDA_SPH_KERNELS3_IMPL_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 #include <Core/CUDA/CUDAUtils.hpp>
17 #include <Core/Utils/Constants.hpp>
18 
19 namespace CubbyFlow
20 {
21 inline CUDASPHStdKernel3::CUDASPHStdKernel3() : h(0), h2(0), h3(0), h5(0)
22 {
23  // Do nothing
24 }
25 
26 inline CUDASPHStdKernel3::CUDASPHStdKernel3(float kernelRadius)
27  : h(kernelRadius), h2(h * h), h3(h2 * h), h5(h2 * h3)
28 {
29  // Do nothing
30 }
31 
32 inline float CUDASPHStdKernel3::operator()(float distance) const
33 {
34  if (distance * distance >= h2)
35  {
36  return 0.0f;
37  }
38 
39  const float x = 1.0f - distance * distance / h2;
40  return 315.0f / (64.0f * PI_FLOAT * h3) * x * x * x;
41 }
42 
43 inline float CUDASPHStdKernel3::FirstDerivative(float distance) const
44 {
45  if (distance >= h)
46  {
47  return 0.0f;
48  }
49 
50  const float x = 1.0f - distance * distance / h2;
51  return -945.0f / (32.0f * PI_FLOAT * h5) * distance * x * x;
52 }
53 
54 inline float CUDASPHStdKernel3::SecondDerivative(float distance) const
55 {
56  if (distance * distance >= h2)
57  {
58  return 0.0f;
59  }
60 
61  const float x = distance * distance / h2;
62  return 945.0f / (32.0f * PI_FLOAT * h5) * (1 - x) * (3 * x - 1);
63 }
64 
65 inline float4 CUDASPHStdKernel3::Gradient(const float4& point) const
66 {
67  float dist = Length(point);
68 
69  if (dist > 0.0f)
70  {
71  return Gradient(dist, point / dist);
72  }
73 
74  return make_float4(0, 0, 0, 0);
75 }
76 
77 inline float4 CUDASPHStdKernel3::Gradient(float distance,
78  const float4& directionToCenter) const
79 {
80  return -FirstDerivative(distance) * directionToCenter;
81 }
82 
83 inline CUDASPHSpikyKernel3::CUDASPHSpikyKernel3()
84  : h(0), h2(0), h3(0), h4(0), h5(0)
85 {
86  // Do nothing
87 }
88 
89 inline CUDASPHSpikyKernel3::CUDASPHSpikyKernel3(float kernelRadius)
90  : h(kernelRadius), h2(h * h), h3(h2 * h), h4(h2 * h2), h5(h3 * h2)
91 {
92  // Do nothing
93 }
94 
95 inline float CUDASPHSpikyKernel3::operator()(float distance) const
96 {
97  if (distance >= h)
98  {
99  return 0.0f;
100  }
101 
102  const float x = 1.0f - distance / h;
103  return 15.0f / (PI_FLOAT * h3) * x * x * x;
104 }
105 
106 inline float CUDASPHSpikyKernel3::FirstDerivative(float distance) const
107 {
108  if (distance >= h)
109  {
110  return 0.0f;
111  }
112 
113  const float x = 1.0f - distance / h;
114  return -45.0f / (PI_FLOAT * h4) * x * x;
115 }
116 
117 inline float CUDASPHSpikyKernel3::SecondDerivative(float distance) const
118 {
119  if (distance >= h)
120  {
121  return 0.0f;
122  }
123 
124  const float x = 1.0f - distance / h;
125  return 90.0f / (PI_FLOAT * h5) * x;
126 }
127 
128 inline float4 CUDASPHSpikyKernel3::Gradient(const float4& point) const
129 {
130  float dist = Length(point);
131 
132  if (dist > 0.0f)
133  {
134  return Gradient(dist, point / dist);
135  }
136 
137  return make_float4(0, 0, 0, 0);
138 }
139 
140 inline float4 CUDASPHSpikyKernel3::Gradient(
141  float distance, const float4& directionToCenter) const
142 {
143  return -FirstDerivative(distance) * directionToCenter;
144 }
145 } // namespace CubbyFlow
146 
147 #endif
148 
149 #endif
Definition: pybind11Utils.hpp:20
constexpr float PI_FLOAT
Float-type PI.
Definition: Constants.hpp:75
size_t Length() const
Definition: ArrayBase-Impl.hpp:84