Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
common_math.h File Reference

Common math functions. More...

#include <array>
#include <vector>
#include <limits>
#include <Kokkos_Core.hpp>
#include "common_typedef.h"

Go to the source code of this file.

Functions

template<uint32_t N>
KOKKOS_INLINE_FUNCTION rtype dot (const rtype *a, const rtype *b)
 Compute the dot product of two arrays.
 
template<>
KOKKOS_INLINE_FUNCTION rtype dot< 2 > (const rtype *a, const rtype *b)
 
template<>
KOKKOS_INLINE_FUNCTION rtype dot< 3 > (const rtype *a, const rtype *b)
 
template<uint32_t N>
KOKKOS_INLINE_FUNCTION rtype norm_2 (const rtype *v)
 Compute the 2-norm of a vector.
 
template<>
KOKKOS_INLINE_FUNCTION rtype norm_2< 2 > (const rtype *v)
 
template<>
KOKKOS_INLINE_FUNCTION rtype norm_2< 3 > (const rtype *v)
 
template<uint32_t N>
KOKKOS_INLINE_FUNCTION void unit (const rtype *v, rtype *u)
 Compute the unit vector of a vector.
 
template<>
KOKKOS_INLINE_FUNCTION void unit< 2 > (const rtype *v, rtype *u)
 
template<>
KOKKOS_INLINE_FUNCTION void unit< 3 > (const rtype *v, rtype *u)
 
KOKKOS_INLINE_FUNCTION void tangent_basis (const rtype *n, rtype *t1, rtype *t2)
 Unit tangents completing the unit normal n to an orthonormal, right-handed basis: (n, t1) in 2D, (n, t1, t2) in 3D. In 2D, t1 = (-n_y, n_x) and t2 is not written.
 
KOKKOS_INLINE_FUNCTION void transpose (const rtype *A, rtype *AT, const uint16_t m, const uint16_t n)
 Transpose a matrix. Only intended for use with small matrices within kernels.
 
template<uint32_t N>
KOKKOS_INLINE_FUNCTION void invert_matrix (const rtype *A, rtype *A_inv)
 Invert a matrix. Will be instantiated for 2x2 and 3x3 matrices.
 
template<>
KOKKOS_INLINE_FUNCTION void invert_matrix< 2 > (const rtype *A, rtype *A_inv)
 
template<>
KOKKOS_INLINE_FUNCTION void invert_matrix< 3 > (const rtype *A, rtype *A_inv)
 
template<uint32_t N>
KOKKOS_INLINE_FUNCTION void gemv (const rtype *A, const rtype *x, rtype *y)
 General matrix-vector multiplication. Will be instantiated for 2x2 and 3x3 matrices.
 
template<>
KOKKOS_INLINE_FUNCTION void gemv< 2 > (const rtype *A, const rtype *x, rtype *y)
 
template<>
KOKKOS_INLINE_FUNCTION void gemv< 3 > (const rtype *A, const rtype *x, rtype *y)
 
KOKKOS_INLINE_FUNCTION void gemm (const rtype *A, const rtype *B, rtype *C, const uint16_t m, const uint16_t n, const uint16_t p, const uint16_t q, const bool tA, const bool tB, const bool print_debug=false)
 General matrix-matrix multiplication. Only intended for use with small matrices within kernels.
 
KOKKOS_INLINE_FUNCTION void QR_householder_noQ (const rtype *A, rtype *R, const uint16_t m, const uint16_t n)
 Compute the R part of the QR decomposition of a matrix.
 
KOKKOS_INLINE_FUNCTION void forward_substitution (const rtype *L, const rtype *B, rtype *X, const uint16_t m, const uint16_t n, const uint16_t p, const bool tL, const bool tB)
 Perform forward substitution to solve a lower triangular system.
 
KOKKOS_INLINE_FUNCTION void back_substitution (const rtype *U, const rtype *B, rtype *X, const uint16_t m, const uint16_t n, const uint16_t p, const bool tU, const bool tB)
 Perform back substitution to solve an upper triangular system.
 
template<uint32_t N>
KOKKOS_INLINE_FUNCTION rtype triangle_area (const rtype *v0, const rtype *v1, const rtype *v2)
 Compute the area of a triangle from its vertices.
 
template<>
KOKKOS_INLINE_FUNCTION rtype triangle_area< 2 > (const rtype *v0, const rtype *v1, const rtype *v2)
 
KOKKOS_INLINE_FUNCTION void triangle_J (const rtype *v0, const rtype *v1, const rtype *v2, rtype *J)
 Get the transformation matrix into a triangle's local coordinates.
 
