Debian Codegraph @

packages/rol/example/PDE-OPT/topo-opt/multimat/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_MULTIMAT_TRACTION_HPP
16 #define ROL_PDEOPT_MULTIMAT_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 MultiMat_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 ~MultiMat_Traction() {}
43
44 MultiMat_Traction(void) {};
45
46 MultiMat_Traction(Teuchos::ParameterList & parlist, std::string ex = "Default") {
47 if (ex == "2D Wheel") {
48 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 if (ex == "2D Cantilever with 1 Load" ||
57 ex == "2D Truss") {
58 dim_ = 2;
59 offset_ = 2;
60 sidesets_.clear();
61 sideids_.clear();
62 loadMagnitude_.clear();
63 loadPolar_.clear();
64 loadAzimuth_.clear();
65 }
66 else if (ex == "2D Cantilever with 3 Loads") {
67 dim_ = 2;
68 offset_ = 0;
69 sidesets_.push_back(1);
70 sidesets_.push_back(3);
71 sidesets_.push_back(5);
72 sideids_.push_back(0);
73 sideids_.push_back(0);
74 sideids_.push_back(0);
75 loadMagnitude_.push_back(static_cast<Real>(1));
76 loadMagnitude_.push_back(static_cast<Real>(1));
77 loadMagnitude_.push_back(static_cast<Real>(1));
78 loadPolar_.push_back(static_cast<Real>(270));
79 loadPolar_.push_back(static_cast<Real>(270));
80 loadPolar_.push_back(static_cast<Real>(270));
81 loadAzimuth_.push_back(static_cast<Real>(0));
82 loadAzimuth_.push_back(static_cast<Real>(0));
83 loadAzimuth_.push_back(static_cast<Real>(0));
84 }
85 else if (ex == "2D Beams") {
86 dim_ = 2;
87 offset_ = 4;
88 sidesets_.clear();
89 sideids_.clear();
90 loadMagnitude_.clear();
91 loadPolar_.clear();
92 loadAzimuth_.clear();
93 }
94 else if (ex == "2D Carrier Plate") {
95 dim_ = 2;
96 offset_ = 0;
97 sidesets_.push_back(2);
98 sidesets_.push_back(4);
99 sideids_.push_back(2);
100 sideids_.push_back(2);
101 loadMagnitude_.push_back(static_cast<Real>(1.0));
102 loadMagnitude_.push_back(static_cast<Real>(0.5));
103 loadPolar_.push_back(static_cast<Real>(270));
104 loadPolar_.push_back(static_cast<Real>(270));
105 loadAzimuth_.push_back(static_cast<Real>(0));
106 loadAzimuth_.push_back(static_cast<Real>(0));
107 }
108 else if (ex == "3D Cantilever") {
109 dim_ = 3;
110 offset_ = 3;
111 sidesets_.clear();
112 sideids_.clear();
113 loadMagnitude_.clear();
114 loadPolar_.clear();
115 loadAzimuth_.clear();
116 }
117 else {
118 if (parlist.isSublist("Traction")) {
119 // Grab problem dimension
120 dim_ = parlist.get("Problem Dimension",2);
121
122 offset_ = 0;
123 if (parlist.isSublist("Load")) {
124 Teuchos::Array<Real> loadMag
125 = Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Load"), "Magnitude");
126 offset_ = dim_*static_cast<int>(loadMag.size());
127 }
128
129 // Grab Sidesets
130 Teuchos::Array<int> sidesets
131 = Teuchos::getArrayFromStringParameter<int>(parlist.sublist("Traction"), "Sidesets");
132 sidesets_ = sidesets.toVector();
133
134 // Grab Side IDs
135 Teuchos::Array<int> sideids
136 = Teuchos::getArrayFromStringParameter<int>(parlist.sublist("Traction"), "Side IDs");
137 sideids_ = sideids.toVector();
138
139 // Grab Magnitudes
140 Teuchos::Array<Real> magnitude
141 = Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Traction"), "Magnitude");
142 loadMagnitude_ = magnitude.toVector();
143
144 // Grab Polar Angle
145 Teuchos::Array<Real> polar
146 = Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Traction"), "Polar Angle");
147 loadPolar_ = polar.toVector();
148
149 if (dim_ == 3) {
150 // Grab Azimuth Angle
151 Teuchos::Array<Real> azimuth
152 = Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Traction"), "Azimuth Angle");
153 loadAzimuth_ = azimuth.toVector();
154 }
155 }
156 }
157
158 int polarSize = loadPolar_.size();
159 for (int i=0; i<polarSize; ++i) {
160 loadPolar_[i] = DegreesToRadians(loadPolar_[i]);
161 }
162
163 int azimuthSize = loadAzimuth_.size();
164 for (int i=0; i<azimuthSize; ++i) {
165 loadAzimuth_[i] = DegreesToRadians(loadAzimuth_[i]);
166 }
167 }
168
169 bool isNull(void) const {
170 return (sidesets_.size()==0);
171 }
172
173 void setCellNodes(const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes,
174 const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) {
175 bdryCellNodes_ = bdryCellNodes;
176 bdryCellLocIds_ = bdryCellLocIds;
177 }
178
179 virtual Real evaluate(const int dir,
180 const int sideset,
181 const std::vector<Real> &param) const {
182 // const int numSideSets = sidesets_.size();
183 const int paramSize = param.size();
184 Real val(0);
185 Real loadMagNoise(0), loadAngNoise0(0);
186 if (paramSize > 0 + dim_*sideset) {
187 loadMagNoise = param[offset_ + 0 + dim_*sideset];
188 }
189 if (paramSize > 1 + dim_*sideset) {
190 loadAngNoise0 = DegreesToRadians(param[offset_ + 1 + dim_*sideset]);
191 }
192 const Real loadMagnitude = loadMagnitude_[sideset] + loadMagNoise;
193 const Real loadAngle0 = loadPolar_[sideset] + loadAngNoise0;
194
195 if (dim_==2) {
196 if (dir==0) {
197 val = loadMagnitude*std::cos(loadAngle0);
198 }
199 if (dir==1) {
200 val = loadMagnitude*std::sin(loadAngle0);
201 }
202 }
203 if (dim_==3) {
204 Real loadAngNoise1(0);
205 if (paramSize > 2 + dim_*sideset) {
206 loadAngNoise1 = DegreesToRadians(param[offset_ + 2 + dim_*sideset]);
207 }
208 const Real loadAngle1 = loadAzimuth_[sideset] + loadAngNoise1;
209
210 if (dir==0) {
211 val = loadMagnitude*std::sin(loadAngle0)*std::cos(loadAngle1);
212 }
213 if (dir==1) {
214 val = loadMagnitude*std::sin(loadAngle0)*std::sin(loadAngle1);
215 }
216 if (dir==2) {
217 val = loadMagnitude*std::cos(loadAngle0);
218 }
219 }
220 return val;
221 }
222
223 void compute(std::vector<std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>>> &traction,
224 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &fe,
225 const std::vector<Real> &param,
226 const Real scale = Real(1)) const {
227 traction.clear();
228 traction.resize(bdryCellLocIds_.size());
229 const int numSideSets = sidesets_.size();
230 if (numSideSets > 0) {
231 for (int i = 0; i < numSideSets; ++i) {
232 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
233 traction[sidesets_[i]].resize(numLocalSideIds);
234 for (int j = 0; j < numLocalSideIds; ++j) {
235 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
236 if (numCellsSide > 0) {
237 const int numCubPerSide = fe[sidesets_[i]][j]->cubPts()->dimension(1);
238 traction[sidesets_[i]][j].resize(dim_);
239 for (int k = 0; k < dim_; ++k) {
240 traction[sidesets_[i]][j][k]
241 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
242 for (int c = 0; c < numCellsSide; ++c) {
243 for (int p = 0; p < numCubPerSide; ++p) {
244 (*traction[sidesets_[i]][j][k])(c,p) = scale*evaluate(k,i,param);
245 }
246 }
247 }
248 }
249 }
250 }
251 }
252 }
253
254 void apply(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> &R,
255 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &fe,
256 const std::vector<Real> &param,
257 const Real scale = Real(1)) const {
258 const int numSideSets = sidesets_.size();
259 const int nf = R[0]->dimension(1);
260 if (numSideSets > 0) {
261 for (int i = 0; i < numSideSets; ++i) {
262 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
263 for (int j = 0; j < numLocalSideIds; ++j) {
264 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
265 if (numCellsSide > 0) {
266 const int numCubPerSide = fe[sidesets_[i]][j]->cubPts()->dimension(1);
267 for (int k = 0; k < dim_; ++k) {
268 Intrepid::FieldContainer<Real> traction(numCellsSide, numCubPerSide);
269 for (int c = 0; c < numCellsSide; ++c) {
270 for (int p = 0; p < numCubPerSide; ++p) {
271 traction(c,p) = scale*evaluate(k,i,param);
272 }
273 }
274 Intrepid::FieldContainer<Real> tractionResidual(numCellsSide, nf);
275 Intrepid::FunctionSpaceTools::integrate<Real>(tractionResidual,
276 traction,
277 *fe[sidesets_[i]][j]->NdetJ(),
278 Intrepid::COMP_CPP, false);
279 // Add traction residual to volume residual
280 for (int l = 0; l < numCellsSide; ++l) {
281 int cidx = bdryCellLocIds_[sidesets_[i]][j][l];
282 for (int m = 0; m < nf; ++m) {
283 (*R[k])(cidx,m) += tractionResidual(l,m);
284 }
285 }
286 }
287 }
288 }
289 }
290 }
291 }
292 };
293
294 #endif