Fluidsim

Fluidsim automation and integration for seamless fluid simulation workflows

Fluidsim is a community skill for computational fluid dynamics simulation using the Fluidsim Python framework, covering solver configuration, spectral methods, turbulence simulation, output analysis, and parameter sweeps for fluid mechanics research.

What Is This?

Overview

Fluidsim provides patterns for running fluid dynamics simulations in Python using pseudospectral numerical methods. It covers solver selection for different flow equations including Navier-Stokes and shallow water models, simulation parameter configuration for resolution, viscosity, and forcing, time integration with adaptive stepping and checkpoint saving, output management for field snapshots and spatiotemporal spectra, and post-processing analysis of simulation results including energy spectra and statistics. The skill enables researchers to set up, run, and analyze fluid simulations with a high-level Python API built on efficient spectral solvers that handle the underlying FFT operations and dealiasing automatically.

Who Should Use This

This skill serves fluid dynamics researchers running turbulence simulations for fundamental studies, physicists studying geophysical and astrophysical fluid phenomena, and graduate students learning computational fluid dynamics with spectral methods. It is particularly valuable for those who want to focus on physical interpretation rather than low-level numerical implementation.

Why Use It?

Problems It Solves

Writing spectral solvers from scratch requires implementing FFT-based differentiation, dealiasing, and time integration correctly. Managing simulation parameters, output schedules, and checkpoint files demands infrastructure code beyond the numerics. Analyzing turbulence statistics from raw field data requires spectral analysis routines that must be consistent with the solver discretization. Running parameter sweeps across viscosity and resolution values needs automated simulation management to remain reproducible and efficient.

Core Highlights

Solver classes implement spectral methods for 2D and 3D fluid equations with dealiasing. Parameter system configures resolution, physics, and output through a structured API. Output manager saves field snapshots, spectra, and time series at configurable intervals. Post-processing tools compute energy spectra, structure functions, and flow statistics from simulation data.

How to Use It?

Basic Usage

from fluidsim.solvers.ns2d.solver import Simul

params = Simul.create_default_params()
params.oper.nx = 256
params.oper.ny = 256
params.oper.Lx = 2 * 3.14159
params.oper.Ly = 2 * 3.14159
params.nu_2 = 1e-4
params.time_stepping.t_end = 10.0
params.time_stepping.deltat_max = 0.01

params.output.periods_save.phys_fields = 1.0
params.output.periods_save.spatial_means = 0.1

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

print(f"Final time: {sim.time_stepping.t:.2f}")
print(f"Output dir: {sim.output.path_run}")

Real-World Examples

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

class TurbulenceStudy:
    def __init__(self, resolution: int = 512,
                 viscosity: float = 1e-4):
        self.params = Simul.create_default_params()
        self.params.oper.nx = resolution
        self.params.oper.ny = resolution
        self.params.oper.Lx = 2 * np.pi
        self.params.oper.Ly = 2 * np.pi
        self.params.nu_2 = viscosity

    def run(self, duration: float = 20.0,
            save_interval: float = 1.0) -> str:
        self.params.time_stepping.t_end = duration
        self.params.output.periods_save\
            .phys_fields = save_interval
        self.params.output.periods_save\
            .spatial_means = 0.1
        sim = Simul(self.params)
        sim.time_stepping.start()
        return sim.output.path_run

    def parameter_sweep(
            self, viscosities: list[float],
            duration: float = 10.0
            ) -> list[dict]:
        results = []
        for nu in viscosities:
            self.params.nu_2 = nu
            path = self.run(duration)
            results.append({
                "viscosity": nu,
                "path": path})
        return results

study = TurbulenceStudy(resolution=256)
path = study.run(duration=10.0)
print(f"Results: {path}")

Advanced Tips

Use checkpoint files to restart simulations from saved states when running long computations. Adjust dealiasing rules based on the nonlinearity of your equations to prevent spectral aliasing errors. Monitor energy conservation during simulation to detect numerical instabilities early. When diagnosing unexpected behavior, reduce the time step and compare outputs to confirm that results are not sensitive to temporal discretization choices.

When to Use It?

Use Cases

Build a turbulence study pipeline that runs simulations across Reynolds numbers and compares energy spectra. Create a shallow water simulation tool for studying geophysical flow dynamics. Implement a parameter optimization workflow that searches for forcing conditions producing target flow statistics.

Related Topics

Computational fluid dynamics, spectral methods, turbulence simulation, Navier-Stokes equations, and geophysical fluid dynamics.

Important Notes

Requirements

Python with the fluidsim package and its dependencies installed. FFTW library for efficient spectral transforms. MPI is optional for parallel execution on multi-core or distributed systems. Sufficient compute resources for the chosen grid resolution and simulation duration.

Usage Recommendations

Do: start with low resolution to verify simulation setup before running production simulations. Save checkpoints at regular intervals for long simulations. Validate results against known analytical solutions for simple test cases.

Don't: use resolutions that under-resolve the dissipation scale, which produces numerical artifacts. Run long simulations without checkpointing, which prevents recovery from interruptions. Ignore energy diagnostics that indicate growing numerical instabilities.

Limitations

Spectral methods require periodic boundary conditions and are not suitable for complex geometries. 3D simulations at high resolution demand significant compute and memory resources. Some physical models may not be available in the current solver library.