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