xref: /libCEED/examples/solids/qfunctions/constant-force.h (revision caee03026e6576cbf7a399c2fc51bb918c77f451)
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 /// Constant forcing term for solid mechanics example using PETSc
10 
11 #ifndef CONSTANT_H
12 #define CONSTANT_H
13 
14 #include <ceed.h>
15 #include <math.h>
16 
17 #ifndef PHYSICS_STRUCT
18 #define PHYSICS_STRUCT
19 typedef struct Physics_private *Physics;
20 struct Physics_private {
21   CeedScalar nu;  // Poisson's ratio
22   CeedScalar E;   // Young's Modulus
23 };
24 #endif
25 
26 // -----------------------------------------------------------------------------
27 // Constant forcing term along specified vector
28 // -----------------------------------------------------------------------------
29 CEED_QFUNCTION(SetupConstantForce)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
30   // Inputs
31   const CeedScalar *q_data = in[1];
32 
33   // Outputs
34   CeedScalar *force = out[0];
35 
36   // Context
37   const CeedScalar *forcing_vector = (CeedScalar(*))ctx;
38 
39   // Quadrature Point Loop
40   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
41     // Setup
42     CeedScalar wdetJ = q_data[i];
43 
44     // Forcing function
45     // -- Component 1
46     force[i + 0 * Q] = forcing_vector[0] * wdetJ;
47 
48     // -- Component 2
49     force[i + 1 * Q] = forcing_vector[1] * wdetJ;
50 
51     // -- Component 3
52     force[i + 2 * Q] = forcing_vector[2] * wdetJ;
53   }  // End of Quadrature Point Loop
54 
55   return 0;
56 }
57 // -----------------------------------------------------------------------------
58 
59 #endif  // End of CONSTANT_H
60