xref: /libCEED/include/ceed/jit-source/gallery/ceed-poisson2dbuild.h (revision cd4035ff32b1ddface7e7603292a8647e8b8628f)
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 2D Poisson operator
10 **/
11 
12 #ifndef poisson2dbuild_h
13 #define poisson2dbuild_h
14 
15 #include <ceed.h>
16 
17 CEED_QFUNCTION(Poisson2DBuild)(void *ctx, const CeedInt Q,
18                                const CeedScalar *const *in,
19                                CeedScalar *const *out) {
20   // At every quadrature point, compute w/det(J).adj(J).adj(J)^T and store
21   // the symmetric part of the result.
22   // *INDENT-OFF*
23   // in[0] is Jacobians with shape [2, nc=2, Q]
24   // in[1] is quadrature weights, size (Q)
25   const CeedScalar (*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0],
26                                     *w = in[1];
27   // out[0] is qdata, size (3*Q)
28   CeedScalar     (*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
29   // *INDENT-ON*
30 
31   // Quadrature point loop
32   CeedPragmaSIMD
33   for (CeedInt i=0; i<Q; i++) {
34     // Qdata stored in Voigt convention
35     // J: 0 2   q_data: 0 2   adj(J):  J11 -J01
36     //    1 3           2 1           -J10  J00
37     const CeedScalar J00 = J[0][0][i];
38     const CeedScalar J10 = J[0][1][i];
39     const CeedScalar J01 = J[1][0][i];
40     const CeedScalar J11 = J[1][1][i];
41     const CeedScalar qw = w[i] / (J00*J11 - J10*J01);
42     q_data[0][i] =   qw * (J01*J01 + J11*J11);
43     q_data[1][i] =   qw * (J00*J00 + J10*J10);
44     q_data[2][i] = - qw * (J00*J01 + J10*J11);
45   } // End of Quadrature Point Loop
46 
47   return CEED_ERROR_SUCCESS;
48 }
49 
50 #endif // poisson2dbuild_h
51