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