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 /// Boundary condition functions for solid mechanics example using PETSc 19 20 #include "../elasticity.h" 21 22 // ----------------------------------------------------------------------------- 23 // Boundary Functions 24 // ----------------------------------------------------------------------------- 25 // Note: If additional boundary conditions are added, an update is needed in 26 // elasticity.h for the boundaryOptions variable. 27 28 // BCMMS - boundary function 29 // Values on all points of the mesh is set based on given solution below 30 // for u[0], u[1], u[2] 31 PetscErrorCode BCMMS(PetscInt dim, PetscReal load_increment, 32 const PetscReal coords[], PetscInt num_comp_u, 33 PetscScalar *u, void *ctx) { 34 PetscScalar x = coords[0]; 35 PetscScalar y = coords[1]; 36 PetscScalar z = coords[2]; 37 38 PetscFunctionBeginUser; 39 40 u[0] = exp(2*x)*sin(3*y)*cos(4*z) / 1e8 * load_increment; 41 u[1] = exp(3*y)*sin(4*z)*cos(2*x) / 1e8 * load_increment; 42 u[2] = exp(4*z)*sin(2*x)*cos(3*y) / 1e8 * load_increment; 43 44 PetscFunctionReturn(0); 45 }; 46 47 #ifndef M_PI 48 # define M_PI 3.14159265358979323846 49 #endif 50 51 // BCClamp - fix boundary values with affine transformation at fraction of load 52 // increment 53 PetscErrorCode BCClamp(PetscInt dim, PetscReal load_increment, 54 const PetscReal coords[], PetscInt num_comp_u, 55 PetscScalar *u, void *ctx) { 56 PetscScalar x = coords[0]; 57 PetscScalar y = coords[1]; 58 PetscScalar z = coords[2]; 59 PetscScalar (*clampMax) = (PetscScalar(*))ctx; 60 61 PetscFunctionBeginUser; 62 PetscScalar 63 // Translation vector 64 lx = clampMax[0]*load_increment, 65 ly = clampMax[1]*load_increment, 66 lz = clampMax[2]*load_increment, 67 // Normalized rotation axis 68 kx = clampMax[3], 69 ky = clampMax[4], 70 kz = clampMax[5], 71 // Rotation polynomial 72 c_0 = clampMax[6] * M_PI, 73 c_1 = clampMax[7] * M_PI, 74 cx = kx * x + ky * y + kz * z, 75 // Rotation magnitude 76 theta = (c_0 + c_1 * cx) * load_increment; 77 PetscScalar c = cos(theta), s = sin(theta); 78 79 u[0] = lx + s*(-kz*y + ky*z) + (1-c)*(-(ky*ky+kz*kz)*x + kx*ky*y + kx*kz*z); 80 u[1] = ly + s*(kz*x + -kx*z) + (1-c)*(kx*ky*x + -(kx*kx+kz*kz)*y + ky*kz*z); 81 u[2] = lz + s*(-ky*x + kx*y) + (1-c)*(kx*kz*x + ky*kz*y + -(kx*kx+ky*ky)*z); 82 PetscFunctionReturn(0); 83 }; 84