1 // Copyright (c) 2017-2022, 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 #ifndef ex1_volume_h 9 #define ex1_volume_h 10 11 #include <ceed.h> 12 13 /// A structure used to pass additional data to f_build_mass 14 struct BuildContext { 15 CeedInt dim, space_dim; 16 }; 17 18 /// libCEED Q-function for building quadrature data for a mass operator 19 CEED_QFUNCTION(f_build_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 20 // in[0] is Jacobians with shape [dim, nc=dim, Q] 21 // in[1] is quadrature weights, size (Q) 22 struct BuildContext *bc = (struct BuildContext *)ctx; 23 const CeedScalar *J = in[0], *w = in[1]; 24 CeedScalar *q_data = out[0]; 25 26 switch (bc->dim + 10 * bc->space_dim) { 27 case 11: 28 // Quadrature Point Loop 29 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { q_data[i] = J[i] * w[i]; } // End of Quadrature Point Loop 30 break; 31 case 22: 32 // Quadrature Point Loop 33 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 34 // 0 2 35 // 1 3 36 q_data[i] = (J[i + Q * 0] * J[i + Q * 3] - J[i + Q * 1] * J[i + Q * 2]) * w[i]; 37 } // End of Quadrature Point Loop 38 break; 39 case 33: 40 // Quadrature Point Loop 41 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 42 // 0 3 6 43 // 1 4 7 44 // 2 5 8 45 q_data[i] = (J[i + Q * 0] * (J[i + Q * 4] * J[i + Q * 8] - J[i + Q * 5] * J[i + Q * 7]) - 46 J[i + Q * 1] * (J[i + Q * 3] * J[i + Q * 8] - J[i + Q * 5] * J[i + Q * 6]) + 47 J[i + Q * 2] * (J[i + Q * 3] * J[i + Q * 7] - J[i + Q * 4] * J[i + Q * 6])) * 48 w[i]; 49 } // End of Quadrature Point Loop 50 break; 51 } 52 return 0; 53 } 54 55 /// libCEED Q-function for applying a mass operator 56 CEED_QFUNCTION(f_apply_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 57 const CeedScalar *u = in[0], *q_data = in[1]; 58 CeedScalar *v = out[0]; 59 60 // Quadrature Point Loop 61 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { v[i] = q_data[i] * u[i]; } // End of Quadrature Point Loop 62 return 0; 63 } 64 65 #endif // ex1_volume_h 66