Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .jules/curator.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@
**Gap:** The `freesurfer` module was a "Visual Void" with no explanation of the cortical reconstruction pipeline or usage.
**Strategy:** Overhauled `freesurfer/mod.rs` with a Mermaid pipeline diagram and a runnable Quick Start example for cortical thickness calculation.
**Outcome:** Users can now understand the MRI processing pipeline and use the tools for surface analysis.

## 2025-05-20 - Visualizing Fluid Dynamics & Stat Mech
**Gap:** The `physics/fluid_dynamics` module was a "Blank Page" with no context, and `physics/stat_mech` lacked visual explanation of phase transitions.
**Strategy:**
- Overhauled `fluid_dynamics/mod.rs` with a Mermaid diagram of Conservation Laws and a runnable Reynolds Number example.
- Overhauled `stat_mech/mod.rs` with a Mermaid diagram of the Ising Phase Transition and a runnable Ferromagnetism example.
**Outcome:** Users can now visualize the physics of flow and statistical ordering without reading the source code.
2 changes: 1 addition & 1 deletion math_explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The library is organized into high-level domains:
- **`biology`**: Biological modeling, including **Neuroscience** (Hodgkin-Huxley) and **Morphogenesis**.
- **`climate`**: Climate modeling tools, featuring the **CERA** autoencoder framework.
- **`epidemiology`**: Disease modeling, from standard **SIR/SEIR** compartmental models to stochastic network dynamics.
- **`physics`**: Simulations of physical systems, including **Quantum Mechanics**, **Fluid Dynamics**, **Chaos Theory** (Lorenz System), and **MRI Physics**.
- **`physics`**: Simulations of physical systems, including **Quantum Mechanics**, **Fluid Dynamics** (Navier-Stokes), **Statistical Mechanics** (Ising Model), **Chaos Theory** (Lorenz System), and **MRI Physics**.
- **`pure_math`**: Foundational mathematics, covering **Algebra**, **Number Theory** (Partitions, Q-Series), **Graph Theory**, and **Differential Geometry**.

## 🚀 Usage
Expand Down
74 changes: 74 additions & 0 deletions math_explorer/src/physics/fluid_dynamics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
//! # Fluid Dynamics
//!
//! > **"Panta Rhei" (Everything Flows)** — Heraclitus
//!
//! This module implements the fundamental laws governing the motion of fluids, from
//! the microscopic conservation laws to macroscopic flow regimes.
//!
//! ## The Physics of Flow
//!
//! Fluid dynamics is built upon three conservation laws which form the Navier-Stokes equations:
//!
//! ```mermaid
//! graph TD
//! subgraph "Conservation Laws"
//! Mass[Conservation of Mass]
//! Momentum[Conservation of Momentum]
//! Energy[Conservation of Energy]
//! end
//!
//! subgraph "Governing Equations"
//! NSE[Navier-Stokes Equations]
//! Euler[Euler Equations]
//! end
//!
//! subgraph "Flow Regimes"
//! Re{Reynolds Number}
//! Laminar[Laminar Flow]
//! Turbulent[Turbulence]
//! end
//!
//! Mass --> NSE
//! Momentum --> NSE
//! Energy --> NSE
//!
//! NSE -->|Viscosity = 0| Euler
//! NSE --> Re
//!
//! Re -->|< 2000| Laminar
//! Re -->|> 4000| Turbulent
//! ```
//!
//! ## 🚀 Quick Start: Flow Regime Classification
//!
//! Determine if a flow is laminar or turbulent based on its Reynolds number.
//!
//! ```rust
//! use math_explorer::physics::fluid_dynamics::types::FluidProperties;
//! use math_explorer::physics::fluid_dynamics::regimes::{PipeFlowClassifier, FlowClassifier};
//!
//! // 1. Define Fluid Properties (Water at 20°C)
//! let water = FluidProperties::water();
//!
//! // 2. Define Flow Conditions
//! let velocity = 2.0; // Flow velocity (m/s)
//! let diameter = 0.05; // Pipe diameter (5 cm)
//!
//! // 3. Calculate Reynolds Number: Re = (rho * v * L) / mu
//! let re = (water.density * velocity * diameter) / water.dynamic_viscosity;
//! println!("Reynolds Number: {:.2}", re);
//!
//! // 4. Classify Regime
//! let classifier = PipeFlowClassifier;
//! let regime = classifier.classify(re);
//!
//! println!("Flow Regime: {:?}", regime);
//! ```
//!
//! ## Modules
//!
//! - **[`conservation`]**: Implementation of Mass and Momentum conservation (Navier-Stokes).
//! - **[`regimes`]**: Strategy pattern for classifying flow (Laminar vs. Turbulent).
//! - **[`turbulence`]**: RANS (Reynolds-Averaged Navier-Stokes) modeling components.
//! - **[`types`]**: Core structs like `FluidProperties` and `FlowState`.

