#include "variables.h"#include "logging.h"#include "Metric.h"#include "setup.h"#include "Filter.h"#include "Boundaries.h"Go to the source code of this file.
Functions | |
| SymTensor | SymTensorSelfOuter (Cmpnts v) |
| Forms a symmetric tensor from a vector's outer product with itself. | |
| SymTensor | SymTensorCombine (PetscReal a, SymTensor x, PetscReal b, SymTensor y) |
Forms the linear combination a*x + b*y. | |
| PetscReal | SymTensorTrace (SymTensor t) |
Returns the trace t_kk. | |
| SymTensor | SymTensorDeviator (SymTensor t) |
Removes the isotropic part, returning t_ij - (1/3) delta_ij t_kk. | |
| PetscReal | SymTensorContract (SymTensor a, SymTensor b) |
Contracts two symmetric tensors as a_ij b_ij. | |
| Cmpnts | SymTensorTimesVector (SymTensor t, Cmpnts v) |
Applies a symmetric tensor to a vector, returning t_ij v_j. | |
| PetscReal | SymTensorNormSq (SymTensor t) |
Returns the squared Frobenius norm t_ij t_ij. | |
| PetscErrorCode | StrainRateFromGradients (Cmpnts dudx, Cmpnts dvdx, Cmpnts dwdx, SymTensor *strain, PetscReal *magnitude) |
| Builds the strain-rate tensor and its magnitude from a velocity gradient. | |
| PetscErrorCode | ComputeCellFilterWidth (LESFilterWidthModel model, PetscReal aj, Cmpnts csi, Cmpnts eta, Cmpnts zet, PetscReal *delta) |
| Computes one cell's grid filter width under the selected width model. | |
| SymTensor | LeonardStress (Cmpnts velocity_filtered, SymTensor velocity_product_filtered) |
Forms the Leonard stress L_ij = (u_i u_j)^ - u^_i u^_j. | |
| SymTensor | GermanoModelTensor (PetscReal delta, PetscReal alpha, PetscReal strain_magnitude_filtered, SymTensor strain_filtered, SymTensor strain_product_filtered) |
Forms the deviatoric Germano model tensor M_ij. | |
| PetscErrorCode | ResolveLESAveragingDirections (UserCtx *user, PetscBool direction[3]) |
| Resolves which logical directions the dynamic coefficient is averaged over. | |
| PetscReal | ClipModelCoefficient (PetscReal coefficient, const LESConfig *config, PetscBool *limited) |
| Applies the configured admissible range to one model coefficient. | |
| PetscReal | EddyViscosityFromCoefficient (PetscReal coefficient, PetscReal delta, PetscReal strain_magnitude, PetscReal molecular_viscosity, PetscReal min_viscosity_ratio) |
| Builds the eddy viscosity from a model coefficient. | |
| PetscReal | WALEEddyViscosity (Cmpnts dudx, Cmpnts dvdx, Cmpnts dwdx, PetscReal delta, PetscReal coefficient) |
| WALE eddy viscosity (Nicoud & Ducros 1999) from the resolved velocity gradient. | |
| PetscReal | VremanEddyViscosity (Cmpnts dudx, Cmpnts dvdx, Cmpnts dwdx, const Cmpnts edges[3], PetscReal coefficient) |
| Vreman eddy viscosity (Vreman 2004), weighting each grid direction by its own spacing. | |
| PetscReal | SubgridKineticEnergy (PetscReal yoshizawa_ci, PetscReal delta, PetscReal strain_magnitude) |
| Returns the modelled subgrid kinetic energy at a cell. | |
| PetscErrorCode | ComputeSmagorinskyConstant (UserCtx *user) |
| Computes the dynamic Smagorinsky coefficient field for one block. | |
| PetscErrorCode | ComputeEddyViscosityLES (UserCtx *user) |
| Computes the turbulent eddy viscosity for one block. | |
| PetscErrorCode | LogLESDiagnostics (UserCtx *user) |
| Appends one row of LES coefficient statistics to the run's log directory. | |
Forms a symmetric tensor from a vector's outer product with itself.
Used to build the resolved velocity products the Leonard stress subtracts.
| [in] | v | Vector to square. |
v_i v_j.Forms a symmetric tensor from a vector's outer product with itself.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 144 of file les.c.
Forms the linear combination a*x + b*y.
One primitive covers addition, subtraction, and scaling, so tensor algebra at the call sites reads as algebra instead of six repeated component expressions.
| [in] | a | Scalar multiplying x. |
| [in] | x | First tensor. |
| [in] | b | Scalar multiplying y. |
| [in] | y | Second tensor. |
Forms the linear combination a*x + b*y.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 165 of file les.c.
| PetscReal SymTensorTrace | ( | SymTensor | t | ) |
Returns the trace t_kk.
| [in] | t | Tensor to trace. |
Returns the trace t_kk.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 186 of file les.c.
Removes the isotropic part, returning t_ij - (1/3) delta_ij t_kk.
The Germano model tensor must be deviatoric so that the trace of the Leonard stress, which the incompressible pressure absorbs, cannot enter the contraction through discrete divergence error.
| [in] | t | Tensor to project. |
t.Removes the isotropic part, returning t_ij - (1/3) delta_ij t_kk.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 199 of file les.c.
Contracts two symmetric tensors as a_ij b_ij.
Only six components are stored, so the three off-diagonal products are counted twice. Centralising that factor is the point: written out at each call site it is a silent error whenever one term is missed.
| [in] | a | First tensor. |
| [in] | b | Second tensor. |
Contracts two symmetric tensors as a_ij b_ij.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 217 of file les.c.
Applies a symmetric tensor to a vector, returning t_ij v_j.
The three stored off-diagonal components each stand for two entries of the full tensor, so a caller writing this out by hand has six chances to reference the wrong one. Centralising it is the same reason SymTensorContract() exists.
| [in] | t | Tensor to apply. |
| [in] | v | Vector to apply it to. |
Applies a symmetric tensor to a vector, returning t_ij v_j.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 232 of file les.c.
| PetscReal SymTensorNormSq | ( | SymTensor | t | ) |
Returns the squared Frobenius norm t_ij t_ij.
| [in] | t | Tensor to measure. |
t.Returns the squared Frobenius norm t_ij t_ij.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 250 of file les.c.
| PetscErrorCode StrainRateFromGradients | ( | Cmpnts | dudx, |
| Cmpnts | dvdx, | ||
| Cmpnts | dwdx, | ||
| SymTensor * | strain, | ||
| PetscReal * | magnitude | ||
| ) |
Builds the strain-rate tensor and its magnitude from a velocity gradient.
S_ij = 0.5 (du_i/dx_j + du_j/dx_i) and |S| = sqrt(2 S_ij S_ij). This is the single definition of both quantities; the dynamic procedure and the eddy-viscosity assembly consume it rather than each expanding the algebra themselves.
| [in] | dudx | Gradient of the x velocity component. |
| [in] | dvdx | Gradient of the y velocity component. |
| [in] | dwdx | Gradient of the z velocity component. |
| [out] | strain | Resolved strain-rate tensor; may be NULL if only the magnitude is wanted. |
| [out] | magnitude | Strain-rate magnitude |S|; may be NULL. |
Builds the strain-rate tensor and its magnitude from a velocity gradient.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 267 of file les.c.
| PetscErrorCode ComputeCellFilterWidth | ( | LESFilterWidthModel | model, |
| PetscReal | aj, | ||
| Cmpnts | csi, | ||
| Cmpnts | eta, | ||
| Cmpnts | zet, | ||
| PetscReal * | delta | ||
| ) |
Computes one cell's grid filter width under the selected width model.
LES_FILTER_WIDTH_CUBE_ROOT_VOLUME uses the cell volume alone and so ignores anisotropy; the other models take the cell's extents along its own grid directions from ComputeCellDirectionalExtents, so they follow the cell's shape and are unchanged by its orientation.
| [in] | model | Width model to apply. |
| [in] | aj | Inverse cell volume (the Jacobian determinant) at the cell. |
| [in] | csi | Xi-direction metric vector at the cell. |
| [in] | eta | Eta-direction metric vector at the cell. |
| [in] | zet | Zeta-direction metric vector at the cell. |
| [out] | delta | Resolved filter width. |
PETSC_ERR_ARG_OUTOFRANGE for a non-positive Jacobian.Computes one cell's grid filter width under the selected width model.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 296 of file les.c.
Forms the Leonard stress L_ij = (u_i u_j)^ - u^_i u^_j.
L_ij is the stress carried by the scales between the grid filter and the test filter. It is computable entirely from the resolved field, which is what makes the dynamic procedure possible.
| [in] | velocity_filtered | Test-filtered resolved velocity u^_i. |
| [in] | velocity_product_filtered | Test filter of the products (u_i u_j)^. |
Forms the Leonard stress L_ij = (u_i u_j)^ - u^_i u^_j.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 359 of file les.c.
| SymTensor GermanoModelTensor | ( | PetscReal | delta, |
| PetscReal | alpha, | ||
| PetscReal | strain_magnitude_filtered, | ||
| SymTensor | strain_filtered, | ||
| SymTensor | strain_product_filtered | ||
| ) |
Forms the deviatoric Germano model tensor M_ij.
M_ij = -2 Delta^2 ( alpha |S^| S^_ij - (|S| S_ij)^ ), made trace-free.
The two terms are structurally different and must stay so. The first is the model evaluated on the test-filtered strain, the product of separately filtered quantities. The second is the grid-level model formed pointwise and then test-filtered, that is, the filter of a product. Their difference is the entire information content of the dynamic procedure: collapsing them into the same expression yields a well-scaled, flow-responsive, and wrong coefficient that is not the Germano-Lilly coefficient and cannot be cited as one.
| [in] | delta | Grid filter width at the cell. |
| [in] | alpha | Squared test-to-grid filter width ratio. |
| [in] | strain_magnitude_filtered | Test-filtered strain magnitude |S|^. |
| [in] | strain_filtered | Test-filtered strain tensor S^_ij. |
| [in] | strain_product_filtered | Test filter of the product (|S| S_ij)^. |
Forms the deviatoric Germano model tensor M_ij.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 374 of file les.c.
| PetscErrorCode ResolveLESAveragingDirections | ( | UserCtx * | user, |
| PetscBool | direction[3] | ||
| ) |
Resolves which logical directions the dynamic coefficient is averaged over.
The resulting selector is passed to PicurvSpatialRatioAverage(), which performs the reduction; this routine only decides which directions it spans.
LES_AVERAGING_LOCAL selects none, LES_AVERAGING_GLOBAL selects all three, and LES_AVERAGING_HOMOGENEOUS uses the directions the configuration names, defaulting to the block's periodic axes when it names none. Periodicity is read from the boundary face configuration, which is the same source the periodic field synchronization uses.
| [in] | user | Block context supplying configuration and boundary faces. |
| [out] | direction | Per-direction averaging flags in (xi, eta, zeta) order. |
PETSC_ERR_ARG_WRONGSTATE when homogeneous averaging is requested but no direction can be resolved.Resolves which logical directions the dynamic coefficient is averaged over.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 410 of file les.c.
| PetscReal ClipModelCoefficient | ( | PetscReal | coefficient, |
| const LESConfig * | config, | ||
| PetscBool * | limited | ||
| ) |
Applies the configured admissible range to one model coefficient.
The coefficient carries the sign of <L:M>; a negative value is backscatter, energy returning from the unresolved scales, not an error. LES_CLIP_NONE keeps it, leaving stability to the total-viscosity floor applied downstream.
| [in] | coefficient | Raw coefficient from the Germano contraction. |
| [in] | config | LES configuration supplying the mode and ceiling. |
| [out] | limited | Set to PETSC_TRUE when the value was modified; may be NULL. |
Applies the configured admissible range to one model coefficient.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 466 of file les.c.
| PetscReal EddyViscosityFromCoefficient | ( | PetscReal | coefficient, |
| PetscReal | delta, | ||
| PetscReal | strain_magnitude, | ||
| PetscReal | molecular_viscosity, | ||
| PetscReal | min_viscosity_ratio | ||
| ) |
Builds the eddy viscosity from a model coefficient.
nu_t = C Delta^2 |S|, floored so that nu + nu_t >= min_viscosity_ratio * nu. The floor constrains the quantity that must stay positive for the momentum operator to remain well posed, which is why backscatter is limited here rather than by forcing the coefficient positive.
| [in] | coefficient | Model coefficient, signed. |
| [in] | delta | Grid filter width at the cell. |
| [in] | strain_magnitude | Resolved strain magnitude |S|. |
| [in] | molecular_viscosity | Molecular kinematic viscosity. |
| [in] | min_viscosity_ratio | Lower bound on total viscosity as a multiple of molecular. |
Builds the eddy viscosity from a model coefficient.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 497 of file les.c.
| PetscReal WALEEddyViscosity | ( | Cmpnts | dudx, |
| Cmpnts | dvdx, | ||
| Cmpnts | dwdx, | ||
| PetscReal | delta, | ||
| PetscReal | coefficient | ||
| ) |
WALE eddy viscosity (Nicoud & Ducros 1999) from the resolved velocity gradient.
nu_t = (C_w Delta)^2 (S^d_ij S^d_ij)^(3/2) / [(S_ij S_ij)^(5/2) + (S^d_ij S^d_ij)^(5/4)], where S^d is the traceless symmetric part of the squared gradient. It vanishes in pure shear, so a laminar shear layer gets none, and it falls as the cube of wall distance approaching a wall without a damping function. It needs no coefficient field, no test filter, and no averaging, so it is valid on geometry with no homogeneous direction.
| [in] | dudx | Gradient of the x velocity component. |
| [in] | dvdx | Gradient of the y velocity component. |
| [in] | dwdx | Gradient of the z velocity component. |
| [in] | delta | Grid filter width at the cell. |
| [in] | coefficient | Model constant C_w. |
WALE eddy viscosity (Nicoud & Ducros 1999) from the resolved velocity gradient.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 520 of file les.c.
| PetscReal VremanEddyViscosity | ( | Cmpnts | dudx, |
| Cmpnts | dvdx, | ||
| Cmpnts | dwdx, | ||
| const Cmpnts | edges[3], | ||
| PetscReal | coefficient | ||
| ) |
Vreman eddy viscosity (Vreman 2004), weighting each grid direction by its own spacing.
nu_t = c sqrt(B_beta / (alpha_ij alpha_ij)), with alpha_ij = du_j/dx_i and beta_ij = sum_m d_i^(m) d_j^(m), where d^(m) is the change in velocity across the cell along grid direction m - edges[m] . grad(u). On an aligned Cartesian grid that is Vreman's Delta_m^2 alpha_mi alpha_mj; on a curvilinear grid it is the same quantity measured along the cell's own edges, so the model is resolved per direction rather than through one scalar width, and unchanged by the grid's orientation. It vanishes in pure shear and needs no coefficient field, test filter, or averaging.
| [in] | dudx | Gradient of the x velocity component. |
| [in] | dvdx | Gradient of the y velocity component. |
| [in] | dwdx | Gradient of the z velocity component. |
| [in] | edges | Cell edge vectors along xi, eta, zeta, from ComputeCellEdgeVectors. |
| [in] | coefficient | Model constant c. |
B_beta vanishes.Vreman eddy viscosity (Vreman 2004), weighting each grid direction by its own spacing.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 557 of file les.c.
| PetscReal SubgridKineticEnergy | ( | PetscReal | yoshizawa_ci, |
| PetscReal | delta, | ||
| PetscReal | strain_magnitude | ||
| ) |
Returns the modelled subgrid kinetic energy at a cell.
Uses the Yoshizawa relation k_sgs = 2 C_I Delta^2 |S|^2. Reported as a diagnostic: compared against the resolved turbulent kinetic energy from the field-statistics pipeline it measures how much of the energy the grid resolves.
| [in] | yoshizawa_ci | Yoshizawa constant C_I. |
| [in] | delta | Grid filter width at the cell. |
| [in] | strain_magnitude | Resolved strain magnitude |S|. |
Returns the modelled subgrid kinetic energy at a cell.
Full API contract is documented with the header declaration in include/les.h.
Definition at line 595 of file les.c.
| PetscErrorCode ComputeSmagorinskyConstant | ( | UserCtx * | user | ) |
Computes the dynamic Smagorinsky coefficient field for one block.
Runs the Germano-Lilly procedure: test-filters the resolved field, forms the Leonard stress and the model tensor, contracts them, averages the two contractions over the configured directions, limits the quotient, and stores it in UserCtx::CS.
The stored quantity is the coefficient C that multiplies Delta^2 |S| in the eddy viscosity, that is, Cs^2 rather than Cs. It is signed under LES_CLIP_NONE. Reported values are converted to Cs at the diagnostic boundary, where the familiar target near 0.16 applies.
Only DYNAMIC_SMAGORINSKY reaches this routine; the constant model prescribes its coefficient from configuration and allocates no field. Callers honour LESConfig::dynamic_frequency, and the caller must have refreshed UserCtx::lUcat and its periodic images beforehand.
| [in,out] | user | The user context for a single computational block. |
Computes the dynamic Smagorinsky coefficient field for one block.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/les.h.
Definition at line 715 of file les.c.
| PetscErrorCode ComputeEddyViscosityLES | ( | UserCtx * | user | ) |
Computes the turbulent eddy viscosity for one block.
Evaluates nu_t = C Delta^2 |S| at every fluid cell and stores it in UserCtx::Nu_t. The coefficient comes from UserCtx::lCs for the dynamic model and directly from LESConfig::constant_cs for the constant model, which therefore needs no coefficient field at all.
| [in,out] | user | The user context for a single computational block. |
Computes the turbulent eddy viscosity for one block.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/les.h.
Definition at line 952 of file les.c.
| PetscErrorCode LogLESDiagnostics | ( | UserCtx * | user | ) |
Appends one row of LES coefficient statistics to the run's log directory.
Writes les_coefficient.csv: the effective coefficient reported as Cs, its spatial spread, eddy-viscosity levels, the modelled subgrid energy, and the fractions of the domain that were backscattering or limited before this step's clipping. Those last two describe the pre-clipping state, which no stored field preserves.
Values are instantaneous volume statistics, not time averages; window averages of the same model's fields come from the field-statistics pipeline instead.
| [in] | user | The user context for a single computational block. |
Appends one row of LES coefficient statistics to the run's log directory.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/les.h.
Definition at line 1045 of file les.c.