|
|
|
@ -17,10 +17,10 @@ pub struct FluidSquare { |
|
|
|
|
impl FluidSquare { |
|
|
|
|
pub fn new(size: i32, diff: f32, visc: f32, dt: f32) -> FluidSquare { |
|
|
|
|
FluidSquare { |
|
|
|
|
size: size, |
|
|
|
|
dt: dt, |
|
|
|
|
diff: diff, |
|
|
|
|
visc: visc, |
|
|
|
|
size, |
|
|
|
|
dt, |
|
|
|
|
diff, |
|
|
|
|
visc, |
|
|
|
|
s: vec![0.0; (size * size) as usize], |
|
|
|
|
density: vec![0.0; (size * size) as usize], |
|
|
|
|
v_x: vec![0.0; (size * size) as usize], |
|
|
|
@ -34,7 +34,7 @@ impl FluidSquare { |
|
|
|
|
diffuse( |
|
|
|
|
1, |
|
|
|
|
&mut self.v_x0, |
|
|
|
|
&mut self.v_x, |
|
|
|
|
&self.v_x, |
|
|
|
|
self.visc, |
|
|
|
|
self.dt, |
|
|
|
|
iter, |
|
|
|
@ -43,7 +43,7 @@ impl FluidSquare { |
|
|
|
|
diffuse( |
|
|
|
|
2, |
|
|
|
|
&mut self.v_y0, |
|
|
|
|
&mut self.v_y, |
|
|
|
|
&self.v_y, |
|
|
|
|
self.visc, |
|
|
|
|
self.dt, |
|
|
|
|
iter, |
|
|
|
@ -90,7 +90,7 @@ impl FluidSquare { |
|
|
|
|
diffuse( |
|
|
|
|
0, |
|
|
|
|
&mut self.s, |
|
|
|
|
&mut self.density, |
|
|
|
|
&self.density, |
|
|
|
|
self.diff, |
|
|
|
|
self.dt, |
|
|
|
|
iter, |
|
|
|
@ -119,12 +119,12 @@ impl FluidSquare { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn diffuse(b: i32, x: &mut Vec<f32>, x0: &Vec<f32>, diff: f32, dt: f32, iter: i32, size: i32) { |
|
|
|
|
fn diffuse(b: i32, x: &mut Vec<f32>, x0: &[f32], diff: f32, dt: f32, iter: i32, size: i32) { |
|
|
|
|
let a: f32 = dt * diff * (size - 2) as f32 * (size - 2) as f32; |
|
|
|
|
lin_solve(b, x, x0, a, 1.0 + 6.0 * a, iter, size) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn lin_solve(b: i32, x: &mut Vec<f32>, x0: &Vec<f32>, a: f32, c: f32, iter: i32, size: i32) { |
|
|
|
|
fn lin_solve(b: i32, x: &mut Vec<f32>, x0: &[f32], a: f32, c: f32, iter: i32, size: i32) { |
|
|
|
|
let c_recip = 1.0 / c; |
|
|
|
|
for _k in 0..iter { |
|
|
|
|
for j in 1..size - 1 { |
|
|
|
@ -217,9 +217,9 @@ fn project( |
|
|
|
|
fn advect( |
|
|
|
|
b: i32, |
|
|
|
|
d: &mut Vec<f32>, |
|
|
|
|
d0: &Vec<f32>, |
|
|
|
|
v_x: &Vec<f32>, |
|
|
|
|
v_y: &Vec<f32>, |
|
|
|
|
d0: &[f32], |
|
|
|
|
v_x: &[f32], |
|
|
|
|
v_y: &[f32], |
|
|
|
|
dt: f32, |
|
|
|
|
size: i32, |
|
|
|
|
) { |
|
|
|
|