1 // Copyright (c) 2017-2024, 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 /// Linear elasticity manufactured solution forcing term for solid mechanics example using PETSc 10 11 #include <ceed.h> 12 #include <math.h> 13 14 #ifndef PHYSICS_STRUCT 15 #define PHYSICS_STRUCT 16 typedef struct Physics_private *Physics; 17 struct Physics_private { 18 CeedScalar nu; // Poisson's ratio 19 CeedScalar E; // Young's Modulus 20 }; 21 #endif 22 23 // ----------------------------------------------------------------------------- 24 // Forcing term for linear elasticity manufactured solution 25 // ----------------------------------------------------------------------------- 26 CEED_QFUNCTION(SetupMMSForce)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 27 // Inputs 28 const CeedScalar *coords = in[0], *q_data = in[1]; 29 30 // Outputs 31 CeedScalar *force = out[0]; 32 33 // Context 34 const Physics context = (Physics)ctx; 35 const CeedScalar E = context->E; 36 const CeedScalar nu = context->nu; 37 38 // Quadrature Point Loop 39 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 40 // Setup 41 CeedScalar x = coords[i + 0 * Q], y = coords[i + 1 * Q], z = coords[i + 2 * Q]; 42 CeedScalar wdetJ = q_data[i]; 43 44 // Forcing function 45 // -- Component 1 46 force[i + 0 * Q] = (-(E * (cos(x * 2.0) * cos(y * 3.0) * exp(z * 4.0) * 4.0 - cos(z * 4.0) * sin(y * 3.0) * exp(x * 2.0) * 8.0) * (nu - 0.5)) / 47 ((nu * 2.0 - 1.0) * (nu + 1.0)) + 48 (E * (cos(z * 4.0) * sin(y * 3.0) * exp(x * 2.0) * (4.5) + sin(x * 2.0) * sin(z * 4.0) * exp(y * 3.0) * 3.0) * (nu - 0.5)) / 49 ((nu * 2.0 - 1.0) * (nu + 1.0)) + 50 (E * nu * cos(x * 2.0) * cos(y * 3.0) * exp(z * 4.0) * 8.0) / ((nu * 2.0 - 1.0) * (nu + 1.0)) - 51 (E * nu * sin(x * 2.0) * sin(z * 4.0) * exp(y * 3.0) * 6.0) / ((nu * 2.0 - 1.0) * (nu + 1.0)) - 52 (E * cos(z * 4.0) * sin(y * 3.0) * exp(x * 2.0) * (nu - 1.0) * 4.0) / ((nu * 2.0 - 1.0) * (nu + 1.0))) * 53 wdetJ / 1e8; 54 55 // -- Component 2 56 force[i + 1 * Q] = (-(E * (cos(y * 3.0) * cos(z * 4.0) * exp(x * 2.0) * 3.0 - cos(x * 2.0) * sin(z * 4.0) * exp(y * 3.0) * 2.0) * (nu - 0.5)) / 57 ((nu * 2.0 - 1.0) * (nu + 1.0)) + 58 (E * (cos(x * 2.0) * sin(z * 4.0) * exp(y * 3.0) * 8.0 + sin(x * 2.0) * sin(y * 3.0) * exp(z * 4.0) * 6.0) * (nu - 0.5)) / 59 ((nu * 2.0 - 1.0) * (nu + 1.0)) + 60 (E * nu * cos(y * 3.0) * cos(z * 4.0) * exp(x * 2.0) * 6.0) / ((nu * 2.0 - 1.0) * (nu + 1.0)) - 61 (E * nu * sin(x * 2.0) * sin(y * 3.0) * exp(z * 4.0) * 12.0) / ((nu * 2.0 - 1.0) * (nu + 1.0)) - 62 (E * cos(x * 2.0) * sin(z * 4.0) * exp(y * 3.0) * (nu - 1.0) * 9.0) / ((nu * 2.0 - 1.0) * (nu + 1.0))) * 63 wdetJ / 1e8; 64 65 // -- Component 3 66 force[i + 2 * Q] = (-(E * (cos(x * 2.0) * cos(z * 4.0) * exp(y * 3.0) * 6.0 - cos(y * 3.0) * sin(x * 2.0) * exp(z * 4.0) * (4.5)) * (nu - 0.5)) / 67 ((nu * 2.0 - 1.0) * (nu + 1.0)) + 68 (E * (cos(y * 3.0) * sin(x * 2.0) * exp(z * 4.0) * 2.0 + sin(y * 3.0) * sin(z * 4.0) * exp(x * 2.0) * 4.0) * (nu - 0.5)) / 69 ((nu * 2.0 - 1.0) * (nu + 1.0)) + 70 (E * nu * cos(x * 2.0) * cos(z * 4.0) * exp(y * 3.0) * 12.0) / ((nu * 2.0 - 1.0) * (nu + 1.0)) - 71 (E * nu * sin(y * 3.0) * sin(z * 4.0) * exp(x * 2.0) * 8.0) / ((nu * 2.0 - 1.0) * (nu + 1.0)) - 72 (E * cos(y * 3.0) * sin(x * 2.0) * exp(z * 4.0) * (nu - 1.0) * 16.0) / ((nu * 2.0 - 1.0) * (nu + 1.0))) * 73 wdetJ / 1e8; 74 75 } // End of Quadrature Point Loop 76 77 return 0; 78 } 79 // ----------------------------------------------------------------------------- 80