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 /// @file 9 /// libCEED QFunctions for mass operator example using PETSc 10 11 #ifndef bp1_h 12 #define bp1_h 13 14 #include <ceed.h> 15 #include <math.h> 16 17 // ----------------------------------------------------------------------------- 18 // This QFunction sets up the geometric factors required to apply the 19 // mass operator 20 // 21 // The quadrature data is stored in the array q_data. 22 // 23 // We require the determinant of the Jacobian to properly compute integrals of 24 // the form: int( u v ) 25 // 26 // Qdata: det_J * w 27 // 28 // ----------------------------------------------------------------------------- 29 CEED_QFUNCTION(SetupMassGeo)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 30 // Inputs 31 const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1]; 32 const CeedScalar(*w) = in[2]; // Note: *X = in[0] 33 // Outputs 34 CeedScalar *q_data = out[0]; 35 36 const CeedInt dim = 3; 37 // Quadrature Point Loop 38 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 39 // Setup 40 CeedScalar A[3][3]; 41 for (CeedInt j = 0; j < dim; j++) { 42 for (CeedInt k = 0; k < dim; k++) { 43 // Equivalent code with no mod operations: 44 // A[k][j] = J[k+1][j+1]*J[k+2][j+2] - J[k+1][j+2]*J[k+2][j+1] 45 A[k][j] = J[(k + 1) % dim][(j + 1) % dim][i] * J[(k + 2) % dim][(j + 2) % dim][i] - 46 J[(k + 1) % dim][(j + 2) % dim][i] * J[(k + 2) % dim][(j + 1) % dim][i]; 47 } 48 } 49 const CeedScalar detJ = J[0][0][i] * A[0][0] + J[0][1][i] * A[0][1] + J[0][2][i] * A[0][2]; 50 q_data[i] = detJ * w[i]; 51 } // End of Quadrature Point Loop 52 return 0; 53 } 54 55 // ----------------------------------------------------------------------------- 56 // This QFunction sets up the rhs and true solution for the problem 57 // ----------------------------------------------------------------------------- 58 CEED_QFUNCTION(SetupMassRhs)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 59 const CeedScalar *x = in[0], *w = in[1]; 60 CeedScalar *true_soln = out[0], *rhs = out[1]; 61 62 // Quadrature Point Loop 63 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 64 true_soln[i] = sqrt(x[i] * x[i] + x[i + Q] * x[i + Q] + x[i + 2 * Q] * x[i + 2 * Q]); 65 rhs[i] = w[i] * true_soln[i]; 66 } // End of Quadrature Point Loop 67 return 0; 68 } 69 70 // ----------------------------------------------------------------------------- 71 // This QFunction applies the mass operator for a scalar field. 72 // 73 // Inputs: 74 // u - Input vector at quadrature points 75 // q_data - Geometric factors 76 // 77 // Output: 78 // v - Output vector (test functions) at quadrature points 79 // 80 // ----------------------------------------------------------------------------- 81 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 82 const CeedScalar *u = in[0], *q_data = in[1]; 83 CeedScalar *v = out[0]; 84 85 // Quadrature Point Loop 86 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) v[i] = q_data[i] * u[i]; 87 88 return 0; 89 } 90 // ----------------------------------------------------------------------------- 91 92 #endif // bp1_h 93