Home
cd ../playbooks
Developer ToolsAdvanced

Scientific Fluidsim

Framework for computational fluid dynamics simulations using Python. Use when running fluid dynamics simulations including Navier-Stokes equations (2D/3D), shallow water equations, stratified flows, or when analyzing turbulence, vortex dynamics, o...

15 minutes
By K-Dense AISource
#scientific#claude-code#fluidsim#visualization#database

Commercial CFD tools cost thousands and have steep learning curves. Fluidsim provides a Python framework for Navier-Stokes simulations, shallow water equations, and stratified flows — letting you set up, run, and analyze fluid dynamics simulations with the flexibility of a programming language instead of a GUI.

Who it's for: fluid dynamics researchers running numerical simulations of turbulent flows, engineering PhD students learning CFD through Python implementations, oceanographers simulating shallow water and stratified flow dynamics, physicists studying vortex dynamics and turbulence, computational scientists prototyping flow simulations before scaling to production CFD

Example

"Simulate 2D turbulent flow around a cylinder" → Fluidsim setup: Navier-Stokes solver configuration with appropriate Reynolds number, domain and mesh definition, boundary condition specification, time-stepping with stability checks, flow field visualization at key timesteps, and drag coefficient computation from the simulation results

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

# FluidSim

## Overview

FluidSim is an object-oriented Python framework for high-performance computational fluid dynamics (CFD) simulations. It provides solvers for periodic-domain equations using pseudospectral methods with FFT, delivering performance comparable to Fortran/C++ while maintaining Python's ease of use.

**Key strengths**:
- Multiple solvers: 2D/3D Navier-Stokes, shallow water, stratified flows
- High performance: Pythran/Transonic compilation, MPI parallelization
- Complete workflow: Parameter configuration, simulation execution, output analysis
- Interactive analysis: Python-based post-processing and visualization

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

FluidSim is an object-oriented Python framework for high-performance computational fluid dynamics (CFD) simulations. It provides solvers for periodic-domain equations using pseudospectral methods with FFT, delivering performance comparable to Fortran/C++ while maintaining Python's ease of use.

Key strengths:

  • Multiple solvers: 2D/3D Navier-Stokes, shallow water, stratified flows
  • High performance: Pythran/Transonic compilation, MPI parallelization
  • Complete workflow: Parameter configuration, simulation execution, output analysis
  • Interactive analysis: Python-based post-processing and visualization

Quick Start

Step 1: Create a Project Folder

mkdir -p ~/Projects/fluidsim

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ~/Projects/fluidsim/

Step 3: Start Claude Code

cd ~/Projects/fluidsim
claude

Core Capabilities

1. Installation and Setup

Install fluidsim using uv with appropriate feature flags:

# Basic installation
uv uv pip install fluidsim

# With FFT support (required for most solvers)
uv uv pip install "fluidsim[fft]"

# With MPI for parallel computing
uv uv pip install "fluidsim[fft,mpi]"

Set environment variables for output directories (optional):

export FLUIDSIM_PATH=/path/to/simulation/outputs
export FLUIDDYN_PATH_SCRATCH=/path/to/working/directory

No API keys or authentication required.

See references/installation.md for complete installation instructions and environment configuration.

2. Running Simulations

Standard workflow consists of five steps:

Step 1: Import solver

from fluidsim.solvers.ns2d.solver import Simul

Step 2: Create and configure parameters

params = Simul.create_default_params()
params.oper.nx = params.oper.ny = 256
params.oper.Lx = params.oper.Ly = 2 * 3.14159
params.nu_2 = 1e-3
params.time_stepping.t_end = 10.0
params.init_fields.type = "noise"

Step 3: Instantiate simulation

sim = Simul(params)

Step 4: Execute

sim.time_stepping.start()

Step 5: Analyze results

sim.output.phys_fields.plot("vorticity")
sim.output.spatial_means.plot()

See references/simulation_workflow.md for complete examples, restarting simulations, and cluster deployment.

3. Available Solvers

Choose solver based on physical problem:

2D Navier-Stokes (ns2d): 2D turbulence, vortex dynamics

from fluidsim.solvers.ns2d.solver import Simul

3D Navier-Stokes (ns3d): 3D turbulence, realistic flows

from fluidsim.solvers.ns3d.solver import Simul

Stratified flows (ns2d.strat, ns3d.strat): Oceanic/atmospheric flows

from fluidsim.solvers.ns2d.strat.solver import Simul
params.N = 1.0  # Brunt-Väisälä frequency

Shallow water (sw1l): Geophysical flows, rotating systems

from fluidsim.solvers.sw1l.solver import Simul
params.f = 1.0  # Coriolis parameter

See references/solvers.md for complete solver list and selection guidance.

4. Parameter Configuration

Parameters are organized hierarchically and accessed via dot notation:

Domain and resolution:

params.oper.nx = 256  # grid points
params.oper.Lx = 2 * pi  # domain size

Physical parameters:

