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