xref: /libCEED/examples/solids/src/boundary.c (revision d1d35e2f02dc969aee8debf3fd943dd784aa847a)
1ccaff030SJeremy L Thompson // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2ccaff030SJeremy L Thompson // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3ccaff030SJeremy L Thompson // reserved. See files LICENSE and NOTICE for details.
4ccaff030SJeremy L Thompson //
5ccaff030SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software
6ccaff030SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral
7ccaff030SJeremy L Thompson // element discretizations for exascale applications. For more information and
8ccaff030SJeremy L Thompson // source code availability see http://github.com/ceed.
9ccaff030SJeremy L Thompson //
10ccaff030SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11ccaff030SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office
12ccaff030SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for
13ccaff030SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including
14ccaff030SJeremy L Thompson // software, applications, hardware, advanced system engineering and early
15ccaff030SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative.
16ccaff030SJeremy L Thompson 
17ccaff030SJeremy L Thompson /// @file
18ccaff030SJeremy L Thompson /// Boundary condition functions for solid mechanics example using PETSc
19ccaff030SJeremy L Thompson 
20ccaff030SJeremy L Thompson #include "../elasticity.h"
21ccaff030SJeremy L Thompson 
22ccaff030SJeremy L Thompson // -----------------------------------------------------------------------------
23ccaff030SJeremy L Thompson // Boundary Functions
24ccaff030SJeremy L Thompson // -----------------------------------------------------------------------------
25ccaff030SJeremy L Thompson // Note: If additional boundary conditions are added, an update is needed in
26ccaff030SJeremy L Thompson //         elasticity.h for the boundaryOptions variable.
27ccaff030SJeremy L Thompson 
28ccaff030SJeremy L Thompson // BCMMS - boundary function
29ccaff030SJeremy L Thompson // Values on all points of the mesh is set based on given solution below
30ccaff030SJeremy L Thompson // for u[0], u[1], u[2]
31*d1d35e2fSjeremylt PetscErrorCode BCMMS(PetscInt dim, PetscReal load_increment,
32*d1d35e2fSjeremylt                      const PetscReal coords[], PetscInt num_comp_u,
33ccaff030SJeremy L Thompson                      PetscScalar *u, void *ctx) {
34ccaff030SJeremy L Thompson   PetscScalar x = coords[0];
35ccaff030SJeremy L Thompson   PetscScalar y = coords[1];
36ccaff030SJeremy L Thompson   PetscScalar z = coords[2];
37ccaff030SJeremy L Thompson 
38ccaff030SJeremy L Thompson   PetscFunctionBeginUser;
39ccaff030SJeremy L Thompson 
40*d1d35e2fSjeremylt   u[0] = exp(2*x)*sin(3*y)*cos(4*z) / 1e8 * load_increment;
41*d1d35e2fSjeremylt   u[1] = exp(3*y)*sin(4*z)*cos(2*x) / 1e8 * load_increment;
42*d1d35e2fSjeremylt   u[2] = exp(4*z)*sin(2*x)*cos(3*y) / 1e8 * load_increment;
43ccaff030SJeremy L Thompson 
44ccaff030SJeremy L Thompson   PetscFunctionReturn(0);
45ccaff030SJeremy L Thompson };
46ccaff030SJeremy L Thompson 
4731dc5d86Sjeremylt #ifndef M_PI
4831dc5d86Sjeremylt #  define M_PI    3.14159265358979323846
4931dc5d86Sjeremylt #endif
5031dc5d86Sjeremylt 
51d642641fSjeremylt // BCClamp - fix boundary values with affine transformation at fraction of load
52d642641fSjeremylt //   increment
53*d1d35e2fSjeremylt PetscErrorCode BCClamp(PetscInt dim, PetscReal load_increment,
54*d1d35e2fSjeremylt                        const PetscReal coords[], PetscInt num_comp_u,
5531dc5d86Sjeremylt                        PetscScalar *u, void *ctx) {
5631dc5d86Sjeremylt   PetscScalar x = coords[0];
5731dc5d86Sjeremylt   PetscScalar y = coords[1];
5831dc5d86Sjeremylt   PetscScalar z = coords[2];
5931dc5d86Sjeremylt   PetscScalar (*clampMax) = (PetscScalar(*))ctx;
6031dc5d86Sjeremylt 
6131dc5d86Sjeremylt   PetscFunctionBeginUser;
6272d03b64SArash Mehraban   PetscScalar
6372d03b64SArash Mehraban   // Translation vector
64*d1d35e2fSjeremylt   lx = clampMax[0]*load_increment,
65*d1d35e2fSjeremylt   ly = clampMax[1]*load_increment,
66*d1d35e2fSjeremylt   lz = clampMax[2]*load_increment,
6772d03b64SArash Mehraban   // Normalized rotation axis
6872d03b64SArash Mehraban   kx = clampMax[3],
6972d03b64SArash Mehraban   ky = clampMax[4],
7072d03b64SArash Mehraban   kz = clampMax[5],
7172d03b64SArash Mehraban   // Rotation polynomial
7272d03b64SArash Mehraban   c_0 = clampMax[6] * M_PI,
7372d03b64SArash Mehraban   c_1 = clampMax[7] * M_PI,
7472d03b64SArash Mehraban   cx = kx * x + ky * y + kz * z,
7572d03b64SArash Mehraban   // Rotation magnitude
76*d1d35e2fSjeremylt   theta = (c_0 + c_1 * cx) * load_increment;
7731dc5d86Sjeremylt   PetscScalar c = cos(theta), s = sin(theta);
7831dc5d86Sjeremylt 
7956f0bea9Sjeremylt   u[0] = lx + s*(-kz*y + ky*z) + (1-c)*(-(ky*ky+kz*kz)*x + kx*ky*y + kx*kz*z);
8056f0bea9Sjeremylt   u[1] = ly + s*(kz*x + -kx*z) + (1-c)*(kx*ky*x + -(kx*kx+kz*kz)*y + ky*kz*z);
8156f0bea9Sjeremylt   u[2] = lz + s*(-ky*x + kx*y) + (1-c)*(kx*kz*x + ky*kz*y + -(kx*kx+ky*ky)*z);
8231dc5d86Sjeremylt   PetscFunctionReturn(0);
8331dc5d86Sjeremylt };
84