xref: /libCEED/examples/petsc/qfunctions/area/areacube.h (revision 3f21f6b10abeb5d85d3454ea5cd38498737dc88a)
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 scalar field on the sphere using PETSc
19 
20 #ifndef areacube_h
21 #define areacube_h
22 
23 #include <math.h>
24 
25 // -----------------------------------------------------------------------------
26 // This QFunction sets up the geometric factor required for integration when
27 //   reference coordinates have a different dimension than the one of
28 //   physical coordinates
29 //
30 // Reference (parent) 2D coordinates: X \in [-1, 1]^2
31 //
32 // Global physical coordinates given by the mesh (3D): xx \in [-l, l]^3
33 //
34 // Local physical coordinates on the manifold (2D): x \in [-l, l]^2
35 //
36 // Change of coordinates matrix computed by the library:
37 //   (physical 3D coords relative to reference 2D coords)
38 //   dxx_j/dX_i (indicial notation) [3 * 2]
39 //
40 // Change of coordinates x (physical 2D) relative to xx (phyisical 3D):
41 //   dx_i/dxx_j (indicial notation) [2 * 3]
42 //
43 // Change of coordinates x (physical 2D) relative to X (reference 2D):
44 //   (by chain rule)
45 //   dx_i/dX_j = dx_i/dxx_k * dxx_k/dX_j
46 //
47 // The quadrature data is stored in the array q_data.
48 //
49 // We require the determinant of the Jacobian to properly compute integrals of
50 //   the form: int( u v )
51 //
52 // Qdata: w * det(dx_i/dX_j)
53 //
54 // -----------------------------------------------------------------------------
55 CEED_QFUNCTION(SetupMassGeoCube)(void *ctx, const CeedInt Q,
56                              const CeedScalar *const *in,
57                              CeedScalar *const *out) {
58   // Inputs
59   const CeedScalar *J = in[1], *w = in[2];
60   // Outputs
61   CeedScalar *q_data = out[0];
62 
63   // Quadrature Point Loop
64   CeedPragmaSIMD
65   for (CeedInt i=0; i<Q; i++) {
66     // Read dxxdX Jacobian entries, stored as
67     // 0 3
68     // 1 4
69     // 2 5
70     const CeedScalar dxxdX[3][2] = {{J[i+Q*0],
71                                      J[i+Q*3]},
72                                     {J[i+Q*1],
73                                      J[i+Q*4]},
74                                     {J[i+Q*2],
75                                      J[i+Q*5]}
76                                    };
77 
78     // Modulus of dxxdX column vectors
79     const CeedScalar mod_g_1 = sqrt(dxxdX[0][0]*dxxdX[0][0] +
80                                     dxxdX[1][0]*dxxdX[1][0] +
81                                     dxxdX[2][0]*dxxdX[2][0]);
82     const CeedScalar mod_g_2 = sqrt(dxxdX[0][1]*dxxdX[0][1] +
83                                     dxxdX[1][1]*dxxdX[1][1] +
84                                     dxxdX[2][1]*dxxdX[2][1]);
85 
86     // Use normalized column vectors of dxxdX as rows of dxdxx
87     const CeedScalar dxdxx[2][3] = {{dxxdX[0][0] / mod_g_1,
88                                      dxxdX[1][0] / mod_g_1,
89                                      dxxdX[2][0] / mod_g_1},
90                                     {dxxdX[0][1] / mod_g_2,
91                                      dxxdX[1][1] / mod_g_2,
92                                      dxxdX[2][1] / mod_g_2}
93                                    };
94 
95     CeedScalar dxdX[2][2];
96     for (int j=0; j<2; j++)
97       for (int k=0; k<2; k++) {
98         dxdX[j][k] = 0;
99         for (int l=0; l<3; l++)
100           dxdX[j][k] += dxdxx[j][l]*dxxdX[l][k];
101       }
102 
103     q_data[i+Q*0] = (dxdX[0][0]*dxdX[1][1] - dxdX[1][0]*dxdX[0][1]) * w[i];
104 
105   } // End of Quadrature Point Loop
106   return 0;
107 }
108 
109 // -----------------------------------------------------------------------------
110 // This QFunction applies the mass operator for a scalar field.
111 //
112 // Inputs:
113 //   u     - Input vector at quadrature points
114 //   q_data - Geometric factors
115 //
116 // Output:
117 //   v     - Output vector (test function) at quadrature points
118 //
119 // -----------------------------------------------------------------------------
120 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q,
121                      const CeedScalar *const *in, CeedScalar *const *out) {
122   // Inputs
123   const CeedScalar *u = in[0], *q_data = in[1];
124   // Outputs
125   CeedScalar *v = out[0];
126 
127   // Quadrature Point Loop
128   CeedPragmaSIMD
129   for (CeedInt i=0; i<Q; i++)
130     v[i] = q_data[i] * u[i];
131 
132   return 0;
133 }
134 // -----------------------------------------------------------------------------
135 
136 #endif // areacube_h
137