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