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 bp2_h 12 #define bp2_h 13 14 #include <ceed.h> 15 #include <math.h> 16 17 // ----------------------------------------------------------------------------- 18 // This QFunction sets up the rhs and true solution for the problem 19 // ----------------------------------------------------------------------------- 20 CEED_QFUNCTION(SetupMassRhs3)(void *ctx, const CeedInt Q, 21 const CeedScalar *const *in, 22 CeedScalar *const *out) { 23 const CeedScalar *x = in[0], *w = in[1]; 24 CeedScalar *true_soln = out[0], *rhs = out[1]; 25 26 // Quadrature Point Loop 27 CeedPragmaSIMD 28 for (CeedInt i=0; i<Q; i++) { 29 // Component 1 30 true_soln[i+0*Q] = sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]); 31 // Component 2 32 true_soln[i+1*Q] = 2 * true_soln[i+0*Q]; 33 // Component 3 34 true_soln[i+2*Q] = 3 * true_soln[i+0*Q]; 35 36 // Component 1 37 rhs[i+0*Q] = w[i] * true_soln[i+0*Q]; 38 // Component 2 39 rhs[i+1*Q] = 2 * rhs[i+0*Q]; 40 // Component 3 41 rhs[i+2*Q] = 3 * rhs[i+0*Q]; 42 } // End of Quadrature Point Loop 43 return 0; 44 } 45 46 // ----------------------------------------------------------------------------- 47 // This QFunction applies the mass operator for a vector field of 3 components. 48 // 49 // Inputs: 50 // u - Input vector at quadrature points 51 // q_data - Geometric factors 52 // 53 // Output: 54 // v - Output vector (test functions) at quadrature points 55 // 56 // ----------------------------------------------------------------------------- 57 CEED_QFUNCTION(Mass3)(void *ctx, const CeedInt Q, 58 const CeedScalar *const *in, CeedScalar *const *out) { 59 const CeedScalar *u = in[0], *q_data = in[1]; 60 CeedScalar *v = out[0]; 61 62 // Quadrature Point Loop 63 CeedPragmaSIMD 64 for (CeedInt i=0; i<Q; i++) { 65 // Component 1 66 v[i+0*Q] = q_data[i] * u[i+0*Q]; 67 // Component 2 68 v[i+1*Q] = q_data[i] * u[i+1*Q]; 69 // Component 3 70 v[i+2*Q] = q_data[i] * u[i+2*Q]; 71 } // End of Quadrature Point Loop 72 return 0; 73 } 74 // ----------------------------------------------------------------------------- 75 76 #endif // bp2_h 77