Debian Codegraph @

packages/rol/example/PDE-OPT/topo-opt/multimat/src/obj_compliance.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 obj.hpp
11 \brief Provides the interface for local (cell-based) objective function computations.
12 */
13
14 #ifndef PDEOPT_QOI_TOPOOPT_MULTIMAT_HPP
15 #define PDEOPT_QOI_TOPOOPT_MULTIMAT_HPP
16
17 #include "../../../TOOLS/qoi.hpp"
18 #include "pde_elasticity.hpp"
19
20 template <class Real>
21 class QoI_Compliance_TopoOpt : public QoI<Real> {
22 private:
23 // Volumetric Information
24 const ROL::Ptr<FE<Real>> fe_;
25 const ROL::Ptr<Load<Real>> load_;
26 // Boundary Information
27 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> feBdry_;
28 const std::vector<std::vector<std::vector<int>>> bdryCellLocIds_;
29 const ROL::Ptr<Traction<Real>> traction_;
30 // Field Information
31 const ROL::Ptr<FieldUtils::FieldInfo> fieldInfo_;
32 // QoI Scaling
33 const Real scale_;
34
35 ROL::Ptr<Intrepid::FieldContainer<Real>> getBoundaryCoeff(
36 const Intrepid::FieldContainer<Real> & cell_coeff,
37 const int sideset, const int locSideId) const {
38 std::vector<int> bdryCellLocId = bdryCellLocIds_[sideset][locSideId];
39 const int numCellsSide = bdryCellLocId.size();
40 const int f = fe_->N()->dimension(1);
41
42 ROL::Ptr<Intrepid::FieldContainer<Real>> bdry_coeff =
43 ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f);
44 for (int i = 0; i < numCellsSide; ++i) {
45 for (int j = 0; j < f; ++j) {
46 (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j);
47 }
48 }
49 return bdry_coeff;
50 }
51
52 public:
53 QoI_Compliance_TopoOpt(const ROL::Ptr<FE<Real>> &fe,
54 const ROL::Ptr<Load<Real>> &load,
55 const ROL::Ptr<FieldUtils::FieldInfo> &fieldInfo,
56 const Real scale = 1.0)
57 : fe_(fe), load_(load), traction_(ROL::makePtr<Traction<Real>>()),
58 fieldInfo_(fieldInfo), scale_(scale) {}
59
60 QoI_Compliance_TopoOpt(const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &feBdry,
61 const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds,
62 const ROL::Ptr<Traction<Real>> &traction,
63 const ROL::Ptr<FieldUtils::FieldInfo> &fieldInfo,
64 const Real scale = 1.0)
65 : feBdry_(feBdry), load_(ROL::makePtr<Load<Real>>()),
66 bdryCellLocIds_(bdryCellLocIds), traction_(traction),
67 fieldInfo_(fieldInfo), scale_(scale) {}
68
69 QoI_Compliance_TopoOpt(const ROL::Ptr<FE<Real>> &fe,
70 const ROL::Ptr<Load<Real>> &load,
71 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &feBdry,
72 const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds,
73 const ROL::Ptr<Traction<Real>> &traction,
74 const ROL::Ptr<FieldUtils::FieldInfo> &fieldInfo,
75 const Real scale = 1.0)
76 : fe_(fe), load_(load), feBdry_(feBdry), bdryCellLocIds_(bdryCellLocIds),
77 traction_(traction), fieldInfo_(fieldInfo), scale_(scale) {}
78
79 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
80 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
81 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
82 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
83 // Get relevant dimensions
84 int c = fe_->gradN()->dimension(0);
85 int p = fe_->gradN()->dimension(2);
86 int d = fe_->gradN()->dimension(3);
87
88 // Initialize output val
89 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
90
91 // Get components of the displacement
92 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
93 FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_);
94
95 // Evaluate on FE basis
96 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> valU_eval(d);
97 for (int i=0; i<d; ++i) {
98 valU_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
99 fe_->evaluateValue(valU_eval[i], U[i]);
100 }
101
102 // Compute load integral
103 if (!load_->isNull()) {
104 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > load_eval(d);
105 for (int i=0; i<d; ++i) {
106 load_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
107 }
108 load_->compute(load_eval, fe_, QoI<Real>::getParameter());
109 for (int i=0; i<d; ++i) {
110 fe_->computeIntegral(val,load_eval[i],valU_eval[i],true);
111 }
112 }
113
114 // Compute traction integral
115 if (!traction_->isNull()) {
116 std::vector<std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > > traction;
117 traction_->compute(traction, feBdry_, QoI<Real>::getParameter());
118 const int numSideSets = bdryCellLocIds_.size();
119 if (numSideSets > 0) {
120 for (int i = 0; i < numSideSets; ++i) {
121 if (traction[i].size() > 0) {
122 const int numLocalSideIds = bdryCellLocIds_[i].size();
123 for (int j = 0; j < numLocalSideIds; ++j) {
124 const int numCellsSide = bdryCellLocIds_[i][j].size();
125 if (numCellsSide > 0 && traction[i][j].size() > 0) {
126 const int numCubPerSide = feBdry_[i][j]->cubPts()->dimension(1);
127 for (int k = 0; k < d; ++k) {
128 // Evaluate i-component of state on FE basis
129 ROL::Ptr<Intrepid::FieldContainer<Real> > u_coeff_bdry
130 = getBoundaryCoeff(*U[k], i, j);
131 ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval
132 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
133 feBdry_[i][j]->evaluateValue(valU_eval, u_coeff_bdry);
134 // Integrate cell traction compliance
135 ROL::Ptr<Intrepid::FieldContainer<Real> > intVal
136 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide);
137 feBdry_[i][j]->computeIntegral(intVal,valU_eval,traction[i][j][k],false);
138 // Add to integral value
139 for (int l = 0; l < numCellsSide; ++l) {
140 int cidx = bdryCellLocIds_[i][j][l];
141 (*val)(cidx) += (*intVal)(l);
142 }
143 }
144 }
145 }
146 }
147 }
148 }
149 }
150
151 Intrepid::RealSpaceTools<Real>::scale(*val, scale_);
152 return static_cast<Real>(0);
153 }
154
155 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
156 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
157 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
158 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
159 // Get relevant dimensions
160 int c = fe_->gradN()->dimension(0);
161 int f = fe_->gradN()->dimension(1);
162 int p = fe_->gradN()->dimension(2);
163 int d = fe_->gradN()->dimension(3);
164
165 // Initialize output grad
166 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d);
167 for (int i=0; i<d; ++i) {
168 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f);
169 }
170
171 // Compute load integral
172 if (!load_->isNull()) {
173 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> load_eval(d);
174 for (int i=0; i<d; ++i) {
175 load_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
176 }
177 load_->compute(load_eval, fe_, QoI<Real>::getParameter());
178 for (int i=0; i<d; ++i) {
179 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
180 *load_eval[i],
181 *(fe_->NdetJ()),
182 Intrepid::COMP_CPP,
183 false);
184 }
185 }
186
187 // Compute traction integral
188 if (!traction_->isNull()) {
189 traction_->apply(G, feBdry_, QoI<Real>::getParameter());
190 }
191
192 // Multiply gradient by compliance scale
193 for (int i=0; i<d; ++i) {
194 Intrepid::RealSpaceTools<Real>::scale(*G[i], scale_);
195 }
196 FieldUtils::combineFieldCoeff<Real>(grad, G, fieldInfo_);
197 }
198
199 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
200 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
201 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
202 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
203 throw Exception::Zero(">>> QoI_Compliance_TopoOpt::gradient_2 is zero.");
204 }
205
206 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
207 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
208 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
209 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
210 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
211 throw Exception::Zero(">>> QoI_Compliance_TopoOpt::HessVec_12 is zero.");
212 }
213
214 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
215 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
216 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
217 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
218 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
219 throw Exception::Zero(">>> QoI_Compliance_TopoOpt::HessVec_12 is zero.");
220 }
221
222 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
223 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
224 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
225 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
226 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
227 throw Exception::Zero(">>> QoI_Compliance_TopoOpt::HessVec_21 is zero.");
228 }
229
230 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
231 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
232 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
233 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
234 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
235 throw Exception::Zero(">>> QoI_Compliance_TopoOpt::HessVec_22 is zero.");
236 }
237
238 }; // QoI_Compliance_TopoOpt
239
240 #endif