Debian Codegraph @

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