fn advect_quantity(&self, delta_t: f64, q: &FluidQuantity) -> FluidQuantity {
        let mut q_next = FluidQuantity::new(q.w, q.h, q.staggered);

        for i in 0..q.w {
            for j in 0..q.h {

                // The starting position of the particle is simply (i, j).
                let mut position = Vector::new(i as f64, j as f64);

                match q.staggered {
                    Staggered::OffsetX => position.x -= 0.5,
                    Staggered::OffsetY => position.y -= 0.5,
                    _ => ()
                }

                // Get the velocity vector at the point where quantity `q` is
                // sampled. For example, the u-component of the velocity field
                // is sampled at the center of the vertical face the grid cell,
                // so we want to trace a particle from this position backwards.
                let velocity = Vector::new(self.get_interpolated_quantity(&self.u, position.x, position.y),
                                                  self.get_interpolated_quantity(&self.v, position.x, position.y));

                // Trace backwards using Runge-Kutta interpolation.
                let position_prev = match self.interpolation_scheme {
                  InterpolationScheme::RK1 => position - velocity * delta_t,
                  InterpolationScheme::RK2 => {
                      let position_mid = position - velocity * delta_t * 0.5;
                      let velocity_mid = Vector::new(self.get_interpolated_quantity(&self.u, position_mid.x, position_mid.y),
                                                            self.get_interpolated_quantity(&self.v, position_mid.x, position_mid.y));
                      position_mid - velocity_mid * delta_t
                  }
                };

                // Set the value of the fluid quantity in the new buffer.
                *q_next.get_mut(i, j) = self.get_interpolated_quantity(q, position_prev.x, position_prev.y);
            }
        }

        q_next
    }
/// Advect quantity `q` through the velocity field for
/// a time interval `delta_t`. This should only be called
/// with a divergence-free velocity field, i.e. one that
/// meets the incompressibility constraint.
Advect quantity `q` through the velocity field for
a time interval `delta_t`. This should only be called
with a divergence-free velocity field, i.e. one that
meets the incompressibility constraint.
Advect quantity ` q ` through the velocity field for a time interval ` delta_t ` . This should only be called with a divergence - free velocity field i . e . one that meets the incompressibility constraint .
fn advect_quantity(&self, delta_t: f64, q: &FluidQuantity) -> FluidQuantity {
        let mut q_next = FluidQuantity::new(q.w, q.h, q.staggered);
        for i in 0..q.w {
            for j in 0..q.h {
                // The starting position of the particle is simply (i, j).
                let mut position = Vector::new(i as f64, j as f64);
                match q.staggered {
                    Staggered::OffsetX => position.x -= 0.5,
                    Staggered::OffsetY => position.y -= 0.5,
                    _ => ()
                }
                // Get the velocity vector at the point where quantity `q` is
                // sampled. For example, the u-component of the velocity field
                // is sampled at the center of the vertical face the grid cell,
                // so we want to trace a particle from this position backwards.
                let velocity = Vector::new(self.get_interpolated_quantity(&self.u, position.x, position.y),
                                                  self.get_interpolated_quantity(&self.v, position.x, position.y));
                // Trace backwards using Runge-Kutta interpolation.
                let position_prev = match self.interpolation_scheme {
                  InterpolationScheme::RK1 => position - velocity * delta_t,
                  InterpolationScheme::RK2 => {
                      let position_mid = position - velocity * delta_t * 0.5;
                      let velocity_mid = Vector::new(self.get_interpolated_quantity(&self.u, position_mid.x, position_mid.y),
                                                            self.get_interpolated_quantity(&self.v, position_mid.x, position_mid.y));
                      position_mid - velocity_mid * delta_t
                  }
                };
                // Set the value of the fluid quantity in the new buffer.
                *q_next.get_mut(i, j) = self.get_interpolated_quantity(q, position_prev.x, position_prev.y);
            }
        }
        q_next
    }
fn advect_quantity ( & self , delta_t : f64 , q : & FluidQuantity ) -> FluidQuantity { let mut q_next = FluidQuantity :: new ( q . w , q . h , q . staggered ) ; for i in 0 .. q . w { for j in 0 .. q . h { // The starting position of the particle is simply (i, j). let mut position = Vector :: new ( i as f64 , j as f64 ) ; match q . staggered { Staggered :: OffsetX => position . x -= 0.5 , Staggered :: OffsetY => position . y -= 0.5 , _ => ( ) } // Get the velocity vector at the point where quantity `q` is // sampled. For example, the u-component of the velocity field // is sampled at the center of the vertical face the grid cell, // so we want to trace a particle from this position backwards. let velocity = Vector :: new ( self . get_interpolated_quantity ( & self . u , position . x , position . y ) , self . get_interpolated_quantity ( & self . v , position . x , position . y ) ) ; // Trace backwards using Runge-Kutta interpolation. let position_prev = match self . interpolation_scheme { InterpolationScheme :: RK1 => position - velocity * delta_t , InterpolationScheme :: RK2 => { let position_mid = position - velocity * delta_t * 0.5 ; let velocity_mid = Vector :: new ( self . get_interpolated_quantity ( & self . u , position_mid . x , position_mid . y ) , self . get_interpolated_quantity ( & self . v , position_mid . x , position_mid . y ) ) ; position_mid - velocity_mid * delta_t } } ; // Set the value of the fluid quantity in the new buffer. * q_next . get_mut ( i , j ) = self . get_interpolated_quantity ( q , position_prev . x , position_prev . y ) ; } } q_next }
Advect quantity `q` through the velocity field for
a time interval `delta_t`.
Advect quantity ` q ` through the velocity field for a time interval ` delta_t ` .
&self
delta_t
f64
q
&FluidQuantity
&self
delta_t
f64
q
&FluidQuantity