1 // Copyright (c) 2017-2026, 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 #include <ceed/types.h>
9
setup(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)10 CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
11 // At every quadrature point, compute qw/det(J).adj(J).adj(J)^T and store
12 // the symmetric part of the result.
13
14 // in[0] is Jacobians with shape [2, nc=2, Q]
15 // in[1] is quadrature weights, size (Q)
16 const CeedScalar *J = in[0], *qw = in[1];
17
18 // out[0] is qdata, size (Q)
19 CeedScalar *qd = out[0];
20
21 // Quadrature point loop
22 for (CeedInt i = 0; i < Q; i++) {
23 // J: 0 2 qd: 0 2 adj(J): J22 -J12
24 // 1 3 2 1 -J21 J11
25 const CeedScalar J11 = J[i + Q * 0];
26 const CeedScalar J21 = J[i + Q * 1];
27 const CeedScalar J12 = J[i + Q * 2];
28 const CeedScalar J22 = J[i + Q * 3];
29 const CeedScalar w = qw[i] / (J11 * J22 - J21 * J12);
30 qd[i + Q * 0] = w * (J12 * J12 + J22 * J22);
31 qd[i + Q * 2] = w * (J11 * J11 + J21 * J21);
32 qd[i + Q * 1] = -w * (J11 * J12 + J21 * J22);
33 }
34
35 return 0;
36 }
37
diff(void * ctx,const CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)38 CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
39 // in[0] is gradient u, shape [2, nc=1, Q]
40 // in[1] is quadrature data, size (3*Q)
41 const CeedScalar *du = in[0], *qd = in[1];
42
43 // out[0] is output to multiply against gradient v, shape [2, nc=1, Q]
44 CeedScalar *dv = out[0];
45
46 // Quadrature point loop
47 for (CeedInt i = 0; i < Q; i++) {
48 const CeedScalar du0 = du[i + Q * 0];
49 const CeedScalar du1 = du[i + Q * 1];
50 dv[i + Q * 0] = qd[i + Q * 0] * du0 + qd[i + Q * 2] * du1;
51 dv[i + Q * 1] = qd[i + Q * 2] * du0 + qd[i + Q * 1] * du1;
52 }
53
54 return 0;
55 }
56