Sub-grid scales

sgs

Filtering

weight_gauss_3d = <xarray.DataArray 'truediv-049dc5ac3a49cba1205f46208d5623e9' (w1: 3, w2: 3)> Size: 72B dask.array<truediv, shape=(3, 3), dtype=float64, chunksize=(3, 3), chunktype=numpy.ndarray> Dimensions without coordinates: w1, w2

3x3 2d Gaussian filter – binomial approximation

weight_gauss_5d = <xarray.DataArray 'array-3ff26ea89580fcbc973ad0755922e2c1' (w1: 5, w2: 5)> Size: 200B dask.array<truediv, shape=(5, 5), dtype=float64, chunksize=(5, 5), chunktype=numpy.ndarray> Dimensions without coordinates: w1, w2

5x5 2d Gaussian filter – binomial approximation

box_kernel(shape)[source]

returns a normalized box kernel with given shape

Parameters:

shape (list[int])

Return type:

DataArray

Returns:

the kernel array with dimesions w1, w2

class Filter(kernel, filter_dims)[source]

Basic filter class with kernel along dimensions the dimensions of kernel and filter_dims are matched one-to-one as given

Variables:
  • kernel – filter kernel

  • filter_dims – dimensions along which to perform filtering; will be paired with dimensions of the kernel.

kernel: DataArray
filter_dims: Sequence[Hashable]
scales()[source]
Return type:

tuple[int, ...]

scale()[source]
Return type:

float

property window: dict[Hashable, int]
with_dims(dims)[source]

return a new filter with same kernel and updated filter_dims

Parameters:

dims (list[Hashable]) – new dimensions; must be the same length as the original ones.

filter(field)[source]

filterer field

Parameters:

field (DataArray) – array to be filtered; must contain all of filter_dims

Return type:

DataArray

class IdentityFilter(kernel, filter_dims)[source]

identity filter

Variables:

kernel – filter kernel will be ignored

filter(field)[source]

returns original field

Parameters:

field (DataArray) – array to be filtered

Return type:

DataArray

class CoarseGrain(window, bc='exact')[source]

Coarse-graining filter class with kernel along dimensions the dimensions of kernel and filter_dims are matched one-to-one as given

Variables:
  • window – {dimension_name: number of grid points to average over}

  • bdry_cnd – boundary conditions: support the same as xr.coarsen, notably ‘trim’ and ‘exact’

filter(field)[source]

coarse grain field; Note: unlike Filter.filter, here the output size is different from the input size

Parameters:

field (DataArray) – array to be filtered; must contain all of filter_dims

Return type:

DataArray

SGS Model Core

class SGSModel(*args, **kwargs)[source]

Base subgrid-scale (SGS) model class

sgs_tensor(filter)[source]

compute model for SGS tensor :math:` au` for a given filter

Parameters:

filter (Filter) – compute the SGS tensor at this scale

Return type:

DataArray

class LinCombSGSModel(model_components)[source]

Linear combination of subgrid-scale (SGS) models

Parameters:

models – List of SGS model components

class LeonardTensor(*args, **kwargs)[source]

compute the Leonard tensor for a large-scale equation

compute(): returns the Leonard tensor for a given filter

class LeonardVelocityTensor(vel, tensor_dims)[source]

Leonard tensor for the velocity

Variables:
  • vel – grid-scale/base velocity field

  • tensor_dims – tensor dimensions

compute(filter)[source]
compute the Leonard tensor as

\(\overline{v_i v_j} - \overline{v_i} \overline{v_j}\), where \(\overline{\ast}\) means filtering

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

class LeonardThetaTensor(vel, theta, tensor_dims)[source]

Leonard tensor for the (potential) temperature \(\theta\)

Variables:
  • vel – grid-scale/base velocity field

  • theta – grid-scale/base temperature field

compute(filter)[source]
compute the Leonard tensor as

\(\overline{v_i \theta} - \overline{v_i} \overline{\theta}\), where \(\overline{\ast}\) means filtering

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

M_Germano_tensor(sgs_model, filter)[source]

compute the Mij Germano model tensor as \((<\tau(\matrhm{at grid})> - \alpha^2 \tau(\mathrm{at filter}))\), where \(\Delta * \alpha\) is the area/volume spanned by the filter kernel and \(\Delta\) is the filter scale.

Parameters:
  • sgs_model (SGSModel) – SGS model used to compute the SGS tensor.

  • filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

class DynamicModelProtcol(*args, **kwargs)[source]

compute the Leonard tensor for a large-scale equation

:meth compute_coeff : returns the SGS tensor for a given filter :meth sgs_tensor: returns the SGS tensor for a given test and regularisation filter

