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, 30 const CeedScalar *const *in, 31 CeedScalar *const *out) { 32 // Inputs 33 const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1]; 34 const CeedScalar(*w) = in[2]; // Note: *X = in[0] 35 // Outputs 36 CeedScalar *q_data = out[0]; 37 38 const CeedInt dim = 3; 39 // Quadrature Point Loop 40 CeedPragmaSIMD 41 for (CeedInt i=0; i<Q; i++) { 42 // Setup 43 CeedScalar A[3][3]; 44 for (CeedInt j = 0; j < dim; j++) { 45 for (CeedInt k = 0; k < dim; k++) { 46 // Equivalent code with no mod operations: 47 // A[k][j] = J[k+1][j+1]*J[k+2][j+2] - J[k+1][j+2]*J[k+2][j+1] 48 A[k][j] = J[(k + 1) % dim][(j + 1) % dim][i] * J[(k + 2) % dim][(j + 2) % dim][i] - 49 J[(k + 1) % dim][(j + 2) % dim][i] * J[(k + 2) % dim][(j + 1) % dim][i]; 50 } 51 } 52 const CeedScalar detJ = J[0][0][i] * A[0][0] + J[0][1][i] * A[0][1] + J[0][2][i] * A[0][2]; 53 q_data[i] = detJ * w[i]; 54 } // End of Quadrature Point Loop 55 return 0; 56 } 57 58 // ----------------------------------------------------------------------------- 59 // This QFunction sets up the rhs and true solution for the problem 60 // ----------------------------------------------------------------------------- 61 CEED_QFUNCTION(SetupMassRhs)(void *ctx, const CeedInt Q, 62 const CeedScalar *const *in, 63 CeedScalar *const *out) { 64 const CeedScalar *x = in[0], *w = in[1]; 65 CeedScalar *true_soln = out[0], *rhs = out[1]; 66 67 // Quadrature Point Loop 68 CeedPragmaSIMD 69 for (CeedInt i=0; i<Q; i++) { 70 true_soln[i] = sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]); 71 rhs[i] = w[i] * true_soln[i]; 72 } // End of Quadrature Point Loop 73 return 0; 74 } 75 76 // ----------------------------------------------------------------------------- 77 // This QFunction applies the mass operator for a scalar field. 78 // 79 // Inputs: 80 // u - Input vector at quadrature points 81 // q_data - Geometric factors 82 // 83 // Output: 84 // v - Output vector (test functions) at quadrature points 85 // 86 // ----------------------------------------------------------------------------- 87 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, 88 const CeedScalar *const *in, CeedScalar *const *out) { 89 const CeedScalar *u = in[0], *q_data = in[1]; 90 CeedScalar *v = out[0]; 91 92 // Quadrature Point Loop 93 CeedPragmaSIMD 94 for (CeedInt i=0; i<Q; i++) 95 v[i] = q_data[i] * u[i]; 96 97 return 0; 98 } 99 // ----------------------------------------------------------------------------- 100 101 #endif // bp1_h 102