KOKKOS_INLINE_FUNCTION void tetrahedron_J (const rtype *v0, const rtype *v1, const rtype *v2, const rtype *v3, rtype *J)
 Get the transformation matrix into a tetrahedron's local coordinates.
 
template<uint32_t N>
std::array< rtype, N > max_array (Kokkos::View< rtype ** > a)
 Compute the maximum of each element along the first dimension of a.
 
template<uint32_t N>
std::array< rtype, N > min_array (Kokkos::View< rtype ** > a)
 Compute the minimum of each element along the first dimension of a.
 

Detailed Description

Common math functions.

Author
Matthew Bonanni (mbona.nosp@m.nni0.nosp@m.01@gm.nosp@m.ail..nosp@m.com)
Version
0.1
Date
2023-12-18

Function Documentation

◆ back_substitution()

KOKKOS_INLINE_FUNCTION void back_substitution ( const rtype *  U,
const rtype *  B,
rtype *  X,
const uint16_t  m,
const uint16_t  n,
const uint16_t  p,
const bool  tU,
const bool  tB 
)

Perform back substitution to solve an upper triangular system.

Parameters
UUpper triangular matrix [m x n].
BRight-hand side matrix [n x p].
XSolution matrix [m x p].
mNumber of rows in U.
nNumber of columns in U.
pNumber of columns in B.
tUTranspose U.
tBTranspose B.

◆ dot()

template<uint32_t N>
KOKKOS_INLINE_FUNCTION rtype dot ( const rtype *  a,
const rtype *  b 
)

Compute the dot product of two arrays.

Parameters
aFirst array.
bSecond array.
Template Parameters
NLength of the arrays.
Returns
Dot product.

◆ dot< 2 >()

template<>
KOKKOS_INLINE_FUNCTION rtype dot< 2 > ( const rtype *  a,
const rtype *  b 
)

◆ dot< 3 >()

template<>
KOKKOS_INLINE_FUNCTION rtype dot< 3 > ( const rtype *  a,
const rtype *  b 
)

◆ forward_substitution()

KOKKOS_INLINE_FUNCTION void forward_substitution ( const rtype *  L,
const rtype *  B,
rtype *  X,
const uint16_t  m,
const uint16_t  n,
const uint16_t  p,
const bool  tL,
const bool  tB 
)

Perform forward substitution to solve a lower triangular system.

Parameters
LLower triangular matrix [m x n].
BRight-hand side matrix [n x p].
XSolution matrix [m x p].
mNumber of rows in L.
nNumber of columns in L.
pNumber of columns in B.
tLTranspose L.
tBTranspose B.

◆ gemm()

KOKKOS_INLINE_FUNCTION void gemm ( const rtype *  A,
const rtype *  B,
rtype *  C,
const uint16_t  m,
const uint16_t  n,
const uint16_t  p,
const uint16_t  q,
const bool  tA,
const bool  tB,
const bool  print_debug = false 
)

General matrix-matrix multiplication. Only intended for use with small matrices within kernels.

Parameters
AMatrix.
BMatrix.
CResulting matrix.
mNumber of rows in A.
nNumber of columns in A.
pNumber of rows in B.
qNumber of columns in B.
tATranspose A.
tBTranspose B.
print_debugPrint the operands and result.

◆ gemv()

template<uint32_t N>
KOKKOS_INLINE_FUNCTION void gemv ( const rtype *  A,
const rtype *  x,
rtype *  y 
)

General matrix-vector multiplication. Will be instantiated for 2x2 and 3x3 matrices.

Parameters
AMatrix.
xVector.
yResulting vector.

◆ gemv< 2 >()

template<>
KOKKOS_INLINE_FUNCTION void gemv< 2 > ( const rtype *  A,
const rtype *  x,
rtype *  y 
)

◆ gemv< 3 >()

template<>
KOKKOS_INLINE_FUNCTION void gemv< 3 > ( const rtype *  A,
const rtype *  x,
rtype *  y 
)

◆ invert_matrix()

template<uint32_t N>
KOKKOS_INLINE_FUNCTION void invert_matrix ( const rtype *  A,
rtype *  A_inv 
)

Invert a matrix. Will be instantiated for 2x2 and 3x3 matrices.

Parameters
AMatrix to invert.
A_invInverted matrix.

◆ invert_matrix< 2 >()

template<>
KOKKOS_INLINE_FUNCTION void invert_matrix< 2 > ( const rtype *  A,
rtype *  A_inv 
)

