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 for a vector field on the sphere using PETSc 10 11 #ifndef bp2sphere_h 12 #define bp2sphere_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 // Inputs 22 const CeedScalar *X = in[0], *q_data = in[1]; 23 // Outputs 24 CeedScalar *true_soln = out[0], *rhs = out[1]; 25 26 // Context 27 const CeedScalar *context = (const CeedScalar *)ctx; 28 const CeedScalar R = context[0]; 29 30 // Quadrature Point Loop 31 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 32 // Compute latitude 33 const CeedScalar theta = asin(X[i + 2 * Q] / R); 34 35 // Use absolute value of latitude for true solution 36 // Component 1 37 true_soln[i + 0 * Q] = fabs(theta); 38 // Component 2 39 true_soln[i + 1 * Q] = 2 * true_soln[i + 0 * Q]; 40 // Component 3 41 true_soln[i + 2 * Q] = 3 * true_soln[i + 0 * Q]; 42 43 // Component 1 44 rhs[i + 0 * Q] = q_data[i] * true_soln[i]; 45 // Component 2 46 rhs[i + 1 * Q] = 2 * rhs[i + 0 * Q]; 47 // Component 3 48 rhs[i + 2 * Q] = 3 * rhs[i + 0 * Q]; 49 } // End of Quadrature Point Loop 50 51 return 0; 52 } 53 54 // ----------------------------------------------------------------------------- 55 // This QFunction applies the mass operator for a vector field of 3 components. 56 // 57 // Inputs: 58 // u - Input vector at quadrature points 59 // q_data - Geometric factors 60 // 61 // Output: 62 // v - Output vector (test functions) at quadrature points 63 // 64 // ----------------------------------------------------------------------------- 65 CEED_QFUNCTION(Mass3)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 66 const CeedScalar *u = in[0], *q_data = in[1]; 67 CeedScalar *v = out[0]; 68 69 // Quadrature Point Loop 70 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 71 // Component 1 72 v[i + 0 * Q] = q_data[i] * u[i + 0 * Q]; 73 // Component 2 74 v[i + 1 * Q] = q_data[i] * u[i + 1 * Q]; 75 // Component 3 76 v[i + 2 * Q] = q_data[i] * u[i + 2 * Q]; 77 } // End of Quadrature Point Loop 78 79 return 0; 80 } 81 // ----------------------------------------------------------------------------- 82 83 #endif // bp2sphere_h 84