xref: /libCEED/tests/t522-operator.h (revision ded9b81dfe1c5b0a720aeaeab78a4be02eef9bb5)
1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3 // All Rights reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q,
18                       const CeedScalar *const *in,
19                       CeedScalar *const *out) {
20   const CeedScalar *qw = in[0], *J = in[1];
21   CeedScalar *qd = out[0];
22 
23   for (CeedInt i=0; i<Q; i++) {
24     // Qdata stored in Voigt convention
25     // J: 0 2   qd: 0 2   adj(J):  J22 -J12
26     //    1 3       2 1           -J21  J11
27     const CeedScalar J11 = J[i+Q*0];
28     const CeedScalar J21 = J[i+Q*1];
29     const CeedScalar J12 = J[i+Q*2];
30     const CeedScalar J22 = J[i+Q*3];
31     const CeedScalar w = qw[i] / (J11*J22 - J21*J12);
32     qd[i+Q*0] =   w * (J12*J12 + J22*J22);
33     qd[i+Q*1] =   w * (J11*J11 + J21*J21);
34     qd[i+Q*2] = - w * (J11*J12 + J21*J22);
35   } // End of Quadrature Point Loop
36   return 0;
37 }
38 
39 CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in,
40                      CeedScalar *const *out) {
41   const CeedScalar *qd = in[0], *ug = in[1];
42   CeedScalar *vg = out[0];
43 
44   for (CeedInt i=0; i<Q; i++) {
45     // Read spatial derivatives of u
46     const CeedScalar du[2]        =  {ug[i+Q*0],
47                                       ug[i+Q*1]
48                                      };
49 
50     // Read qdata (dXdxdXdxT symmetric matrix)
51     // Stored in Voigt convention
52     // 0 2
53     // 2 1
54     // *INDENT-OFF*
55     const CeedScalar dXdxdXdxT[2][2] = {{qd[i+0*Q],
56                                          qd[i+2*Q]},
57                                         {qd[i+2*Q],
58                                          qd[i+1*Q]}
59                                        };
60     // *INDENT-ON*
61     // j = direction of vg
62     for (int j=0; j<2; j++)
63       vg[i+j*Q] = (du[0] * dXdxdXdxT[0][j] +
64                    du[1] * dXdxdXdxT[1][j]);
65   }
66   return 0;
67 }
68