-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFluidSolver.java
72 lines (63 loc) · 1.64 KB
/
FluidSolver.java
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
/**
* Fluid solver with vorticity confinement and buoyancy force.
*
* Used for teaching purpose at ISTY
*
* Based on original work from Alexander McKenzie, Caltech
* This Class is basically sending in/out data from the Webserver to the Core computing C libraries
**/
public class FluidSolver
{
int n, size;
float dt;
float visc = 0.0f;
float diff = 0.0f;
float[] d, dOld;
float[] u, uOld;
float[] v, vOld;
float[] curl;
/**
* Set the grid size and timestep.
**/
public void setup(int n, float dt)
{
this.n = n;
this.dt = dt;
size = (n + 2) * (n + 2);
reset();
}
/**
* Reset the datastructures.
* We use 1d arrays for speed.
**/
public void reset()
{
d = new float[size];
dOld = new float[size];
u = new float[size];
uOld = new float[size];
v = new float[size];
vOld = new float[size];
curl = new float[size];
for (int i = 0; i < size; i++)
{
u[i] = uOld[i] = v[i] = vOld[i] = 0.0f;
d[i] = dOld[i] = curl[i] = 0.0f;
}
}
/**
* The basic velocity solving routine as described by Stam. This function is simply a stub to call the C routine
**/
public void velocitySolver()
{
fluid.c_velocitySolver(u, uOld, v, vOld, curl, d, visc, dt, n, size);
}
/**
* The basic density solving routine. This function is simply a stub to call the C routine
**/
public void densitySolver()
{
// add density inputted by mouse
fluid.c_densitySolver(d, dOld, diff, u, v , dt, n, size);
}
}