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