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