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, or geophysical flows. Provides pseudospectral methods with FFT, HPC support, and comprehensive output analysis.
# Basic installation
uv pip install fluidsim
# With FFT support (required for most solvers)
uv pip install "fluidsim[fft]"
# With MPI for parallel computing
uv pip install "fluidsim[fft,mpi]"
export FLUIDSIM_PATH=/path/to/simulation/outputs
export FLUIDDYN_PATH_SCRATCH=/path/to/working/directory
references/installation.md for complete installation instructions and environment configuration.from fluidsim.solvers.ns2d.solver import Simul
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"
sim = Simul(params)
sim.time_stepping.start()
sim.output.phys_fields.plot("vorticity")
sim.output.spatial_means.plot()
references/simulation_workflow.md for complete examples, restarting simulations, and cluster deployment.ns2d): 2D turbulence, vortex dynamicsfrom fluidsim.solvers.ns2d.solver import Simul
ns3d): 3D turbulence, realistic flowsfrom fluidsim.solvers.ns3d.solver import Simul
ns2d.strat, ns3d.strat): Oceanic/atmospheric flowsfrom fluidsim.solvers.ns2d.strat.solver import Simul
params.N = 1.0 # Brunt-Väisälä frequency
sw1l): Geophysical flows, rotating systemsfrom fluidsim.solvers.sw1l.solver import Simul
params.f = 1.0 # Coriolis parameter
references/solvers.md for complete solver list and selection guidance.params.oper.nx = 256 # grid points
params.oper.Lx = 2 * pi # domain size
params.nu_2 = 1e-3 # viscosity
params.nu_4 = 0 # hyperviscosity (optional)
params.time_stepping.t_end = 10.0
params.time_stepping.USE_CFL = True # adaptive time step
params.time_stepping.CFL = 0.5
params.init_fields.type = "noise" # or "dipole", "vortex", "from_file", "in_script"
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
AttributeError for typos, preventing silent configuration errors.references/parameters.md for comprehensive parameter documentation.sim.output.phys_fields.plot("vorticity")
sim.output.phys_fields.plot("vx")
sim.output.spatial_means.plot()
sim.output.spectra.plot1d()
sim.output.spectra.plot2d()
from fluidsim import load_sim_for_plot
sim = load_sim_for_plot("simulation_dir")
sim.output.phys_fields.plot()
.h5 files in ParaView or VisIt for 3D visualization.references/output_analysis.md for detailed analysis workflows, parametric study analysis, and data export.params.forcing.enable = True
params.forcing.type = "tcrandom" # time-correlated random forcing
params.forcing.forcing_rate = 1.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")
vx[:] = sin(X) * cos(Y)
sim.time_stepping.start()
mpirun -np 8 python simulation_script.py
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()
references/advanced_features.md for forcing types, custom solvers, cluster submission, and performance optimization.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)
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")
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()
mpirun -np 64 python script.py
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
from fluidsim.solvers.ns2d.solver import Simulparams = Simul.create_default_params()params.oper.nx = params.oper.ny = 256params.nu_2 = 1e-3params.time_stepping.t_end = 10.0sim = Simul(params); sim.time_stepping.start()sim.output.phys_fields.plot("vorticity")sim = load_sim_for_plot("path/to/sim")references/installation.md: Complete installation instructionsreferences/solvers.md: Available solvers and selection guidereferences/simulation_workflow.md: Detailed workflow examplesreferences/parameters.md: Comprehensive parameter documentationreferences/output_analysis.md: Output types and analysis methodsreferences/advanced_features.md: Forcing, MPI, parametric studies, custom solvers