xref: /libCEED/include/ceed/jit-source/gallery/ceed-poisson3dbuild.h (revision 19aef5fe4217d01a7c9a3619a4db06ed23296669)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 /**
9   @brief Ceed QFunction for building the geometric data for the 3D Poisson
10            operator
11 **/
12 
13 #ifndef poisson3dbuild_h
14 #define poisson3dbuild_h
15 
16 CEED_QFUNCTION(Poisson3DBuild)(void *ctx, const CeedInt Q,
17                                const CeedScalar *const *in,
18                                CeedScalar *const *out) {
19   // At every quadrature point, compute w/det(J).adj(J).adj(J)^T and store
20   // the symmetric part of the result.
21   // *INDENT-OFF*
22   // in[0] is Jacobians with shape [3, nc=3, Q]
23   // in[1] is quadrature weights, size (Q)
24   const CeedScalar (*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0],
25                                     *w = in[1];
26   // out[0] is qdata, size (6*Q)
27   CeedScalar     (*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
28   // *INDENT-ON*
29 
30   const CeedInt dim = 3;
31 
32   // Quadrature point loop
33   CeedPragmaSIMD
34   for (CeedInt i=0; i<Q; i++) {
35     // Compute the adjoint
36     CeedScalar A[3][3];
37     for (CeedInt j=0; j<dim; j++)
38       for (CeedInt k=0; k<dim; k++)
39         // Equivalent code with no mod operations:
40         // A[k][j] = J[k+1][j+1]*J[k+2][j+2] - J[k+2][j+1]*J[k+1][j+2]
41         A[k][j] = J[(k+1)%dim][(j+1)%dim][i]*J[(k+2)%dim][(j+2)%dim][i] -
42                   J[(k+2)%dim][(j+1)%dim][i]*J[(k+1)%dim][(j+2)%dim][i];
43 
44     // Compute quadrature weight / det(J)
45     const CeedScalar qw = w[i] / (J[0][0][i]*A[0][0] + J[0][1][i]*A[0][1] +
46                                   J[0][2][i]*A[0][2]);
47 
48     // Compute geometric factors
49     // Stored in Voigt convention
50     // 0 5 4
51     // 5 1 3
52     // 4 3 2
53     q_data[0][i] = qw * (A[0][0]*A[0][0] + A[0][1]*A[0][1] + A[0][2]*A[0][2]);
54     q_data[1][i] = qw * (A[1][0]*A[1][0] + A[1][1]*A[1][1] + A[1][2]*A[1][2]);
55     q_data[2][i] = qw * (A[2][0]*A[2][0] + A[2][1]*A[2][1] + A[2][2]*A[2][2]);
56     q_data[3][i] = qw * (A[1][0]*A[2][0] + A[1][1]*A[2][1] + A[1][2]*A[2][2]);
57     q_data[4][i] = qw * (A[0][0]*A[2][0] + A[0][1]*A[2][1] + A[0][2]*A[2][2]);
58     q_data[5][i] = qw * (A[0][0]*A[1][0] + A[0][1]*A[1][1] + A[0][2]*A[1][2]);
59   } // End of Quadrature Point Loop
60 
61   return CEED_ERROR_SUCCESS;
62 }
63 
64 #endif // poisson3dbuild_h
65