pub mod analysis;
pub mod conservation;
pub mod regimes;
Expand Down
28 changes: 19 additions & 9 deletions math_explorer/src/physics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//! # Physics
//!
//! This module contains implementations of physical formulas and concepts, bridging theoretical physics with computational models.
//!
//! ## Domains
//!
//! - **Astrophysics**: Galaxy properties and orbital mechanics.
//! - **Chaos Theory**: Deterministic chaos (Lorenz System) and Lyapunov exponents.
//! - **Fluid Dynamics**: Conservation laws (Navier-Stokes), flow regimes, and turbulence.
//! - **High Energy Physics**: Special/General Relativity and particle physics.
//! - **Medical Physics**: Radiation therapy planning and dosimetry.
//! - **MRI**: Magnetic Resonance Imaging simulation.
//! - **Nuclear Physics**: Liquid drop models, shell models, and decay chains.
//! - **Optics**: Wave optics and ray tracing.
//! - **Quantum Mechanics**: Angular momentum coupling (Clebsch-Gordan), Qubits, and time evolution.
//! - **Solid State**: Many-Body Physics, Phonons, and BCS theory.
//! - **Standard Model**: Particle physics classifications.
//! - **Statistical Mechanics**: Ising model, Ensembles, and Phase Transitions.

pub mod astrophysics;
pub mod chaos;
pub mod fluid_dynamics;
Expand All @@ -6,15 +25,6 @@ pub mod medical;
pub mod mri;
pub mod nuclear;
pub mod optics;
/// The physics module contains implementations of physical formulas and concepts.
///
/// It currently includes:
/// - Astrophysics (galaxy properties).
/// - Quantum mechanics (angular momentum coupling).
/// - Fluid Dynamics (conservation laws, turbulence).
/// - Nuclear Physics (properties, liquid drop, shell model, decay, reactions).
/// - Solid State Physics (Many-Body Physics, Phonons, BCS).
/// - MRI (Magnetic Resonance Imaging) simulation.
pub mod quantum;
pub mod solid_state;
pub mod standard_model;
Expand Down
81 changes: 77 additions & 4 deletions math_explorer/src/physics/stat_mech/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,81 @@
//! Statistical Mechanics module.
//! # Statistical Mechanics
//!
//! This module serves as the mathematical bridge between quantum/classical micro-physics
//! and macroscopic thermodynamics, covering Ensemble Theory, Quantum Statistics,
//! Phase Transitions, and Non-Equilibrium dynamics.
//! > **"Ludwig Boltzmann, who spent much of his life studying statistical mechanics, died in 1906, by his own hand. Paul Ehrenfest, carrying on the work, died similarly in 1933. Now it is our turn."** — David L. Goodstein
//!
//! This module bridges the gap between the microscopic world of quantum mechanics and the macroscopic world of thermodynamics.
//!
//! ## The Ising Model
//!
//! The Ising model is the simplest model of a phase transition. It describes ferromagnetism using discrete spins on a lattice.
//!
//! ```mermaid
//! graph TD
//! subgraph "Microscopic State"
//! Spins[Spin Lattice (+1/-1)]
//! Interaction[Neighbor Interaction J]
//! Temp[Temperature T]
//! end
//!
//! subgraph "Metropolis Dynamics"
//! Flip{Flip Spin?}
//! Energy[Delta E]
//! Prob[Boltzmann Probability]
//! end
//!
//! subgraph "Macroscopic Phase"
//! Order[Ferromagnetic (Ordered)]
//! Critical[Critical Point Tc]
//! Disorder[Paramagnetic (Disordered)]
//! end
//!
//! Spins --> Interaction
//! Interaction --> Flip
//! Temp --> Prob
//!
//! Flip -->|Delta E < 0| Update
//! Flip -->|Random < Prob| Update
//!
//! Temp --> Critical
//! Critical -->|T < Tc| Order
//! Critical -->|T > Tc| Disorder
//! ```
//!
//! ## 🚀 Quick Start: Simulating Ferromagnetism
//!
//! Simulate a 2D Ising model and observe the magnetization.
//!
//! ```rust
//! use math_explorer::physics::stat_mech::ising::SpinLattice;
//! use math_explorer::physics::stat_mech::KB;
//!
//! // 1. Setup Lattice (50x50 spins)
//! let width = 50;
//! let height = 50;
//! let mut lattice = SpinLattice::new(width, height);
//!
//! // 2. Define Physics Parameters
//! let j_coupling = 1.0; // Interaction strength
//! let h_field = 0.0; // No external magnetic field
//!
//! // 3. Set Temperature (T < Tc implies Order)
//! // Tc approx 2.269 * J / KB
//! let temp = 1.5 * j_coupling / KB;
//!
//! // 4. Evolve System (Monte Carlo Simulation)
//! // 1000 steps per spin (MCS)
//! let steps = 1000 * width * height;
//! lattice.evolve(steps, temp, j_coupling, h_field);
//!
//! // 5. Measure Magnetization
//! let m = lattice.magnetization();
//! println!("Final Magnetization: {}", m);
//! ```
//!
//! ## Modules
//!
//! - **[`ising`]**: 2D Ising Model simulation using Metropolis-Hastings.
//! - **[`ensembles`]**: Canonical and Grand Canonical ensemble properties.
//! - **[`dynamics`]**: Time-evolution and equilibration logic.

/// Boltzmann Constant in J/K.
pub const KB: f64 = 1.380649e-23;
Expand Down