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