xref: /libCEED/examples/solids/src/boundary.c (revision 31dc5d865475121074fe3baac54cb8ba7e9abd40)
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 
47ccaff030SJeremy L Thompson // BCZero - fix boundary values at zero
48ccaff030SJeremy L Thompson PetscErrorCode BCZero(PetscInt dim, PetscReal loadIncrement,
49ccaff030SJeremy L Thompson                       const PetscReal coords[], PetscInt ncompu,
50ccaff030SJeremy L Thompson                       PetscScalar *u, void *ctx) {
51ccaff030SJeremy L Thompson   PetscFunctionBeginUser;
52ccaff030SJeremy L Thompson 
53ccaff030SJeremy L Thompson   u[0] = 0;
54ccaff030SJeremy L Thompson   u[1] = 0;
55ccaff030SJeremy L Thompson   u[2] = 0;
56ccaff030SJeremy L Thompson 
57ccaff030SJeremy L Thompson   PetscFunctionReturn(0);
58ccaff030SJeremy L Thompson };
59ccaff030SJeremy L Thompson 
60*31dc5d86Sjeremylt // BCClampTranslate - translate boundary values at fraction of load increment
61*31dc5d86Sjeremylt PetscErrorCode BCClampTranslate(PetscInt dim, PetscReal loadIncrement,
62ccaff030SJeremy L Thompson                                 const PetscReal coords[], PetscInt ncompu,
63ccaff030SJeremy L Thompson                                 PetscScalar *u, void *ctx) {
64e4659345Sjeremylt   PetscScalar (*clampMax) = (PetscScalar(*))ctx;
65e4659345Sjeremylt 
66ccaff030SJeremy L Thompson   PetscFunctionBeginUser;
67ccaff030SJeremy L Thompson 
68e4659345Sjeremylt   u[0] = clampMax[0]*loadIncrement;
69e4659345Sjeremylt   u[1] = clampMax[1]*loadIncrement;
70e4659345Sjeremylt   u[2] = clampMax[2]*loadIncrement;
71ccaff030SJeremy L Thompson 
72ccaff030SJeremy L Thompson   PetscFunctionReturn(0);
73ccaff030SJeremy L Thompson };
74*31dc5d86Sjeremylt 
75*31dc5d86Sjeremylt #ifndef M_PI
76*31dc5d86Sjeremylt #  define M_PI    3.14159265358979323846
77*31dc5d86Sjeremylt #endif
78*31dc5d86Sjeremylt 
79*31dc5d86Sjeremylt // BCClampRotate - rotate boundary values at fraction of load increment
80*31dc5d86Sjeremylt PetscErrorCode BCClampRotate(PetscInt dim, PetscReal loadIncrement,
81*31dc5d86Sjeremylt                              const PetscReal coords[], PetscInt ncompu,
82*31dc5d86Sjeremylt                              PetscScalar *u, void *ctx) {
83*31dc5d86Sjeremylt   PetscScalar x = coords[0];
84*31dc5d86Sjeremylt   PetscScalar y = coords[1];
85*31dc5d86Sjeremylt   PetscScalar z = coords[2];
86*31dc5d86Sjeremylt   PetscScalar (*clampMax) = (PetscScalar(*))ctx;
87*31dc5d86Sjeremylt 
88*31dc5d86Sjeremylt   PetscFunctionBeginUser;
89*31dc5d86Sjeremylt 
90*31dc5d86Sjeremylt   PetscScalar theta = clampMax[3]*M_PI*loadIncrement,
91*31dc5d86Sjeremylt               kx = clampMax[0], ky = clampMax[1], kz = clampMax[2];
92*31dc5d86Sjeremylt   PetscScalar c = cos(theta), s = sin(theta);
93*31dc5d86Sjeremylt 
94*31dc5d86Sjeremylt   u[0] = s*(-kz*y + ky*z) + (1-c)*(-ky*ky+kz*kz*x + kx*ky*y + kx*kz*z);
95*31dc5d86Sjeremylt   u[1] = s*(kz*x + -kx*z) + (1-c)*(kx*ky*x - (kx*kx+kz*kz)*y + ky*kz*z);
96*31dc5d86Sjeremylt   u[2] = s*(-ky*x + kx*y) + (1-c)*(kx*kz*x + ky*kz*y - (kx*kx+ky*ky)*z);
97*31dc5d86Sjeremylt 
98*31dc5d86Sjeremylt   PetscFunctionReturn(0);
99*31dc5d86Sjeremylt };
100