Debian Codegraph @

packages/rol/example/PDE-OPT/thermal-fluids/obj_thermal-fluids_ex03.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_THERMALFLUIDS_HPP
15 #define PDEOPT_QOI_THERMALFLUIDS_HPP
16
17 #include "../TOOLS/qoi.hpp"
18 #include "pde_thermal-fluids_ex03.hpp"
19
20 template <class Real>
21 class QoI_Vorticity_ThermalFluids : public QoI<Real> {
22 private:
23 const ROL::Ptr<FE<Real> > feVel_;
24 const ROL::Ptr<FE<Real> > fePrs_;
25 const ROL::Ptr<FE<Real> > feThr_;
26 const ROL::Ptr<FieldHelper<Real> > fieldHelper_;
27 ROL::Ptr<Intrepid::FieldContainer<Real> > weight_;
28
29 Real weightFunc(const std::vector<Real> & x) const {
30 return static_cast<Real>(1);
31 }
32
33 public:
34 QoI_Vorticity_ThermalFluids(const ROL::Ptr<FE<Real> > &feVel,
35 const ROL::Ptr<FE<Real> > &fePrs,
36 const ROL::Ptr<FE<Real> > &feThr,
37 const ROL::Ptr<FieldHelper<Real> > &fieldHelper,
38 Teuchos::ParameterList &parlist)
39 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
40 int c = feVel_->cubPts()->dimension(0);
41 int p = feVel_->cubPts()->dimension(1);
42 int d = feVel_->cubPts()->dimension(2);
43 std::vector<Real> pt(d);
44 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
45 for (int i = 0; i < c; ++i) {
46 for (int j = 0; j < p; ++j) {
47 for (int k = 0; k < d; ++k) {
48 pt[k] = (*feVel_->cubPts())(i,j,k);
49 }
50 (*weight_)(i,j) = weightFunc(pt);
51 }
52 }
53 }
54
55 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
56 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
57 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
58 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
59 // Get relevant dimensions
60 int c = u_coeff->dimension(0);
61 int p = feVel_->cubPts()->dimension(1);
62 int d = feVel_->cubPts()->dimension(2);
63 // Initialize output val
64 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
65 // Get components of the control
66 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U;
67 fieldHelper_->splitFieldCoeff(U, u_coeff);
68 // Evaluate on FE basis
69 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > gradU_vec(d);
70 for (int i = 0; i < d; ++i) {
71 gradU_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
72 feVel_->evaluateGradient(gradU_vec[i], U[i]);
73 }
74 // Compute weighted curl
75 ROL::Ptr<Intrepid::FieldContainer<Real> > curlU_eval;
76 if (d==2) {
77 curlU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
78 }
79 else if (d==3) {
80 curlU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
81 }
82 for (int i = 0; i < c; ++i) {
83 for (int j = 0; j < p; ++j) {
84 if (d==2) {
85 (*curlU_eval)(i,j) = (*weight_)(i,j)
86 * ((*gradU_vec[1])(i,j,0) - (*gradU_vec[0])(i,j,1));
87 }
88 else if (d==3) {
89 for (int k = 0; k < d; ++k) {
90 int i1 = (k+2)%d, i2 = (k+1)%d;
91 (*curlU_eval)(i,j,k) = (*weight_)(i,j)
92 * ((*gradU_vec[i1])(i,j,i2) - (*gradU_vec[i2])(i,j,i1));
93 }
94 }
95 }
96 }
97 // Compute L2 norm squared
98 feVel_->computeIntegral(val,curlU_eval,curlU_eval,false);
99 Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5));
100 return static_cast<Real>(0);
101 }
102
103 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
104 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
105 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
106 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
107 // Get relevant dimensions
108 int c = u_coeff->dimension(0);
109 int fv = feVel_->N()->dimension(1);
110 int fp = fePrs_->N()->dimension(1);
111 int fh = feThr_->N()->dimension(1);
112 int p = feVel_->cubPts()->dimension(1);
113 int d = feVel_->cubPts()->dimension(2);
114 // Initialize output grad
115 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > G(d+2);
116 for (int i = 0; i < d; ++i) {
117 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
118 }
119 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
120 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
121 // Get components of the control
122 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U;
123 fieldHelper_->splitFieldCoeff(U, u_coeff);
124 // Evaluate on FE basis
125 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > gradU_vec(d);
126 for (int i = 0; i < d; ++i) {
127 gradU_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
128 feVel_->evaluateGradient(gradU_vec[i], U[i]);
129 }
130 // Compute weighted curl
131 int size = (d==2) ? 1 : d;
132 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > curlU_vec(size);
133 if (d==2) {
134 curlU_vec[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
135 for (int i = 0; i < c; ++i) {
136 for (int j = 0; j < p; ++j) {
137 (*curlU_vec[0])(i,j) = (*weight_)(i,j)
138 * ((*gradU_vec[1])(i,j,0) - (*gradU_vec[0])(i,j,1));
139 }
140 }
141 }
142 else if (d==3) {
143 for (int i = 0; i < d; ++i) {
144 curlU_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
145 for (int j = 0; j < c; ++j) {
146 for (int k = 0; k < p; ++k) {
147 int i1 = (i+2)%d, i2 = (i+1)%d;
148 (*curlU_vec[i])(j,k) = (*weight_)(j,k)
149 * ((*gradU_vec[i1])(j,k,i2) - (*gradU_vec[i2])(j,k,i1));
150 }
151 }
152 }
153 }
154 // Build local gradient of state tracking term
155 if (d==2) {
156 Intrepid::FunctionSpaceTools::integrate<Real>(*G[0],
157 *curlU_vec[0],
158 *(feVel_->DNDdetJ(1)),
159 Intrepid::COMP_CPP, false);
160 Intrepid::RealSpaceTools<Real>::scale(*G[0],static_cast<Real>(-1));
161 Intrepid::FunctionSpaceTools::integrate<Real>(*G[1],
162 *curlU_vec[0],
163 *(feVel_->DNDdetJ(0)),
164 Intrepid::COMP_CPP, false);
165 }
166 else if (d==3) {
167 for (int i = 0; i < d; ++i) {
168 int i1 = (i+2)%d, i2 = (i+1)%d;
169 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
170 *curlU_vec[i1],
171 *(feVel_->DNDdetJ(i2)),
172 Intrepid::COMP_CPP, false);
173 Intrepid::RealSpaceTools<Real>::scale(*G[i],static_cast<Real>(-1));
174 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
175 *curlU_vec[i2],
176 *(feVel_->DNDdetJ(i1)),
177 Intrepid::COMP_CPP, true);
178 }
179 }
180 fieldHelper_->combineFieldCoeff(grad, G);
181 }
182
183 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
184 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
185 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
186 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
187 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::gradient_2 is zero.");
188 }
189
190 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
191 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
192 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
193 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
194 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
195 // Get relevant dimensions
196 int c = z_coeff->dimension(0);
197 int p = feVel_->cubPts()->dimension(1);
198 int fv = feVel_->N()->dimension(1);
199 int fp = fePrs_->N()->dimension(1);
200 int fh = feThr_->N()->dimension(1);
201 int d = feVel_->cubPts()->dimension(2);
202 // Initialize output grad
203 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > H(d+2);
204 for (int i = 0; i < d; ++i) {
205 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
206 }
207 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
208 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
209 // Get components of the control
210 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > V;
211 fieldHelper_->splitFieldCoeff(V, v_coeff);
212 // Evaluate on FE basis
213 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > gradV_vec(d);
214 for (int i = 0; i < d; ++i) {
215 gradV_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
216 feVel_->evaluateGradient(gradV_vec[i], V[i]);
217 }
218 // Compute weighted curl
219 int size = (d==2) ? 1 : d;
220 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > curlV_vec(size);
221 if (d==2) {
222 curlV_vec[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
223 for (int i = 0; i < c; ++i) {
224 for (int j = 0; j < p; ++j) {
225 (*curlV_vec[0])(i,j) = (*weight_)(i,j)
226 * ((*gradV_vec[1])(i,j,0) - (*gradV_vec[0])(i,j,1));
227 }
228 }
229 }
230 else if (d==3) {
231 for (int i = 0; i < d; ++i) {
232 curlV_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
233 for (int j = 0; j < c; ++j) {
234 for (int k = 0; k < p; ++k) {
235 int i1 = (i+2)%d, i2 = (i+1)%d;
236 (*curlV_vec[i])(j,k) = (*weight_)(j,k)
237 * ((*gradV_vec[i1])(j,k,i2) - (*gradV_vec[i2])(j,k,i1));
238 }
239 }
240 }
241 }
242 // Build local gradient of state tracking term
243 if (d==2) {
244 Intrepid::FunctionSpaceTools::integrate<Real>(*H[0],
245 *curlV_vec[0],
246 *(feVel_->DNDdetJ(1)),
247 Intrepid::COMP_CPP, false);
248 Intrepid::RealSpaceTools<Real>::scale(*H[0],static_cast<Real>(-1));
249 Intrepid::FunctionSpaceTools::integrate<Real>(*H[1],
250 *curlV_vec[0],
251 *(feVel_->DNDdetJ(0)),
252 Intrepid::COMP_CPP, false);
253 }
254 else if (d==3) {
255 for (int i = 0; i < d; ++i) {
256 int i1 = (i+2)%d, i2 = (i+1)%d;
257 Intrepid::FunctionSpaceTools::integrate<Real>(*H[i],
258 *curlV_vec[i1],
259 *(feVel_->DNDdetJ(i2)),
260 Intrepid::COMP_CPP, false);
261 Intrepid::RealSpaceTools<Real>::scale(*H[i],static_cast<Real>(-1));
262 Intrepid::FunctionSpaceTools::integrate<Real>(*H[i],
263 *curlV_vec[i2],
264 *(feVel_->DNDdetJ(i1)),
265 Intrepid::COMP_CPP, true);
266 }
267 }
268
269 fieldHelper_->combineFieldCoeff(hess, H);
270 }
271
272 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
273 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
274 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
275 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
276 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
277 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::HessVec_12 is zero.");
278 }
279
280 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
281 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
282 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
283 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
284 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
285 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::HessVec_21 is zero.");
286 }
287
288 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
289 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
290 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
291 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
292 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
293 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::HessVec_22 is zero.");
294 }
295
296 }; // QoI_Vorticity_ThermalFluids
297
298 template <class Real>
299 class QoI_Circulation_ThermalFluids : public QoI<Real> {
300 private:
301 const ROL::Ptr<FE<Real> > feVel_;
302 const ROL::Ptr<FE<Real> > fePrs_;
303 const ROL::Ptr<FE<Real> > feThr_;
304 const ROL::Ptr<FieldHelper<Real> > fieldHelper_;
305 ROL::Ptr<Intrepid::FieldContainer<Real> > weight_;
306
307 Real weightFunc(const std::vector<Real> & x) const {
308 return static_cast<Real>(1);
309 }
310
311 public:
312 QoI_Circulation_ThermalFluids(const ROL::Ptr<FE<Real> > &feVel,
313 const ROL::Ptr<FE<Real> > &fePrs,
314 const ROL::Ptr<FE<Real> > &feThr,
315 const ROL::Ptr<FieldHelper<Real> > &fieldHelper)
316 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
317 int c = feVel_->cubPts()->dimension(0);
318 int p = feVel_->cubPts()->dimension(1);
319 int d = feVel_->cubPts()->dimension(2);
320 std::vector<Real> pt(d);
321 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
322 for (int i = 0; i < c; ++i) {
323 for (int j = 0; j < p; ++j) {
324 for (int k = 0; k < d; ++k) {
325 pt[k] = (*feVel_->cubPts())(i,j,k);
326 }
327 (*weight_)(i,j) = weightFunc(pt);
328 }
329 }
330 }
331
332 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
333 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
334 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
335 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
336 // Get relevant dimensions
337 int c = u_coeff->dimension(0);
338 int p = feVel_->cubPts()->dimension(1);
339 int d = feVel_->cubPts()->dimension(2);
340 // Initialize output val
341 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
342 // Get components of the control
343 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U;
344 fieldHelper_->splitFieldCoeff(U, u_coeff);
345 // Evaluate on FE basis
346 ROL::Ptr<Intrepid::FieldContainer<Real> > gradUX_eval =
347 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
348 ROL::Ptr<Intrepid::FieldContainer<Real> > gradUY_eval =
349 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
350 feVel_->evaluateGradient(gradUX_eval, U[0]);
351 feVel_->evaluateGradient(gradUY_eval, U[1]);
352 // Compute curl
353 ROL::Ptr<Intrepid::FieldContainer<Real> > curlU_eval =
354 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
355 for (int i = 0; i < c; ++i) {
356 for (int j = 0; j < p; ++j) {
357 (*curlU_eval)(i,j) = (*gradUY_eval)(i,j,0) - (*gradUX_eval)(i,j,1);
358 }
359 }
360 // Compute circulation
361 feVel_->computeIntegral(val,curlU_eval,weight_,false);
362 return static_cast<Real>(0);
363 }
364
365 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
366 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
367 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
368 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
369 // Get relevant dimensions
370 int c = u_coeff->dimension(0);
371 int fv = feVel_->N()->dimension(1);
372 int fp = fePrs_->N()->dimension(1);
373 int fh = feThr_->N()->dimension(1);
374 int d = feVel_->cubPts()->dimension(2);
375 // Initialize output grad
376 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > G(d+2);
377 for (int i = 0; i < d; ++i) {
378 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
379 }
380 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
381 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
382 // Build local gradient of state tracking term
383 Intrepid::FunctionSpaceTools::integrate<Real>(*G[0],
384 *weight_,
385 *(feVel_->DNDdetJ(1)),
386 Intrepid::COMP_CPP, false);
387 Intrepid::RealSpaceTools<Real>::scale(*G[0],static_cast<Real>(-1));
388 Intrepid::FunctionSpaceTools::integrate<Real>(*G[1],
389 *weight_,
390 *(feVel_->DNDdetJ(0)),
391 Intrepid::COMP_CPP, false);
392
393 fieldHelper_->combineFieldCoeff(grad, G);
394 }
395
396 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
397 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
398 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
399 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
400 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::gradient_2 is zero.");
401 }
402
403 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
404 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
405 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
406 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
407 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
408 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_11 is zero.");
409 }
410
411 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
412 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
413 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
414 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
415 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
416 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_12 is zero.");
417 }
418
419 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
420 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
421 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
422 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
423 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
424 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_21 is zero.");
425 }
426
427 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
428 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
429 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
430 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
431 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
432 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_22 is zero.");
433 }
434
435 }; // QoI_Circulation_ThermalFluids
436
437 template <class Real>
438 class QoI_Horizontal_ThermalFluids : public QoI<Real> {
439 private:
440 const ROL::Ptr<FE<Real> > feVel_;
441 const ROL::Ptr<FE<Real> > fePrs_;
442 const ROL::Ptr<FE<Real> > feThr_;
443 const ROL::Ptr<FieldHelper<Real> > fieldHelper_;
444 ROL::Ptr<Intrepid::FieldContainer<Real> > weight_;
445
446 Real weightFunc(const std::vector<Real> & x) const {
447 return static_cast<Real>(1);
448 }
449
450 public:
451 QoI_Horizontal_ThermalFluids(const ROL::Ptr<FE<Real> > &feVel,
452 const ROL::Ptr<FE<Real> > &fePrs,
453 const ROL::Ptr<FE<Real> > &feThr,
454 const ROL::Ptr<FieldHelper<Real> > &fieldHelper)
455 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
456 int c = feVel_->cubPts()->dimension(0);
457 int p = feVel_->cubPts()->dimension(1);
458 int d = feVel_->cubPts()->dimension(2);
459 std::vector<Real> pt(d);
460 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
461 for (int i = 0; i < c; ++i) {
462 for (int j = 0; j < p; ++j) {
463 for (int k = 0; k < d; ++k) {
464 pt[k] = (*feVel_->cubPts())(i,j,k);
465 }
466 (*weight_)(i,j) = weightFunc(pt);
467 }
468 }
469 }
470
471 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
472 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
473 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
474 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
475 // Get relevant dimensions
476 int c = u_coeff->dimension(0);
477 int p = feVel_->cubPts()->dimension(1);
478 // Initialize output val
479 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
480 // Get components of the control
481 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U;
482 fieldHelper_->splitFieldCoeff(U, u_coeff);
483 // Evaluate on FE basis
484 ROL::Ptr<Intrepid::FieldContainer<Real> > valUX_eval =
485 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
486 ROL::Ptr<Intrepid::FieldContainer<Real> > valUY_eval =
487 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
488 feVel_->evaluateValue(valUX_eval, U[0]);
489 feVel_->evaluateValue(valUY_eval, U[1]);
490 // Compute negative part of x-velocity
491 ROL::Ptr<Intrepid::FieldContainer<Real> > minUX_eval =
492 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
493 for (int i = 0; i < c; ++i) {
494 for (int j = 0; j < p; ++j) {
495 (*minUX_eval)(i,j) = std::min(static_cast<Real>(0),(*valUX_eval)(i,j));
496 }
497 }
498 // Multiply by weight
499 ROL::Ptr<Intrepid::FieldContainer<Real> > weighted_minUX_eval =
500 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
501 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*weighted_minUX_eval,
502 *weight_,
503 *minUX_eval);
504 ROL::Ptr<Intrepid::FieldContainer<Real> > weighted_valUY_eval =
505 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
506 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*weighted_valUY_eval,
507 *weight_,
508 *valUY_eval);
509 // Compute L2 norm squared
510 feVel_->computeIntegral(val,minUX_eval,weighted_minUX_eval,false);
511 feVel_->computeIntegral(val,valUY_eval,weighted_valUY_eval,true);
512
513 Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5));
514 return static_cast<Real>(0);
515 }
516
517 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
518 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
519 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
520 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
521 // Get relevant dimensions
522 int c = u_coeff->dimension(0);
523 int fv = feVel_->N()->dimension(1);
524 int fp = fePrs_->N()->dimension(1);
525 int fh = feThr_->N()->dimension(1);
526 int p = feVel_->cubPts()->dimension(1);
527 int d = feVel_->cubPts()->dimension(2);
528 // Initialize output grad
529 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > G(d+2);
530 for (int i = 0; i < d; ++i) {
531 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
532 }
533 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
534 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
535 // Get components of the control
536 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U;
537 fieldHelper_->splitFieldCoeff(U, u_coeff);
538 // Evaluate on FE basis
539 ROL::Ptr<Intrepid::FieldContainer<Real> > valUX_eval =
540 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
541 ROL::Ptr<Intrepid::FieldContainer<Real> > valUY_eval =
542 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
543 feVel_->evaluateValue(valUX_eval, U[0]);
544 feVel_->evaluateValue(valUY_eval, U[1]);
545 // Compute negative part of x-velocity
546 ROL::Ptr<Intrepid::FieldContainer<Real> > weighted_minUX_eval =
547 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
548 ROL::Ptr<Intrepid::FieldContainer<Real> > weighted_valUY_eval =
549 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
550 for (int i = 0; i < c; ++i) {
551 for (int j = 0; j < p; ++j) {
552 (*weighted_minUX_eval)(i,j)
553 = (*weight_)(i,j) * std::min(static_cast<Real>(0),(*valUX_eval)(i,j));
554 (*weighted_valUY_eval)(i,j)
555 = (*weight_)(i,j) * (*valUY_eval)(i,j);
556 }
557 }
558 // Build local gradient of state tracking term
559 Intrepid::FunctionSpaceTools::integrate<Real>(*G[0],
560 *weighted_minUX_eval,
561 *(feVel_->NdetJ()),
562 Intrepid::COMP_CPP, false);
563 Intrepid::FunctionSpaceTools::integrate<Real>(*G[1],
564 *weighted_valUY_eval,
565 *(feVel_->NdetJ()),
566 Intrepid::COMP_CPP, false);
567
568 fieldHelper_->combineFieldCoeff(grad, G);
569 }
570
571 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
572 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
573 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
574 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
575 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::gradient_2 is zero.");
576 }
577
578 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
579 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
580 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
581 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
582 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
583 // Get relevant dimensions
584 int c = z_coeff->dimension(0);
585 int p = feVel_->cubPts()->dimension(1);
586 int fv = feVel_->N()->dimension(1);
587 int fp = fePrs_->N()->dimension(1);
588 int fh = feThr_->N()->dimension(1);
589 int d = feVel_->cubPts()->dimension(2);
590 // Initialize output grad
591 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > H(d+2);
592 for (int i = 0; i < d; ++i) {
593 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
594 }
595 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
596 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
597 // Get components of the control
598 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > U;
599 fieldHelper_->splitFieldCoeff(U, u_coeff);
600 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > V;
601 fieldHelper_->splitFieldCoeff(V, v_coeff);
602 // Evaluate on FE basis
603 ROL::Ptr<Intrepid::FieldContainer<Real> > valUX_eval =
604 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
605 ROL::Ptr<Intrepid::FieldContainer<Real> > valVX_eval =
606 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
607 ROL::Ptr<Intrepid::FieldContainer<Real> > valVY_eval =
608 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
609 feVel_->evaluateValue(valUX_eval, U[0]);
610 feVel_->evaluateValue(valVX_eval, V[0]);
611 feVel_->evaluateValue(valVY_eval, V[1]);
612 // Compute negative part of x-velocity
613 ROL::Ptr<Intrepid::FieldContainer<Real> > weighted_minVX_eval =
614 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
615 ROL::Ptr<Intrepid::FieldContainer<Real> > weighted_valVY_eval =
616 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
617 Real scale(0);
618 for (int i = 0; i < c; ++i) {
619 for (int j = 0; j < p; ++j) {
620 if ( (*valUX_eval)(i,j) < static_cast<Real>(0) ) {
621 scale = static_cast<Real>(1);
622 }
623 else if ( (*valUX_eval)(i,j) > static_cast<Real>(0) ) {
624 scale = static_cast<Real>(0);
625 }
626 else {
627 //scale = static_cast<Real>(0);
628 //scale = static_cast<Real>(0.5);
629 scale = static_cast<Real>(1);
630 }
631 (*weighted_minVX_eval)(i,j)
632 = scale * (*weight_)(i,j) * (*valVX_eval)(i,j);
633 (*weighted_valVY_eval)(i,j)
634 = (*weight_)(i,j) * (*valVY_eval)(i,j);
635 }
636 }
637 // Build local gradient of state tracking term
638 Intrepid::FunctionSpaceTools::integrate<Real>(*H[0],
639 *weighted_minVX_eval,
640 *(feVel_->NdetJ()),
641 Intrepid::COMP_CPP, false);
642 Intrepid::FunctionSpaceTools::integrate<Real>(*H[1],
643 *weighted_valVY_eval,
644 *(feVel_->NdetJ()),
645 Intrepid::COMP_CPP, false);
646
647 fieldHelper_->combineFieldCoeff(hess, H);
648 }
649
650 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
651 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
652 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
653 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
654 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
655 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::HessVec_12 is zero.");
656 }
657
658 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
659 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
660 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
661 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
662 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
663 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::HessVec_21 is zero.");
664 }
665
666 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
667 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
668 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
669 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
670 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
671 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::HessVec_22 is zero.");
672 }
673
674 }; // QoI_Horizontal_ThermalFluids
675
676 template <class Real>
677 class QoI_State_ThermalFluids : public QoI<Real> {
678 private:
679 ROL::Ptr<QoI<Real> > qoi_;
680
681 public:
682 QoI_State_ThermalFluids(Teuchos::ParameterList &parlist,
683 const ROL::Ptr<FE<Real> > &feVel,
684 const ROL::Ptr<FE<Real> > &fePrs,
685 const ROL::Ptr<FE<Real> > &feThr,
686 const ROL::Ptr<FieldHelper<Real> > &fieldHelper) {
687 std::string stateObj = parlist.sublist("Problem").get("Objective type","Vorticity");
688 if ( stateObj != "Vorticity" && stateObj != "Circulation" && stateObj != "Directional" ) {
689 throw Exception::NotImplemented(">>> (QoI_State_ThermalFluids): Unknown objective type.");
690 }
691 if ( stateObj == "Vorticity" ) {
692 qoi_ = ROL::makePtr<QoI_Vorticity_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper,parlist);
693 }
694 else if ( stateObj == "Directional" ) {
695 qoi_ = ROL::makePtr<QoI_Horizontal_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper);
696 }
697 else {
698 qoi_ = ROL::makePtr<QoI_Circulation_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper);
699 }
700 }
701
702 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
703 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
704 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
705 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
706 return qoi_->value(val, u_coeff, z_coeff, z_param);
707 }
708
709 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
710 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
711 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
712 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
713 qoi_->gradient_1(grad, u_coeff, z_coeff, z_param);
714 }
715
716 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
717 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
718 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
719 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
720 qoi_->gradient_2(grad, u_coeff, z_coeff, z_param);
721 }
722
723 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
724 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
725 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
726 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
727 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
728 qoi_->HessVec_11(hess, v_coeff, u_coeff, z_coeff, z_param);
729 }
730
731 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
732 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
733 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
734 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
735 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
736 qoi_->HessVec_12(hess, v_coeff, u_coeff, z_coeff, z_param);
737 }
738
739 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
740 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
741 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
742 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
743 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
744 qoi_->HessVec_21(hess, v_coeff, u_coeff, z_coeff, z_param);
745 }
746
747 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
748 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
749 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
750 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
751 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
752 qoi_->HessVec_22(hess, v_coeff, u_coeff, z_coeff, z_param);
753 }
754
755 };
756
757 template <class Real>
758 class QoI_L2Penalty_ThermalFluids : public QoI<Real> {
759 private:
760 const ROL::Ptr<FE<Real> > feVel_;
761 const ROL::Ptr<FE<Real> > fePrs_;
762 const ROL::Ptr<FE<Real> > feThr_;
763 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > feThrBdry_;
764 const std::vector<std::vector<std::vector<int> > > bdryCellLocIds_;
765 const ROL::Ptr<FieldHelper<Real> > fieldHelper_;
766
767 ROL::Ptr<Intrepid::FieldContainer<Real> > getBoundaryCoeff(
768 const Intrepid::FieldContainer<Real> & cell_coeff,
769 int sideSet, int cell) const {
770 std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][cell];
771 const int numCellsSide = bdryCellLocId.size();
772 const int f = feThr_->N()->dimension(1);
773
774 ROL::Ptr<Intrepid::FieldContainer<Real > > bdry_coeff =
775 ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f);
776 for (int i = 0; i < numCellsSide; ++i) {
777 for (int j = 0; j < f; ++j) {
778 (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j);
779 }
780 }
781 return bdry_coeff;
782 }
783
784 public:
785 QoI_L2Penalty_ThermalFluids(const ROL::Ptr<FE<Real> > &feVel,
786 const ROL::Ptr<FE<Real> > &fePrs,
787 const ROL::Ptr<FE<Real> > &feThr,
788 const std::vector<std::vector<ROL::Ptr<FE<Real> > > > &feThrBdry,
789 const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds,
790 const ROL::Ptr<FieldHelper<Real> > &fieldHelper)
791 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), feThrBdry_(feThrBdry),
792 bdryCellLocIds_(bdryCellLocIds), fieldHelper_(fieldHelper) {}
793
794 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
795 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
796 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
797 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
798 const int c = feVel_->gradN()->dimension(0);
799 const int d = feVel_->gradN()->dimension(3);
800 // Get components of the control
801 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > Z;
802 fieldHelper_->splitFieldCoeff(Z, z_coeff);
803 // Initialize output val
804 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
805 // Compute cost integral
806 const int numSideSets = bdryCellLocIds_.size();
807 if (numSideSets > 0) {
808 for (int i = 0; i < numSideSets; ++i) {
809 if ( i == 1 || i == 2 ) {
810 const int numLocalSideIds = bdryCellLocIds_[i].size();
811 for (int j = 0; j < numLocalSideIds; ++j) {
812 const int numCellsSide = bdryCellLocIds_[i][j].size();
813 if ( numCellsSide ) {
814 const int numCubPerSide = feThrBdry_[i][j]->cubPts()->dimension(1);
815 // Evaluate control on FE basis
816 ROL::Ptr<Intrepid::FieldContainer<Real> > z_coeff_bdry
817 = getBoundaryCoeff(*Z[d+1], i, j);
818 ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval
819 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
820 feThrBdry_[i][j]->evaluateValue(valZ_eval, z_coeff_bdry);
821 // Integrate cell L2 norm squared
822 ROL::Ptr<Intrepid::FieldContainer<Real> > intVal
823 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide);
824 feThrBdry_[i][j]->computeIntegral(intVal,valZ_eval,valZ_eval,false);
825 // Add to integral value
826 for (int k = 0; k < numCellsSide; ++k) {
827 int cidx = bdryCellLocIds_[i][j][k];
828 (*val)(cidx) += static_cast<Real>(0.5)*(*intVal)(k);
829 }
830 }
831 }
832 }
833 }
834 }
835 return static_cast<Real>(0);
836 }
837
838 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
839 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
840 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
841 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
842 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::gradient_1 is zero.");
843 }
844
845 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
846 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
847 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
848 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
849 const int c = feVel_->gradN()->dimension(0);
850 const int fv = feVel_->gradN()->dimension(1);
851 const int fp = fePrs_->gradN()->dimension(1);
852 const int fh = feThr_->gradN()->dimension(1);
853 const int d = feThr_->gradN()->dimension(3);
854 // Initialize output grad
855 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > G(d+2);
856 for (int i = 0; i < d; ++i) {
857 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
858 }
859 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
860 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
861 // Get components of the control
862 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > Z;
863 fieldHelper_->splitFieldCoeff(Z, z_coeff);
864 // Compute cost integral
865 const int numSideSets = bdryCellLocIds_.size();
866 if (numSideSets > 0) {
867 for (int i = 0; i < numSideSets; ++i) {
868 if ( i == 1 || i == 2 ) {
869 const int numLocalSideIds = bdryCellLocIds_[i].size();
870 for (int j = 0; j < numLocalSideIds; ++j) {
871 const int numCellsSide = bdryCellLocIds_[i][j].size();
872 if ( numCellsSide ) {
873 const int numCubPerSide = feThrBdry_[i][j]->cubPts()->dimension(1);
874 // Evaluate control on FE basis
875 ROL::Ptr<Intrepid::FieldContainer<Real> > z_coeff_bdry
876 = getBoundaryCoeff(*Z[d+1], i, j);
877 ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval
878 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
879 feThrBdry_[i][j]->evaluateValue(valZ_eval, z_coeff_bdry);
880 // Compute gradient of squared L2-norm of diff
881 ROL::Ptr<Intrepid::FieldContainer<Real> > intGrad
882 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fh);
883 Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad,
884 *valZ_eval,
885 *(feThrBdry_[i][j]->NdetJ()),
886 Intrepid::COMP_CPP, false);
887 // Add to integral value
888 for (int k = 0; k < numCellsSide; ++k) {
889 int cidx = bdryCellLocIds_[i][j][k];
890 for (int l = 0; l < fh; ++l) {
891 (*G[d+1])(cidx,l) += (*intGrad)(k,l);
892 }
893 }
894 }
895 }
896 }
897 }
898 }
899
900 fieldHelper_->combineFieldCoeff(grad, G);
901 }
902
903 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
904 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
905 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
906 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
907 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
908 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::HessVec_11 is zero.");
909 }
910
911 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
912 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
913 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
914 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
915 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
916 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::HessVec_12 is zero.");
917 }
918
919 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
920 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
921 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
922 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
923 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
924 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::HessVec_21 is zero.");
925 }
926
927 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
928 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
929 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
930 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
931 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
932 const int c = feVel_->gradN()->dimension(0);
933 const int fv = feVel_->gradN()->dimension(1);
934 const int fp = fePrs_->gradN()->dimension(1);
935 const int fh = feThr_->gradN()->dimension(1);
936 const int d = feThr_->gradN()->dimension(3);
937 // Initialize output grad
938 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > H(d+2);
939 for (int i = 0; i < d; ++i) {
940 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
941 }
942 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
943 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
944 // Get components of the control
945 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > V;
946 fieldHelper_->splitFieldCoeff(V, v_coeff);
947 // Compute cost integral
948 const int numSideSets = bdryCellLocIds_.size();
949 if (numSideSets > 0) {
950 for (int i = 0; i < numSideSets; ++i) {
951 if ( i == 1 || i == 2 ) {
952 const int numLocalSideIds = bdryCellLocIds_[i].size();
953 for (int j = 0; j < numLocalSideIds; ++j) {
954 const int numCellsSide = bdryCellLocIds_[i][j].size();
955 if ( numCellsSide ) {
956 const int numCubPerSide = feThrBdry_[i][j]->cubPts()->dimension(1);
957 // Evaluate control on FE basis
958 ROL::Ptr<Intrepid::FieldContainer<Real> > v_coeff_bdry
959 = getBoundaryCoeff(*V[d+1], i, j);
960 ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval
961 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
962 feThrBdry_[i][j]->evaluateValue(valV_eval, v_coeff_bdry);
963 // Compute gradient of squared L2-norm of diff
964 ROL::Ptr<Intrepid::FieldContainer<Real> > intHess
965 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fh);
966 Intrepid::FunctionSpaceTools::integrate<Real>(*intHess,
967 *valV_eval,
968 *(feThrBdry_[i][j]->NdetJ()),
969 Intrepid::COMP_CPP, false);
970 // Add to integral value
971 for (int k = 0; k < numCellsSide; ++k) {
972 int cidx = bdryCellLocIds_[i][j][k];
973 for (int l = 0; l < fh; ++l) {
974 (*H[d+1])(cidx,l) += (*intHess)(k,l);
975 }
976 }
977 }
978 }
979 }
980 }
981 }
982
983 fieldHelper_->combineFieldCoeff(hess, H);
984 }
985
986 }; // QoI_L2Penalty_ThermalFluids
987
988 template <class Real>
989 class StdObjective_ThermalFluids : public ROL::StdObjective<Real> {
990 private:
991 Real alpha_;
992 std::string stateObj_;
993
994 public:
995 StdObjective_ThermalFluids(Teuchos::ParameterList &parlist) {
996 alpha_ = parlist.sublist("Problem").get("Control penalty parameter",1.e-4);
997 stateObj_ = parlist.sublist("Problem").get("Objective type","Vorticity");
998 if ( stateObj_ != "Vorticity" && stateObj_ != "Circulation" && stateObj_ != "Directional") {
999 throw Exception::NotImplemented(">>> (StdObjective_ThermalFluids): Unknown objective type.");
1000 }
1001 }
1002
1003 Real value(const std::vector<Real> &x, Real &tol) {
1004 Real val = alpha_*x[1];
1005 if ( stateObj_ == "Vorticity" || stateObj_ == "Directional" ) {
1006 val += x[0];
1007 }
1008 else {
1009 val += static_cast<Real>(0.5)*x[0]*x[0];
1010 }
1011 return val;
1012 }
1013
1014 void gradient(std::vector<Real> &g, const std::vector<Real> &x, Real &tol) {
1015 const Real one(1);
1016 if ( stateObj_ == "Vorticity" || stateObj_ == "Directional" ) {
1017 g[0] = one;
1018 }
1019 else {
1020 g[0] = x[0];
1021 }
1022 g[1] = alpha_;
1023 }
1024
1025 void hessVec(std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol) {
1026 const Real zero(0);
1027 if ( stateObj_ == "Vorticity" || stateObj_ == "Directional" ) {
1028 hv[0] = zero;
1029 }
1030 else {
1031 hv[0] = v[0];
1032 }
1033 hv[1] = zero;
1034 }
1035
1036 }; // OBJ_SCALAR
1037
1038 #endif