xref: /libCEED/examples/solids/src/boundary.c (revision 72d03b64dfaace424f74301442c9d3d26107f190)
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]
31ccaff030SJeremy L Thompson PetscErrorCode BCMMS(PetscInt dim, PetscReal loadIncrement,
32ccaff030SJeremy L Thompson                      const PetscReal coords[], PetscInt ncompu,
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 
40ccaff030SJeremy L Thompson   u[0] = exp(2*x)*sin(3*y)*cos(4*z) / 1e8 * loadIncrement;
41ccaff030SJeremy L Thompson   u[1] = exp(3*y)*sin(4*z)*cos(2*x) / 1e8 * loadIncrement;
42ccaff030SJeremy L Thompson   u[2] = exp(4*z)*sin(2*x)*cos(3*y) / 1e8 * loadIncrement;
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
53d642641fSjeremylt PetscErrorCode BCClamp(PetscInt dim, PetscReal loadIncrement,
5431dc5d86Sjeremylt                        const PetscReal coords[], PetscInt ncompu,
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;
62*72d03b64SArash Mehraban   PetscScalar
63*72d03b64SArash Mehraban   // Translation vector
64*72d03b64SArash Mehraban   lx = clampMax[0]*loadIncrement,
65*72d03b64SArash Mehraban   ly = clampMax[1]*loadIncrement,
66d642641fSjeremylt   lz = clampMax[2]*loadIncrement,
67*72d03b64SArash Mehraban   // Normalized rotation axis
68*72d03b64SArash Mehraban   kx = clampMax[3],
69*72d03b64SArash Mehraban   ky = clampMax[4],
70*72d03b64SArash Mehraban   kz = clampMax[5],
71*72d03b64SArash Mehraban   // Rotation polynomial
72*72d03b64SArash Mehraban   c_0 = clampMax[6] * M_PI,
73*72d03b64SArash Mehraban   c_1 = clampMax[7] * M_PI,
74*72d03b64SArash Mehraban   cx = kx * x + ky * y + kz * z,
75*72d03b64SArash Mehraban   // Rotation magnitude
76*72d03b64SArash Mehraban   theta = (c_0 + c_1 * cx) * loadIncrement;
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