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