phipict.Simulation

class phipict.Simulation(domain: phipict._C.Domain, dt: float, substeps: int | Literal['ADAPTIVE'] = 1, corrector_steps: int = 2, density_viscosity: float | None = None, adaptive_CFL: float = 0.8, adaptive_CFL_per_env: bool = True, prep_fn: Hooks | dict | None = None, advection_use_BiCG: bool = True, pressure_use_BiCG: bool = False, scipy_solve_advection: bool = False, scipy_solve_pressure: bool = False, preconditionBiCG: bool = False, BiCG_precondition_fallback: bool = True, advection_tol: float | SolverTolerance | None = None, pressure_tol: float | SolverTolerance | None = None, pressure_tol_intermediate: float | SolverTolerance | None = None, pressure_warm_start: bool = False, flux_balance_tol: float = 1e-05, convergence_tol: float | None = None, solver_double_fallback: bool = False, advect_non_ortho_steps: int = 1, pressure_non_ortho_steps: int = 1, normalize_pressure_result: bool = True, pressure_return_best_result: bool = False, advect_passive_scalar: bool = True, pressure_time_step_normalized: bool = False, velocity_corrector: str = 'FD', non_orthogonal: bool = True, differentiable: bool = False, exclude_advection_solve_gradients: bool = False, exclude_pressure_solve_gradients: bool = False, output_resampling_shape: tuple[int, ...] | None = None, output_resampling_fill_max_steps: int = 0, hooks: Hooks | dict | None = None)[source]

FluidGym simulation class based on the PICT PISO solver.

Parameters:
  • domain (_C.Domain) – The simulation domain.

  • dt (float) – The simulation time step.

  • substeps (int | Literal["ADAPTIVE"]) – Number of substeps per simulation step or “ADAPTIVE” for adaptive substepping. Defaults to 1.

  • corrector_steps (int) – Number of corrector steps in the PISO algorithm. Defaults to 2.

  • density_viscosity (float | None) – Fluid density viscosity. If None, uses domain default. Defaults to None.

  • adaptive_CFL (float) – CFL number for adaptive time stepping. Defaults to 0.8.

  • adaptive_CFL_per_env (bool) – With batched environments, derive the adaptive substeps of every environment from its own maximum velocity, so it takes the substeps it would take on its own. Defaults to True.

  • hooks (Hooks | dict | None) – Callbacks run at the hooks of every PISO step, see Hooks. Defaults to None.

  • prep_fn (Hooks | dict | None) – The former name of hooks, kept for compatibility. Defaults to None.

  • advection_use_BiCG (bool) – Whether to use BiCG solver for advection. Defaults to True.

  • pressure_use_BiCG (bool) – Whether to use BiCG solver for pressure. Defaults to False.

  • scipy_solve_advection (bool) – Whether to use SciPy solver for advection. Defaults to False.

  • scipy_solve_pressure (bool) – Whether to use SciPy solver for pressure. Defaults to False.

  • preconditionBiCG (bool) – Whether to precondition BiCG solver. Defaults to False.

  • BiCG_precondition_fallback (bool) – Whether to fallback if preconditioning fails. Defaults to True.

  • advection_tol (float | SolverTolerance | None) – Tolerance for the advection solves (momentum and passive scalar). A float is an absolute tolerance on ||r||_2/sqrt(n); a SolverTolerance specifies it relative to the RHS instead, which keeps its meaning across domain sizes. If None, uses the dtype default. Defaults to None.

  • pressure_tol (float | SolverTolerance | None) – Tolerance for the pressure solve; same forms as advection_tol. The residual of this solve is the mass-conservation error of the projection. If None, uses the dtype default. Defaults to None.

  • pressure_tol_intermediate (float | SolverTolerance | None) – Tolerance for every pressure solve that is not the final corrector. Only the final corrector’s pressure survives into the solution, so the earlier ones can be solved loosely. None (the default) applies pressure_tol everywhere, i.e. the historical behaviour.

  • pressure_warm_start (bool) – Seed each pressure solve with the previous sub-step’s result for the same corrector index instead of with zero. An initial guess cannot change the converged answer, only the iteration count. Defaults to False.

  • flux_balance_tol (float) – Tolerance for flux balance check before each step. Defaults to 1e-5.

  • convergence_tol (float | None) – Convergence tolerance for the solver. If None, uses default. Defaults to None.

  • solver_double_fallback (bool) – Whether to fallback to double precision if single precision fails. Defaults to False.

  • advect_non_ortho_steps (int) – Number of non-orthogonal corrector steps for advection. Defaults to 1.

  • pressure_non_ortho_steps (int) – Number of non-orthogonal corrector steps for pressure. Defaults to 1.

  • normalize_pressure_result (bool) – Whether to normalize pressure results. Defaults to True.

  • pressure_return_best_result (bool) – Whether to return the best pressure result. Defaults to False.

  • advect_passive_scalar (bool) – Whether to advect passive scalars. Defaults to True.

  • pressure_time_step_normalized (bool) – Whether pressure is normalized by time step. Defaults to False.

  • velocity_corrector (str) – Type of velocity corrector to use. Defaults to “FD”.

  • non_orthogonal (bool) – Whether to use non-orthogonal corrections. Defaults to True.

  • differentiable (bool) – Whether to use the differentiable solver backend. Defaults to False.

  • exclude_advection_solve_gradients (bool) – Whether to exclude gradients from advection solve. Defaults to False.

  • exclude_pressure_solve_gradients (bool) – Whether to exclude gradients from pressure solve. Defaults to False.

  • output_resampling_shape (tuple[int, ...] | None) – Shape for output resampling. If None, dynamic shape is used. Defaults to None.

  • output_resampling_fill_max_steps (int) – Number of steps to fill for max step resampling. Defaults to 0.

