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