class DynamicModel(static_model, leonard, minimisation)[source]

Dynamic model for SGS model

Variables:
  • static_model – Static SGS model

  • leonard – Leonard tensor for the large-scale equation

  • minimisation – Minimisation method to compute coefficients

Meth compute_coeff:

computes the amplitude coefficients for the SGS model

Meth sgs_tensor:

computes the SGS tensor for a given test and regularisation filters

compute_coeff(test_filter, reg_filter)[source]

compute the amplitude coefficient for the SGS model

Parameters:
  • test_filter (Filter) – Filter used to separate “large” and “small” scales

  • reg_filter (Filter) – Filter used for regularisation

Return type:

DataArray

sgs_tensor(test_filter, reg_filter)[source]

compute the SGS tensor for a given test and regularisation filter

Parameters:
  • test_filter (Filter) – Filter used to separate “large” and “small” scales

  • reg_filter (Filter) – Filter used for regularisation

Return type:

DataArray

class LinCombDynamicModel(static_model, leonard, minimisation)[source]

Dynamic model for linear combination SGS model

Variables:
  • static_model – Static linear combination SGS model

  • leonard – Leonard tensor for the large-scale equation

  • minimisation – Minimisation method to compute coefficients

Meth compute_coeff:

computes the coefficients for the SGS model

Meth sgs_tensor:

computes the SGS tensor for a given test and regularisation filter

compute_coeff(test_filter, reg_filter)[source]

compute the coefficients for the SGS model

Parameters:
  • test_filter (Filter) – Filter used to separate “large” and “small” scales

  • reg_filter (Filter) – Filter used for regularisation

Return type:

DataArray

sgs_tensor(test_filter, reg_filter)[source]

compute the SGS tensor for a given test and regularisation filter

Parameters:
  • test_filter (Filter) – Filter used to separate “large” and “small” scales

  • reg_filter (Filter) – Filter used for regularisation

Return type:

DataArray

class Minimisation(*args, **kwargs)[source]

Protocol for solving the over-determined tensor equation \(L = \sum_i c_i M_i\), where \(L\) and \(M_i\) are tensors and \(c_i\) are scalar coefficients to be computed.

Variables:
  • contraction_dims – Names of the dimensions to contract when forming the tensor products \(L M_i\) and \(M_i M_j\).

  • coeff_dim – Dimension label along which the resulting coefficients \(c_i\) are concatenated.

compute(L, Mi, reg_filter)[source]
solve for \({c_i}\) the over-determined system

\(L = \sum_i(c_i M_i)\).

Parameters:
  • L (DataArray) – LHS tensor

  • M – a sequence of RHS tensors

  • reg_filter (Filter) – Filter used to regularize the contracted tensor products.

Return type:

DataArray

class LillyMinimisation1Model(contraction_dims, coeff_dim)[source]
Lilly Minimisation (least square error) for a 1-global-coefficient model using

the Lilly identity as \(\overline{L \cdot M} / \overline{M \cdot M}\). where \(\cdot\) means tensor contraction, \(\overline{*}\) means regularisation filtering

Parameters:
  • contraction_dims (Sequence[str]) – labels of dimensions to be contracted to form \(L M_i\) and \(M_i M_j\) products.

  • coeff_dim (str) – label of dimension along which to concatenate the arrays \(c_i\)

compute(L, Mi, reg_filter)[source]

Compute \(\overline{L\cdot M} / \overline{M \cdot M}\). where \(\overline{*}\) means regularisation filtering

Parameters:
  • L (DataArray) – LHS tensor

  • M – a sequence of 1 RHS tensors

  • reg_filter (Filter) – Filter used to regularize the contracted tensor products.

Return type:

DataArray

class LillyMinimisation2Model(contraction_dims, coeff_dim)[source]

Lilly Minimisation (least square error) for a 2-coefficient model using the Lilly identity as \(L = \sum_i^2 c_i M_i\).

Parameters:
  • contraction_dims (Sequence[str]) – labels of dimensions to be contracted to form \(L M_i\) and \(M_i M_j\) products.

  • coeff_dim (str) – label of dimension along which to concatenate the arrays \(c_i\)

compute(L, Mi, reg_filter)[source]

Compute dynamic coefficients of a 2-component models using Germano identity as \(L = C_1 M_1 + C_2 M_2\) using regularized least-square minimisation. Inverting the \(\overline{M_i M_j}\) matrix analytically.

Parameters:
  • L (DataArray) – LHS tensor

  • M – a sequence of 2 RHS tensors

  • reg_filter (Filter) – Filter used to regularize the contracted tensor products.

Return type:

DataArray

