xref: /libCEED/examples/fluids/qfunctions/utils.h (revision 13fa47b256d7b8fa7dc04000fe86398448c8602c)
1*13fa47b2SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2*13fa47b2SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*13fa47b2SJames Wright //
4*13fa47b2SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5*13fa47b2SJames Wright //
6*13fa47b2SJames Wright // This file is part of CEED:  http://github.com/ceed
7*13fa47b2SJames Wright 
8*13fa47b2SJames Wright #ifndef utils_h
9*13fa47b2SJames Wright #define utils_h
10*13fa47b2SJames Wright 
11*13fa47b2SJames Wright #include <math.h>
12*13fa47b2SJames Wright #include <ceed.h>
13*13fa47b2SJames Wright 
14*13fa47b2SJames Wright #ifndef M_PI
15*13fa47b2SJames Wright #define M_PI    3.14159265358979323846
16*13fa47b2SJames Wright #endif
17*13fa47b2SJames Wright 
18*13fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Max(CeedScalar a, CeedScalar b) { return a < b ? b : a; }
19*13fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Min(CeedScalar a, CeedScalar b) { return a < b ? a : b; }
20*13fa47b2SJames Wright 
21*13fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Square(CeedScalar x) { return x*x; }
22*13fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Cube(CeedScalar x) { return x*x*x; }
23*13fa47b2SJames Wright 
24*13fa47b2SJames Wright // @brief Dot product of 3 element vectors
25*13fa47b2SJames Wright CEED_QFUNCTION_HELPER CeedScalar Dot3(const CeedScalar u[3],
26*13fa47b2SJames Wright                                       const CeedScalar v[3]) {
27*13fa47b2SJames Wright   return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
28*13fa47b2SJames Wright }
29*13fa47b2SJames Wright 
30*13fa47b2SJames Wright // @brief Unpack Kelvin-Mandel notation symmetric tensor into full tensor
31*13fa47b2SJames Wright CEED_QFUNCTION_HELPER void KMUnpack(const CeedScalar v[6], CeedScalar A[3][3]) {
32*13fa47b2SJames Wright   const CeedScalar weight = 1 / sqrt(2.);
33*13fa47b2SJames Wright   A[0][0] = v[0];
34*13fa47b2SJames Wright   A[1][1] = v[1];
35*13fa47b2SJames Wright   A[2][2] = v[2];
36*13fa47b2SJames Wright   A[2][1] = A[1][2] = weight * v[3];
37*13fa47b2SJames Wright   A[2][0] = A[0][2] = weight * v[4];
38*13fa47b2SJames Wright   A[1][0] = A[0][1] = weight * v[5];
39*13fa47b2SJames Wright }
40*13fa47b2SJames Wright 
41*13fa47b2SJames Wright #endif // utils_h
42