-
Notifications
You must be signed in to change notification settings - Fork 15
/
fluidsim.h
73 lines (50 loc) · 1.38 KB
/
fluidsim.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
#ifndef FLUIDSIM_H
#define FLUIDSIM_H
#include "array3.h"
#include "vec.h"
#include "pcgsolver/sparse_matrix.h"
#include "pcgsolver/pcg_solver.h"
#include <vector>
#include <stdio.h>
class FluidSim {
public:
void initialize(float width, int ni_, int nj_, int nk_);
void set_boundary(float (*phi)(const Vec3f&));
void set_liquid(float (*phi)(const Vec3f&));
void add_particle(const Vec3f& pos);
void advance(float dt);
//Grid dimensions
int ni,nj,nk;
float dx;
//Fluid velocity
Array3f u, v, w;
Array3f temp_u, temp_v, temp_w;
//Static geometry representation
Array3f nodal_solid_phi;
Array3f u_weights, v_weights, w_weights;
Array3c u_valid, v_valid, w_valid;
std::vector<Vec3f> particles;
float particle_radius;
Array3f liquid_phi;
//Data arrays for extrapolation
Array3c valid, old_valid;
//Solver data
PCGSolver<double> solver;
SparseMatrixd matrix;
std::vector<double> rhs;
std::vector<double> pressure;
Vec3f get_velocity(const Vec3f& position);
private:
Vec3f trace_rk2(const Vec3f& position, float dt);
float cfl();
void advect_particles(float dt);
void advect(float dt);
void add_force(float dt);
void project(float dt);
void constrain_velocity();
//helpers for pressure projection
void compute_weights();
void solve_pressure(float dt);
void compute_phi();
};
#endif