Documentation 6b54b78464
Loading...
Searching...
No Matches
util.hpp File Reference

Generic auxiliary functions. More...

Go to the source code of this file.

Classes

struct  CAlignTraits< Type >
 Alignment of the static containers backing a flux value type. More...
 
struct  CAlignTraits< simd::Array< Scalar_t, N > >
 
struct  CValueTraits< unsigned long >
 
struct  CValueTraits< simd::Array< unsigned long, N > >
 
struct  CLaneTraits< su2double >
 
struct  CLaneTraits< simd::Array< Scalar_t, N > >
 
struct  CPair< T >
 Simple pair type for i/j variables. More...
 
struct  CIdentity< T >
 Blocks a template parameter from participating in argument deduction. More...
 
struct  EdgeResidual< Double, nVar_ >
 Residual of one edge, accumulated by the convective and the diffusive terms. More...
 
struct  CGradientBlock< nVarGrad, nDim, Double, Gradient_t >
 Reads the gradient rows of one point as one block, gathered up front. More...
 
struct  CGradientRows< nDim, Double, Gradient_t >
 Reads the gradient rows of one point one row at a time. More...
 

Typedefs

using SparseMatrixType = CSysMatrix< su2mixedfloat >
 
template<class Type , size_t Size>
using Vector = C2DContainer< unsigned long, Type, StorageType::ColumnMajor, CAlignTraits< Type >::Align, Size, 1 >
 Static vector and matrix types.
 
template<class Type , size_t Rows, size_t Cols>
using Matrix = C2DContainer< unsigned long, Type, StorageType::RowMajor, CAlignTraits< Type >::Align, Rows, Cols >
 
template<class T >
using CNonDeduced = typename CIdentity< T >::type
 

Enumerations

enum class  UpdateType { COLORING , REDUCTION }
 Ways to update vectors and system matrices. COLORING is the typical i/j update, whereas for REDUCTION the fluxes are stored and the matrix diagonal is not modified. More...
 
enum class  MusclLimiter { NONE , EDGE , POINT }
 How the reconstructed differences are limited. More...
 

Functions

constexpr size_t Max (size_t a, size_t b)
 Constexpr version of max.
 
template<size_t nDim, class ForwardIterator , class T >
auto dot (ForwardIterator iterator, const T *ptr) -> typename std::decay< decltype(*ptr)>::type
 Dot product.
 
template<size_t nDim, class Double , class ForwardIterator >
Double dot (ForwardIterator iterator, const Vector< Double, nDim > &vector)
 
template<size_t nDim, class Double >
Double dot (const Vector< Double, nDim > &a, const Vector< Double, nDim > &b)
 
template<size_t nDim, class ForwardIterator >
auto squaredNorm (ForwardIterator iterator) -> typename std::decay< decltype(*iterator)>::type
 Squared norm.
 
template<size_t nDim, class Double >
Double squaredNorm (const Vector< Double, nDim > &vector)
 
template<size_t nDim, class Double >
Vector< Double, nDim > tangentProjection (const Matrix< Double, nDim, nDim > &tensor, const Vector< Double, nDim > &unitVector)
 Tangential projection.
 
template<size_t nDim, class Double >
Double norm (const Vector< Double, nDim > &vector)
 Vector norm.
 
template<class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Double gatherVariables (Int iPoint, const Container &vars, size_t iVar=0)
 Gather a single variable, from column iVar (0 by default) of row iPoint of a 2D container, or from index iPoint of a 1D container.
 
template<size_t nVar, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Vector< Double, nVar > gatherVariables (Int iPoint, const Container &vars, size_t iVar=0)
 Gather nVar contiguous variables starting at column iVar (0 by default) of row iPoint of a 2D container.
 
template<size_t nRows, size_t nCols, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Matrix< Double, nRows, nCols > gatherVariables (Int iPoint, const Container &vars, size_t iRow=0)
 Gather an nRows x nCols block of a 3D container, from outer index iPoint and starting at middle index iRow.
 
template<class Double , size_t Size>
void setPreaccOut (Vector< Double, Size > &x, size_t nVar)
 Register the leading nVar entries of a static vector as preaccumulation outputs.
 
template<class Double , size_t nVar>
void stopPreacc (Vector< Double, nVar > &x)
 Stop the AD preaccumulation.
 
template<size_t nDim, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Vector< Double, nDim > distanceVector (Int iPoint, Int jPoint, const Container &coords)
 Distance vector, from point i to point j of one container.
 
template<size_t nDim, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Vector< Double, nDim > distanceVector (Int iPoint, const Container &coords_i, Int jPoint, const Container &coords_j)
 Distance vector, from point i of one container to point j of another.
 