◆ invert_matrix< 3 >()

template<>
KOKKOS_INLINE_FUNCTION void invert_matrix< 3 > ( const rtype *  A,
rtype *  A_inv 
)

◆ max_array()

template<uint32_t N>
std::array< rtype, N > max_array ( Kokkos::View< rtype ** >  a)

Compute the maximum of each element along the first dimension of a.

Parameters
aArray.
Returns
Maximum of each element.

◆ min_array()

template<uint32_t N>
std::array< rtype, N > min_array ( Kokkos::View< rtype ** >  a)

Compute the minimum of each element along the first dimension of a.

Parameters
aArray.
Returns
Minimum of each element.

◆ norm_2()

template<uint32_t N>
KOKKOS_INLINE_FUNCTION rtype norm_2 ( const rtype *  v)

Compute the 2-norm of a vector.

Parameters
vVector.
Template Parameters
NLength of the vector.
Returns
Norm.

◆ norm_2< 2 >()

template<>
KOKKOS_INLINE_FUNCTION rtype norm_2< 2 > ( const rtype *  v)

◆ norm_2< 3 >()

template<>
KOKKOS_INLINE_FUNCTION rtype norm_2< 3 > ( const rtype *  v)

◆ QR_householder_noQ()

KOKKOS_INLINE_FUNCTION void QR_householder_noQ ( const rtype *  A,
rtype *  R,
const uint16_t  m,
const uint16_t  n 
)

Compute the R part of the QR decomposition of a matrix.

Parameters
AMatrix.
RUpper triangular matrix.
mNumber of rows.
nNumber of columns.

◆ tangent_basis()

KOKKOS_INLINE_FUNCTION void tangent_basis ( const rtype *  n,
rtype *  t1,
rtype *  t2 
)

Unit tangents completing the unit normal n to an orthonormal, right-handed basis: (n, t1) in 2D, (n, t1, t2) in 3D. In 2D, t1 = (-n_y, n_x) and t2 is not written.

Parameters
nUnit normal.
t1First tangent.
t2Second tangent (3D only).

◆ tetrahedron_J()

KOKKOS_INLINE_FUNCTION void tetrahedron_J ( const rtype *  v0,
const rtype *  v1,
const rtype *  v2,
const rtype *  v3,
rtype *  J 
)

Get the transformation matrix into a tetrahedron's local coordinates.

Parameters
v0Coordinates of the first vertex.
v1Coordinates of the second vertex.
v2Coordinates of the third vertex.
v3Coordinates of the fourth vertex.
JTransformation matrix.

◆ transpose()

KOKKOS_INLINE_FUNCTION void transpose ( const rtype *  A,
rtype *  AT,
const uint16_t  m,
const uint16_t  n 
)

Transpose a matrix. Only intended for use with small matrices within kernels.

Parameters
AMatrix
ATTransposed matrix
mNumber of rows in A
nNumber of columns in A

◆ triangle_area()

template<uint32_t N>
KOKKOS_INLINE_FUNCTION rtype triangle_area ( const rtype *  v0,
const rtype *  v1,
const rtype *  v2 
)

Compute the area of a triangle from its vertices.

Parameters
v0Coordinates of the first vertex.
v1Coordinates of the second vertex.
v2Coordinates of the third vertex.
Returns
Area of the triangle.

◆ triangle_area< 2 >()

template<>
KOKKOS_INLINE_FUNCTION rtype triangle_area< 2 > ( const rtype *  v0,
const rtype *  v1,
const rtype *  v2 
)

◆ triangle_J()

KOKKOS_INLINE_FUNCTION void triangle_J ( const rtype *  v0,
const rtype *  v1,
const rtype *  v2,
rtype *  J 
)

Get the transformation matrix into a triangle's local coordinates.

Parameters
v0Coordinates of the first vertex.
v1Coordinates of the second vertex.
v2Coordinates of the third vertex.
JTransformation matrix.

◆ unit()

template<uint32_t N>
KOKKOS_INLINE_FUNCTION void unit ( const rtype *  v,
rtype *  u 
)

Compute the unit vector of a vector.

Parameters
vVector.
uUnit vector.
Template Parameters
NLength of the vector.

◆ unit< 2 >()

template<>
KOKKOS_INLINE_FUNCTION void unit< 2 > ( const rtype *  v,
rtype *  u 
)

◆ unit< 3 >()

template<>
KOKKOS_INLINE_FUNCTION void unit< 3 > ( const rtype *  v,
rtype *  u 
)