altEngine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sph.h
Go to the documentation of this file.
1 #include "include.h"
2 
3 #ifndef SPH_H
4 #define SPH_H
5 
6 #define kMass 0.010543f //kg uniform particle mass
7 #define kRadius 0.005f //m -- physical particle radius (for collision detection against mainly)
8 #define kH (0.03f) //m 6 * kRadius -- radius particles will interact with neighbors
9 #define kH2 (0.0009f) //m^2 (kH * kH) -- radius of interaction squared
10 #define kStiffness 0.08f
11 #define kRestDensity 82.0f //kg.m^3
12 #define kLinearViscocity 0.02f
13 
14 
15 
16 #define kGravity 9.8f
17 #define kWallStiff 10000
18 #define kWallDamp 256
19 #define kDeltaTime 0.004f
20 #define kMaxAccel 200 //m.s^2
21 #define kScale 0.04f
22 #define kEpsilon 0.000001f
23 
24 /*
25 W(r-rb,h) = 315 / 64pi h^9(h^2 - |r-rb|^2)^3
26 gradW(r-rb,h) = -45 / pi h^6 (h - |r-rb|)^2 [r-rb]/[r-rb]
27 lapW(r-rb,h)= 45 / pi h^6 [ h - |r-rb|)
28 */
29 
30 #define POLY6_KERN (315.0f / (64.0f * MY_PI * (float)pow(kH, 9)))
31 #define GRAD_POLY6_KERN 945.0f / (32.0f * MY_PI * (float)pow(kH, 9));
32 #define LAP_POLY6_KERN 945.0f / (32.0f * MY_PI * (float)pow(kH, 9));
33 #define SPIKY_KERN (-45.0f / (MY_PI * (float)pow(kH, 6)))
34 #define VISCOSITY_KERN (45.0f / (MY_PI * (float)pow(kH, 6)))
35 
36 #define MAX_NEIGHBOR 64
37 
38 typedef struct
39 {
43  float pressure;
44  float density;
45  // float near_pressure;
46  // float near_density;
47  float mass;
48  int nbCount;
49  int nbList[MAX_NEIGHBOR];
50 } particle_t;
51 
52 #define GRID_SIZE 6
53 
54 #define MAX_GRID_PARTICLE 4000
55 typedef struct
56 {
58  int num_part;
59 } voxel_t;
60 
61 
62 
63 class Sph
64 {
65 public:
66  Sph();
67  void init(int num_particle);
68  void step(int frame);
69  void render();
70 
71 private:
72  void calc_density_pressure(int i);
73  void calc_force(int i);
74  void calc_pos(int i);
75  void update_grid();
76  void update_neighbors();
77  float norm2(vec3 &x, vec3 &y);
78 
79 
82  unsigned int last_rendered;
83  unsigned int last_calculated;
85 
86 
87  // define fluid bounds
94 
95 
96 
97  // constant kernel factors
98  float poly6_kern;
101  float spiky_kern;
103 };
104 
105 #endif