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