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