class LillyMinimisation3Model(contraction_dims, coeff_dim)[source]
Lilly Minimisation (least square error) for a 3-coefficient model using

the Lilly identity as \(L = \sum_i^3 c_i M_i\).

Parameters:
  • contraction_dims (Sequence[str]) – labels of dimensions to be contracted to form \(L M_i\) and \(M_i M_j\) products.

  • coeff_dim (str) – label of dimension along which to concatenate the arrays \(c_i\)

compute(L, Mi, reg_filter)[source]

Compute dynamic coefficients of a 3-component models using Germano identity as \(L = C_1 M_1 + C_2 M_2 + C_3 M_3\) using regularized least-square minimisation (inverting the \(M_i M_j\) matrix explicitly).

Parameters:
  • L (DataArray) – LHS tensor

  • M – a sequence of 3 RHS tensors

  • reg_filter (Filter) – Filter used to regularize the contracted tensor products.

Return type:

DataArray

class LillyMinimisationNModel(contraction_dims, coeff_dim)[source]
Lilly Minimisation (least square error) for an N-coefficient model using

the Lilly identity as \(L = \sum_i^N c_i M_i\).

Parameters:
  • contraction_dims (Sequence[str]) – labels of dimensions to be contracted to form \(L M_i\) and \(M_i M_j\) products.

  • coeff_dim (str) – label of dimension along which to concatenate the arrays \(c_i\)

compute(L, Mi, reg_filter)[source]

Solve the system \(\overline{L \cdot M_i} = \sum_i^N c_j \overline{M_i \cdot M_j}\) using np.linalg.SVD, where \(L \cdot M_i\) and \(M_i \cdot M_j\) are scalar fields

Parameters:
  • L (DataArray) – LHS tensor

  • M – a sequence of RHS tensors

  • reg_filter (Filter) – Filter used to regularize the contracted tensor products.

Return type:

DataArray

SGG models

class SmagorinskyVelocityModel(vel, strain, cs, dx, tensor_dims)[source]

Smagorinsky model for the velocity equation

Variables:
  • vel – grid-scale velocity

  • strain – grid-scale rate-of-strain

  • cs – Smagorinsky coefficient

  • dx – constant resolution with respect to dimension to-be-filtered

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = (c_s \Delta) ^2 |\overline{S_{ij}}| \overline{S_{ij}}\) for a given filter (which can be trivial, i.e. IdentityFilter)

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

class SmagorinskyHeatModel(vel, grad_theta, strain, ctheta, dx, tensor_dims)[source]

Smagorinsky model for the Heat equation

Variables:
  • vel – grid-scale velocity

  • grad_theta – grid-scale (potential) temperature gradient

  • strain – grid-scale rate-of-strain

  • ctheta – Smagorinsky coefficient for the heat equation

  • dx – constant resolution with respect to dimension to-be-filtered

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = c_\theta \Delta^2 |\overline{S_{ij}}| \overline{\nabla \theta}\) for a given filter (which can be trivial, i.e. IdentityFilter)

Parameters:

filter – Filter used to separate “large” and “small” scales

class SSquaredVelocityModel(strain, cs, dx, tensor_dims)[source]

Kosovic JFM 1997, 336 and Speziale 1991 Ann Rev Fluid Mech 23 compoment \(\tau = (c_s \Delta)^2 \mathrm{Traceless}(\overline{S_{ik}} \overline{S_{kj}})\)

Variables:
  • strain – grid-scale rate-of-strain

  • cs – Smagorinsky coefficient

  • dx – constant resolution with respect to dimension to-be-filtered

  • tensor_dims – labels of dimensions indexing tensor components

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = (c_s \Delta) ^2 \overline{S_{ik}}\overline{S_{kj}}\) for a given filter (which can be trivial, i.e. IdentityFilter)

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

class SOmegaVelocityModel(strain, rot, cs, dx, tensor_dims)[source]

Kosovic JFM 1997, 336 / Speziale 1991 Ann Rev Fluid Mech 23 component \(\tau = (c_s \Delta) ^2 \mathrm{Sym}[\overline{S_{ik}}\overline{\Omega_{kj}}]\)

Variables:
  • strain – grid-scale rate-of-strain

  • rot – grid-scale rate-of-rotation

  • cs – Smagorinsky coefficient

  • dx – constant resolution with respect to dimension to-be-filtered

  • tensor_dims – labels of dimensions indexing tensor components

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = (c_s \Delta) ^2 \mathrm{Sym}[\overline{S_{ik}}\overline{\Omega_{kj}}]\) for a given filter (which can be trivial, i.e. IdentityFilter)

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

