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