forked from ruudandriessen/2imv15-assignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kernels.cpp
65 lines (57 loc) · 1.67 KB
/
Kernels.cpp
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
//
// Created by Ruud Andriessen on 11/06/2017.
//
#include <iostream>
#include "Kernels.h"
// Use poly for all computations except for visc. and pressure
float Poly6::W(const Vector3f &r, float h) {
float rd = r.norm();
if (rd >= 0 && rd <= h) {
return 315 / (64 * M_PI * pow(h, 9)) * pow(h * h - rd * rd, 3);
}
return 0;
}
Vector3f Poly6::dW(const Vector3f &r, float h) {
float rd = r.norm();
if (rd >= 0 && rd <= h) {
return 315 / (64 * M_PI * pow(h, 9)) * -6 * pow(h * h - rd * rd, 2) * r;
}
return Vector3f(0,0,0);
}
float Poly6::ddW(const Vector3f &r, float h) {
float rd = r.norm();
if (rd >= 0 && rd <= h) {
return 315 / (64 * M_PI * pow(h, 9)) * (24 * rd * rd * (h * h - rd * rd) - 6 * pow(h * h - rd * rd, 2));
}
return 0;
}
// Use spiky for pressure computations
float Spiky::W(const Vector3f &r, float h) {
float rd = r.norm();
if (rd >= 0 && rd <= h) {
return 15 / (M_PI * pow(h, 6)) * pow(h - rd, 3);
}
return 0;
}
Vector3f Spiky::dW(const Vector3f &r, float h) {
float rd = r.norm();
if (rd > 0 && rd <= h) {
return - 45 / (M_PI * pow(h, 6) * rd) * pow(h - rd, 2) * r;
}
return Vector3f(0,0,0);
};
// Use viscosity for viscosity computations
float Viscosity::W(const Vector3f &r, float h) {
float rd = r.norm();
if (rd >= 0 && rd <= h) {
return 15 / (2 * M_PI * pow(h, 3)) * (-pow(rd, 3) / (2 * pow(h, 3)) + (rd * rd) / (h * h) + h / (2 * rd) - 1);
}
return 0;
}
float Viscosity::ddW(const Vector3f &r, float h) {
float rd = r.norm();
if (rd >= 0 && rd <= h) {
return 45 / (M_PI * pow(h, 6)) * (h - rd);
}
return 0;
}