template<class Double >
Double umusclProjection (const Double &gradProj, const Double &delta, const CNonDeduced< Double > &kappa)
 Blended difference for U-MUSCL reconstruction.
 
template<size_t nVarGrad_, size_t nDim, class Double , class Gradient_t >
auto gradientReader (typename CLaneTraits< Double >::Int iPoint, const Gradient_t &gradient, size_t iRow)
 Gradient reader of one point, blocked or row by row according to nVarGrad_.
 
template<MusclLimiter limiterKind, size_t nVarGrad_ = 0, size_t nDim, class Double , class VarType , class Limiter_t , class Gradient_t >
void muscl (typename CLaneTraits< Double >::Int iPoint, typename CLaneTraits< Double >::Int jPoint, const Vector< Double, nDim > &vector_ij, const Gradient_t &gradient, const Limiter_t &limiter, size_t iRow, CPair< VarType > &V, const CNonDeduced< Double > &kappa, const CNonDeduced< Double > &umusclRamp, size_t nVarGradRuntime)
 U-MUSCL reconstruction of nVarGrad variables, from the gradient rows starting at iRow.
 
template<size_t nVarGrad_ = 0, size_t nDim, class Double , class VarType , class Limiter_t , class Gradient_t >
void reconstruct (typename CLaneTraits< Double >::Int iPoint, typename CLaneTraits< Double >::Int jPoint, const Vector< Double, nDim > &vector_ij, const Gradient_t &gradient, const Limiter_t &limiter, LIMITER limiterType, size_t iRow, CPair< VarType > &V, const CNonDeduced< Double > &kappa, const CNonDeduced< Double > &umusclRamp, size_t nVarGradRuntime=0)
 Reconstruct a slice of nVarGrad variables starting at column iRow, dispatching on the limiter type; shared by the flow and the scalar reconstructions so both call one body.
 
template<size_t nVar, class Double , class Int = typename CLaneTraits<Double>::Int>
void updateLinearSystem (Int iEdge, Int iPoint, Int jPoint, bool implicit, UpdateType updateType, Double updateMask, const Vector< Double, nVar > &flux, const Matrix< Double, nVar, nVar > &jac_i, const Matrix< Double, nVar, nVar > &jac_j, CSysVector< su2double > &vector, SparseMatrixType &matrix)
 Update the matrix and right-hand-side of a linear system with one conservative flux.
 
template<size_t nVar, class Double , class Int = typename CLaneTraits<Double>::Int>
void updateLinearSystem (Int iEdge, Int iPoint, Int jPoint, bool implicit, UpdateType updateType, Double updateMask, const EdgeResidual< Double, nVar > &res, CSysVector< su2double > &vector, CSysVector< su2double > &vectorDiff, SparseMatrixType &matrix)
 Update the matrix and right-hand-side of a linear system with two independent row contributions and four independent Jacobian blocks.
 
template<class Double , class Int = typename CLaneTraits<Double>::Int>
void updateEdgeMassFlux (Int iEdge, const Double &massFlux, su2activevector *target)
 Store the (scalar) mass flux of an edge, e.g. for "bounded scalar" transport equations.
 

Variables

constexpr size_t Dynamic = size_t(-1)
 Equation count of a model whose value is only known at runtime.
 
constexpr size_t MaxScalarVar = 8
 Backing size of the static arrays of a dynamic model.
 

Detailed Description

Generic auxiliary functions.

Author
P. Gomes
Version
8.5.0 "Harrier"

SU2 Project Website: https://su2code.github.io

The SU2 Project is maintained by the SU2 Foundation (http://su2foundation.org)

Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)

SU2 is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

SU2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with SU2. If not, see http://www.gnu.org/licenses/.

Typedef Documentation

◆ CNonDeduced

template<class T >
using CNonDeduced = typename CIdentity<T>::type

◆ Matrix

template<class Type , size_t Rows, size_t Cols>
using Matrix = C2DContainer<unsigned long, Type, StorageType::RowMajor, CAlignTraits<Type>::Align, Rows, Cols>

◆ SparseMatrixType

◆ Vector

template<class Type , size_t Size>
using Vector = C2DContainer<unsigned long, Type, StorageType::ColumnMajor, CAlignTraits<Type>::Align, Size, 1>

Static vector and matrix types.

Note
These should be used instead of C-style arrays.

Enumeration Type Documentation

◆ MusclLimiter

enum class MusclLimiter
strong

How the reconstructed differences are limited.

Enumerator
NONE 
EDGE 
POINT 

◆ UpdateType

enum class UpdateType
strong

Ways to update vectors and system matrices. COLORING is the typical i/j update, whereas for REDUCTION the fluxes are stored and the matrix diagonal is not modified.

