$npx -y skills add K-Dense-AI/scientific-agent-skills --skill fluidsimFramework 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 pse
| 1 | # FluidSim |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | **Key strengths**: |
| 8 | - Multiple solvers: 2D/3D Navier-Stokes, shallow water, stratified flows |
| 9 | - High performance: Pythran/Transonic compilation, MPI parallelization |
| 10 | - Complete workflow: Parameter configuration, simulation execution, output analysis |
| 11 | - Interactive analysis: Python-based post-processing and visualization |
| 12 | |
| 13 | ## Core Capabilities |
| 14 | |
| 15 | ### 1. Installation and Setup |
| 16 | |
| 17 | Install fluidsim using uv with appropriate feature flags: |
| 18 | |
| 19 | ```bash |
| 20 | # Basic installation |
| 21 | uv pip install fluidsim |
| 22 | |
| 23 | # With FFT support (required for most solvers) |
| 24 | uv pip install "fluidsim[fft]" |
| 25 | |
| 26 | # With MPI for parallel computing |
| 27 | uv pip install "fluidsim[fft,mpi]" |
| 28 | ``` |
| 29 | |
| 30 | Set environment variables for output directories (optional): |
| 31 | |
| 32 | ```bash |
| 33 | export FLUIDSIM_PATH=/path/to/simulation/outputs |
| 34 | export FLUIDDYN_PATH_SCRATCH=/path/to/working/directory |
| 35 | ``` |
| 36 | |
| 37 | No API keys or authentication required. |
| 38 | |
| 39 | See `references/installation.md` for complete installation instructions and environment configuration. |
| 40 | |
| 41 | ### 2. Running Simulations |
| 42 | |
| 43 | Standard workflow consists of five steps: |
| 44 | |
| 45 | **Step 1**: Import solver |
| 46 | ```python |
| 47 | from fluidsim.solvers.ns2d.solver import Simul |
| 48 | ``` |
| 49 | |
| 50 | **Step 2**: Create and configure parameters |
| 51 | ```python |
| 52 | params = Simul.create_default_params() |
| 53 | params.oper.nx = params.oper.ny = 256 |
| 54 | params.oper.Lx = params.oper.Ly = 2 * 3.14159 |
| 55 | params.nu_2 = 1e-3 |
| 56 | params.time_stepping.t_end = 10.0 |
| 57 | params.init_fields.type = "noise" |
| 58 | ``` |
| 59 | |
| 60 | **Step 3**: Instantiate simulation |
| 61 | ```python |
| 62 | sim = Simul(params) |
| 63 | ``` |
| 64 | |
| 65 | **Step 4**: Execute |
| 66 | ```python |
| 67 | sim.time_stepping.start() |
| 68 | ``` |
| 69 | |
| 70 | **Step 5**: Analyze results |
| 71 | ```python |
| 72 | sim.output.phys_fields.plot("vorticity") |
| 73 | sim.output.spatial_means.plot() |
| 74 | ``` |
| 75 | |
| 76 | See `references/simulation_workflow.md` for complete examples, restarting simulations, and cluster deployment. |
| 77 | |
| 78 | ### 3. Available Solvers |
| 79 | |
| 80 | Choose solver based on physical problem: |
| 81 | |
| 82 | **2D Navier-Stokes** (`ns2d`): 2D turbulence, vortex dynamics |
| 83 | ```python |
| 84 | from fluidsim.solvers.ns2d.solver import Simul |
| 85 | ``` |
| 86 | |
| 87 | **3D Navier-Stokes** (`ns3d`): 3D turbulence, realistic flows |
| 88 | ```python |
| 89 | from fluidsim.solvers.ns3d.solver import Simul |
| 90 | ``` |
| 91 | |
| 92 | **Stratified flows** (`ns2d.strat`, `ns3d.strat`): Oceanic/atmospheric flows |
| 93 | ```python |
| 94 | from fluidsim.solvers.ns2d.strat.solver import Simul |
| 95 | params.N = 1.0 # Brunt-Väisälä frequency |
| 96 | ``` |
| 97 | |
| 98 | **Shallow water** (`sw1l`): Geophysical flows, rotating systems |
| 99 | ```python |
| 100 | from fluidsim.solvers.sw1l.solver import Simul |
| 101 | params.f = 1.0 # Coriolis parameter |
| 102 | ``` |
| 103 | |
| 104 | See `references/solvers.md` for complete solver list and selection guidance. |
| 105 | |
| 106 | ### 4. Parameter Configuration |
| 107 | |
| 108 | Parameters are organized hierarchically and accessed via dot notation: |
| 109 | |
| 110 | **Domain and resolution**: |
| 111 | ```python |
| 112 | params.oper.nx = 256 # grid points |
| 113 | params.oper.Lx = 2 * pi # domain size |
| 114 | ``` |
| 115 | |
| 116 | **Physical parameters**: |
| 117 | ```python |
| 118 | params.nu_2 = 1e-3 # viscosity |
| 119 | params.nu_4 = 0 # hyperviscosity (optional) |
| 120 | ``` |
| 121 | |
| 122 | **Time stepping**: |
| 123 | ```python |
| 124 | params.time_stepping.t_end = 10.0 |
| 125 | params.time_stepping.USE_CFL = True # adaptive time step |
| 126 | params.time_stepping.CFL = 0.5 |
| 127 | ``` |
| 128 | |
| 129 | **Initial conditions**: |
| 130 | ```python |
| 131 | params.init_fields.type = "noise" # or "dipole", "vortex", "from_file", "in_script" |
| 132 | ``` |
| 133 | |
| 134 | **Output settings**: |
| 135 | ```python |
| 136 | params.output.periods_save.phys_fields = 1.0 # save every 1.0 time units |
| 137 | params.output.periods_save.spectra = 0.5 |
| 138 | params.output.periods_save.spatial_means = 0.1 |
| 139 | ``` |
| 140 | |
| 141 | The Parameters object raises `AttributeError` for typos, preventing silent configuration errors. |
| 142 | |
| 143 | See `references/parameters.md` for comprehensive parameter documentation. |
| 144 | |
| 145 | ### 5. Output and Analysis |
| 146 | |
| 147 | FluidSim produces multiple output types automatically saved during simulation: |
| 148 | |
| 149 | **Physical fields**: Velocity, vorticity in HDF5 format |
| 150 | ```python |
| 151 | sim.output.phys_fields.plot("vorticity") |
| 152 | sim.output.phys_fields.plot("vx") |
| 153 | ``` |
| 154 | |
| 155 | **Spatial means**: Time series of volume-averaged quantities |
| 156 | ```python |
| 157 | sim.output.spatial_means.plot() |
| 158 | ``` |
| 159 | |
| 160 | **Spectra**: Energy and enstrophy spectra |
| 161 | ```python |
| 162 | sim.output.spectra.plot1d() |
| 163 | sim.output.spectra.plot2d() |
| 164 | ``` |
| 165 | |
| 166 | **Load previous simulations**: |
| 167 | ```python |
| 168 | from fluidsim import load_sim_for_plot |
| 169 | sim = load_sim_for_plot("simulation_dir") |
| 170 | sim.output.phys_fields.plot() |
| 171 | ``` |
| 172 | |
| 173 | **Advanced visualization**: Open `.h5` files in ParaView |