Debian Codegraph @

packages/rol/example/PDE-OPT/dynamic/thermal-fluids/obj_thermal-fluids.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 DYNAMIC_PDEOPT_QOI_THERMALFLUIDS_HPP
15 #define DYNAMIC_PDEOPT_QOI_THERMALFLUIDS_HPP
16
17 #include "../../TOOLS/qoi.hpp"
18 #include "pde_thermal-fluids.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 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
39 int c = feVel_->cubPts()->dimension(0);
40 int p = feVel_->cubPts()->dimension(1);
41 int d = feVel_->cubPts()->dimension(2);
42 std::vector<Real> pt(d);
43 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
44 for (int i = 0; i < c; ++i) {
45 for (int j = 0; j < p; ++j) {
46 for (int k = 0; k < d; ++k) {
47 pt[k] = (*feVel_->cubPts())(i,j,k);
48 }
49 (*weight_)(i,j) = weightFunc(pt);
50 }
51 }
52 }
53
54 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
55 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
56 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
57 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
58 // Get relevant dimensions
59 int c = feVel_->cubPts()->dimension(0);
60 int p = feVel_->cubPts()->dimension(1);
61 int d = feVel_->cubPts()->dimension(2);
62 // Initialize output val
63 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
64 // Get components of the control
65 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
66 fieldHelper_->splitFieldCoeff(U, u_coeff);
67 // Evaluate on FE basis
68 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradU_vec(d);
69 for (int i = 0; i < d; ++i) {
70 gradU_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
71 feVel_->evaluateGradient(gradU_vec[i], U[i]);
72 }
73 // Compute weighted curl
74 ROL::Ptr<Intrepid::FieldContainer<Real>> curlU_eval;
75 if (d==2) {
76 curlU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
77 }
78 else if (d==3) {
79 curlU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
80 }
81 for (int i = 0; i < c; ++i) {
82 for (int j = 0; j < p; ++j) {
83 if (d==2) {
84 (*curlU_eval)(i,j) = (*weight_)(i,j)
85 * ((*gradU_vec[1])(i,j,0) - (*gradU_vec[0])(i,j,1));
86 }
87 else if (d==3) {
88 for (int k = 0; k < d; ++k) {
89 int i1 = (k+2)%d, i2 = (k+1)%d;
90 (*curlU_eval)(i,j,k) = (*weight_)(i,j)
91 * ((*gradU_vec[i1])(i,j,i2) - (*gradU_vec[i2])(i,j,i1));
92 }
93 }
94 }
95 }
96 // Compute L2 norm squared
97 feVel_->computeIntegral(val,curlU_eval,curlU_eval,false);
98 Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5));
99 return static_cast<Real>(0);
100 }
101
102 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
103 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
104 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
105 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
106 // Get relevant dimensions
107 int c = feVel_->gradN()->dimension(0);
108 int fv = feVel_->gradN()->dimension(1);
109 int fp = fePrs_->gradN()->dimension(1);
110 int fh = feThr_->gradN()->dimension(1);
111 int p = feVel_->gradN()->dimension(2);
112 int d = feVel_->gradN()->dimension(3);
113 // Initialize output grad
114 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2);
115 for (int i = 0; i < d; ++i) {
116 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
117 }
118 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
119 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
120 // Get components of the control
121 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
122 fieldHelper_->splitFieldCoeff(U, u_coeff);
123 // Evaluate on FE basis
124 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradU_vec(d);
125 for (int i = 0; i < d; ++i) {
126 gradU_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
127 feVel_->evaluateGradient(gradU_vec[i], U[i]);
128 }
129 // Compute weighted curl
130 int size = (d==2) ? 1 : d;
131 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> curlU_vec(size);
132 if (d==2) {
133 curlU_vec[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
134 for (int i = 0; i < c; ++i) {
135 for (int j = 0; j < p; ++j) {
136 (*curlU_vec[0])(i,j) = (*weight_)(i,j)
137 * ((*gradU_vec[1])(i,j,0) - (*gradU_vec[0])(i,j,1));
138 }
139 }
140 }
141 else if (d==3) {
142 for (int i = 0; i < d; ++i) {
143 curlU_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
144 for (int j = 0; j < c; ++j) {
145 for (int k = 0; k < p; ++k) {
146 int i1 = (i+2)%d, i2 = (i+1)%d;
147 (*curlU_vec[i])(j,k) = (*weight_)(j,k)
148 * ((*gradU_vec[i1])(j,k,i2) - (*gradU_vec[i2])(j,k,i1));
149 }
150 }
151 }
152 }
153 // Build local gradient of state tracking term
154 if (d==2) {
155 Intrepid::FunctionSpaceTools::integrate<Real>(*G[0],
156 *curlU_vec[0],
157 *(feVel_->DNDdetJ(1)),
158 Intrepid::COMP_CPP, false);
159 Intrepid::RealSpaceTools<Real>::scale(*G[0],static_cast<Real>(-1));
160 Intrepid::FunctionSpaceTools::integrate<Real>(*G[1],
161 *curlU_vec[0],
162 *(feVel_->DNDdetJ(0)),
163 Intrepid::COMP_CPP, false);
164 }
165 else if (d==3) {
166 for (int i = 0; i < d; ++i) {
167 int i1 = (i+2)%d, i2 = (i+1)%d;
168 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
169 *curlU_vec[i1],
170 *(feVel_->DNDdetJ(i2)),
171 Intrepid::COMP_CPP, false);
172 Intrepid::RealSpaceTools<Real>::scale(*G[i],static_cast<Real>(-1));
173 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
174 *curlU_vec[i2],
175 *(feVel_->DNDdetJ(i1)),
176 Intrepid::COMP_CPP, true);
177 }
178 }
179 fieldHelper_->combineFieldCoeff(grad, G);
180 }
181
182 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
183 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
184 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
185 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
186 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::gradient_2 is zero.");
187 }
188
189 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
190 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
191 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
192 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
193 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
194 // Get relevant dimensions
195 int c = feVel_->gradN()->dimension(0);
196 int fv = feVel_->gradN()->dimension(1);
197 int fp = fePrs_->gradN()->dimension(1);
198 int fh = feThr_->gradN()->dimension(1);
199 int p = feVel_->gradN()->dimension(2);
200 int d = feVel_->gradN()->dimension(3);
201 // Initialize output grad
202 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2);
203 for (int i = 0; i < d; ++i) {
204 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
205 }
206 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
207 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
208 // Get components of the control
209 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V;
210 fieldHelper_->splitFieldCoeff(V, v_coeff);
211 // Evaluate on FE basis
212 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradV_vec(d);
213 for (int i = 0; i < d; ++i) {
214 gradV_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
215 feVel_->evaluateGradient(gradV_vec[i], V[i]);
216 }
217 // Compute weighted curl
218 int size = (d==2) ? 1 : d;
219 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> curlV_vec(size);
220 if (d==2) {
221 curlV_vec[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
222 for (int i = 0; i < c; ++i) {
223 for (int j = 0; j < p; ++j) {
224 (*curlV_vec[0])(i,j) = (*weight_)(i,j)
225 * ((*gradV_vec[1])(i,j,0) - (*gradV_vec[0])(i,j,1));
226 }
227 }
228 }
229 else if (d==3) {
230 for (int i = 0; i < d; ++i) {
231 curlV_vec[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
232 for (int j = 0; j < c; ++j) {
233 for (int k = 0; k < p; ++k) {
234 int i1 = (i+2)%d, i2 = (i+1)%d;
235 (*curlV_vec[i])(j,k) = (*weight_)(j,k)
236 * ((*gradV_vec[i1])(j,k,i2) - (*gradV_vec[i2])(j,k,i1));
237 }
238 }
239 }
240 }
241 // Build local gradient of state tracking term
242 if (d==2) {
243 Intrepid::FunctionSpaceTools::integrate<Real>(*H[0],
244 *curlV_vec[0],
245 *(feVel_->DNDdetJ(1)),
246 Intrepid::COMP_CPP, false);
247 Intrepid::RealSpaceTools<Real>::scale(*H[0],static_cast<Real>(-1));
248 Intrepid::FunctionSpaceTools::integrate<Real>(*H[1],
249 *curlV_vec[0],
250 *(feVel_->DNDdetJ(0)),
251 Intrepid::COMP_CPP, false);
252 }
253 else if (d==3) {
254 for (int i = 0; i < d; ++i) {
255 int i1 = (i+2)%d, i2 = (i+1)%d;
256 Intrepid::FunctionSpaceTools::integrate<Real>(*H[i],
257 *curlV_vec[i1],
258 *(feVel_->DNDdetJ(i2)),
259 Intrepid::COMP_CPP, false);
260 Intrepid::RealSpaceTools<Real>::scale(*H[i],static_cast<Real>(-1));
261 Intrepid::FunctionSpaceTools::integrate<Real>(*H[i],
262 *curlV_vec[i2],
263 *(feVel_->DNDdetJ(i1)),
264 Intrepid::COMP_CPP, true);
265 }
266 }
267
268 fieldHelper_->combineFieldCoeff(hess, H);
269 }
270
271 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
272 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
273 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
274 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
275 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
276 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::HessVec_12 is zero.");
277 }
278
279 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
280 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
281 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
282 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
283 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
284 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::HessVec_21 is zero.");
285 }
286
287 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
288 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
289 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
290 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
291 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
292 throw Exception::Zero(">>> QoI_Vorticity_ThermalFluids::HessVec_22 is zero.");
293 }
294
295 }; // QoI_Vorticity_ThermalFluids
296
297 template <class Real>
298 class QoI_Circulation_ThermalFluids : public QoI<Real> {
299 private:
300 const ROL::Ptr<FE<Real>> feVel_;
301 const ROL::Ptr<FE<Real>> fePrs_;
302 const ROL::Ptr<FE<Real>> feThr_;
303 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
304 ROL::Ptr<Intrepid::FieldContainer<Real>> weight_;
305
306 Real weightFunc(const std::vector<Real> & x) const {
307 return static_cast<Real>(1);
308 }
309
310 public:
311 QoI_Circulation_ThermalFluids(const ROL::Ptr<FE<Real>> &feVel,
312 const ROL::Ptr<FE<Real>> &fePrs,
313 const ROL::Ptr<FE<Real>> &feThr,
314 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
315 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
316 int c = feVel_->cubPts()->dimension(0);
317 int p = feVel_->cubPts()->dimension(1);
318 int d = feVel_->cubPts()->dimension(2);
319 std::vector<Real> pt(d);
320 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
321 for (int i = 0; i < c; ++i) {
322 for (int j = 0; j < p; ++j) {
323 for (int k = 0; k < d; ++k) {
324 pt[k] = (*feVel_->cubPts())(i,j,k);
325 }
326 (*weight_)(i,j) = weightFunc(pt);
327 }
328 }
329 }
330
331 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
332 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
333 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
334 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
335 // Get relevant dimensions
336 int c = feVel_->cubPts()->dimension(0);
337 int p = feVel_->cubPts()->dimension(1);
338 int d = feVel_->cubPts()->dimension(2);
339 // Initialize output val
340 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
341 // Get components of the control
342 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
343 fieldHelper_->splitFieldCoeff(U, u_coeff);
344 // Evaluate on FE basis
345 ROL::Ptr<Intrepid::FieldContainer<Real>> gradUX_eval =
346 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
347 ROL::Ptr<Intrepid::FieldContainer<Real>> gradUY_eval =
348 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
349 feVel_->evaluateGradient(gradUX_eval, U[0]);
350 feVel_->evaluateGradient(gradUY_eval, U[1]);
351 // Compute curl
352 ROL::Ptr<Intrepid::FieldContainer<Real>> curlU_eval =
353 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
354 for (int i = 0; i < c; ++i) {
355 for (int j = 0; j < p; ++j) {
356 (*curlU_eval)(i,j) = (*gradUY_eval)(i,j,0) - (*gradUX_eval)(i,j,1);
357 }
358 }
359 // Compute circulation
360 feVel_->computeIntegral(val,curlU_eval,weight_,false);
361 return static_cast<Real>(0);
362 }
363
364 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
365 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
366 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
367 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
368 // Get relevant dimensions
369 int c = feVel_->gradN()->dimension(0);
370 int fv = feVel_->gradN()->dimension(1);
371 int fp = fePrs_->gradN()->dimension(1);
372 int fh = feThr_->gradN()->dimension(1);
373 int d = feVel_->gradN()->dimension(3);
374 // Initialize output grad
375 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2);
376 for (int i = 0; i < d; ++i) {
377 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
378 }
379 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
380 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
381 // Build local gradient of state tracking term
382 Intrepid::FunctionSpaceTools::integrate<Real>(*G[0],
383 *weight_,
384 *(feVel_->DNDdetJ(1)),
385 Intrepid::COMP_CPP, false);
386 Intrepid::RealSpaceTools<Real>::scale(*G[0],static_cast<Real>(-1));
387 Intrepid::FunctionSpaceTools::integrate<Real>(*G[1],
388 *weight_,
389 *(feVel_->DNDdetJ(0)),
390 Intrepid::COMP_CPP, false);
391
392 fieldHelper_->combineFieldCoeff(grad, G);
393 }
394
395 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
396 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
397 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
398 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
399 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::gradient_2 is zero.");
400 }
401
402 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
403 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
404 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
405 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
406 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
407 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_11 is zero.");
408 }
409
410 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
411 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
412 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
413 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
414 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
415 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_12 is zero.");
416 }
417
418 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
419 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
420 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
421 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
422 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
423 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_21 is zero.");
424 }
425
426 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
427 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
428 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
429 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
430 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
431 throw Exception::Zero(">>> QoI_Circulation_ThermalFluids::HessVec_22 is zero.");
432 }
433
434 }; // QoI_Circulation_ThermalFluids
435
436 template <class Real>
437 class QoI_Horizontal_ThermalFluids : public QoI<Real> {
438 private:
439 const ROL::Ptr<FE<Real>> feVel_;
440 const ROL::Ptr<FE<Real>> fePrs_;
441 const ROL::Ptr<FE<Real>> feThr_;
442 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
443 ROL::Ptr<Intrepid::FieldContainer<Real>> weight_;
444
445 Real weightFunc(const std::vector<Real> & x) const {
446 return static_cast<Real>(1);
447 }
448
449 public:
450 QoI_Horizontal_ThermalFluids(const ROL::Ptr<FE<Real>> &feVel,
451 const ROL::Ptr<FE<Real>> &fePrs,
452 const ROL::Ptr<FE<Real>> &feThr,
453 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
454 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
455 int c = feVel_->cubPts()->dimension(0);
456 int p = feVel_->cubPts()->dimension(1);
457 int d = feVel_->cubPts()->dimension(2);
458 std::vector<Real> pt(d);
459 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
460 for (int i = 0; i < c; ++i) {
461 for (int j = 0; j < p; ++j) {
462 for (int k = 0; k < d; ++k) {
463 pt[k] = (*feVel_->cubPts())(i,j,k);
464 }
465 (*weight_)(i,j) = weightFunc(pt);
466 }
467 }
468 }
469
470 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
471 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
472 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
473 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
474 // Get relevant dimensions
475 int c = feVel_->cubPts()->dimension(0);
476 int p = feVel_->cubPts()->dimension(1);
477 // Initialize output val
478 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
479 // Get components of the control
480 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
481 fieldHelper_->splitFieldCoeff(U, u_coeff);
482 // Evaluate on FE basis
483 ROL::Ptr<Intrepid::FieldContainer<Real>> valUX_eval =
484 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
485 ROL::Ptr<Intrepid::FieldContainer<Real>> valUY_eval =
486 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
487 feVel_->evaluateValue(valUX_eval, U[0]);
488 feVel_->evaluateValue(valUY_eval, U[1]);
489 // Compute negative part of x-velocity
490 ROL::Ptr<Intrepid::FieldContainer<Real>> minUX_eval =
491 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
492 for (int i = 0; i < c; ++i) {
493 for (int j = 0; j < p; ++j) {
494 (*minUX_eval)(i,j) = std::min(static_cast<Real>(0),(*valUX_eval)(i,j));
495 }
496 }
497 // Multiply by weight
498 ROL::Ptr<Intrepid::FieldContainer<Real>> weighted_minUX_eval =
499 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
500 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*weighted_minUX_eval,
501 *weight_,
502 *minUX_eval);
503 ROL::Ptr<Intrepid::FieldContainer<Real>> weighted_valUY_eval =
504 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
505 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*weighted_valUY_eval,
506 *weight_,
507 *valUY_eval);
508 // Compute L2 norm squared
509 feVel_->computeIntegral(val,minUX_eval,weighted_minUX_eval,false);
510 feVel_->computeIntegral(val,valUY_eval,weighted_valUY_eval,true);
511
512 Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5));
513 return static_cast<Real>(0);
514 }
515
516 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
517 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
518 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
519 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
520 // Get relevant dimensions
521 int c = feVel_->gradN()->dimension(0);
522 int fv = feVel_->gradN()->dimension(1);
523 int fp = fePrs_->gradN()->dimension(1);
524 int fh = feThr_->gradN()->dimension(1);
525 int p = feVel_->gradN()->dimension(2);
526 int d = feVel_->gradN()->dimension(3);
527 // Initialize output grad
528 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2);
529 for (int i = 0; i < d; ++i) {
530 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
531 }
532 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
533 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
534 // Get components of the control
535 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
536 fieldHelper_->splitFieldCoeff(U, u_coeff);
537 // Evaluate on FE basis
538 ROL::Ptr<Intrepid::FieldContainer<Real>> valUX_eval =
539 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
540 ROL::Ptr<Intrepid::FieldContainer<Real>> valUY_eval =
541 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
542 feVel_->evaluateValue(valUX_eval, U[0]);
543 feVel_->evaluateValue(valUY_eval, U[1]);
544 // Compute negative part of x-velocity
545 ROL::Ptr<Intrepid::FieldContainer<Real>> weighted_minUX_eval =
546 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
547 ROL::Ptr<Intrepid::FieldContainer<Real>> weighted_valUY_eval =
548 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
549 for (int i = 0; i < c; ++i) {
550 for (int j = 0; j < p; ++j) {
551 (*weighted_minUX_eval)(i,j)
552 = (*weight_)(i,j) * std::min(static_cast<Real>(0),(*valUX_eval)(i,j));
553 (*weighted_valUY_eval)(i,j)
554 = (*weight_)(i,j) * (*valUY_eval)(i,j);
555 }
556 }
557 // Build local gradient of state tracking term
558 Intrepid::FunctionSpaceTools::integrate<Real>(*G[0],
559 *weighted_minUX_eval,
560 *(feVel_->NdetJ()),
561 Intrepid::COMP_CPP, false);
562 Intrepid::FunctionSpaceTools::integrate<Real>(*G[1],
563 *weighted_valUY_eval,
564 *(feVel_->NdetJ()),
565 Intrepid::COMP_CPP, false);
566
567 fieldHelper_->combineFieldCoeff(grad, G);
568 }
569
570 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
571 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
572 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
573 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
574 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::gradient_2 is zero.");
575 }
576
577 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
578 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
579 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
580 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
581 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
582 // Get relevant dimensions
583 int c = feVel_->gradN()->dimension(0);
584 int fv = feVel_->gradN()->dimension(1);
585 int fp = fePrs_->gradN()->dimension(1);
586 int fh = feThr_->gradN()->dimension(1);
587 int p = feVel_->gradN()->dimension(2);
588 int d = feVel_->gradN()->dimension(3);
589 // Initialize output grad
590 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2);
591 for (int i = 0; i < d; ++i) {
592 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
593 }
594 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
595 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
596 // Get components of the control
597 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
598 fieldHelper_->splitFieldCoeff(U, u_coeff);
599 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V;
600 fieldHelper_->splitFieldCoeff(V, v_coeff);
601 // Evaluate on FE basis
602 ROL::Ptr<Intrepid::FieldContainer<Real>> valUX_eval =
603 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
604 ROL::Ptr<Intrepid::FieldContainer<Real>> valVX_eval =
605 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
606 ROL::Ptr<Intrepid::FieldContainer<Real>> valVY_eval =
607 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
608 feVel_->evaluateValue(valUX_eval, U[0]);
609 feVel_->evaluateValue(valVX_eval, V[0]);
610 feVel_->evaluateValue(valVY_eval, V[1]);
611 // Compute negative part of x-velocity
612 ROL::Ptr<Intrepid::FieldContainer<Real>> weighted_minVX_eval =
613 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
614 ROL::Ptr<Intrepid::FieldContainer<Real>> weighted_valVY_eval =
615 ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
616 Real scale(0);
617 for (int i = 0; i < c; ++i) {
618 for (int j = 0; j < p; ++j) {
619 if ( (*valUX_eval)(i,j) < static_cast<Real>(0) ) {
620 scale = static_cast<Real>(1);
621 }
622 else if ( (*valUX_eval)(i,j) > static_cast<Real>(0) ) {
623 scale = static_cast<Real>(0);
624 }
625 else {
626 //scale = static_cast<Real>(0);
627 //scale = static_cast<Real>(0.5);
628 scale = static_cast<Real>(1);
629 }
630 (*weighted_minVX_eval)(i,j)
631 = scale * (*weight_)(i,j) * (*valVX_eval)(i,j);
632 (*weighted_valVY_eval)(i,j)
633 = (*weight_)(i,j) * (*valVY_eval)(i,j);
634 }
635 }
636 // Build local gradient of state tracking term
637 Intrepid::FunctionSpaceTools::integrate<Real>(*H[0],
638 *weighted_minVX_eval,
639 *(feVel_->NdetJ()),
640 Intrepid::COMP_CPP, false);
641 Intrepid::FunctionSpaceTools::integrate<Real>(*H[1],
642 *weighted_valVY_eval,
643 *(feVel_->NdetJ()),
644 Intrepid::COMP_CPP, false);
645
646 fieldHelper_->combineFieldCoeff(hess, H);
647 }
648
649 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
650 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
651 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
652 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
653 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
654 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::HessVec_12 is zero.");
655 }
656
657 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
658 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
659 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
660 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
661 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
662 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::HessVec_21 is zero.");
663 }
664
665 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
666 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
667 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
668 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
669 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
670 throw Exception::Zero(">>> QoI_Horizontal_ThermalFluids::HessVec_22 is zero.");
671 }
672
673 }; // QoI_Horizontal_ThermalFluids
674
675 template <class Real>
676 class QoI_Tracking_ThermalFluids : public QoI<Real> {
677 private:
678 const ROL::Ptr<FE<Real>> feVel_;
679 const ROL::Ptr<FE<Real>> fePrs_;
680 const ROL::Ptr<FE<Real>> feThr_;
681 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
682 ROL::Ptr<Intrepid::FieldContainer<Real>> weight_;
683 ROL::Ptr<Intrepid::FieldContainer<Real>> target_;
684
685 Real weightFunc(const std::vector<Real> & x) const {
686 const Real one(1);
687 return one;
688 }
689
690 Real target(const std::vector<Real> &x, const int dir) const {
691 const Real zero(0), one(1);
692 return (dir == 0 ? one : zero);
693 }
694
695 public:
696 QoI_Tracking_ThermalFluids(const ROL::Ptr<FE<Real>> &feVel,
697 const ROL::Ptr<FE<Real>> &fePrs,
698 const ROL::Ptr<FE<Real>> &feThr,
699 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
700 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
701 int c = feVel_->cubPts()->dimension(0);
702 int p = feVel_->cubPts()->dimension(1);
703 int d = feVel_->cubPts()->dimension(2);
704 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
705 target_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
706 std::vector<Real> pt(d);
707 for (int i = 0; i < c; ++i) {
708 for (int j = 0; j < p; ++j) {
709 for (int k = 0; k < d; ++k) {
710 pt[k] = (*feVel_->cubPts())(i, j, k);
711 }
712 (*weight_)(i, j) = weightFunc(pt);
713 for (int k = 0; k < d; ++k) {
714 (*target_)(i, j, k) = target(pt, k);
715 }
716 }
717 }
718 }
719
720 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
721 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
722 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
723 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
724 // Get relevant dimensions
725 int c = feVel_->gradN()->dimension(0);
726 int p = feVel_->gradN()->dimension(2);
727 int d = feVel_->gradN()->dimension(3);
728 // Initialize output val
729 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
730 // Get components of the control
731 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
732 fieldHelper_->splitFieldCoeff(U, u_coeff);
733 // Compute tracking term and integrate
734 ROL::Ptr<Intrepid::FieldContainer<Real>> U_eval
735 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
736 for (int i = 0; i < d; ++i) {
737 // Evaluate u value on FE basis
738 U_eval->initialize();
739 feVel_->evaluateValue(U_eval, U[i]);
740 // Compute distance to target
741 for (int j = 0; j < c; ++j) {
742 for (int k = 0; k < p; ++k) {
743 (*U_eval)(j, k) -= (*target_)(j, k, i);
744 (*U_eval)(j, k) *= std::sqrt((*weight_)(j, k));
745 }
746 }
747 // Compute L2 norm squared
748 feVel_->computeIntegral(val,U_eval,U_eval,true);
749 }
750 Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5));
751 return static_cast<Real>(0);
752 }
753
754 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
755 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
756 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
757 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
758 // Get relevant dimensions
759 int c = feVel_->gradN()->dimension(0);
760 int fv = feVel_->gradN()->dimension(1);
761 int fp = fePrs_->gradN()->dimension(1);
762 int fh = feThr_->gradN()->dimension(1);
763 int p = feVel_->gradN()->dimension(2);
764 int d = feVel_->gradN()->dimension(3);
765 // Get components of the control
766 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
767 fieldHelper_->splitFieldCoeff(U, u_coeff);
768 // Compute weighted u value and integrate
769 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2, ROL::nullPtr);
770 ROL::Ptr<Intrepid::FieldContainer<Real>> U_eval
771 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
772 for (int i = 0; i < d; ++i) {
773 // Evaluate on FE basis
774 U_eval->initialize();
775 feVel_->evaluateValue(U_eval, U[i]);
776 // Compute tracking term
777 for (int j = 0; j < c; ++j) {
778 for (int k = 0; k < p; ++k) {
779 (*U_eval)(j, k) -= (*target_)(j, k, i);
780 (*U_eval)(j, k) *= (*weight_)(j, k);
781 }
782 }
783 // Build local gradient of state tracking term
784 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
785 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
786 *U_eval,
787 *(feVel_->NdetJ()),
788 Intrepid::COMP_CPP,
789 false);
790 }
791 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
792 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
793 fieldHelper_->combineFieldCoeff(grad, G);
794 }
795
796 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
797 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
798 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
799 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
800 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::gradient_2 is zero.");
801 }
802
803 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
804 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
805 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
806 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
807 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
808 // Get relevant dimensions
809 int c = feVel_->gradN()->dimension(0);
810 int fv = feVel_->gradN()->dimension(1);
811 int fp = fePrs_->gradN()->dimension(1);
812 int fh = feThr_->gradN()->dimension(1);
813 int p = feVel_->gradN()->dimension(2);
814 int d = feVel_->gradN()->dimension(3);
815 // Get components of the control
816 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V;
817 fieldHelper_->splitFieldCoeff(V, v_coeff);
818 // Compute weighted v value and integrate
819 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2, ROL::nullPtr);
820 ROL::Ptr<Intrepid::FieldContainer<Real>> V_eval
821 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
822 for (int i = 0; i < d; ++i) {
823 // Evaluate v value on FE basis
824 V_eval->initialize();
825 feVel_->evaluateValue(V_eval, V[i]);
826 // Weight v value
827 for (int j = 0; j < c; ++j) {
828 for (int k = 0; k < p; ++k) {
829 (*V_eval)(j, k) *= (*weight_)(j, k);
830 }
831 }
832 // Integrate v value
833 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
834 Intrepid::FunctionSpaceTools::integrate<Real>(*H[i],
835 *V_eval,
836 *(feVel_->NdetJ()),
837 Intrepid::COMP_CPP,
838 false);
839 }
840 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
841 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
842 fieldHelper_->combineFieldCoeff(hess, H);
843 }
844
845 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
846 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
847 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
848 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
849 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
850 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::HessVec_12 is zero.");
851 }
852
853 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
854 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
855 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
856 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
857 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
858 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::HessVec_21 is zero.");
859 }
860
861 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
862 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
863 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
864 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
865 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
866 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::HessVec_22 is zero.");
867 }
868
869 }; // QoI_Tracking_ThermalFluids
870
871 template <class Real>
872 class QoI_Dissipation_ThermalFluids : public QoI<Real> {
873 private:
874 const ROL::Ptr<FE<Real>> feVel_;
875 const ROL::Ptr<FE<Real>> fePrs_;
876 const ROL::Ptr<FE<Real>> feThr_;
877 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
878 ROL::Ptr<Intrepid::FieldContainer<Real>> weight_;
879
880 Real nu_;
881
882 Real weightFunc(const std::vector<Real> & x) const {
883 return static_cast<Real>(1);
884 }
885
886 public:
887 QoI_Dissipation_ThermalFluids(Teuchos::ParameterList &parlist,
888 const ROL::Ptr<FE<Real>> &feVel,
889 const ROL::Ptr<FE<Real>> &fePrs,
890 const ROL::Ptr<FE<Real>> &feThr,
891 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
892 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
893 Real Re = parlist.sublist("Problem").get("Reynolds Number", 40.0);
894 nu_ = static_cast<Real>(1.0)/Re;
895 int c = feVel_->cubPts()->dimension(0);
896 int p = feVel_->cubPts()->dimension(1);
897 int d = feVel_->cubPts()->dimension(2);
898 std::vector<Real> pt(d);
899 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p);
900 for (int i = 0; i < c; ++i) {
901 for (int j = 0; j < p; ++j) {
902 for (int k = 0; k < d; ++k) {
903 pt[k] = (*feVel_->cubPts())(i,j,k);
904 }
905 (*weight_)(i,j) = weightFunc(pt);
906 }
907 }
908 }
909
910 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
911 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
912 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
913 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
914 const Real half(0.5);
915 // Get relevant dimensions
916 const int c = feVel_->gradN()->dimension(0);
917 const int p = feVel_->gradN()->dimension(2);
918 const int d = feVel_->gradN()->dimension(3);
919 // Initialize output val
920 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
921 // Get components of the control
922 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
923 fieldHelper_->splitFieldCoeff(U, u_coeff);
924 // Evaluate on FE basis
925 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradU(d);
926 for (int i = 0; i < d; ++i) {
927 gradU[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
928 feVel_->evaluateGradient(gradU[i], U[i]);
929 }
930 // Compute energy dissipation rate
931 ROL::Ptr<Intrepid::FieldContainer<Real>> sigmaU
932 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
933 for (int i = 0; i < d; ++i) {
934 for (int j = 0; j < d; ++j) {
935 for (int k = 0; k < c; ++k) {
936 for (int l = 0; l < p; ++l) {
937 (*sigmaU)(k,l) = (*weight_)(k,l)*((*gradU[i])(k,l,j)+(*gradU[j])(k,l,i));
938 }
939 }
940 feVel_->computeIntegral(val,sigmaU,sigmaU,true);
941 }
942 }
943 Intrepid::RealSpaceTools<Real>::scale(*val, half*nu_);
944 return static_cast<Real>(0);
945 }
946
947 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
948 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
949 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
950 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
951 // Get relevant dimensions
952 const int c = feVel_->gradN()->dimension(0);
953 const int fv = feVel_->gradN()->dimension(1);
954 const int fp = fePrs_->gradN()->dimension(1);
955 const int fh = feThr_->gradN()->dimension(1);
956 const int p = feVel_->gradN()->dimension(2);
957 const int d = feVel_->gradN()->dimension(3);
958 // Initialize output grad
959 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2);
960 for (int i = 0; i < d; ++i) {
961 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
962 }
963 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
964 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
965 // Get components of the control
966 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
967 fieldHelper_->splitFieldCoeff(U, u_coeff);
968 // Evaluate on FE basis
969 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradU(d);
970 for (int i = 0; i < d; ++i) {
971 gradU[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
972 feVel_->evaluateGradient(gradU[i], U[i]);
973 }
974 // Compute energy dissipation gradient
975 ROL::Ptr<Intrepid::FieldContainer<Real>> sigmaU
976 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
977 for (int i = 0; i < d; ++i) {
978 for (int j = 0; j < d; ++j) {
979 for (int k = 0; k < c; ++k) {
980 for (int l = 0; l < p; ++l) {
981 (*sigmaU)(k,l) = std::pow((*weight_)(k,l),2)*((*gradU[i])(k,l,j)+(*gradU[j])(k,l,i));
982 }
983 }
984 Intrepid::FunctionSpaceTools::integrate<Real>(*G[j],
985 *sigmaU,
986 *(feVel_->DNDdetJ(i)),
987 Intrepid::COMP_CPP,
988 true);
989 Intrepid::FunctionSpaceTools::integrate<Real>(*G[i],
990 *sigmaU,
991 *(feVel_->DNDdetJ(j)),
992 Intrepid::COMP_CPP,
993 true);
994 }
995 }
996 fieldHelper_->combineFieldCoeff(grad, G);
997 Intrepid::RealSpaceTools<Real>::scale(*grad, nu_);
998 }
999
1000 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1001 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1002 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1003 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1004 throw Exception::Zero(">>> QoI_Dissipation_ThermalFluids::gradient_2 is zero.");
1005 }
1006
1007 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1008 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1009 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1010 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1011 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1012 // Get relevant dimensions
1013 const int c = feVel_->gradN()->dimension(0);
1014 const int fv = feVel_->gradN()->dimension(1);
1015 const int fp = fePrs_->gradN()->dimension(1);
1016 const int fh = feThr_->gradN()->dimension(1);
1017 const int p = feVel_->gradN()->dimension(2);
1018 const int d = feVel_->gradN()->dimension(3);
1019 // Initialize output grad
1020 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2);
1021 for (int i = 0; i < d; ++i) {
1022 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1023 }
1024 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1025 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1026 // Get components of the control
1027 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V;
1028 fieldHelper_->splitFieldCoeff(V, v_coeff);
1029 // Evaluate on FE basis
1030 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradV(d);
1031 for (int i = 0; i < d; ++i) {
1032 gradV[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d);
1033 feVel_->evaluateGradient(gradV[i], V[i]);
1034 }
1035 // Compute energy dissipation gradient
1036 ROL::Ptr<Intrepid::FieldContainer<Real>> sigmaV
1037 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1038 for (int i = 0; i < d; ++i) {
1039 for (int j = 0; j < d; ++j) {
1040 for (int k = 0; k < c; ++k) {
1041 for (int l = 0; l < p; ++l) {
1042 (*sigmaV)(k,l) = std::pow((*weight_)(k,l),2)*((*gradV[i])(k,l,j)+(*gradV[j])(k,l,i));
1043 }
1044 }
1045 Intrepid::FunctionSpaceTools::integrate<Real>(*H[j],
1046 *sigmaV,
1047 *(feVel_->DNDdetJ(i)),
1048 Intrepid::COMP_CPP,
1049 true);
1050 Intrepid::FunctionSpaceTools::integrate<Real>(*H[i],
1051 *sigmaV,
1052 *(feVel_->DNDdetJ(j)),
1053 Intrepid::COMP_CPP,
1054 true);
1055 }
1056 }
1057 fieldHelper_->combineFieldCoeff(hess, H);
1058 Intrepid::RealSpaceTools<Real>::scale(*hess, nu_);
1059 }
1060
1061 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1062 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1063 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1064 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1065 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1066 throw Exception::Zero(">>> QoI_Dissipation_ThermalFluids::HessVec_12 is zero.");
1067 }
1068
1069 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1070 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1071 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1072 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1073 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1074 throw Exception::Zero(">>> QoI_Dissipation_ThermalFluids::HessVec_21 is zero.");
1075 }
1076
1077 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1078 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1079 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1080 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1081 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1082 throw Exception::Zero(">>> QoI_Dissipation_ThermalFluids::HessVec_22 is zero.");
1083 }
1084
1085 }; // QoI_Dissipation_ThermalFluids
1086
1087 template <class Real>
1088 class QoI_Bouyancy_ThermalFluids : public QoI<Real> {
1089 private:
1090 const ROL::Ptr<FE<Real>> feVel_;
1091 const ROL::Ptr<FE<Real>> fePrs_;
1092 const ROL::Ptr<FE<Real>> feThr_;
1093 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
1094 ROL::Ptr<Intrepid::FieldContainer<Real>> weight_;
1095 Real alpha_;
1096
1097 Real weightFunc(const std::vector<Real> & x) const {
1098 const Real one(1);
1099 return one;
1100 }
1101
1102 public:
1103 QoI_Bouyancy_ThermalFluids(Teuchos::ParameterList &parlist,
1104 const ROL::Ptr<FE<Real>> &feVel,
1105 const ROL::Ptr<FE<Real>> &fePrs,
1106 const ROL::Ptr<FE<Real>> &feThr,
1107 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
1108 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), fieldHelper_(fieldHelper) {
1109 Real Re = parlist.sublist("Problem").get("Reynolds Number", 200.0);
1110 Real Gr = parlist.sublist("Problem").get("Grashof Number", 40000.0);
1111 alpha_ = static_cast<Real>(-1)*Gr/(Re*Re);
1112 int c = feVel_->cubPts()->dimension(0);
1113 int p = feVel_->cubPts()->dimension(1);
1114 int d = feVel_->cubPts()->dimension(2);
1115 weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1116 std::vector<Real> pt(d);
1117 for (int i = 0; i < c; ++i) {
1118 for (int j = 0; j < p; ++j) {
1119 for (int k = 0; k < d; ++k) {
1120 pt[k] = (*feVel_->cubPts())(i, j, k);
1121 }
1122 (*weight_)(i, j) = alpha_*weightFunc(pt);
1123 }
1124 }
1125 }
1126
1127 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
1128 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1129 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1130 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1131 // Get relevant dimensions
1132 int c = feVel_->gradN()->dimension(0);
1133 int p = feVel_->gradN()->dimension(2);
1134 int d = feVel_->gradN()->dimension(3);
1135 // Initialize output val
1136 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
1137 // Get components of the control
1138 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
1139 fieldHelper_->splitFieldCoeff(U, u_coeff);
1140 // Compute tracking term and integrate
1141 ROL::Ptr<Intrepid::FieldContainer<Real>> Uv, Ut, Uvt;
1142 Uv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1143 Ut = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1144 Uvt = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1145 feVel_->evaluateValue(Uv, U[d-1]);
1146 feThr_->evaluateValue(Ut, U[d+1]);
1147 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*Uvt, *Uv, *Ut);
1148 feVel_->computeIntegral(val,weight_,Uvt,false);
1149 return static_cast<Real>(0);
1150 }
1151
1152 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1153 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1154 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1155 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1156 // Get relevant dimensions
1157 int c = feVel_->gradN()->dimension(0);
1158 int fv = feVel_->gradN()->dimension(1);
1159 int fp = fePrs_->gradN()->dimension(1);
1160 int fh = feThr_->gradN()->dimension(1);
1161 int p = feVel_->gradN()->dimension(2);
1162 int d = feVel_->gradN()->dimension(3);
1163 // Get components of the control
1164 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U;
1165 fieldHelper_->splitFieldCoeff(U, u_coeff);
1166 // Compute weighted u value and integrate
1167 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2, ROL::nullPtr);
1168 for (int i = 0; i < d; ++i) {
1169 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1170 }
1171 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1172 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1173
1174 ROL::Ptr<Intrepid::FieldContainer<Real>> Uv, Ut, wUv, wUt;
1175 Uv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1176 Ut = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1177 wUv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1178 wUt = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1179 feVel_->evaluateValue(Uv, U[d-1]);
1180 feThr_->evaluateValue(Ut, U[d+1]);
1181 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*wUv, *weight_, *Uv);
1182 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*wUt, *weight_, *Ut);
1183
1184 Intrepid::FunctionSpaceTools::integrate<Real>(*G[d-1],
1185 *wUt,
1186 *(feVel_->NdetJ()),
1187 Intrepid::COMP_CPP,
1188 false);
1189
1190 Intrepid::FunctionSpaceTools::integrate<Real>(*G[d+1],
1191 *wUv,
1192 *(feThr_->NdetJ()),
1193 Intrepid::COMP_CPP,
1194 false);
1195
1196 fieldHelper_->combineFieldCoeff(grad, G);
1197 }
1198
1199 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1200 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1201 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1202 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1203 throw Exception::Zero(">>> QoI_Bouyancy_ThermalFluids::gradient_2 is zero.");
1204 }
1205
1206 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1207 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1208 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1209 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1210 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1211 // Get relevant dimensions
1212 int c = feVel_->gradN()->dimension(0);
1213 int fv = feVel_->gradN()->dimension(1);
1214 int fp = fePrs_->gradN()->dimension(1);
1215 int fh = feThr_->gradN()->dimension(1);
1216 int p = feVel_->gradN()->dimension(2);
1217 int d = feVel_->gradN()->dimension(3);
1218 // Get components of the control
1219 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V;
1220 fieldHelper_->splitFieldCoeff(V, v_coeff);
1221 // Compute weighted v value and integrate
1222 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2, ROL::nullPtr);
1223 for (int i = 0; i < d; ++i) {
1224 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1225 }
1226 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1227 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1228
1229 ROL::Ptr<Intrepid::FieldContainer<Real>> Vv, Vt, wVv, wVt;
1230 Vv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1231 Vt = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1232 wVv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1233 wVt = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p);
1234 feVel_->evaluateValue(Vv, V[d-1]);
1235 feThr_->evaluateValue(Vt, V[d+1]);
1236 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*wVv, *weight_, *Vv);
1237 Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*wVt, *weight_, *Vt);
1238
1239 Intrepid::FunctionSpaceTools::integrate<Real>(*H[d-1],
1240 *wVt,
1241 *(feVel_->NdetJ()),
1242 Intrepid::COMP_CPP,
1243 false);
1244
1245 Intrepid::FunctionSpaceTools::integrate<Real>(*H[d+1],
1246 *wVv,
1247 *(feThr_->NdetJ()),
1248 Intrepid::COMP_CPP,
1249 false);
1250
1251 fieldHelper_->combineFieldCoeff(hess, H);
1252 }
1253
1254 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1255 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1256 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1257 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1258 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1259 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::HessVec_12 is zero.");
1260 }
1261
1262 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1263 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1264 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1265 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1266 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1267 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::HessVec_21 is zero.");
1268 }
1269
1270 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1271 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1272 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1273 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1274 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1275 throw Exception::Zero(">>> QoI_Tracking_ThermalFluids::HessVec_22 is zero.");
1276 }
1277
1278 }; // QoI_Tracking_ThermalFluids
1279
1280 template <class Real>
1281 class QoI_State_ThermalFluids : public QoI<Real> {
1282 private:
1283 ROL::Ptr<QoI<Real>> qoi_;
1284
1285 void initialize(const std::string &stateObj,
1286 Teuchos::ParameterList &parlist,
1287 const ROL::Ptr<FE<Real>> &feVel,
1288 const ROL::Ptr<FE<Real>> &fePrs,
1289 const ROL::Ptr<FE<Real>> &feThr,
1290 const ROL::Ptr<FieldHelper<Real>> &fieldHelper) {
1291 if ( stateObj == "Circulation" ) {
1292 qoi_ = ROL::makePtr<QoI_Circulation_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper);
1293 }
1294 else if ( stateObj == "Vorticity" ) {
1295 qoi_ = ROL::makePtr<QoI_Vorticity_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper);
1296 }
1297 else if ( stateObj == "Directional" ) {
1298 qoi_ = ROL::makePtr<QoI_Horizontal_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper);
1299 }
1300 else if ( stateObj == "Tracking" ) {
1301 qoi_ = ROL::makePtr<QoI_Tracking_ThermalFluids<Real>>(feVel,fePrs,feThr,fieldHelper);
1302 }
1303 else if ( stateObj == "Dissipation" ) {
1304 qoi_ = ROL::makePtr<QoI_Dissipation_ThermalFluids<Real>>(parlist,feVel,fePrs,feThr,fieldHelper);
1305 }
1306 else if ( stateObj == "Bouyancy" ) {
1307 qoi_ = ROL::makePtr<QoI_Bouyancy_ThermalFluids<Real>>(parlist,feVel,fePrs,feThr,fieldHelper);
1308 }
1309 else {
1310 throw Exception::NotImplemented(">>> (QoI_State_ThermalFluids): Unknown objective type.");
1311 }
1312 }
1313
1314 public:
1315 QoI_State_ThermalFluids(Teuchos::ParameterList &parlist,
1316 const ROL::Ptr<FE<Real>> &feVel,
1317 const ROL::Ptr<FE<Real>> &fePrs,
1318 const ROL::Ptr<FE<Real>> &feThr,
1319 const ROL::Ptr<FieldHelper<Real>> &fieldHelper) {
1320 std::string stateObj = parlist.sublist("Problem").get("Objective type","Vorticity");
1321 initialize(stateObj,parlist,feVel,fePrs,feThr,fieldHelper);
1322 }
1323
1324 QoI_State_ThermalFluids(const std::string &stateObj,
1325 Teuchos::ParameterList &parlist,
1326 const ROL::Ptr<FE<Real>> &feVel,
1327 const ROL::Ptr<FE<Real>> &fePrs,
1328 const ROL::Ptr<FE<Real>> &feThr,
1329 const ROL::Ptr<FieldHelper<Real>> &fieldHelper) {
1330 initialize(stateObj,parlist,feVel,fePrs,feThr,fieldHelper);
1331 }
1332
1333 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
1334 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1335 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1336 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1337 return qoi_->value(val, u_coeff, z_coeff, z_param);
1338 }
1339
1340 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1341 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1342 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1343 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1344 qoi_->gradient_1(grad, u_coeff, z_coeff, z_param);
1345 }
1346
1347 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1348 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1349 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1350 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1351 qoi_->gradient_2(grad, u_coeff, z_coeff, z_param);
1352 }
1353
1354 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1355 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1356 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1357 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1358 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1359 qoi_->HessVec_11(hess, v_coeff, u_coeff, z_coeff, z_param);
1360 }
1361
1362 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1363 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1364 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1365 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1366 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1367 qoi_->HessVec_12(hess, v_coeff, u_coeff, z_coeff, z_param);
1368 }
1369
1370 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1371 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1372 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1373 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1374 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1375 qoi_->HessVec_21(hess, v_coeff, u_coeff, z_coeff, z_param);
1376 }
1377
1378 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1379 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1380 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1381 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1382 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1383 qoi_->HessVec_22(hess, v_coeff, u_coeff, z_coeff, z_param);
1384 }
1385
1386 };
1387
1388 template <class Real>
1389 class QoI_DownStreamPower_ThermalFluids : public QoI<Real> {
1390 private:
1391 const ROL::Ptr<FE<Real>> feVel_;
1392 const ROL::Ptr<FE<Real>> fePrs_;
1393 const ROL::Ptr<FE<Real>> feThr_;
1394 const std::vector<ROL::Ptr<FE<Real>>> feVelBdry_;
1395 const std::vector<std::vector<int>> bdryCellLocIds_;
1396 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
1397 const std::vector<Real> target_;
1398
1399 ROL::Ptr<Intrepid::FieldContainer<Real>> getBoundaryCoeff(
1400 const Intrepid::FieldContainer<Real> &cell_coeff,
1401 const int locSideId) const {
1402 std::vector<int> bdryCellLocId = bdryCellLocIds_[locSideId];
1403 const int numCellsSide = bdryCellLocId.size();
1404 const int f = feVel_->N()->dimension(1);
1405
1406 ROL::Ptr<Intrepid::FieldContainer<Real >> bdry_coeff =
1407 ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f);
1408 for (int i = 0; i < numCellsSide; ++i) {
1409 for (int j = 0; j < f; ++j) {
1410 (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j);
1411 }
1412 }
1413 return bdry_coeff;
1414 }
1415
1416 public:
1417 QoI_DownStreamPower_ThermalFluids(const ROL::Ptr<FE<Real>> &feVel,
1418 const ROL::Ptr<FE<Real>> &fePrs,
1419 const ROL::Ptr<FE<Real>> &feThr,
1420 const std::vector<ROL::Ptr<FE<Real>>> &feVelBdry,
1421 const std::vector<std::vector<int>> &bdryCellLocIds,
1422 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
1423 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), feVelBdry_(feVelBdry),
1424 bdryCellLocIds_(bdryCellLocIds), fieldHelper_(fieldHelper),
1425 target_({1, 0, 0}) {}
1426
1427 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> &val,
1428 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1429 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1430 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1431 const Real half(0.5);
1432 const int c = feVel_->gradN()->dimension(0);
1433 const int d = feVel_->gradN()->dimension(3);
1434 const int numLocSides = bdryCellLocIds_.size();
1435 // Initialize storage
1436 int numCellsSide(0), numCubPerSide(0), cidx(0);
1437 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, u(d);
1438 ROL::Ptr<Intrepid::FieldContainer<Real>> tmp, u_diff, intVal;
1439 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
1440 fieldHelper_->splitFieldCoeff(U, u_coeff);
1441 // Compute cost integral
1442 for (int l = 0; l < numLocSides; ++l) {
1443 numCellsSide = bdryCellLocIds_[l].size();
1444 if ( numCellsSide ) {
1445 numCubPerSide = feVelBdry_[l]->cubPts()->dimension(1);
1446 u_diff = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1447 intVal = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide);
1448 // Evaluate objective function value
1449 for (int i = 0; i < d; ++i) {
1450 u[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1451 tmp = getBoundaryCoeff(*U[i], l);
1452 feVelBdry_[l]->evaluateValue(u[i], tmp);
1453 for (int j = 0; j < numCellsSide; ++j) {
1454 for (int k = 0; k < numCubPerSide; ++k) {
1455 (*u_diff)(j,k) += std::pow((*u[i])(j,k)-target_[i],2);
1456 }
1457 }
1458 }
1459 // Integrate objective function
1460 feVelBdry_[l]->computeIntegral(intVal,u_diff,u[0],false);
1461 // Add to volume integral value
1462 for (int i = 0; i < numCellsSide; ++i) {
1463 cidx = bdryCellLocIds_[l][i];
1464 (*val)(cidx) += half*(*intVal)(i);
1465 }
1466 }
1467 }
1468 return static_cast<Real>(0);
1469 }
1470
1471 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> &grad,
1472 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1473 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1474 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1475 const Real half(0.5);
1476 const int c = feVel_->gradN()->dimension(0);
1477 const int fv = feVel_->gradN()->dimension(1);
1478 const int fp = fePrs_->gradN()->dimension(1);
1479 const int fh = feThr_->gradN()->dimension(1);
1480 const int d = feVel_->gradN()->dimension(3);
1481 const int numLocSides = bdryCellLocIds_.size();
1482 // Initialize output grad
1483 int numCellsSide(0), numCubPerSide(0), cidx(0);
1484 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2), u(d), U;
1485 ROL::Ptr<Intrepid::FieldContainer<Real>> tmp, du, intGrad;
1486 for (int i = 0; i < d; ++i) {
1487 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1488 }
1489 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1490 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1491 fieldHelper_->splitFieldCoeff(U, u_coeff);
1492 // Compute cost integral
1493 for (int l = 0; l < numLocSides; ++l) {
1494 numCellsSide = bdryCellLocIds_[l].size();
1495 if ( numCellsSide ) {
1496 numCubPerSide = feVelBdry_[l]->cubPts()->dimension(1);
1497 // Evaluate objective function gradient
1498 du = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1499 intGrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fv);
1500 for (int i = 0; i < d; ++i) {
1501 tmp = getBoundaryCoeff(*U[i], l);
1502 u[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1503 feVelBdry_[l]->evaluateValue(u[i], tmp);
1504 }
1505 for (int i = 0; i < d; ++i) {
1506 for (int j = 0; j < numCellsSide; ++j) {
1507 for (int k = 0; k < numCubPerSide; ++k) {
1508 (*du)(j,k) = ((*u[i])(j,k)-target_[i])*(*u[0])(j,k);
1509 if (i==0) {
1510 for (int m = 0; m < d; ++m) {
1511 (*du)(j,k) += half*std::pow((*u[m])(j,k)-target_[m],2);
1512 }
1513 }
1514 }
1515 }
1516 // Integrate gradient
1517 Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad,
1518 *du,
1519 *(feVelBdry_[l]->NdetJ()),
1520 Intrepid::COMP_CPP,
1521 false);
1522 for (int j = 0; j < numCellsSide; ++j) {
1523 cidx = bdryCellLocIds_[l][j];
1524 for (int k = 0; k < fv; ++k) {
1525 (*G[i])(cidx,k) += (*intGrad)(j,k);
1526 }
1527 }
1528 }
1529 }
1530 }
1531 fieldHelper_->combineFieldCoeff(grad, G);
1532 }
1533
1534 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> &grad,
1535 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1536 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1537 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1538 throw Exception::Zero(">>> QoI_DownStreamPower_ThermalFluids::gradient_2 is zero.");
1539 }
1540
1541 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess,
1542 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &v_coeff,
1543 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1544 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1545 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1546 const int c = feVel_->gradN()->dimension(0);
1547 const int fv = feVel_->gradN()->dimension(1);
1548 const int fp = fePrs_->gradN()->dimension(1);
1549 const int fh = feThr_->gradN()->dimension(1);
1550 const int d = feVel_->gradN()->dimension(3);
1551 const int numLocSides = bdryCellLocIds_.size();
1552 // Initialize output hess
1553 int numCellsSide(0), numCubPerSide(0), cidx(0);
1554 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2), U, V, u(d), v(d);
1555 ROL::Ptr<Intrepid::FieldContainer<Real>> tmp, du, intHess;
1556 for (int i = 0; i < d; ++i) {
1557 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1558 }
1559 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1560 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1561 fieldHelper_->splitFieldCoeff(U, u_coeff);
1562 fieldHelper_->splitFieldCoeff(V, v_coeff);
1563 // Compute cost integral
1564 for (int l = 0; l < numLocSides; ++l) {
1565 numCellsSide = bdryCellLocIds_[l].size();
1566 if ( numCellsSide ) {
1567 numCubPerSide = feVelBdry_[l]->cubPts()->dimension(1);
1568 // Evaluate state and direction on FE basis
1569 du = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1570 intHess = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fv);
1571 for (int i = 0; i < d; ++i) {
1572 tmp = getBoundaryCoeff(*U[i], l);
1573 u[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1574 feVelBdry_[l]->evaluateValue(u[i], tmp);
1575 tmp = getBoundaryCoeff(*V[i], l);
1576 v[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1577 feVelBdry_[l]->evaluateValue(v[i], tmp);
1578 }
1579 // Compute hessian times a vector
1580 for (int i = 0; i < d; ++i) {
1581 for (int j = 0; j < numCellsSide; ++j) {
1582 for (int k = 0; k < numCubPerSide; ++k) {
1583 if (i==0) {
1584 (*du)(j,k) = (((*u[0])(j,k)-target_[i])+(*u[0])(j,k))*(*v[0])(j,k);
1585 for (int m = 0; m < d; ++m) {
1586 (*du)(j,k) += ((*u[m])(j,k)-target_[m])*(*v[m])(j,k);
1587 }
1588 }
1589 else {
1590 (*du)(j,k) = (*u[i])(j,k)*(*v[0])(j,k) + (*u[0])(j,k)*(*v[i])(j,k);
1591 }
1592 }
1593 }
1594 // Integrate hessian
1595 Intrepid::FunctionSpaceTools::integrate<Real>(*intHess,
1596 *du,
1597 *(feVelBdry_[l]->NdetJ()),
1598 Intrepid::COMP_CPP,
1599 false);
1600 for (int j = 0; j < numCellsSide; ++j) {
1601 cidx = bdryCellLocIds_[l][j];
1602 for (int k = 0; k < fv; ++k) {
1603 (*H[i])(cidx,k) += (*intHess)(j,k);
1604 }
1605 }
1606 }
1607 }
1608 }
1609 fieldHelper_->combineFieldCoeff(hess, H);
1610 }
1611
1612 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess,
1613 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &v_coeff,
1614 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1615 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1616 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1617 throw Exception::Zero(">>> QoI_DownStreamPower_ThermalFluids::HessVec_12 is zero.");
1618 }
1619
1620 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess,
1621 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &v_coeff,
1622 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1623 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1624 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1625 throw Exception::Zero(">>> QoI_DownStreamPower_ThermalFluids::HessVec_21 is zero.");
1626 }
1627
1628 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess,
1629 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &v_coeff,
1630 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff,
1631 const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr,
1632 const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) {
1633 throw Exception::Zero(">>> QoI_DownStreamPower_ThermalFluids::HessVec_22 is zero.");
1634 }
1635
1636 }; // QoI_DownStreamPower_ThermalFluids
1637
1638 template <class Real>
1639 class QoI_L2Penalty_ThermalFluids : public QoI<Real> {
1640 private:
1641 const ROL::Ptr<FE<Real>> feVel_;
1642 const ROL::Ptr<FE<Real>> fePrs_;
1643 const ROL::Ptr<FE<Real>> feThr_;
1644 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> feThrBdry_;
1645 const std::vector<std::vector<std::vector<int>>> bdryCellLocIds_;
1646 const ROL::Ptr<FieldHelper<Real>> fieldHelper_;
1647
1648 ROL::Ptr<Intrepid::FieldContainer<Real>> getBoundaryCoeff(
1649 const Intrepid::FieldContainer<Real> & cell_coeff,
1650 int sideSet, int cell) const {
1651 std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][cell];
1652 const int numCellsSide = bdryCellLocId.size();
1653 const int f = feThr_->N()->dimension(1);
1654
1655 ROL::Ptr<Intrepid::FieldContainer<Real >> bdry_coeff =
1656 ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f);
1657 for (int i = 0; i < numCellsSide; ++i) {
1658 for (int j = 0; j < f; ++j) {
1659 (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j);
1660 }
1661 }
1662 return bdry_coeff;
1663 }
1664
1665 public:
1666 QoI_L2Penalty_ThermalFluids(const ROL::Ptr<FE<Real>> &feVel,
1667 const ROL::Ptr<FE<Real>> &fePrs,
1668 const ROL::Ptr<FE<Real>> &feThr,
1669 const std::vector<std::vector<ROL::Ptr<FE<Real>>>> &feThrBdry,
1670 const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds,
1671 const ROL::Ptr<FieldHelper<Real>> &fieldHelper)
1672 : feVel_(feVel), fePrs_(fePrs), feThr_(feThr), feThrBdry_(feThrBdry),
1673 bdryCellLocIds_(bdryCellLocIds), fieldHelper_(fieldHelper) {}
1674
1675 Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val,
1676 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1677 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1678 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1679 const int c = feVel_->gradN()->dimension(0);
1680 const int d = feVel_->gradN()->dimension(3);
1681 // Get components of the control
1682 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> Z;
1683 fieldHelper_->splitFieldCoeff(Z, z_coeff);
1684 // Initialize output val
1685 val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c);
1686 // Compute cost integral
1687 const int numSideSets = bdryCellLocIds_.size();
1688 if (numSideSets > 0) {
1689 for (int i = 0; i < numSideSets; ++i) {
1690 if (i==4) {
1691 const int numLocalSideIds = bdryCellLocIds_[i].size();
1692 for (int j = 0; j < numLocalSideIds; ++j) {
1693 const int numCellsSide = bdryCellLocIds_[i][j].size();
1694 if ( numCellsSide ) {
1695 const int numCubPerSide = feThrBdry_[i][j]->cubPts()->dimension(1);
1696 // Evaluate control on FE basis
1697 ROL::Ptr<Intrepid::FieldContainer<Real>> z_coeff_bdry
1698 = getBoundaryCoeff(*Z[d+1], i, j);
1699 ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval
1700 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1701 feThrBdry_[i][j]->evaluateValue(valZ_eval, z_coeff_bdry);
1702 // Integrate cell L2 norm squared
1703 ROL::Ptr<Intrepid::FieldContainer<Real>> intVal
1704 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide);
1705 feThrBdry_[i][j]->computeIntegral(intVal,valZ_eval,valZ_eval,false);
1706 // Add to integral value
1707 for (int k = 0; k < numCellsSide; ++k) {
1708 int cidx = bdryCellLocIds_[i][j][k];
1709 (*val)(cidx) += static_cast<Real>(0.5)*(*intVal)(k);
1710 }
1711 }
1712 }
1713 }
1714 }
1715 }
1716 return static_cast<Real>(0);
1717 }
1718
1719 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1720 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1721 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1722 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1723 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::gradient_1 is zero.");
1724 }
1725
1726 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad,
1727 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1728 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1729 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1730 const int c = feVel_->gradN()->dimension(0);
1731 const int fv = feVel_->gradN()->dimension(1);
1732 const int fp = fePrs_->gradN()->dimension(1);
1733 const int fh = feThr_->gradN()->dimension(1);
1734 const int d = feThr_->gradN()->dimension(3);
1735 // Initialize output grad
1736 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G(d+2);
1737 for (int i = 0; i < d; ++i) {
1738 G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1739 }
1740 G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1741 G[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1742 // Get components of the control
1743 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> Z;
1744 fieldHelper_->splitFieldCoeff(Z, z_coeff);
1745 // Compute cost integral
1746 const int numSideSets = bdryCellLocIds_.size();
1747 if (numSideSets > 0) {
1748 for (int i = 0; i < numSideSets; ++i) {
1749 if (i==4) {
1750 const int numLocalSideIds = bdryCellLocIds_[i].size();
1751 for (int j = 0; j < numLocalSideIds; ++j) {
1752 const int numCellsSide = bdryCellLocIds_[i][j].size();
1753 if ( numCellsSide ) {
1754 const int numCubPerSide = feThrBdry_[i][j]->cubPts()->dimension(1);
1755 // Evaluate control on FE basis
1756 ROL::Ptr<Intrepid::FieldContainer<Real>> z_coeff_bdry
1757 = getBoundaryCoeff(*Z[d+1], i, j);
1758 ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval
1759 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1760 feThrBdry_[i][j]->evaluateValue(valZ_eval, z_coeff_bdry);
1761 // Compute gradient of squared L2-norm of diff
1762 ROL::Ptr<Intrepid::FieldContainer<Real>> intGrad
1763 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fh);
1764 Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad,
1765 *valZ_eval,
1766 *(feThrBdry_[i][j]->NdetJ()),
1767 Intrepid::COMP_CPP, false);
1768 // Add to integral value
1769 for (int k = 0; k < numCellsSide; ++k) {
1770 int cidx = bdryCellLocIds_[i][j][k];
1771 for (int l = 0; l < fh; ++l) {
1772 (*G[d+1])(cidx,l) += (*intGrad)(k,l);
1773 }
1774 }
1775 }
1776 }
1777 }
1778 }
1779 }
1780
1781 fieldHelper_->combineFieldCoeff(grad, G);
1782 }
1783
1784 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1785 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1786 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1787 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1788 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1789 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::HessVec_11 is zero.");
1790 }
1791
1792 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1793 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1794 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1795 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1796 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1797 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::HessVec_12 is zero.");
1798 }
1799
1800 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1801 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1802 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1803 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1804 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1805 throw Exception::Zero(">>> QoI_L2Penalty_ThermalFluids::HessVec_21 is zero.");
1806 }
1807
1808 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess,
1809 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff,
1810 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff,
1811 const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr,
1812 const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) {
1813 const int c = feVel_->gradN()->dimension(0);
1814 const int fv = feVel_->gradN()->dimension(1);
1815 const int fp = fePrs_->gradN()->dimension(1);
1816 const int fh = feThr_->gradN()->dimension(1);
1817 const int d = feThr_->gradN()->dimension(3);
1818 // Initialize output grad
1819 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H(d+2);
1820 for (int i = 0; i < d; ++i) {
1821 H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv);
1822 }
1823 H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp);
1824 H[d+1] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fh);
1825 // Get components of the control
1826 std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V;
1827 fieldHelper_->splitFieldCoeff(V, v_coeff);
1828 // Compute cost integral
1829 const int numSideSets = bdryCellLocIds_.size();
1830 if (numSideSets > 0) {
1831 for (int i = 0; i < numSideSets; ++i) {
1832 if (i==4) {
1833 const int numLocalSideIds = bdryCellLocIds_[i].size();
1834 for (int j = 0; j < numLocalSideIds; ++j) {
1835 const int numCellsSide = bdryCellLocIds_[i][j].size();
1836 if ( numCellsSide ) {
1837 const int numCubPerSide = feThrBdry_[i][j]->cubPts()->dimension(1);
1838 // Evaluate control on FE basis
1839 ROL::Ptr<Intrepid::FieldContainer<Real>> v_coeff_bdry
1840 = getBoundaryCoeff(*V[d+1], i, j);
1841 ROL::Ptr<Intrepid::FieldContainer<Real>> valV_eval
1842 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide);
1843 feThrBdry_[i][j]->evaluateValue(valV_eval, v_coeff_bdry);
1844 // Compute gradient of squared L2-norm of diff
1845 ROL::Ptr<Intrepid::FieldContainer<Real>> intHess
1846 = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fh);
1847 Intrepid::FunctionSpaceTools::integrate<Real>(*intHess,
1848 *valV_eval,
1849 *(feThrBdry_[i][j]->NdetJ()),
1850 Intrepid::COMP_CPP, false);
1851 // Add to integral value
1852 for (int k = 0; k < numCellsSide; ++k) {
1853 int cidx = bdryCellLocIds_[i][j][k];
1854 for (int l = 0; l < fh; ++l) {
1855 (*H[d+1])(cidx,l) += (*intHess)(k,l);
1856 }
1857 }
1858 }
1859 }
1860 }
1861 }
1862 }
1863
1864 fieldHelper_->combineFieldCoeff(hess, H);
1865 }
1866
1867 }; // QoI_L2Penalty_ThermalFluids
1868
1869 template <class Real>
1870 class QoI_RotationControl_ThermalFluids : public QoI<Real> {
1871 public:
1872 QoI_RotationControl_ThermalFluids(void) {}
1873
1874 Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val,
1875 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1876 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1877 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1878 const int size = z_param->size();
1879 Real half(0.5), sum(0);
1880 for (int i = 0; i < size; ++i) {
1881 sum += std::pow((*z_param)[i],2);
1882 }
1883 val = ROL::nullPtr;
1884 return half * sum;
1885 }
1886
1887 void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
1888 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1889 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1890 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1891 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::gradient_1 is zero.");
1892 }
1893
1894 void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad,
1895 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1896 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1897 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1898 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::gradient_2 is zero.");
1899 }
1900
1901 std::vector<Real> gradient_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & grad,
1902 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1903 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1904 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1905 std::vector<Real> g; g.assign(z_param->begin(),z_param->end());
1906 return g;
1907 }
1908
1909 void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1910 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
1911 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1912 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1913 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1914 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_11 is zero.");
1915 }
1916
1917 void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1918 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
1919 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1920 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1921 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1922 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_12 is zero.");
1923 }
1924
1925 void HessVec_13(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess,
1926 const ROL::Ptr<const std::vector<Real> > & v_param,
1927 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1928 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1929 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1930 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_13 is zero.");
1931 }
1932
1933 void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1934 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
1935 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1936 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1937 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1938 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_21 is zero.");
1939 }
1940
1941 void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess,
1942 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
1943 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1944 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1945 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1946 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_22 is zero.");
1947 }
1948
1949 void HessVec_23(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess,
1950 const ROL::Ptr<const std::vector<Real> > & v_param,
1951 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1952 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1953 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1954 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_23 is zero.");
1955 }
1956
1957 std::vector<Real> HessVec_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess,
1958 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
1959 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1960 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1961 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1962 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_31 is zero.");
1963 }
1964
1965 std::vector<Real> HessVec_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess,
1966 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff,
1967 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1968 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1969 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1970 throw Exception::Zero(">>> QoI_RotationControl_ThermalFluids::HessVec_32 is zero.");
1971 }
1972
1973 std::vector<Real> HessVec_33(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess,
1974 const ROL::Ptr<const std::vector<Real> > & v_param,
1975 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff,
1976 const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr,
1977 const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) {
1978 std::vector<Real> h; h.assign(v_param->begin(),v_param->end());
1979 return h;
1980 }
1981
1982 }; // QoI_RotationControl_NavierStoke
1983 #endif