Enumerator
COLORING 
REDUCTION 

Function Documentation

◆ distanceVector() [1/2]

template<size_t nDim, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Vector< Double, nDim > distanceVector ( Int  iPoint,
const Container &  coords_i,
Int  jPoint,
const Container &  coords_j 
)
inline

Distance vector, from point i of one container to point j of another.

Note
The two endpoints of a boundary flux read different containers, the solver's own and the marker's ghost one; the interior edge loop passes the same container twice.

◆ distanceVector() [2/2]

template<size_t nDim, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Vector< Double, nDim > distanceVector ( Int  iPoint,
Int  jPoint,
const Container &  coords 
)
inline

Distance vector, from point i to point j of one container.

◆ dot() [1/3]

template<size_t nDim, class Double >
Double dot ( const Vector< Double, nDim > &  a,
const Vector< Double, nDim > &  b 
)
inline

◆ dot() [2/3]

template<size_t nDim, class ForwardIterator , class T >
auto dot ( ForwardIterator  iterator,
const T *  ptr 
) -> typename std::decay<decltype(*ptr)>::type
inline

Dot product.

◆ dot() [3/3]

template<size_t nDim, class Double , class ForwardIterator >
Double dot ( ForwardIterator  iterator,
const Vector< Double, nDim > &  vector 
)
inline

◆ gatherVariables() [1/3]

template<size_t nRows, size_t nCols, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Matrix< Double, nRows, nCols > gatherVariables ( Int  iPoint,
const Container &  vars,
size_t  iRow = 0 
)
inline

Gather an nRows x nCols block of a 3D container, from outer index iPoint and starting at middle index iRow.

◆ gatherVariables() [2/3]

template<class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Double gatherVariables ( Int  iPoint,
const Container &  vars,
size_t  iVar = 0 
)
inline

Gather a single variable, from column iVar (0 by default) of row iPoint of a 2D container, or from index iPoint of a 1D container.

◆ gatherVariables() [3/3]

template<size_t nVar, class Int , class Container , class Double = typename CValueTraits<Int>::Double>
Vector< Double, nVar > gatherVariables ( Int  iPoint,
const Container &  vars,
size_t  iVar = 0 
)
inline

Gather nVar contiguous variables starting at column iVar (0 by default) of row iPoint of a 2D container.

◆ gradientReader()

template<size_t nVarGrad_, size_t nDim, class Double , class Gradient_t >
auto gradientReader ( typename CLaneTraits< Double >::Int  iPoint,
const Gradient_t &  gradient,
size_t  iRow 
)
inline

Gradient reader of one point, blocked or row by row according to nVarGrad_.

◆ Max()

constexpr size_t Max ( size_t  a,
size_t  b 
)
inlineconstexpr

Constexpr version of max.

◆ muscl()

template<MusclLimiter limiterKind, size_t nVarGrad_ = 0, size_t nDim, class Double , class VarType , class Limiter_t , class Gradient_t >
void muscl ( typename CLaneTraits< Double >::Int  iPoint,
typename CLaneTraits< Double >::Int  jPoint,
const Vector< Double, nDim > &  vector_ij,
const Gradient_t &  gradient,
const Limiter_t &  limiter,
size_t  iRow,
CPair< VarType > &  V,
const CNonDeduced< Double > &  kappa,
const CNonDeduced< Double > &  umusclRamp,
size_t  nVarGradRuntime 
)
inline

U-MUSCL reconstruction of nVarGrad variables, from the gradient rows starting at iRow.

Note
The limiter kind is a template parameter so that the choice is made once, outside the loop, by the dispatching overload below.
Parameters
[in]iRow- Starting row of gradient (and column of limiter) to read, for reconstructing a slice of a larger set of gradients (e.g. only the velocity out of the primitives).
[in]nVarGradRuntime- Variable count of a Dynamic model, known only at runtime; ignored (falling back to nVarGrad_ or VarType::nVar) when left at its default of 0.

◆ norm()

template<size_t nDim, class Double >
Double norm ( const Vector< Double, nDim > &  vector)
inline

Vector norm.

◆ reconstruct()

template<size_t nVarGrad_ = 0, size_t nDim, class Double , class VarType , class Limiter_t , class Gradient_t >
void reconstruct ( typename CLaneTraits< Double >::Int  iPoint,
typename CLaneTraits< Double >::Int  jPoint,
const Vector< Double, nDim > &  vector_ij,
const Gradient_t &  gradient,
const Limiter_t &  limiter,
LIMITER  limiterType,
size_t  iRow,
CPair< VarType > &  V,
const CNonDeduced< Double > &  kappa,
const CNonDeduced< Double > &  umusclRamp,
size_t  nVarGradRuntime = 0 
)
inline

