Debian Codegraph @

packages/rol/example/PDE-OPT/published/TRSPG_Kouri2021/elasticity/src/dirichlet.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 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(void) {
64 sidesets_.push_back(0);
65 types_.push_back(0);
66 }
67
68 void setCellNodes(const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes,
69 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds,
70 const std::vector<std::vector<int> > fidx) {
71 bdryCellNodes_ = bdryCellNodes;
72 bdryCellLocIds_ = bdryCellLocIds;
73 fidx_ = fidx;
74 }
75
76 void applyResidual(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > &R,
77 const std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > &U) const {
78 const int d = R.size();
79 const int numSideSets = sidesets_.size();
80 if (numSideSets > 0) {
81 for (int i = 0; i < numSideSets; ++i) {
82 const std::vector<int> conDim = getConstrainedDimensions(types_[i],d);
83 const int numConDim = conDim.size();
84 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
85 for (int j = 0; j < numLocalSideIds; ++j) {
86 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
87 const int numBdryDofs = fidx_[j].size();
88 for (int k = 0; k < numCellsSide; ++k) {
89 const int cidx = bdryCellLocIds_[sidesets_[i]][j][k];
90 for (int l = 0; l < numBdryDofs; ++l) {
91 for (int m=0; m < numConDim; ++m) {
92 (*R[conDim[m]])(cidx,fidx_[j][l]) = (*U[conDim[m]])(cidx,fidx_[j][l]);
93 }
94 }
95 }
96 }
97 }
98 }
99 }
100
101 void applyJacobian1(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &J) const {
102 const int d = J.size();
103 const int f = J[0][0]->dimension(1);
104 const int numSideSets = sidesets_.size();
105 if (numSideSets > 0) {
106 for (int i = 0; i < numSideSets; ++i) {
107 const std::vector<int> conDim = getConstrainedDimensions(types_[i],d);
108 const int numConDim = conDim.size();
109 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
110 for (int j = 0; j < numLocalSideIds; ++j) {
111 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
112 const int numBdryDofs = fidx_[j].size();
113 for (int k = 0; k < numCellsSide; ++k) {
114 const int cidx = bdryCellLocIds_[sidesets_[i]][j][k];
115 for (int l = 0; l < numBdryDofs; ++l) {
116 for (int m=0; m < f; ++m) {
117 for (int n=0; n < numConDim; ++n) {
118 for (int p=0; p < d; ++p) {
119 (*J[conDim[n]][p])(cidx,fidx_[j][l],m) = static_cast<Real>(0);
120 }
121 (*J[conDim[n]][conDim[n]])(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1);
122 }
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130
131 void applyJacobian2(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &J) const {
132 const int d = J.size();
133 const int f = J[0][0]->dimension(2);
134 const int numSideSets = sidesets_.size();
135 if (numSideSets > 0) {
136 for (int i = 0; i < numSideSets; ++i) {
137 const std::vector<int> conDim = getConstrainedDimensions(types_[i],d);
138 const int numConDim = conDim.size();
139 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
140 for (int j = 0; j < numLocalSideIds; ++j) {
141 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
142 const int numBdryDofs = fidx_[j].size();
143 for (int k = 0; k < numCellsSide; ++k) {
144 const int cidx = bdryCellLocIds_[sidesets_[i]][j][k];
145 for (int l = 0; l < numBdryDofs; ++l) {
146 for (int m=0; m < f; ++m) {
147 for (int n=0; n < numConDim; ++n) {
148 (*J[conDim[n]][0])(cidx,fidx_[j][l],m) = static_cast<Real>(0);
149 }
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157
158 void applyMultiplier(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > &L) const {
159 const int d = L.size();
160 const int numSideSets = sidesets_.size();
161 if (numSideSets > 0) {
162 for (int i = 0; i < numSideSets; ++i) {
163 const std::vector<int> conDim = getConstrainedDimensions(types_[i],d);
164 const int numConDim = conDim.size();
165 const int numLocalSideIds = bdryCellLocIds_[sidesets_[i]].size();
166 for (int j = 0; j < numLocalSideIds; ++j) {
167 const int numCellsSide = bdryCellLocIds_[sidesets_[i]][j].size();
168 const int numBdryDofs = fidx_[j].size();
169 for (int k = 0; k < numCellsSide; ++k) {
170 const int cidx = bdryCellLocIds_[sidesets_[i]][j][k];
171 for (int l = 0; l < numBdryDofs; ++l) {
172 for (int m=0; m < numConDim; ++m) {
173 (*L[conDim[m]])(cidx,fidx_[j][l]) = static_cast<Real>(0);
174 }
175 }
176 }
177 }
178 }
179 }
180 }
181 };
182
183 #endif
184
185 // Real dirichletFunc(const std::vector<Real> & coords, const int sideset, const int locSideId, const int dir) const {
186 // Real val(0);
187 // return val;
188 // }
189 //
190 // void computeDirichlet(void) {
191 // // Compute Dirichlet values at DOFs.
192 // int d = basisPtr_->getBaseCellTopology().getDimension();
193 // int numSidesets = bdryCellLocIds_.size();
194 // bdryCellDofValues_.resize(numSidesets);
195 // for (int i=0; i<numSidesets; ++i) {
196 // int numLocSides = bdryCellLocIds_[i].size();
197 // bdryCellDofValues_[i].resize(numLocSides);
198 // for (int j=0; j<numLocSides; ++j) {
199 // int c = bdryCellLocIds_[i][j].size();
200 // int f = basisPtr_->getCardinality();
201 // bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d);
202 // ROL::Ptr<Intrepid::FieldContainer<Real> > coords =
203 // ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d);
204 // if (c > 0) {
205 // fe_->computeDofCoords(coords, bdryCellNodes_[i][j]);
206 // }
207 // for (int k=0; k<c; ++k) {
208 // for (int l=0; l<f; ++l) {
209 // std::vector<Real> dofpoint(d);
210 // //std::cout << "Sideset " << i << " LocalSide " << j << " Cell " << k << " Field " << l << " Coord ";
211 // for (int m=0; m<d; ++m) {
212 // dofpoint[m] = (*coords)(k, l, m);
213 // //std::cout << dofpoint[m] << " ";
214 // }
215 //
216 // for (int m=0; m<d; ++m) {
217 // (*bdryCellDofValues_[i][j])(k, l, m) = dirichletFunc(dofpoint, i, j, m);
218 // //std::cout << " " << m << "-Value " << dirichletFunc(dofpoint, i, j, m);
219 // }
220 // //std::cout << std::endl;
221 // }
222 // }
223 // }
224 // }
225 // }