xref: /libCEED/examples/fluids/qfunctions/utils.h (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
113fa47b2SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
213fa47b2SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
313fa47b2SJames Wright //
413fa47b2SJames Wright // SPDX-License-Identifier: BSD-2-Clause
513fa47b2SJames Wright //
613fa47b2SJames Wright // This file is part of CEED:  http://github.com/ceed
713fa47b2SJames Wright 
813fa47b2SJames Wright #ifndef utils_h
913fa47b2SJames Wright #define utils_h
1013fa47b2SJames Wright 
1113fa47b2SJames Wright #include <ceed.h>
12c9c2c079SJeremy L Thompson #include <math.h>
1313fa47b2SJames Wright 
1413fa47b2SJames Wright #ifndef M_PI
1513fa47b2SJames Wright #define M_PI 3.14159265358979323846
1613fa47b2SJames Wright #endif
1713fa47b2SJames Wright 
1813fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Max(CeedScalar a, CeedScalar b) { return a < b ? b : a; }
1913fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Min(CeedScalar a, CeedScalar b) { return a < b ? a : b; }
2013fa47b2SJames Wright 
2113fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Square(CeedScalar x) { return x * x; }
2213fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Cube(CeedScalar x) { return x * x * x; }
2313fa47b2SJames Wright 
2413fa47b2SJames Wright // @brief Dot product of 3 element vectors
25*2b730f8bSJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar Dot3(const CeedScalar u[3], const CeedScalar v[3]) { return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]; }
2613fa47b2SJames Wright 
2713fa47b2SJames Wright // @brief Unpack Kelvin-Mandel notation symmetric tensor into full tensor
2813fa47b2SJames Wright CEED_QFUNCTION_HELPER void KMUnpack(const CeedScalar v[6], CeedScalar A[3][3]) {
2913fa47b2SJames Wright   const CeedScalar weight = 1 / sqrt(2.);
3013fa47b2SJames Wright   A[0][0]                 = v[0];
3113fa47b2SJames Wright   A[1][1]                 = v[1];
3213fa47b2SJames Wright   A[2][2]                 = v[2];
3313fa47b2SJames Wright   A[2][1] = A[1][2] = weight * v[3];
3413fa47b2SJames Wright   A[2][0] = A[0][2] = weight * v[4];
3513fa47b2SJames Wright   A[1][0] = A[0][1] = weight * v[5];
3613fa47b2SJames Wright }
3713fa47b2SJames Wright 
3813fa47b2SJames Wright #endif  // utils_h
39