params.nu_2 = 1e-3  # viscosity
params.nu_4 = 0     # hyperviscosity (optional)

Time stepping:

params.time_stepping.t_end = 10.0
params.time_stepping.USE_CFL = True  # adaptive time step
params.time_stepping.CFL = 0.5

Initial conditions:

params.init_fields.type = "noise"  # or "dipole", "vortex", "from_file", "in_script"

Output settings:

params.output.periods_save.phys_fields = 1.0  # save every 1.0 time units
params.output.periods_save.spectra = 0.5
params.output.periods_save.spatial_means = 0.1

The Parameters object raises AttributeError for typos, preventing silent configuration errors.

See references/parameters.md for comprehensive parameter documentation.

5. Output and Analysis

FluidSim produces multiple output types automatically saved during simulation:

Physical fields: Velocity, vorticity in HDF5 format

sim.output.phys_fields.plot("vorticity")
sim.output.phys_fields.plot("vx")

Spatial means: Time series of volume-averaged quantities

sim.output.spatial_means.plot()

Spectra: Energy and enstrophy spectra

sim.output.spectra.plot1d()
sim.output.spectra.plot2d()

Load previous simulations:

from fluidsim import load_sim_for_plot
sim = load_sim_for_plot("simulation_dir")
sim.output.phys_fields.plot()

Advanced visualization: Open .h5 files in ParaView or VisIt for 3D visualization.

See references/output_analysis.md for detailed analysis workflows, parametric study analysis, and data export.

6. Advanced Features

Custom forcing: Maintain turbulence or drive specific dynamics

params.forcing.enable = True
params.forcing.type = "tcrandom"  # time-correlated random forcing
params.forcing.forcing_rate = 1.0

Custom initial conditions: Define fields in script

params.init_fields.type = "in_script"
sim = Simul(params)
X, Y = sim.oper.get_XY_loc()
vx = sim.state.state_phys.get_var("vx")
vx[:] = sin(X) * cos(Y)
sim.time_stepping.start()

MPI parallelization: Run on multiple processors

mpirun -np 8 python simulation_script.py

Parametric studies: Run multiple simulations with different parameters

for nu in [1e-3, 5e-4, 1e-4]:
    params = Simul.create_default_params()
    params.nu_2 = nu
    params.output.sub_directory = f"nu{nu}"
    sim = Simul(params)
    sim.time_stepping.start()

See references/advanced_features.md for forcing types, custom solvers, cluster submission, and performance optimization.

Common Use Cases

2D Turbulence Study

from fluidsim.solvers.ns2d.solver import Simul
from math import pi

params = Simul.create_default_params()
params.oper.nx = params.oper.ny = 512
params.oper.Lx = params.oper.Ly = 2 * pi
params.nu_2 = 1e-4
params.time_stepping.t_end = 50.0
params.time_stepping.USE_CFL = True
params.init_fields.type = "noise"
params.output.periods_save.phys_fields = 5.0
params.output.periods_save.spectra = 1.0

sim = Simul(params)
sim.time_stepping.start()

# Analyze energy cascade
sim.output.spectra.plot1d(tmin=30.0, tmax=50.0)

Stratified Flow Simulation

from fluidsim.solvers.ns2d.strat.solver import Simul

params = Simul.create_default_params()
params.oper.nx = params.oper.ny = 256
params.N = 2.0  # stratification strength
params.nu_2 = 5e-4
params.time_stepping.t_end = 20.0

# Initialize with dense layer
params.init_fields.type = "in_script"
sim = Simul(params)
X, Y = sim.oper.get_XY_loc()
b = sim.state.state_phys.get_var("b")
b[:] = exp(-((X - 3.14)**2 + (Y - 3.14)**2) / 0.5)
sim.state.statephys_from_statespect()

sim.time_stepping.start()
sim.output.phys_fields.plot("b")

High-Resolution 3D Simulation with MPI

from fluidsim.solvers.ns3d.solver import Simul

params = Simul.create_default_params()
params.oper.nx = params.oper.ny = params.oper.nz = 512
params.nu_2 = 1e-5
params.time_stepping.t_end = 10.0
params.init_fields.type = "noise"

sim = Simul(params)
sim.time_stepping.start()

Run with:

mpirun -np 64 python script.py

Taylor-Green Vortex Validation

from fluidsim.solvers.ns2d.solver import Simul
import numpy as np
from math import pi

params = Simul.create_default_params()
params.oper.nx = params.oper.ny = 128
params.oper.Lx = params.oper.Ly = 2 * pi
params.nu_2 = 1e-3
params.time_stepping.t_end = 10.0
params.init_fields.type = "in_script"

sim = Simul(params)
X, Y = sim.oper.get_XY_loc()
vx = sim.state.state_phys.get_var("vx")
vy = sim.state.state_phys.get_var("vy")
vx[:] = np.sin(X) * np.cos(Y)
vy[:] = -np.cos(X) * np.sin(Y)
sim.state.statephys_from_statespect()

sim.time_stepping.start()

