phipict.simulation.sgs.append_sgs_viscosity_prep_fn
- phipict.simulation.sgs.append_sgs_viscosity_prep_fn(prep_fn: Hooks | dict[str, Any], model: Literal['none', 'smagorinsky', 'wale'], coefficient: float, ndims: int, dtype: dtype, cuda_device: device, cpu_device: device | None = None, scale_sqr: list[Tensor] | None = None) None[source]
Register a
Hook.PREcallback settingblock.viscosity = nu_SGS + nu.The eddy viscosity is recomputed from the current velocity field before the momentum matrix is assembled, and added to the molecular viscosity per cell. It affects momentum only; passive scalars keep their molecular diffusivity.
- Parameters:
prep_fn (Hooks or dict[str, Any]) – The hooks (or legacy callback dict) to append to. Modified in place.
model (SGSModel) – The sub-grid-scale model.
"none"registers nothing.coefficient (float) – The model coefficient. The conventions differ per model and are not interchangeable:
"smagorinsky"expectsC_s**2, while"wale"expects the textbookCw(~0.325-0.5), which the extension squares internally.ndims (int) – Number of spatial dimensions.
"wale"requires 3.dtype (torch.dtype) – Dtype of the domain; the coefficient tensor must match it.
cuda_device (torch.device) – The CUDA device the simulation runs on.
cpu_device (torch.device | None) – Device for the coefficient tensor, which the extension requires on the host. Defaults to CPU.
scale_sqr (list[torch.Tensor] | None) – Optional per-block multiplicative damping field applied to nu_SGS before the molecular viscosity is added (e.g. squared van Driest for a channel).