Debian Codegraph @

packages/rol/example/PDE-OPT/published/TRSPG_Kouri2021/elasticity/src/traction.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 /*! \file traction.hpp
11 \brief Implements traction loads for the structural topology
12 optimization problem.
13 */
14
15 #ifndef ROL_PDEOPT_ELASTICITY_TRACTION_HPP
16 #define ROL_PDEOPT_ELASTICITY_TRACTION_HPP
17
18 #include "ROL_Ptr.hpp"
19 #include "Teuchos_ParameterList.hpp"
20 #include "Intrepid_FieldContainer.hpp"
21
22 #include "../../../../TOOLS/fe.hpp"
23
24 #include <vector>
25
26 template<class Real>
27 class Traction {
28 private:
29 std::vector<int> sidesets_, sideids_;
30 std::vector<Real> loadMagnitude_;
31 std::vector<Real> loadPolar_, loadAzimuth_;
32 std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellNodes_;
33 std::vector<std::vector<std::vector<int>>> bdryCellLocIds_;
34 int dim_, offset_;
35
36 protected:
37 Real DegreesToRadians(const Real deg) const {
38 return deg * static_cast<Real>(M_PI) / static_cast<Real>(180);
39 }
40
41 public:
42 virtual ~Traction() {}
43
44 Traction(void) {};
45
46 Traction(int dim) : dim_(dim) {
47 assert(dim > 3 || dim < 2);
48 if (dim==2) {
49 offset_ = 0;
50 sidesets_.push_back(2);
51 sideids_.push_back(0);
52 loadMagnitude_.push_back(static_cast<Real>(1));
53 loadPolar_.push_back(static_cast<Real>(270));
54 loadAzimuth_.push_back(static_cast<Real>(0));
55 }
56 else {
57 offset_ = 0;
58 sidesets_.push_back(2);
59 sideids_.push_back(1);
60 loadMagnitude_.push_back(static_cast<Real>(1));
61 loadPolar_.push_back(static_cast<Real>(270));
62 loadAzimuth_.push_back(static_cast<Real>(90));
63 }
64
65 int polarSize = loadPolar_.size();
66 for (int i=0; i<polarSize; ++i)
67 loadPolar_[i] = DegreesToRadians(loadPolar_[i]);
68
69 int azimuthSize = loadAzimuth_.size();
70 for (int i=0; i<azimuthSize; ++i)
71 loadAzimuth_[i] = DegreesToRadians(loadAzimuth_[i]);
72 }
73
74 bool isNull(void) const {
75 return (sidesets_.size()==0);
76 }
77
78 void setCellNodes(const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes,
79 const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) {
80 bdryCellNodes_ = bdryCellNodes;
81 bdryCellLocIds_ = bdryCellLocIds;
82 }
83
84 virtual Real evaluate(const int dir,
85 const int sideset,
86 const std::vector<Real> &param) const {
87 // const int numSideSets = sidesets_.size();
88 const int paramSize = param.size();
89 Real val(0);
90 Real loadMagNoise(0), loadAngNoise0(0);
91 if (paramSize > 0 + dim_*sideset) {
92 loadMagNoise = param[offset_ + 0 + dim_*sideset];
93 }
94 if (paramSize > 1 + dim_*sideset) {
95 loadAngNoise0 = DegreesToRadians(param[offset_ + 1 + dim_*sideset]);
96 }
97 const Real loadMagnitude = loadMagnitude_[sideset] + loadMagNoise;
98 const Real loadAngle0 = loadPolar_[sideset] + loadAngNoise0;
99
100 if (dim_==2) {
101 if (dir==0) {
102 val = loadMagnitude*std::cos(loadAngle0);
103 }
104 if (dir==1) {
105 val = loadMagnitude*std::sin(loadAngle0);
106 }
107 }
108 if (dim_==3) {
109 Real loadAngNoise1(0);
110 if (paramSize > 2 + dim_*sideset) {
111 loadAngNoise1 = DegreesToRadians(param[offset_ + 2 + dim_*sideset]);
112 }
113 const Real loadAngle1 = loadAzimuth_[sideset] + loadAngNoise1;
114
115 if (dir==0) {
116 val = loadMagnitude*std::sin(loadAngle0)*std::cos(loadAngle1);
117 }
118 if (dir==1) {
119 val = loadMagnitude*std::sin(loadAngle0)*std::sin(loadAngle1);
120 }
121 if (dir==2) {
122 val = loadMagnitude*std::cos(loadAngle0);
123 }
124 }
125 return val;
126 }
127
128 void compute(std::vector<std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>>> &traction,
129 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &fe,
130 const std::vector<Real> &param,
131 const Real scale = Real(1)) const {
132 traction.clear();
133 traction.resize(bdryCellLocIds_.size());
134 const int numSideSets = sidesets_.size();
135 if (numSideSets > 0) {
136 for (int i = 0; i < numSideSets; ++i) {
137 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
138 traction[sidesets_[i]].resize(numLocalSideIds);
139 for (int j = 0; j < numLocalSideIds; ++j) {
140 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
141 if (numCellsSide > 0) {
142 const int numCubPerSide = fe[sidesets_[i]][j]->cubPts()->dimension(1);
143 traction[sidesets_[i]][j].resize(dim_);
144 for (int k = 0; k < dim_; ++k) {
145 traction[sidesets_[i]][j][k]
146 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
147 for (int c = 0; c < numCellsSide; ++c) {
148 for (int p = 0; p < numCubPerSide; ++p) {
149 (*traction[sidesets_[i]][j][k])(c,p) = scale*evaluate(k,i,param);
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157 }
158
159 void apply(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> &R,
160 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &fe,
161 const std::vector<Real> &param,
162 const Real scale = Real(1)) const {
163 const int numSideSets = sidesets_.size();
164 const int nf = R[0]->dimension(1);
165 if (numSideSets > 0) {
166 for (int i = 0; i < numSideSets; ++i) {
167 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
168 for (int j = 0; j < numLocalSideIds; ++j) {
169 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
170 if (numCellsSide > 0) {
171 const int numCubPerSide = fe[sidesets_[i]][j]->cubPts()->dimension(1);
172 for (int k = 0; k < dim_; ++k) {
173 Intrepid::FieldContainer<Real> traction(numCellsSide, numCubPerSide);
174 for (int c = 0; c < numCellsSide; ++c) {
175 for (int p = 0; p < numCubPerSide; ++p) {
176 traction(c,p) = scale*evaluate(k,i,param);
177 }
178 }
179 Intrepid::FieldContainer<Real> tractionResidual(numCellsSide, nf);
180 Intrepid::FunctionSpaceTools::integrate<Real>(tractionResidual,
181 traction,
182 *fe[sidesets_[i]][j]->NdetJ(),
183 Intrepid::COMP_CPP, false);
184 // Add traction residual to volume residual
185 for (int l = 0; l < numCellsSide; ++l) {
186 int cidx = bdryCellLocIds_[sidesets_[i]][j][l];
187 for (int m = 0; m < nf; ++m) {
188 (*R[k])(cidx,m) += tractionResidual(l,m);
189 }
190 }
191 }
192 }
193 }
194 }
195 }
196 }
197 };
198
199 #endif