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