| 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 dirichlet.hpp |
| 11 |
\brief Implements Dirichlet boundary conditions for the structural |
| 12 |
topology optimization problem. |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifndef ROL_PDEOPT_ELASTICITY_DIRICHLET_HPP |
| 16 |
#define ROL_PDEOPT_ELASTICITY_DIRICHLET_HPP |
| 17 |
|
| 18 |
#include "ROL_Ptr.hpp" |
| 19 |
#include "Teuchos_ParameterList.hpp" |
| 20 |
#include "Intrepid_FieldContainer.hpp" |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
template<class Real> |
| 24 |
class Dirichlet { |
| 25 |
private: |
| 26 |
std::vector<int> sidesets_, types_; |
| 27 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_; |
| 28 |
std::vector<std::vector<std::vector<int> > > bdryCellLocIds_; |
| 29 |
std::vector<std::vector<int> > fidx_; |
| 30 |
|
| 31 |
std::vector<int> getConstrainedDimensions(const int type, const int dim) const { |
| 32 |
std::vector<int> conDim; |
| 33 |
if ( type == 1 ) { |
| 34 |
conDim.push_back(0); |
| 35 |
} |
| 36 |
else if ( type == 2 ) { |
| 37 |
conDim.push_back(1); |
| 38 |
} |
| 39 |
else if ( type == 3 && dim > 2 ) { |
| 40 |
conDim.push_back(2); |
| 41 |
} |
| 42 |
else if ( type == 4 && dim > 2 ) { |
| 43 |
conDim.push_back(0); |
| 44 |
conDim.push_back(1); |
| 45 |
} |
| 46 |
else if ( type == 5 && dim > 2 ) { |
| 47 |
conDim.push_back(0); |
| 48 |
conDim.push_back(2); |
| 49 |
} |
| 50 |
else if ( type == 6 && dim > 2 ) { |
| 51 |
conDim.push_back(1); |
| 52 |
conDim.push_back(2); |
| 53 |
} |
| 54 |
else { |
| 55 |
for (int i = 0; i < dim; ++i) { |
| 56 |
conDim.push_back(i); |
| 57 |
} |
| 58 |
} |
| 59 |
return conDim; |
| 60 |
} |
| 61 |
|
| 62 |
public: |
| 63 |
Dirichlet(Teuchos::ParameterList &parlist, std::string ex = "Default") { |
| 64 |
if (ex == "2D Cantilever with 1 Load" || |
| 65 |
ex == "3D Cantilever" || |
| 66 |
ex == "2D Truss" || |
| 67 |
ex == "2D Beams") { |
| 68 |
sidesets_.push_back(3); |
| 69 |
types_.push_back(0); |
| 70 |
} |
| 71 |
else if (ex == "2D Cantilever with 3 Loads") { |
| 72 |
sidesets_.push_back(8); |
| 73 |
types_.push_back(0); |
| 74 |
} |
| 75 |
else if (ex == "2D Wheel") { |
| 76 |
sidesets_.push_back(0); |
| 77 |
sidesets_.push_back(4); |
| 78 |
types_.push_back(0); |
| 79 |
types_.push_back(2); |
| 80 |
} |
| 81 |
else if (ex == "2D Carrier Plate") { |
| 82 |
sidesets_.push_back(0); |
| 83 |
types_.push_back(0); |
| 84 |
} |
| 85 |
else if (ex == "3D L Beam") { |
| 86 |
sidesets_.push_back(0); |
| 87 |
types_.push_back(0); |
| 88 |
} |
| 89 |
else { |
| 90 |
// Grab sidesets |
| 91 |
Teuchos::Array<int> sidesets |
| 92 |
= Teuchos::getArrayFromStringParameter<int>(parlist.sublist("Dirichlet"), "Sidesets"); |
| 93 |
sidesets_ = sidesets.toVector(); |
| 94 |
// Grab type |
| 95 |
Teuchos::Array<int> types |
| 96 |
= Teuchos::getArrayFromStringParameter<int>(parlist.sublist("Dirichlet"), "Types"); |
| 97 |
types_ = types.toVector(); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
void setCellNodes(const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes, |
| 102 |
const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds, |
| 103 |
const std::vector<std::vector<int> > fidx) { |
| 104 |
bdryCellNodes_ = bdryCellNodes; |
| 105 |
bdryCellLocIds_ = bdryCellLocIds; |
| 106 |
fidx_ = fidx; |
| 107 |
} |
| 108 |
|
| 109 |
void applyResidual(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > &R, |
| 110 |
const std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > &U) const { |
| 111 |
const int d = R.size(); |
| 112 |
const int numSideSets = sidesets_.size(); |
| 113 |
if (numSideSets > 0) { |
| 114 |
for (int i = 0; i < numSideSets; ++i) { |
| 115 |
const std::vector<int> conDim = getConstrainedDimensions(types_[i],d); |
| 116 |
const int numConDim = conDim.size(); |
| 117 |
const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size(); |
| 118 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 119 |
const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size(); |
| 120 |
const int numBdryDofs = fidx_[j].size(); |
| 121 |
for (int k = 0; k < numCellsSide; ++k) { |
| 122 |
const int cidx = bdryCellLocIds_[sidesets_[i]][j][k]; |
| 123 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 124 |
for (int m=0; m < numConDim; ++m) { |
| 125 |
(*R[conDim[m]])(cidx,fidx_[j][l]) = (*U[conDim[m]])(cidx,fidx_[j][l]); |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
void applyJacobian1(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &J) const { |
| 135 |
const int d = J.size(); |
| 136 |
const int f = J[0][0]->dimension(1); |
| 137 |
const int numSideSets = sidesets_.size(); |
| 138 |
if (numSideSets > 0) { |
| 139 |
for (int i = 0; i < numSideSets; ++i) { |
| 140 |
const std::vector<int> conDim = getConstrainedDimensions(types_[i],d); |
| 141 |
const int numConDim = conDim.size(); |
| 142 |
const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size(); |
| 143 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 144 |
const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size(); |
| 145 |
const int numBdryDofs = fidx_[j].size(); |
| 146 |
for (int k = 0; k < numCellsSide; ++k) { |
| 147 |
const int cidx = bdryCellLocIds_[sidesets_[i]][j][k]; |
| 148 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 149 |
for (int m=0; m < f; ++m) { |
| 150 |
for (int n=0; n < numConDim; ++n) { |
| 151 |
for (int p=0; p < d; ++p) { |
| 152 |
(*J[conDim[n]][p])(cidx,fidx_[j][l],m) = static_cast<Real>(0); |
| 153 |
} |
| 154 |
(*J[conDim[n]][conDim[n]])(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
void applyJacobian2(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &J) const { |
| 165 |
const int d = J.size(); |
| 166 |
const int f = J[0][0]->dimension(2); |
| 167 |
const int numSideSets = sidesets_.size(); |
| 168 |
if (numSideSets > 0) { |
| 169 |
for (int i = 0; i < numSideSets; ++i) { |
| 170 |
const std::vector<int> conDim = getConstrainedDimensions(types_[i],d); |
| 171 |
const int numConDim = conDim.size(); |
| 172 |
const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size(); |
| 173 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 174 |
const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size(); |
| 175 |
const int numBdryDofs = fidx_[j].size(); |
| 176 |
for (int k = 0; k < numCellsSide; ++k) { |
| 177 |
const int cidx = bdryCellLocIds_[sidesets_[i]][j][k]; |
| 178 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 179 |
for (int m=0; m < f; ++m) { |
| 180 |
for (int n=0; n < numConDim; ++n) { |
| 181 |
(*J[conDim[n]][0])(cidx,fidx_[j][l],m) = static_cast<Real>(0); |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
void applyMultiplier(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > &L) const { |
| 192 |
const int d = L.size(); |
| 193 |
const int numSideSets = sidesets_.size(); |
| 194 |
if (numSideSets > 0) { |
| 195 |
for (int i = 0; i < numSideSets; ++i) { |
| 196 |
const std::vector<int> conDim = getConstrainedDimensions(types_[i],d); |
| 197 |
const int numConDim = conDim.size(); |
| 198 |
const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size(); |
| 199 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 200 |
const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size(); |
| 201 |
const int numBdryDofs = fidx_[j].size(); |
| 202 |
for (int k = 0; k < numCellsSide; ++k) { |
| 203 |
const int cidx = bdryCellLocIds_[sidesets_[i]][j][k]; |
| 204 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 205 |
for (int m=0; m < numConDim; ++m) { |
| 206 |
(*L[conDim[m]])(cidx,fidx_[j][l]) = static_cast<Real>(0); |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
}; |
| 215 |
|
| 216 |
#endif |
| 217 |
|
| 218 |
// Real dirichletFunc(const std::vector<Real> & coords, const int sideset, const int locSideId, const int dir) const { |
| 219 |
// Real val(0); |
| 220 |
// return val; |
| 221 |
// } |
| 222 |
// |
| 223 |
// void computeDirichlet(void) { |
| 224 |
// // Compute Dirichlet values at DOFs. |
| 225 |
// int d = basisPtr_->getBaseCellTopology().getDimension(); |
| 226 |
// int numSidesets = bdryCellLocIds_.size(); |
| 227 |
// bdryCellDofValues_.resize(numSidesets); |
| 228 |
// for (int i=0; i<numSidesets; ++i) { |
| 229 |
// int numLocSides = bdryCellLocIds_[i].size(); |
| 230 |
// bdryCellDofValues_[i].resize(numLocSides); |
| 231 |
// for (int j=0; j<numLocSides; ++j) { |
| 232 |
// int c = bdryCellLocIds_[i][j].size(); |
| 233 |
// int f = basisPtr_->getCardinality(); |
| 234 |
// bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 235 |
// ROL::Ptr<Intrepid::FieldContainer<Real> > coords = |
| 236 |
// ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 237 |
// if (c > 0) { |
| 238 |
// fe_->computeDofCoords(coords, bdryCellNodes_[i][j]); |
| 239 |
// } |
| 240 |
// for (int k=0; k<c; ++k) { |
| 241 |
// for (int l=0; l<f; ++l) { |
| 242 |
// std::vector<Real> dofpoint(d); |
| 243 |
// //std::cout << "Sideset " << i << " LocalSide " << j << " Cell " << k << " Field " << l << " Coord "; |
| 244 |
// for (int m=0; m<d; ++m) { |
| 245 |
// dofpoint[m] = (*coords)(k, l, m); |
| 246 |
// //std::cout << dofpoint[m] << " "; |
| 247 |
// } |
| 248 |
// |
| 249 |
// for (int m=0; m<d; ++m) { |
| 250 |
// (*bdryCellDofValues_[i][j])(k, l, m) = dirichletFunc(dofpoint, i, j, m); |
| 251 |
// //std::cout << " " << m << "-Value " << dirichletFunc(dofpoint, i, j, m); |
| 252 |
// } |
| 253 |
// //std::cout << std::endl; |
| 254 |
// } |
| 255 |
// } |
| 256 |
// } |
| 257 |
// } |
| 258 |
// } |