xref: /libCEED/examples/solids/qfunctions/common.h (revision ce18bed930e8f3bfebcf709a18844aba97fe4630)
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 /// Geometric factors for solid mechanics example using PETSc
10 
11 #ifndef COMMON_H
12 #define COMMON_H
13 
14 // -----------------------------------------------------------------------------
15 // This QFunction sets up the geometric factors required for integration and
16 //   coordinate transformations
17 //
18 // Reference (parent) coordinates: X
19 // Physical (current) coordinates: x
20 // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
21 // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
22 //
23 // All quadrature data is stored in 10 field vector of quadrature data.
24 //
25 // We require the transpose of the inverse of the Jacobian to properly compute
26 //   integrals of the form: int( gradv u )
27 //
28 // Inverse of Jacobian:
29 //   dXdx_i,j = Aij / detJ
30 //
31 // Stored: Aij / detJ
32 //   in q_data[1:9] as
33 //              [A11 A12 A13]
34 //  (detJ^-1) * [A21 A22 A23]
35 //              [A31 A32 A33]
36 //
37 // -----------------------------------------------------------------------------
38 CEED_QFUNCTION(SetupGeo)(void *ctx, CeedInt Q, const CeedScalar *const *in,
39                          CeedScalar *const *out) {
40     // *INDENT-OFF*
41      // Inputs
42      const CeedScalar (*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0],
43                       (*w) = in[1];
44 
45      // Outputs
46      CeedScalar (*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
47      // *INDENT-ON*
48 
49   CeedPragmaSIMD
50   // Quadrature Point Loop
51   for (CeedInt i=0; i<Q; i++) {
52     // Setup
53     const CeedScalar J11 = J[0][0][i];
54     const CeedScalar J21 = J[0][1][i];
55     const CeedScalar J31 = J[0][2][i];
56     const CeedScalar J12 = J[1][0][i];
57     const CeedScalar J22 = J[1][1][i];
58     const CeedScalar J32 = J[1][2][i];
59     const CeedScalar J13 = J[2][0][i];
60     const CeedScalar J23 = J[2][1][i];
61     const CeedScalar J33 = J[2][2][i];
62     const CeedScalar A11 = J22*J33 - J23*J32;
63     const CeedScalar A12 = J13*J32 - J12*J33;
64     const CeedScalar A13 = J12*J23 - J13*J22;
65     const CeedScalar A21 = J23*J31 - J21*J33;
66     const CeedScalar A22 = J11*J33 - J13*J31;
67     const CeedScalar A23 = J13*J21 - J11*J23;
68     const CeedScalar A31 = J21*J32 - J22*J31;
69     const CeedScalar A32 = J12*J31 - J11*J32;
70     const CeedScalar A33 = J11*J22 - J12*J21;
71     const CeedScalar detJ = J11*A11 + J21*A12 + J31*A13;
72 
73     // Qdata
74     // -- Interp-to-Interp q_data
75     q_data[0][i] = w[i] * detJ;
76 
77     // -- Interp-to-Grad q_data
78     // Inverse of change of coordinate matrix: X_i,j
79     q_data[1][i] = A11 / detJ;
80     q_data[2][i] = A12 / detJ;
81     q_data[3][i] = A13 / detJ;
82     q_data[4][i] = A21 / detJ;
83     q_data[5][i] = A22 / detJ;
84     q_data[6][i] = A23 / detJ;
85     q_data[7][i] = A31 / detJ;
86     q_data[8][i] = A32 / detJ;
87     q_data[9][i] = A33 / detJ;
88 
89   } // End of Quadrature Point Loop
90 
91   return 0;
92 }
93 // -----------------------------------------------------------------------------
94 
95 #endif // End of COMMON_H
96