Reconstruct a slice of nVarGrad variables starting at column iRow, dispatching on the limiter type; shared by the flow and the scalar reconstructions so both call one body.

◆ setPreaccOut()

template<class Double , size_t Size>
void setPreaccOut ( Vector< Double, Size > &  x,
size_t  nVar 
)
inline

Register the leading nVar entries of a static vector as preaccumulation outputs.

Note
A lane vector is registered one lane at a time, a scalar in one call; a kernel therefore reaches this rather than AD::SetPreaccOut directly, and reads the same whichever value type it is bound to.

◆ squaredNorm() [1/2]

template<size_t nDim, class Double >
Double squaredNorm ( const Vector< Double, nDim > &  vector)
inline

◆ squaredNorm() [2/2]

template<size_t nDim, class ForwardIterator >
auto squaredNorm ( ForwardIterator  iterator) -> typename std::decay<decltype(*iterator)>::type
inline

Squared norm.

◆ stopPreacc()

template<class Double , size_t nVar>
void stopPreacc ( Vector< Double, nVar > &  x)
inline

Stop the AD preaccumulation.

◆ tangentProjection()

template<size_t nDim, class Double >
Vector< Double, nDim > tangentProjection ( const Matrix< Double, nDim, nDim > &  tensor,
const Vector< Double, nDim > &  unitVector 
)
inline

Tangential projection.

◆ umusclProjection()

template<class Double >
Double umusclProjection ( const Double &  gradProj,
const Double &  delta,
const CNonDeduced< Double > &  kappa 
)
inline

Blended difference for U-MUSCL reconstruction.

Parameters
[in]gradProj- Gradient projection at point i: dot(grad_i, vector_ij).
[in]delta- Centered difference: V_j - V_i.
[in]kappa- Blending parameter.
Returns
Blended difference for reconstruction from point i.

◆ updateEdgeMassFlux()

template<class Double , class Int = typename CLaneTraits<Double>::Int>
void updateEdgeMassFlux ( Int  iEdge,
const Double &  massFlux,
su2activevector *  target 
)
inline

Store the (scalar) mass flux of an edge, e.g. for "bounded scalar" transport equations.

Note
No-op if "target" is null. As with CEdge's Nodes/Normal, edges within a SIMD group are contiguous (coloring groups are multiples of the SIMD size), so this is a plain vectorized store starting at iEdge[0], relying on "target" being padded to a multiple of the SIMD size.

◆ updateLinearSystem() [1/2]

template<size_t nVar, class Double , class Int = typename CLaneTraits<Double>::Int>
void updateLinearSystem ( Int  iEdge,
Int  iPoint,
Int  jPoint,
bool  implicit,
UpdateType  updateType,
Double  updateMask,
const EdgeResidual< Double, nVar > &  res,
CSysVector< su2double > &  vector,
CSysVector< su2double > &  vectorDiff,
SparseMatrixType &  matrix 
)
inline

Update the matrix and right-hand-side of a linear system with two independent row contributions and four independent Jacobian blocks.

Note
It carries a second CSysVector, the target of flux_j under UpdateType::REDUCTION and unused under COLORING, where both rows are written directly.
The residual is the same under both update types, the Jacobian is not: REDUCTION writes the off-diagonal blocks only and CSysMatrix::SetDiagonalAsColumnSum then derives each diagonal block as minus the sum of its column, which equals the jac_ii and jac_jj computed here only where the flux is conservative (jac_ii == -jac_ji). A model whose diffusion coefficients differ between the two orientations of an edge, i.e. one that evaluates a non-conservative term at the point whose row it is writing, therefore converges along a slightly different path under the reducer, to the same solution.

◆ updateLinearSystem() [2/2]

template<size_t nVar, class Double , class Int = typename CLaneTraits<Double>::Int>
void updateLinearSystem ( Int  iEdge,
Int  iPoint,
Int  jPoint,
bool  implicit,
UpdateType  updateType,
Double  updateMask,
const Vector< Double, nVar > &  flux,
const Matrix< Double, nVar, nVar > &  jac_i,
const Matrix< Double, nVar, nVar > &  jac_j,
CSysVector< su2double > &  vector,
SparseMatrixType &  matrix 
)
inline

Update the matrix and right-hand-side of a linear system with one conservative flux.

Variable Documentation

◆ Dynamic

constexpr size_t Dynamic = size_t(-1)
constexpr

Equation count of a model whose value is only known at runtime.

◆ MaxScalarVar

constexpr size_t MaxScalarVar = 8
constexpr

Backing size of the static arrays of a dynamic model.

Note
The scalar numerics cap the equation count at this value and error above it, so a configuration that fits them fits these kernels.