///|
/// D2Q9 equilibrium distribution for a direction.
pub fn equilibrium(d : Int, rho : Double, ux : Double, uy : Double) -> Double {
let cu = cx[d].to_double() * ux + cy[d].to_double() * uy
let u2 = ux * ux + uy * uy
weights[d] * rho * (1.0 + 3.0 * cu + 4.5 * cu * cu - 1.5 * u2)
}
///|
/// Reconstruct density and velocity at a cell from distribution values.
pub fn Lattice::cell(self : Lattice, x : Int, y : Int) -> Cell {
if self.is_solid(x, y) {
{ rho: 1.0, ux: 0.0, uy: 0.0 }
} else {
let base = self.dist_index(x, y, 0)
let mut rho = 0.0
let mut ux = 0.0
let mut uy = 0.0
for d in 0.. Unit {
if self.contains(x, y) {
let base = self.dist_index(x, y, 0)
for d in 0.. Unit {
self.next.fill(0.0)
for y in 0.. Unit {
for _ in 0.. Unit {
let c = self.cell(x, y)
let ux = c.ux + self.config.force_x
let uy = c.uy + self.config.force_y
let src = self.dist_index(x, y, 0)
for d in 0.. Unit {
let base = self.dist_index(x, y, 0)
for d in 0..