# Validate energy decay
df = sim.output.spatial_means.load()
# Compare with analytical solution

Quick Reference

Import solver: from fluidsim.solvers.ns2d.solver import Simul

Create parameters: params = Simul.create_default_params()

Set resolution: params.oper.nx = params.oper.ny = 256

Set viscosity: params.nu_2 = 1e-3

Set end time: params.time_stepping.t_end = 10.0

Run simulation: sim = Simul(params); sim.time_stepping.start()

Plot results: sim.output.phys_fields.plot("vorticity")

Load simulation: sim = load_sim_for_plot("path/to/sim")

Resources

Documentation: https://fluidsim.readthedocs.io/

Reference files:

  • references/installation.md: Complete installation instructions
  • references/solvers.md: Available solvers and selection guide
  • references/simulation_workflow.md: Detailed workflow examples
  • references/parameters.md: Comprehensive parameter documentation
  • references/output_analysis.md: Output types and analysis methods
  • references/advanced_features.md: Forcing, MPI, parametric studies, custom solvers

Tips

  • Read the docs: Check the official fluidsim documentation for latest API changes
  • Start simple: Begin with basic examples before tackling complex workflows
  • Save your work: Keep intermediate results in case of long-running analyses

$Related Playbooks

Developer Tools

Scientific Get Available Resources

This skill should be used at the start of any computationally intensive scientific task to detect and report available system resources (CPU cores, GPUs, memory, disk space). It creates a JSON file with resource information and strategic recommend...

5 minutes
Beginner
Developer Tools

Web App Testing

Test local web applications with Playwright automation for frontend verification, UI debugging, and screenshot capture.

15 minutes
Intermediate
Developer Tools

Writing for AI Agents: A Craft Reference

A theory of writing any document an agent consumes — skills, CLAUDE.md, reference docs — built on context pointers, an information hierarchy of steps versus disclosed reference, completion criteria, and leading words that anchor behavior in the fewest tokens.

10 minutes
Advanced
Developer Tools

Office MCP Server Setup

MCP server with 39 tools for Word, Excel, PowerPoint, PDF, OCR operations

10 minutes
Intermediate
Developer Tools

Tech Debt Analyzer

Identify, analyze, document, and track technical debt in JavaScript/TypeScript codebases with automated detection and prioritized remediation plans.

10 minutes
Intermediate
Developer Tools

Test Specialist

Comprehensive JavaScript/TypeScript testing guidance with test writing, bug analysis, coverage analysis, and proactive issue detection.

10 minutes
Intermediate
Developer Tools

Accessibility Engineering for Components

Build accessible UI components at the code level, not just the audit level — 14 concrete engineering principles (focus-visible over bare :focus, roving tabindex for composite widgets, inert-based modal focus trapping, WCAG 2.5.8 hit-area minimums), a common-mistakes table with fixes, and a severity-rated review format ending in a hard Block/Needs-changes/Approve verdict.

5 minutes
Intermediate
Developer Tools

Adversary Emulation: MuddyWater

An intelligence-grounded, authorized purple-team emulation profile for MuddyWater (MITRE ATT&CK G0069), Iran's MOIS-linked cyber-espionage group — attribution, targeting, representative TTPs by ATT&CK tactic, emulation guidance mapped to generic red-team tooling, and paired detection/defense recommendations for every offensive technique, all under an explicit authorized-use caveat.

15 minutes
Advanced
Developer Tools

Adversary Emulation: Turla

An intelligence-grounded, authorized purple-team emulation profile for Turla (MITRE ATT&CK G0010), Russia's FSB-linked espionage group — attribution, distinctive TTPs (satellite C2 hijacking, steganographic email backdoors, parasitizing rival APT infrastructure), emulation guidance mapped to generic red-team tooling, and paired detection recommendations, under an explicit authorized-use and lab-only caveat for rootkit techniques.

15 minutes
Advanced
Developer Tools

AI Agent Red Team Methodology

A first-principles methodology for authorized red-team exercises against AI products, agents, MCP servers, skills, and repositories — capability and trust-boundary modeling, AI-specific attack hypothesis families (prompt injection, tool misuse, data leakage, SSRF), harmless-proof testing with canaries, one-variable-at-a-time adaptive iteration, and business-language evidence-based reporting.

10 minutes
Advanced
Developer Tools

Datadog Error Triage to PR

Take Datadog Error Tracking issues from raw occurrence counts to a reviewable, tested PR — a five-class bug taxonomy that filters out infra noise and deploy-skew before ranking, a recency premium that catches fresh regressions early, a mandatory approval gate before any fix is written, and a test-first fix workflow that generalizes past the one reported occurrence.

10 minutes
Advanced
Developer Tools

Agent DX CLI Scale

A 7-axis, 0-21 scoring scale for evaluating how well a CLI is designed for AI agents rather than humans — machine-readable output, raw payload input, schema introspection, context-window discipline, input hardening, safety rails, and agent knowledge packaging.

5 minutes
Intermediate

Browse all Developer Tools playbooks →