xref: /libCEED/tests/t534-operator.h (revision 3d8e882215d238700cdceb37404f76ca7fa24eaa)
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 CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q,
9                       const CeedScalar *const *in,
10                       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 
38 CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in,
39                      CeedScalar *const *out) {
40   // in[0] is gradient u, shape [2, nc=1, Q]
41   // in[1] is quadrature data, size (3*Q)
42   const CeedScalar *du = in[0], *qd = in[1];
43 
44   // out[0] is output to multiply against gradient v, shape [2, nc=1, Q]
45   CeedScalar *dv = out[0];
46 
47   // Quadrature point loop
48   for (CeedInt i=0; i<Q; i++) {
49     const CeedScalar du0 = du[i+Q*0];
50     const CeedScalar du1 = du[i+Q*1];
51     dv[i+Q*0] = qd[i+Q*0]*du0 + qd[i+Q*2]*du1;
52     dv[i+Q*1] = qd[i+Q*2]*du0 + qd[i+Q*1]*du1;
53   }
54 
55   return 0;
56 }
57