xref: /libCEED/tests/t567-operator.h (revision 96461910ed4bdb415adf6fb966585f810826484d)
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     // *INDENT-OFF*
12   const CeedScalar                  *w = in[0],
13                    (*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[1];
14   CeedScalar     (*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
15     // *INDENT-ON*
16 
17   // Quadrature point loop
18   CeedPragmaSIMD
19   for (CeedInt i=0; i<Q; i++) {
20     // Qdata stored in Voigt convention
21     // J: 0 2   q_data: 0 2   adj(J):  J11 -J01
22     //    1 3           2 1           -J10  J00
23     const CeedScalar J00 = J[0][0][i];
24     const CeedScalar J10 = J[0][1][i];
25     const CeedScalar J01 = J[1][0][i];
26     const CeedScalar J11 = J[1][1][i];
27     const CeedScalar qw = w[i] / (J00*J11 - J10*J01);
28     q_data[0][i] =   qw * (J01*J01 + J11*J11);
29     q_data[1][i] =   qw * (J00*J00 + J10*J10);
30     q_data[2][i] = - qw * (J00*J01 + J10*J11);
31   } // End of Quadrature Point Loop
32 
33   return 0;
34 }
35 
36 CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in,
37                      CeedScalar *const *out) {
38     // *INDENT-OFF*
39   const CeedScalar (*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0],
40                        (*ug)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1];
41   CeedScalar           (*vg)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
42     // *INDENT-ON*
43 
44   const CeedInt dim = 2;
45   const CeedScalar scale[2][2] = {
46     {1.0, 2.0},
47     {3.0, 4.0},
48   };
49 
50   // Quadrature point loop
51   CeedPragmaSIMD
52   for (CeedInt i=0; i<Q; i++) {
53     // Read qdata (dXdxdXdxT symmetric matrix)
54     // Stored in Voigt convention
55     // 0 2
56     // 2 1
57     // *INDENT-OFF*
58     const CeedScalar dXdxdXdxT[2][2] = {{q_data[0][i],
59                                          q_data[2][i]},
60                                         {q_data[2][i],
61                                          q_data[1][i]}
62                                        };
63     // *INDENT-ON*
64 
65     // Apply Poisson operator
66     // j = direction of vg
67     for (CeedInt j=0; j<dim; j++)
68       vg[j][i] = (ug[0][i] * dXdxdXdxT[0][j] * scale[0][j] +
69                   ug[1][i] * dXdxdXdxT[1][j] * scale[1][j]);
70   } // End of Quadrature Point Loop
71 
72   return 0;
73 }
74