fn apply_pressure(&mut self, delta_t: f64) {
        let scale = delta_t  / (self.density * self.grid_cell_size);
        for i in 1..self.w {
            for j in 1..self.h {
                let (grad_p_x, grad_p_y) = self.p.grad(i, j);

                // Update velocity
                *self.u.get_mut(i, j) -= scale * grad_p_x;
                *self.v.get_mut(i, j) -= scale * grad_p_y;
            }
        }

        // Set the velocity field along the borders to zero.
        for j in 0..self.h {
            *self.u.get_mut(0, j) = 0.0;          // Left column
            *self.u.get_mut(self.w - 1, j) = 0.0; // Right column
        }
        for i in 0..self.w {
            *self.v.get_mut(i, 0) = 0.0;          // Bottom row
            *self.v.get_mut(i, self.h - 1) = 0.0; // Top row
        }
    }
/// Update each component of the velocity field based on the
/// pressure gradient. Note that this update should only be
/// applied to components of the velocity that border a grid
/// cell that contains fluid.
///
/// Some updates may require the pressure of grid cells that
/// lie either outside of the grid or outside of the fluid.
/// We must specify boundary conditions to handle this:
///
/// a) Dirichlet: at free surface boundaries, the pressure
///    is zero. We handle this automatically when we initialize
///    the solver.
/// b) Neumann: at solid walls, we substitute in the solid's
///    velocity, which is zero for static solids. We handle this
///    by setting the velocity components along the border
///    to zero.
Update each component of the velocity field based on the
pressure gradient. Note that this update should only be
applied to components of the velocity that border a grid
cell that contains fluid.

Some updates may require the pressure of grid cells that
lie either outside of the grid or outside of the fluid.
We must specify boundary conditions to handle this.

a) Dirichlet: at free surface boundaries, the pressure
is zero. We handle this automatically when we initialize
the solver.
b) Neumann: at solid walls, we substitute in the solid's
velocity, which is zero for static solids. We handle this
by setting the velocity components along the border
to zero.
Update each component of the velocity field based on the pressure gradient . Note that this update should only be applied to components of the velocity that border a grid cell that contains fluid . Some updates may require the pressure of grid cells that lie either outside of the grid or outside of the fluid . We must specify boundary conditions to handle this . a ) Dirichlet : at free surface boundaries the pressure is zero . We handle this automatically when we initialize the solver . b ) Neumann : at solid walls we substitute in the solid ' s velocity which is zero for static solids . We handle this by setting the velocity components along the border to zero .
fn apply_pressure(&mut self, delta_t: f64) {
        let scale = delta_t  / (self.density * self.grid_cell_size);
        for i in 1..self.w {
            for j in 1..self.h {
                let (grad_p_x, grad_p_y) = self.p.grad(i, j);
                // Update velocity
                *self.u.get_mut(i, j) -= scale * grad_p_x;
                *self.v.get_mut(i, j) -= scale * grad_p_y;
            }
        }
        // Set the velocity field along the borders to zero.
        for j in 0..self.h {
            *self.u.get_mut(0, j) = 0.0;          // Left column
            *self.u.get_mut(self.w - 1, j) = 0.0; // Right column
        }
        for i in 0..self.w {
            *self.v.get_mut(i, 0) = 0.0;          // Bottom row
            *self.v.get_mut(i, self.h - 1) = 0.0; // Top row
        }
    }
fn apply_pressure ( & mut self , delta_t : f64 ) { let scale = delta_t / ( self . density * self . grid_cell_size ) ; for i in 1 .. self . w { for j in 1 .. self . h { let ( grad_p_x , grad_p_y ) = self . p . grad ( i , j ) ; // Update velocity * self . u . get_mut ( i , j ) -= scale * grad_p_x ; * self . v . get_mut ( i , j ) -= scale * grad_p_y ; } } // Set the velocity field along the borders to zero. for j in 0 .. self . h { * self . u . get_mut ( 0 , j ) = 0.0 ; // Left column * self . u . get_mut ( self . w - 1 , j ) = 0.0 ; // Right column } for i in 0 .. self . w { * self . v . get_mut ( i , 0 ) = 0.0 ; // Bottom row * self . v . get_mut ( i , self . h - 1 ) = 0.0 ; // Top row } }
Update each component of the velocity field based on the
pressure gradient.
Update each component of the velocity field based on the pressure gradient .
&mut self
delta_t
f64
&mut self
delta_t
f64