-
Notifications
You must be signed in to change notification settings - Fork 1
/
SPHKernel.h
102 lines (82 loc) · 2.09 KB
/
SPHKernel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef _SPH_KERNEL_H_
#define _SPH_KERNEL_H_
#include "common.h"
class SPHKernel
{
public:
static float Poly6_W(float distance, float effective_radius)
{
if (distance >= 0 && distance <= effective_radius)
{
const double h = static_cast<double>(effective_radius);
const double d = static_cast<double>(distance);
double h2 = h * h;
double h9 = glm::pow(h, 9);
double d2 = d * d;
double q = h2 - d2;
double q3 = q * q * q;
double result = (315.0 / (64.0 * M_PI * h9)) * q3;
return static_cast<float>(result);
}
else
{
return 0.0f;
}
}
static glm::vec3 Poly6_W_Gradient(glm::vec3 diff, float distance, float effective_radius)
{
if (distance >= 0 && distance <= effective_radius)
{
const double h = static_cast<double>(effective_radius);
const double d = static_cast<double>(distance);
double h2 = h * h;
double h9 = glm::pow(h, 9);
double d2 = d * d;
double q = h2 - d2;
double q2 = q * q;
double scalar = (-945.0 / (32.0 * M_PI * h9));
glm::vec3 result = static_cast<float>(scalar) * static_cast<float>(q2) * diff;
return result;
}
else
{
return glm::vec3(0);
}
}
static float Spiky_W(float distance, float effective_radius)
{
if (distance >= 0 && distance <= effective_radius)
{
const double h = static_cast<double>(effective_radius);
const double d = static_cast<double>(distance);
double h6 = glm::pow(h, 6);
double q = h - d;
double q3 = q * q * q;
float result = static_cast<float>((15.0 / (M_PI * h6)) * q3);
return result;
}
else
{
return 0.0f;
}
}
static glm::vec3 Spiky_W_Gradient(glm::vec3 diff, float distance, float effective_radius)
{
if (distance >= 0 && distance <= effective_radius)
{
const double h = static_cast<double>(effective_radius);
const double d = static_cast<double>(distance);
double h6 = glm::pow(h, 6);
double q = h - d;
double q2 = q * q;
double scalar = (-45.0 / (M_PI * h6)) * (q2 / distance);
glm::vec3 result = static_cast<float>(scalar) * diff;
return result;
}
else
{
return glm::vec3(0);
}
}
};
#endif