xref: /libCEED/include/ceed/jit-source/gallery/ceed-poisson2dbuild.h (revision c0b5abf0f23b15c4f0ada76f8abe9f8d2b6fa247)
15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
2a0154adeSJed Brown // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3a0154adeSJed Brown //
4a0154adeSJed Brown // SPDX-License-Identifier: BSD-2-Clause
5a0154adeSJed Brown //
6a0154adeSJed Brown // This file is part of CEED:  http://github.com/ceed
7a0154adeSJed Brown 
8a0154adeSJed Brown /**
9a0154adeSJed Brown   @brief Ceed QFunction for building the geometric data for the 2D Poisson operator
10a0154adeSJed Brown **/
11a0154adeSJed Brown 
12*c0b5abf0SJeremy L Thompson #include <ceed/types.h>
13c9c2c079SJeremy L Thompson 
142b730f8bSJeremy L Thompson CEED_QFUNCTION(Poisson2DBuild)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
15a0154adeSJed Brown   // At every quadrature point, compute w/det(J).adj(J).adj(J)^T and store
16a0154adeSJed Brown   // the symmetric part of the result.
17a0154adeSJed Brown   // in[0] is Jacobians with shape [2, nc=2, Q]
18a0154adeSJed Brown   // in[1] is quadrature weights, size (Q)
192b730f8bSJeremy L Thompson   const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0], *w = in[1];
20a0154adeSJed Brown   // out[0] is qdata, size (3*Q)
21a0154adeSJed Brown   CeedScalar(*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
22a0154adeSJed Brown 
23a0154adeSJed Brown   // Quadrature point loop
242b730f8bSJeremy L Thompson   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
25a0154adeSJed Brown     // Qdata stored in Voigt convention
26a0154adeSJed Brown     // J: 0 2   q_data: 0 2   adj(J):  J11 -J01
27a0154adeSJed Brown     //    1 3           2 1           -J10  J00
28a0154adeSJed Brown     const CeedScalar J00 = J[0][0][i];
29a0154adeSJed Brown     const CeedScalar J10 = J[0][1][i];
30a0154adeSJed Brown     const CeedScalar J01 = J[1][0][i];
31a0154adeSJed Brown     const CeedScalar J11 = J[1][1][i];
32a0154adeSJed Brown     const CeedScalar qw  = w[i] / (J00 * J11 - J10 * J01);
33a0154adeSJed Brown     q_data[0][i]         = qw * (J01 * J01 + J11 * J11);
34a0154adeSJed Brown     q_data[1][i]         = qw * (J00 * J00 + J10 * J10);
35a0154adeSJed Brown     q_data[2][i]         = -qw * (J00 * J01 + J10 * J11);
36a0154adeSJed Brown   }  // End of Quadrature Point Loop
37a0154adeSJed Brown 
38a0154adeSJed Brown   return CEED_ERROR_SUCCESS;
39a0154adeSJed Brown }
40