__init__(domain: phipict._C.Domain, dt: float, substeps: int | Literal['ADAPTIVE'] = 1, corrector_steps: int = 2, density_viscosity: float | None = None, adaptive_CFL: float = 0.8, adaptive_CFL_per_env: bool = True, prep_fn: Hooks | dict | None = None, advection_use_BiCG: bool = True, pressure_use_BiCG: bool = False, scipy_solve_advection: bool = False, scipy_solve_pressure: bool = False, preconditionBiCG: bool = False, BiCG_precondition_fallback: bool = True, advection_tol: float | SolverTolerance | None = None, pressure_tol: float | SolverTolerance | None = None, pressure_tol_intermediate: float | SolverTolerance | None = None, pressure_warm_start: bool = False, flux_balance_tol: float = 1e-05, convergence_tol: float | None = None, solver_double_fallback: bool = False, advect_non_ortho_steps: int = 1, pressure_non_ortho_steps: int = 1, normalize_pressure_result: bool = True, pressure_return_best_result: bool = False, advect_passive_scalar: bool = True, pressure_time_step_normalized: bool = False, velocity_corrector: str = 'FD', non_orthogonal: bool = True, differentiable: bool = False, exclude_advection_solve_gradients: bool = False, exclude_pressure_solve_gradients: bool = False, output_resampling_shape: tuple[int, ...] | None = None, output_resampling_fill_max_steps: int = 0, hooks: Hooks | dict | None = None) → None[source]

Methods

__init__(domain, dt[, substeps, ...])

advect_static(iterations[, time_step])

Advect only the passive scalar in the current velocity field.

clear_pressure_guess()

Drop the warm-start cache, e.g. after the domain or dt changed.

end_step([time_step])

Advance the step counter and the simulated time.

linear_solve(csrMat, rhs[, x, use_BiCG, ...])

Solve A x = b with the configured solver.

linear_solve_AMG(rhs, x, amg_hierarchy, tol, ...)

Solve with AMG-preconditioned CG (host setup, on-device V-cycle).

linear_solve_GPU(csrMat, rhs[, x, use_BiCG, ...])

Solve A x = b with the CUDA solvers.

linear_solve_scipy(csrMat, rhs[, x])

Solve A x = b with SciPy's direct sparse solver on the host.

make_divergence_free([iterations, max_iter])

Run pressure corrections to make the velocity divergence free.

resample(field[, out_indices])

Resample a field of all blocks onto the uniform output grid.

reset_image_out_idx()

Reset the index of written images to 0.

reset_step_counters()

Reset the step, time and image counters.

reset_total_step()

Reset the total step counter to 0.

reset_total_time()

Reset the total simulated time to 0.

run(iterations[, static, log_domain])

Run the simulation.

save_domain([name])

Save the domain to the log directory, logging failures.

save_domain_images([idx, max_mag, vel_exr])

Write images of the domain fields to the log directory.

single_step([static])

Perform a single simulation step.

Attributes

NON_ORTHO_CENTER_MATRIX

NON_ORTHO_DIAGONAL_MATRIX

NON_ORTHO_DIAGONAL_RHS

NON_ORTHO_DIRECT_MATRIX

NON_ORTHO_DIRECT_RHS

adaptive_CFL

CFL number for adaptive substeps.

advect_non_ortho_steps

Non-orthogonal correction steps of the advection.

advection_tol

Advection solver tolerance, the dtype default if unset.

advection_use_BiCG

Whether the advection is solved with BiCGStab.

block_layout

Block arrangement of images.

convergence_tol

Velocity change below which the simulation stops.

corrector_steps

Number of PISO corrector steps.

density_viscosity

Superseded by Domain.scalarViscosity; always None.

differentiable

Whether the differentiable backend is used.

domain

The simulation domain.

hooks

The callbacks run at the hooks of every PISO step.

log_dir

Output directory, created on assignment.

log_images

Whether images are written.

log_interval

Iterations between log outputs, 0 if disabled.

non_orthogonal

Whether non-orthogonal corrections are used.

norm_vel

Whether velocity images are normalized.

normalize_pressure_result

Whether the mean pressure is subtracted.

output_resampling_coords

Vertex coordinates for resampled images, defaulting to the domain's.

prep_fn

The former name of hooks, kept for compatibility.

pressure_guess_state

The warm-start cache as one stacked tensor, or None if empty.

pressure_non_ortho_steps

Non-orthogonal correction steps of the pressure.

pressure_return_best_result

Whether a non-converged pressure solve returns its best iterate.

pressure_tol

Pressure solver tolerance, the dtype default (as tensor) if unset.

pressure_tol_intermediate

Tolerance for every pressure solve that is not the final corrector.

pressure_use_BiCG

Whether the pressure is solved with BiCGStab.

pressure_warm_start

Seed each pressure solve with the previous sub-step's result.

scipy_solve_advection

Whether the advection is solved with SciPy.

scipy_solve_pressure

Whether the pressure is solved with SciPy.

stop_fn

Function returning True to stop the simulation.

substeps

Substeps per iteration, -1 for adaptive substeps.

time_step

Time step per substep.

velocity_corrector

Pressure gradient discretization of the velocity correction.