← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / scientific-agent-skills / skills / fluidsim / references / advanced_features.md

Forcing, operators, MPI, extensions, and migrations

Forcing architecture

FluidSim assembles forcing classes through the selected solver's registry. NS2D 0.9 advertises:

Availability and default forced variable are solver-specific.

Base fields:

params.forcing.enable = True
params.forcing.type = "tcrandom"
params.forcing.forcing_rate = 1.0
params.forcing.key_forced = None
params.forcing.nkmin_forcing = 4
params.forcing.nkmax_forcing = 5
params.forcing.tcrandom.time_correlation = "based_on_forcing_rate"

Current source converts nkmin_forcing/nkmax_forcing to dimensional wave-number bounds using the operator's wave-number spacing. Inspect the resulting forced region; the integers are not necessarily physical wave numbers.

Normalization

Current normalized-forcing fields include:

params.forcing.normalized.constant_rate_of = None
params.forcing.normalized.type = "2nd_degree_eq"
params.forcing.normalized.which_root = "minabs"

The implementation can solve a quadratic normalization so the time-step-mean injection of a quadratic quantity matches forcing_rate. The exact quadratic quantity and key depend on the solver/forced field. Therefore:

Do not call forcing_rate “energy input” without verifying the selected class.

Time-correlated random forcing

The 0.9 field is:

params.forcing.tcrandom.time_correlation = "based_on_forcing_rate"

or a finite time value. Current source derives the default period as a power of the forcing rate and stores two random seeds plus the last-change time in state parameters. FluidSim 0.9.0 writes these state parameters into restart files; 0.8.6 fixed a time-correlated forcing restart bug.

For reproducibility, preserve:

In-script forcing

Use the solver's registered InScriptForcing* interface and documented compute_forcing_fft_each_time or coarse equivalent. Do not monkey-patch a method with a lambda copied from an old example:

Implement a reviewed subclass/extension with unit tests on tiny sequential and MPI layouts. Validate zero-net/target injection, symmetry, and budget effects.

Operators and array ownership

sim.oper provides solver-selected grids, FFT/IFFT, differentiation, vector calculus, projections, spectra, dealiasing, and distributed-array helpers. Method names and array layouts depend on operator class.

Never assume:

Use documented operator methods and inspect:

print(type(sim.oper))
print(sim.oper.axes)
print(sim.params.oper)

For custom diagnostics, test sequential and distributed shapes and compare against analytical transforms at tiny resolution.

Dealiasing

The common Cartesian field is:

params.oper.coef_dealiasing = 2 / 3
params.oper.truncation_shape = "cubic"

FluidSim also implements phase-shift time schemes. A coefficient or scheme name does not prove alias removal for a custom nonlinearity. Verify:

Do not combine an aggressive cutoff and high-order dissipation merely to obtain a visually smooth spectrum.

Time schemes

Documented pseudospectral names:

The implementation treats linear terms with exact coefficients in its pseudospectral stepper and evaluates nonlinear tendencies according to the named scheme. Verify source and solver coupling before making an order/stability claim.

Always check:

USE_CFL=True only activates the solver's CFL logic; it does not guarantee all accuracy/stability constraints are resolved.

Custom initial conditions

in_script gives direct control, but use current state keys:

  1. Construct Simul with init_fields.type = "in_script".
  2. Inspect the solver's state documentation/keys.
  3. Fill canonical physical or spectral variables.
  4. Call the documented conversion in the correct direction.
  5. Apply projection/dealiasing/constraints as required.
  6. Save an initialization checkpoint and verify budgets before stepping.

Old examples that fill vx/vy and then call a spectral-to-physical conversion can overwrite the intended state. NS2D 0.9 documentation shows physical keys including ux, uy, and rot; use the selected solver's actual keys.

Extending a solver

FluidSim's InfoSolver/class registry supports extensions. For a research extension:

Avoid private-method snippets from old versions without source review.

FluidFFT backend selection

Installed methods are entry points. Discover them:

from fluidfft import get_methods

print(sorted(get_methods(ndim=2)))
print(sorted(get_methods(ndim=3)))

Set per run:

params.oper.type_fft = "fft2d.with_pyfftw"

or use FLUIDSIM_TYPE_FFT2D/FLUIDSIM_TYPE_FFT3D before process start. Record actual method and plugin distribution.

FluidFFT's 2019 primary paper demonstrates:

Do not transfer its fastest-method or wall-time numbers to current hardware. Benchmark a bounded representative shape in the target environment.

MPI planning and safety

Never call mpirun, mpiexec, srun, qsub, sbatch, OAR tools, or a FluidDyn cluster submitter automatically.

Required preflight:

Output behavior can differ with MPI-enabled h5py. Standard h5py usually causes rank 0 to write assembled state; MPI h5py can use an mpio driver. Verify the locked h5py build and output path with a tiny test.

Parametric studies

Do not loop over simulations and start them directly in one script by default. Instead:

  1. Materialize one strict config per case.
  2. Assign a stable case ID and seed.
  3. Validate/estimate each case.
  4. Sum aggregate CPU, memory concurrency, disk, files, and wall time.
  5. Generate scripts only.
  6. Review sampling design and avoid changing multiple factors ambiguously.
  7. Submit through an approved external workflow.
  8. Track failures/missing cases without silently resampling.

Analyze observables with refinement and stochastic uncertainty, not only final values.

Checkpoint and restart

Physical-state saving is checkpoint creation:

params.output.periods_save.phys_fields = 1.0

But checkpoint usability requires:

Use the bundled compatibility checker before every continuation. A mechanically compatible state can still be scientifically invalid after changed viscosity, forcing, timestep, backend, or resolution.

Migration notes to 0.9.0

0.9.0 (release notes dated 2025-12-03)

0.8.6 (2025-11-23)

0.8.5 (2025-10-23)

0.8.2 (2024-08-17)

0.8.0 (2024-01-31)

Practical migrations from the previous skill:

Sources (verified 2026-07-23)