Skip to main content

PyLbmSimulation

Struct PyLbmSimulation 

Source
pub struct PyLbmSimulation { /* private fields */ }
Expand description

A 2-D D2Q9 Lattice-Boltzmann fluid simulation.

Supports:

  • BGK collision operator (single relaxation time)
  • Periodic streaming
  • No-slip bounce-back walls via boundary map
  • Velocity and density field extraction
  • Lid-driven velocity boundary on top row

Implementations§

Source§

impl PyLbmSimulation

Source

pub fn new(config: &PyLbmConfig) -> Self

Create a new LBM simulation from configuration.

All cells are initialised to equilibrium at the configured density and velocity.

Source

pub fn width(&self) -> usize

Grid width.

Source

pub fn height(&self) -> usize

Grid height.

Source

pub fn step_count(&self) -> u64

Number of completed steps.

Source

pub fn set_boundary(&mut self, x: usize, y: usize, btype: LbmBoundary)

Set the boundary type of cell (x, y).

Source

pub fn get_boundary(&self, x: usize, y: usize) -> Option<LbmBoundary>

Get the boundary type of cell (x, y).

Source

pub fn add_top_wall(&mut self)

Mark all cells along the top row as NoSlipWall.

Source

pub fn add_bottom_wall(&mut self)

Mark all cells along the bottom row as NoSlipWall.

Source

pub fn add_enclosing_walls(&mut self)

Mark all four enclosing walls as NoSlipWall (cavity setup).

Source

pub fn set_lid_velocity(&mut self, vel: Option<[f64; 2]>)

Set a lid velocity applied to the top row every step.

Pass None to disable.

Source

pub fn velocity_at(&self, x: usize, y: usize) -> [f64; 2]

Get macroscopic velocity [ux, uy] at cell (x, y).

Returns [0, 0] for out-of-bounds or wall cells.

Source

pub fn density_at(&self, x: usize, y: usize) -> f64

Get macroscopic density at cell (x, y). Returns 0 if out of bounds.

Source

pub fn get_velocity_field(&self) -> Vec<f64>

Return the full velocity field as a flat Vecf64of[ux, uy]pairs, row-major (y outer, x inner). Length =width * height * 2`.

Source

pub fn get_density_field(&self) -> Vec<f64>

Return the full density field as a flat Vecf64, row-major. Length = width * height`.

Source

pub fn step(&mut self)

Advance the simulation by one LBM time step.

Steps:

  1. Collision (BGK) + optional body-force correction.
  2. Apply lid velocity (if set) as equilibrium on top row.
  3. Streaming with periodic boundaries.
  4. Bounce-back for NoSlipWall cells.
Source

pub fn run(&mut self, steps: u64)

Run n steps.

Source§

impl PyLbmSimulation

Source

pub fn mean_density(&self) -> f64

Mean macroscopic density over all non-wall cells.

Source

pub fn max_speed(&self) -> f64

Maximum speed (magnitude of velocity) over all non-wall cells.

Source

pub fn vorticity_field(&self) -> Vec<f64>

Vorticity field (z-component of curl) as a flat Vecf64.

Uses central differences. Length = width * height.

Source

pub fn enstrophy(&self) -> f64

Enstrophy (0.5 ∫ ω² dA) — scalar measure of total vorticity.

Source

pub fn reynolds_number(&self, omega: f64) -> f64

Reynolds number estimate: Re = L * U / ν (characteristic length = height/2).

Source

pub fn speed_field(&self) -> Vec<f64>

Return the velocity magnitude field as a flat Vecf64.

Source

pub fn reset_to_equilibrium(&mut self, rho: f64, ux: f64, uy: f64)

Reset all cells to equilibrium at given density and velocity.

Source

pub fn add_circular_obstacle(&mut self, cx: usize, cy: usize, r: usize)

Set a circular obstacle (no-slip) at (cx, cy) with integer radius r.

Source

pub fn fluid_cell_count(&self) -> usize

Count of fluid (non-wall) cells.

Source

pub fn wall_cell_count(&self) -> usize

Count of wall cells.

Source§

impl PyLbmSimulation

Source

pub fn collect_stats(&self) -> LbmStats

Collect per-step statistics.

Trait Implementations§

Source§

impl Clone for PyLbmSimulation

Source§

fn clone(&self) -> PyLbmSimulation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PyLbmSimulation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.