xref: /libCEED/examples/petsc/qfunctions/bps/bp2sphere.h (revision d7891dc809a4722b5367707216c83c098763e324)
1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3 // reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 /// @file
18 /// libCEED QFunctions for mass operator example for a vector field on the sphere using PETSc
19 
20 #ifndef bp2sphere_h
21 #define bp2sphere_h
22 
23 #include <math.h>
24 
25 // -----------------------------------------------------------------------------
26 // This QFunction sets up the rhs and true solution for the problem
27 // -----------------------------------------------------------------------------
28 CEED_QFUNCTION(SetupMassRhs3)(void *ctx, const CeedInt Q,
29                              const CeedScalar *const *in,
30                              CeedScalar *const *out) {
31   // Inputs
32   const CeedScalar *X = in[0], *q_data = in[1];
33   // Outputs
34   CeedScalar *true_soln = out[0], *rhs = out[1];
35 
36   // Context
37   const CeedScalar *context = (const CeedScalar*)ctx;
38   const CeedScalar R        = context[0];
39 
40   // Quadrature Point Loop
41   CeedPragmaSIMD
42   for (CeedInt i=0; i<Q; i++) {
43     // Compute latitude
44     const CeedScalar theta =  asin(X[i+2*Q] / R);
45 
46     // Use absolute value of latitude for true solution
47     // Component 1
48     true_soln[i+0*Q] = fabs(theta);
49     // Component 2
50     true_soln[i+1*Q] = 2 * true_soln[i+0*Q];
51     // Component 3
52     true_soln[i+2*Q] = 3 * true_soln[i+0*Q];
53 
54     // Component 1
55     rhs[i+0*Q] = q_data[i] * true_soln[i];
56     // Component 2
57     rhs[i+1*Q] = 2 * rhs[i+0*Q];
58     // Component 3
59     rhs[i+2*Q] = 3 * rhs[i+0*Q];
60   } // End of Quadrature Point Loop
61 
62   return 0;
63 }
64 
65 // -----------------------------------------------------------------------------
66 // This QFunction applies the mass operator for a vector field of 3 components.
67 //
68 // Inputs:
69 //   u     - Input vector at quadrature points
70 //   q_data - Geometric factors
71 //
72 // Output:
73 //   v     - Output vector (test functions) at quadrature points
74 //
75 // -----------------------------------------------------------------------------
76 CEED_QFUNCTION(Mass3)(void *ctx, const CeedInt Q,
77                       const CeedScalar *const *in, CeedScalar *const *out) {
78   const CeedScalar *u = in[0], *q_data = in[1];
79   CeedScalar *v = out[0];
80 
81   // Quadrature Point Loop
82   CeedPragmaSIMD
83   for (CeedInt i=0; i<Q; i++) {
84     // Component 1
85     v[i+0*Q] = q_data[i] * u[i+0*Q];
86     // Component 2
87     v[i+1*Q] = q_data[i] * u[i+1*Q];
88     // Component 3
89     v[i+2*Q] = q_data[i] * u[i+2*Q];
90   } // End of Quadrature Point Loop
91 
92   return 0;
93 }
94 // -----------------------------------------------------------------------------
95 
96 #endif // bp2sphere_h
97