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