xref: /honee/qfunctions/utils.h (revision 2b916ea7fa53b5c2584160b9274b1b14ca18ff4f)
1704b8bbeSJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2704b8bbeSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3704b8bbeSJames Wright //
4704b8bbeSJames Wright // SPDX-License-Identifier: BSD-2-Clause
5704b8bbeSJames Wright //
6704b8bbeSJames Wright // This file is part of CEED:  http://github.com/ceed
7704b8bbeSJames Wright 
8704b8bbeSJames Wright #ifndef utils_h
9704b8bbeSJames Wright #define utils_h
10704b8bbeSJames Wright 
11704b8bbeSJames Wright #include <ceed.h>
12d0cce58aSJeremy L Thompson #include <math.h>
13704b8bbeSJames Wright 
14704b8bbeSJames Wright #ifndef M_PI
15704b8bbeSJames Wright #define M_PI 3.14159265358979323846
16704b8bbeSJames Wright #endif
17704b8bbeSJames Wright 
18704b8bbeSJames Wright CEED_QFUNCTION_HELPER CeedScalar Max(CeedScalar a, CeedScalar b) { return a < b ? b : a; }
19704b8bbeSJames Wright CEED_QFUNCTION_HELPER CeedScalar Min(CeedScalar a, CeedScalar b) { return a < b ? a : b; }
20704b8bbeSJames Wright 
21704b8bbeSJames Wright CEED_QFUNCTION_HELPER CeedScalar Square(CeedScalar x) { return x * x; }
22704b8bbeSJames Wright CEED_QFUNCTION_HELPER CeedScalar Cube(CeedScalar x) { return x * x * x; }
23704b8bbeSJames Wright 
24704b8bbeSJames Wright // @brief Dot product of 3 element vectors
25*2b916ea7SJeremy 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]; }
26704b8bbeSJames Wright 
27704b8bbeSJames Wright // @brief Unpack Kelvin-Mandel notation symmetric tensor into full tensor
28704b8bbeSJames Wright CEED_QFUNCTION_HELPER void KMUnpack(const CeedScalar v[6], CeedScalar A[3][3]) {
29704b8bbeSJames Wright   const CeedScalar weight = 1 / sqrt(2.);
30704b8bbeSJames Wright   A[0][0]                 = v[0];
31704b8bbeSJames Wright   A[1][1]                 = v[1];
32704b8bbeSJames Wright   A[2][2]                 = v[2];
33704b8bbeSJames Wright   A[2][1] = A[1][2] = weight * v[3];
34704b8bbeSJames Wright   A[2][0] = A[0][2] = weight * v[4];
35704b8bbeSJames Wright   A[1][0] = A[0][1] = weight * v[5];
36704b8bbeSJames Wright }
37704b8bbeSJames Wright 
38704b8bbeSJames Wright #endif  // utils_h
39