Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Example: cfd_demo

Figure 1.2 — Example: CFD Demo

Crate: cfd-core
Run: cargo run -p cfd-core --example cfd_demo
Source: crates/cfd-core/examples/cfd_demo.rs

What This Example Demonstrates

Baseline sanity check covering three primitives of the CFDrs stack:

ConceptAPI
3D incompressible flow fieldFlowField::<f64>::new(nx, ny, nz)
Divergence, vorticity, KE, enstrophyFlowOperations::{divergence, vorticity, kinetic_energy, enstrophy}
Laminar/transitional/turbulent classificationReynoldsNumber::new(re, FlowGeometry::Pipe)

Key Code Snippet

use cfd_core::physics::fluid_dynamics::{FlowField, FlowOperations};

let flow_field = FlowField::<f64>::new(32, 32, 32);
let div  = FlowOperations::divergence(&flow_field.velocity); // ≈ 0 for incompressible
let ke   = FlowOperations::kinetic_energy(&flow_field.velocity);

use cfd_core::physics::values::{FlowGeometry, ReynoldsNumber};
let re = ReynoldsNumber::new(2300.0, FlowGeometry::Pipe)?;
assert!(re.is_transitional()); // 2100 < Re < 4000 for pipe flow

Physics Background

The continuity equation for an incompressible flow requires ∇·u = 0. A healthy initial condition should give a divergence close to machine epsilon. The enstrophy Ω = ∫½|ω|² dV is a global vorticity measure used for turbulence diagnostics; for a quiescent initial field it should be zero.

Book Chapter

← CFDrs Architecture and Problem Setup