| 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(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 if (ex == "3D L Beam") { |
| 118 |
dim_ = 3; |
| 119 |
offset_ = 0; |
| 120 |
sidesets_.push_back(1); |
| 121 |
sideids_.push_back(1); |
| 122 |
loadMagnitude_.push_back(static_cast<Real>(100)); |
| 123 |
loadPolar_.push_back(static_cast<Real>(270)); |
| 124 |
loadAzimuth_.push_back(static_cast<Real>(90)); |
| 125 |
} |
| 126 |
else { |
| 127 |
if (parlist.isSublist("Traction")) { |
| 128 |
// Grab problem dimension |
| 129 |
dim_ = parlist.get("Problem Dimension",2); |
| 130 |
|
| 131 |
offset_ = 0; |
| 132 |
if (parlist.isSublist("Load")) { |
| 133 |
Teuchos::Array<Real> loadMag |
| 134 |
= Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Load"), "Magnitude"); |
| 135 |
offset_ = dim_*static_cast<int>(loadMag.size()); |
| 136 |
} |
| 137 |
|
| 138 |
// Grab Sidesets |
| 139 |
Teuchos::Array<int> sidesets |
| 140 |
= Teuchos::getArrayFromStringParameter<int>(parlist.sublist("Traction"), "Sidesets"); |
| 141 |
sidesets_ = sidesets.toVector(); |
| 142 |
|
| 143 |
// Grab Side IDs |
| 144 |
Teuchos::Array<int> sideids |
| 145 |
= Teuchos::getArrayFromStringParameter<int>(parlist.sublist("Traction"), "Side IDs"); |
| 146 |
sideids_ = sideids.toVector(); |
| 147 |
|
| 148 |
// Grab Magnitudes |
| 149 |
Teuchos::Array<Real> magnitude |
| 150 |
= Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Traction"), "Magnitude"); |
| 151 |
loadMagnitude_ = magnitude.toVector(); |
| 152 |
|
| 153 |
// Grab Polar Angle |
| 154 |
Teuchos::Array<Real> polar |
| 155 |
= Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Traction"), "Polar Angle"); |
| 156 |
loadPolar_ = polar.toVector(); |
| 157 |
|
| 158 |
if (dim_ == 3) { |
| 159 |
// Grab Azimuth Angle |
| 160 |
Teuchos::Array<Real> azimuth |
| 161 |
= Teuchos::getArrayFromStringParameter<double>(parlist.sublist("Traction"), "Azimuth Angle"); |
| 162 |
loadAzimuth_ = azimuth.toVector(); |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
int polarSize = loadPolar_.size(); |
| 168 |
for (int i=0; i<polarSize; ++i) { |
| 169 |
loadPolar_[i] = DegreesToRadians(loadPolar_[i]); |
| 170 |
} |
| 171 |
|
| 172 |
int azimuthSize = loadAzimuth_.size(); |
| 173 |
for (int i=0; i<azimuthSize; ++i) { |
| 174 |
loadAzimuth_[i] = DegreesToRadians(loadAzimuth_[i]); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
bool isNull(void) const { |
| 179 |
return (sidesets_.size()==0); |
| 180 |
} |
| 181 |
|
| 182 |
void setCellNodes(const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 183 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 184 |
bdryCellNodes_ = bdryCellNodes; |
| 185 |
bdryCellLocIds_ = bdryCellLocIds; |
| 186 |
} |
| 187 |
|
| 188 |
virtual Real evaluate(const int dir, |
| 189 |
const int sideset, |
| 190 |
const std::vector<Real> ¶m) const { |
| 191 |
// const int numSideSets = sidesets_.size(); |
| 192 |
const int paramSize = param.size(); |
| 193 |
Real val(0); |
| 194 |
Real loadMagNoise(0), loadAngNoise0(0); |
| 195 |
if (paramSize > 0 + dim_*sideset) { |
| 196 |
loadMagNoise = param[offset_ + 0 + dim_*sideset]; |
| 197 |
} |
| 198 |
if (paramSize > 1 + dim_*sideset) { |
| 199 |
loadAngNoise0 = DegreesToRadians(param[offset_ + 1 + dim_*sideset]); |
| 200 |
} |
| 201 |
const Real loadMagnitude = loadMagnitude_[sideset] + loadMagNoise; |
| 202 |
const Real loadAngle0 = loadPolar_[sideset] + loadAngNoise0; |
| 203 |
|
| 204 |
if (dim_==2) { |
| 205 |
if (dir==0) { |
| 206 |
val = loadMagnitude*std::cos(loadAngle0); |
| 207 |
} |
| 208 |
if (dir==1) { |
| 209 |
val = loadMagnitude*std::sin(loadAngle0); |
| 210 |
} |
| 211 |
} |
| 212 |
if (dim_==3) { |
| 213 |
Real loadAngNoise1(0); |
| 214 |
if (paramSize > 2 + dim_*sideset) { |
| 215 |
loadAngNoise1 = DegreesToRadians(param[offset_ + 2 + dim_*sideset]); |
| 216 |
} |
| 217 |
const Real loadAngle1 = loadAzimuth_[sideset] + loadAngNoise1; |
| 218 |
|
| 219 |
if (dir==0) { |
| 220 |
val = loadMagnitude*std::sin(loadAngle0)*std::cos(loadAngle1); |
| 221 |
} |
| 222 |
if (dir==1) { |
| 223 |
val = loadMagnitude*std::sin(loadAngle0)*std::sin(loadAngle1); |
| 224 |
} |
| 225 |
if (dir==2) { |
| 226 |
val = loadMagnitude*std::cos(loadAngle0); |
| 227 |
} |
| 228 |
} |
| 229 |
return val; |
| 230 |
} |
| 231 |
|
| 232 |
void compute(std::vector<std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>>> &traction, |
| 233 |
const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &fe, |
| 234 |
const std::vector<Real> ¶m, |
| 235 |
const Real scale = Real(1)) const { |
| 236 |
traction.clear(); |
| 237 |
traction.resize(bdryCellLocIds_.size()); |
| 238 |
const int numSideSets = sidesets_.size(); |
| 239 |
if (numSideSets > 0) { |
| 240 |
for (int i = 0; i < numSideSets; ++i) { |
| 241 |
const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size(); |
| 242 |
traction[sidesets_[i]].resize(numLocalSideIds); |
| 243 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 244 |
const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size(); |
| 245 |
if (numCellsSide > 0) { |
| 246 |
const int numCubPerSide = fe[sidesets_[i]][j]->cubPts()->dimension(1); |
| 247 |
traction[sidesets_[i]][j].resize(dim_); |
| 248 |
for (int k = 0; k < dim_; ++k) { |
| 249 |
traction[sidesets_[i]][j][k] |
| 250 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 251 |
for (int c = 0; c < numCellsSide; ++c) { |
| 252 |
for (int p = 0; p < numCubPerSide; ++p) { |
| 253 |
(*traction[sidesets_[i]][j][k])(c,p) = scale*evaluate(k,i,param); |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
void apply(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> &R, |
| 264 |
const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &fe, |
| 265 |
const std::vector<Real> ¶m, |
| 266 |
const Real scale = Real(1)) const { |
| 267 |
const int numSideSets = sidesets_.size(); |
| 268 |
const int nf = R[0]->dimension(1); |
| 269 |
if (numSideSets > 0) { |
| 270 |
for (int i = 0; i < numSideSets; ++i) { |
| 271 |
const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size(); |
| 272 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 273 |
const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size(); |
| 274 |
if (numCellsSide > 0) { |
| 275 |
const int numCubPerSide = fe[sidesets_[i]][j]->cubPts()->dimension(1); |
| 276 |
for (int k = 0; k < dim_; ++k) { |
| 277 |
Intrepid::FieldContainer<Real> traction(numCellsSide, numCubPerSide); |
| 278 |
for (int c = 0; c < numCellsSide; ++c) { |
| 279 |
for (int p = 0; p < numCubPerSide; ++p) { |
| 280 |
traction(c,p) = scale*evaluate(k,i,param); |
| 281 |
} |
| 282 |
} |
| 283 |
Intrepid::FieldContainer<Real> tractionResidual(numCellsSide, nf); |
| 284 |
Intrepid::FunctionSpaceTools::integrate<Real>(tractionResidual, |
| 285 |
traction, |
| 286 |
*fe[sidesets_[i]][j]->NdetJ(), |
| 287 |
Intrepid::COMP_CPP, false); |
| 288 |
// Add traction residual to volume residual |
| 289 |
for (int l = 0; l < numCellsSide; ++l) { |
| 290 |
int cidx = bdryCellLocIds_[sidesets_[i]][j][l]; |
| 291 |
for (int m = 0; m < nf; ++m) { |
| 292 |
(*R[k])(cidx,m) += tractionResidual(l,m); |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
}; |
| 302 |
|
| 303 |
#endif |