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 // At every quadrature point, compute qw/det(J).adj(J).adj(J)^T and store 21 // the symmetric part of the result. 22 23 // in[0] is Jacobians with shape [2, nc=2, Q] 24 // in[1] is quadrature weights, size (Q) 25 const CeedScalar *J = in[0], *qw = in[1]; 26 27 // out[0] is qdata, size (Q) 28 CeedScalar *qd = out[0]; 29 30 // Quadrature point loop 31 for (CeedInt i=0; i<Q; i++) { 32 // J: 0 2 qd: 0 2 adj(J): J22 -J12 33 // 1 3 2 1 -J21 J11 34 const CeedScalar J11 = J[i+Q*0]; 35 const CeedScalar J21 = J[i+Q*1]; 36 const CeedScalar J12 = J[i+Q*2]; 37 const CeedScalar J22 = J[i+Q*3]; 38 const CeedScalar w = qw[i] / (J11*J22 - J21*J12); 39 qd[i+Q*0] = w * (J12*J12 + J22*J22); 40 qd[i+Q*2] = w * (J11*J11 + J21*J21); 41 qd[i+Q*1] = - w * (J11*J12 + J21*J22); 42 } 43 44 return 0; 45 } 46 47 CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in, 48 CeedScalar *const *out) { 49 // in[0] is gradient u, shape [2, nc=1, Q] 50 // in[1] is quadrature data, size (3*Q) 51 const CeedScalar *du = in[0], *qd = in[1]; 52 53 // out[0] is output to multiply against gradient v, shape [2, nc=1, Q] 54 CeedScalar *dv = out[0]; 55 56 // Quadrature point loop 57 for (CeedInt i=0; i<Q; i++) { 58 const CeedScalar du0 = du[i+Q*0]; 59 const CeedScalar du1 = du[i+Q*1]; 60 dv[i+Q*0] = qd[i+Q*0]*du0 + qd[i+Q*2]*du1; 61 dv[i+Q*1] = qd[i+Q*2]*du0 + qd[i+Q*1]*du1; 62 } 63 64 return 0; 65 } 66