DynamicKosovicModel(sij, omegaij, vel, res, compoment_coeff, tensor_dims=('c1', 'c2'), minimisation=LillyMinimisation2Model(contraction_dims=['c1', 'c2'], coeff_dim='cdim'))[source]

Dynamic version of the model by Carati & Cabot Proceedings of the 1996 Summer Program – Center for Turbulence Research

Parameters:
  • sij (DataArray) – grid-scale rate-of-strain tensor

  • omegaij (DataArray) – grid-scale rate-of-rotation tensor

  • vel (DataArray) – velocity field used for dynamic coefficient computation

  • res (float) – constant resolution with respect to dimension to-be-filtered

  • compoment_coeff (Sequence[float]) – tuple of three Smagorinsky coefficients for parallel, perpendicular, and normal components

  • tensor_dims (tuple[str, str]) – labels of dimensions indexing tensor components, defaults to (“c1”, “c2”)

Return type:

LinCombDynamicModel

Returns:

Combined SGS model with dynamically computed coefficients

s_parallel(s, n, tensor_dims)[source]

Projection of s in the n-direction: \(s^{\parallel}=(n_i (s.n)_j + (s.n)_i n_j - \frac{2}{3} \delta_{ij} (n.s.n) )\)

Return type:

DataArray

s_perpendicular(s, n, tensor_dims)[source]

Projection of s perpendicular to the n-direction: \(s - s^{\parallel}\)

Return type:

DataArray

class SparallelVelocityModel(strain, cs, dx, tensor_dims, n)[source]

Carati & Cabot Proceedings of the 1996 Summer Program – Center for Turbulence Research S_parallel component = \(|S| Traceless[Symmetric[(S.n)n]]\)

Variables:
  • strain – grid-scale rate-of-strain

  • cs – Smagorinsky coefficient

  • dx – constant resolution with respect to dimension to-be-filtered

  • n – triple of floats to be coerce as a 3d constant vector along one of the tensor dimensions

  • tensor_dims – labels of dimensions indexing tensor components

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = |S| Traceless[Symmetric[(S.n)n]]\)

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

class SperpVelocityModel(strain, cs, dx, n, tensor_dims)[source]

Carati & Cabot Proceedings of the 1996 Summer Program – Center for Turbulence Research \(S_{\textrm{perp component}} = |S| Traceless(S - (S.n + n.S))\)

Variables:
  • strain – grid-scale rate-of-strain

  • cs – Smagorinsky coefficient

  • dx – constant resolution with respect to dimension to-be-filtered

  • n – triple of floats to be coerce as a 3d constant vector along one of the tensor dimensions

  • tensor_dims – labels of dimensions indexing tensor components

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = |S| Traceless(S - (S.n + n.S))\) for a given filter (which can be trivial, i.e. IdentityFilter)

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

class NVelocityModel(strain, cs, dx, n, tensor_dims)[source]

Carati & Cabot Proceedings of the 1996 Summer Program – Center for Turbulence Research \(N component = |S|(n.s.n) Traceless(n * n)\)

Variables:
  • strain – grid-scale rate-of-strain

  • cs – Smagorinsky coefficient

  • dx – constant resolution with respect to dimension to-be-filtered

  • n – triple of floats to be coerce as a 3d constant vector along one of the tensor dimensions

  • tensor_dims – labels of dimensions indexing tensor components

sgs_tensor(filter)[source]
compute model for SGS tensor

\(\tau = (c_s \Delta) ^2 |\overline{S_{ij}}| \overline{S_{ik} N_{kj}}\) for a given filter (which can be trivial, i.e. IdentityFilter)

Parameters:

filter (Filter) – Filter used to separate “large” and “small” scales

Return type:

DataArray

DynamicCaratiCabotModel(sij, vel, res, compoment_coeff, n, tensor_dims=('c1', 'c2'), minimisation=LillyMinimisation3Model(contraction_dims=['c1', 'c2'], coeff_dim='cdim'))[source]
Dynamic version of the model by

Carati & Cabot Proceedings of the 1996 Summer Program – Center for Turbulence Research

Parameters:
  • sij (DataArray) – grid-scale rate-of-strain tensor

  • vel (DataArray) – velocity field used for dynamic coefficient computation

  • res (float) – constant resolution with respect to dimension to-be-filtered

  • compoment_coeff (Sequence[float]) – tuple of three Smagorinsky coefficients for parallel, perpendicular, and normal components

  • n (Sequence[float]) – triple of floats to be coerced as a 3d constant vector along one of the tensor dimensions

  • tensor_dims (tuple[str, str]) – labels of dimensions indexing tensor components, defaults to (“c1”, “c2”)

Return type:

LinCombDynamicModel

Returns:

Combined SGS model with dynamically computed coefficients