| 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 |
#include "impermiability.hpp" |
| 20 |
|
| 21 |
template <class Real> |
| 22 |
class QoI_Power_NavierStokes : public QoI<Real> { |
| 23 |
private: |
| 24 |
const ROL::Ptr<FE<Real>> feVel_; |
| 25 |
const ROL::Ptr<FE<Real>> fePrs_; |
| 26 |
const ROL::Ptr<FE<Real>> feCtrl_; |
| 27 |
const ROL::Ptr<const FieldUtils::FieldInfo> fieldInfo_; |
| 28 |
const ROL::Ptr<const FieldUtils::FieldInfo> fieldInfoCtrl_; |
| 29 |
|
| 30 |
ROL::Ptr<Impermiability<Real>> imp_; |
| 31 |
Real viscosity_; |
| 32 |
|
| 33 |
public: |
| 34 |
QoI_Power_NavierStokes(Teuchos::ParameterList &list, |
| 35 |
const ROL::Ptr<FE<Real>> &feVel, |
| 36 |
const ROL::Ptr<FE<Real>> &fePrs, |
| 37 |
const ROL::Ptr<FE<Real>> &feCtrl, |
| 38 |
const ROL::Ptr<const FieldUtils::FieldInfo> &fieldInfo, |
| 39 |
const ROL::Ptr<const FieldUtils::FieldInfo> &fieldInfoCtrl) |
| 40 |
: feVel_(feVel), fePrs_(fePrs), feCtrl_(feCtrl), fieldInfo_(fieldInfo), fieldInfoCtrl_(fieldInfoCtrl) { |
| 41 |
viscosity_ = list.sublist("Problem").get("Viscosity",5e-3); |
| 42 |
imp_ = ROL::makePtr<Impermiability<Real>>(list); |
| 43 |
} |
| 44 |
|
| 45 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val, |
| 46 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 47 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 48 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 49 |
// Get relevant dimensions |
| 50 |
const int c = feVel_->gradN()->dimension(0); |
| 51 |
const int p = feVel_->gradN()->dimension(2); |
| 52 |
const int d = feVel_->gradN()->dimension(3); |
| 53 |
// Initialize output val |
| 54 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 55 |
// Get components of the control |
| 56 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, Z; |
| 57 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 58 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 59 |
// Evaluate on FE basis |
| 60 |
ROL::Ptr<Intrepid::FieldContainer<Real>> alpha, Zval, Uval, aUval, Ugrad, nUgrad; |
| 61 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 62 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 63 |
Uval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 64 |
aUval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 65 |
Ugrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 66 |
nUgrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 67 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 68 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 0); |
| 69 |
for (int i = 0; i < d; ++i) { |
| 70 |
Uval->initialize(); |
| 71 |
Ugrad->initialize(); |
| 72 |
aUval->initialize(); |
| 73 |
nUgrad->initialize(); |
| 74 |
// Evaluate on FE basis |
| 75 |
feVel_->evaluateValue(Uval, U[i]); |
| 76 |
feVel_->evaluateGradient(Ugrad, U[i]); |
| 77 |
// Scale |
| 78 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUval, *alpha, *Uval); |
| 79 |
Intrepid::RealSpaceTools<Real>::scale(*nUgrad, *Ugrad, viscosity_); |
| 80 |
// Integrate |
| 81 |
feVel_->computeIntegral(val, nUgrad, Ugrad, true); |
| 82 |
feVel_->computeIntegral(val, aUval, Uval, true); |
| 83 |
} |
| 84 |
Intrepid::RealSpaceTools<Real>::scale(*val, static_cast<Real>(0.5)); |
| 85 |
return static_cast<Real>(0); |
| 86 |
} |
| 87 |
|
| 88 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 89 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 90 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 91 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 92 |
// Get relevant dimensions |
| 93 |
const int c = feVel_->gradN()->dimension(0); |
| 94 |
const int fv = feVel_->gradN()->dimension(1); |
| 95 |
const int fp = fePrs_->gradN()->dimension(1); |
| 96 |
const int p = feVel_->gradN()->dimension(2); |
| 97 |
const int d = feVel_->gradN()->dimension(3); |
| 98 |
// Initialize output grad |
| 99 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G; |
| 100 |
G.resize(fieldInfo_->numFields); |
| 101 |
for (int i = 0; i < d; ++i) { |
| 102 |
G[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv); |
| 103 |
} |
| 104 |
G[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp); |
| 105 |
// Get components of the control |
| 106 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, Z; |
| 107 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 108 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 109 |
// Create storage |
| 110 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Zval, alpha, Uval, aUval, Ugrad; |
| 111 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 112 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 113 |
Uval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 114 |
aUval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 115 |
Ugrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 116 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 117 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 0); |
| 118 |
for (int i = 0; i < d; ++i) { |
| 119 |
Uval->initialize(); |
| 120 |
Ugrad->initialize(); |
| 121 |
aUval->initialize(); |
| 122 |
// Evaluate on FE basis |
| 123 |
feVel_->evaluateValue(Uval, U[i]); |
| 124 |
feVel_->evaluateGradient(Ugrad, U[i]); |
| 125 |
// Scale |
| 126 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUval, *alpha, *Uval); |
| 127 |
Intrepid::RealSpaceTools<Real>::scale(*Ugrad, viscosity_); |
| 128 |
// Integrate |
| 129 |
Intrepid::FunctionSpaceTools::integrate<Real>(*G[i], |
| 130 |
*Ugrad, |
| 131 |
*(feVel_->gradNdetJ()), |
| 132 |
Intrepid::COMP_CPP, false); |
| 133 |
Intrepid::FunctionSpaceTools::integrate<Real>(*G[i], |
| 134 |
*aUval, |
| 135 |
*(feVel_->NdetJ()), |
| 136 |
Intrepid::COMP_CPP, true); |
| 137 |
} |
| 138 |
FieldUtils::combineFieldCoeff<Real>(grad, G, fieldInfo_); |
| 139 |
} |
| 140 |
|
| 141 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 142 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 143 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 144 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 145 |
// Get relevant dimensions |
| 146 |
const int c = feVel_->gradN()->dimension(0); |
| 147 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 148 |
const int p = feVel_->gradN()->dimension(2); |
| 149 |
const int d = feVel_->gradN()->dimension(3); |
| 150 |
// Initialize output grad |
| 151 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G; |
| 152 |
G.resize(fieldInfoCtrl_->numFields); |
| 153 |
G[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 154 |
// Get components of the control |
| 155 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, Z; |
| 156 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 157 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 158 |
// Create storage |
| 159 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Zval, alpha, Uval, aUval, aU2val; |
| 160 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 161 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 162 |
Uval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 163 |
aUval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 164 |
aU2val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 165 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 166 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 1); |
| 167 |
for (int i = 0; i < d; ++i) { |
| 168 |
Uval->initialize(); |
| 169 |
aUval->initialize(); |
| 170 |
aU2val->initialize(); |
| 171 |
// Evaluate on FE basis |
| 172 |
feVel_->evaluateValue(Uval, U[i]); |
| 173 |
// Scale |
| 174 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUval, *alpha, *Uval); |
| 175 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aU2val, *aUval, *Uval); |
| 176 |
// Integrate |
| 177 |
Intrepid::FunctionSpaceTools::integrate<Real>(*G[0], |
| 178 |
*aU2val, |
| 179 |
*(feCtrl_->NdetJ()), |
| 180 |
Intrepid::COMP_CPP, true); |
| 181 |
} |
| 182 |
Intrepid::RealSpaceTools<Real>::scale(*G[0], static_cast<Real>(0.5)); |
| 183 |
FieldUtils::combineFieldCoeff<Real>(grad, G, fieldInfoCtrl_); |
| 184 |
} |
| 185 |
|
| 186 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 187 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 188 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 189 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 190 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 191 |
// Get relevant dimensions |
| 192 |
const int c = feVel_->gradN()->dimension(0); |
| 193 |
const int fv = feVel_->gradN()->dimension(1); |
| 194 |
const int fp = fePrs_->gradN()->dimension(1); |
| 195 |
const int p = feVel_->gradN()->dimension(2); |
| 196 |
const int d = feVel_->gradN()->dimension(3); |
| 197 |
// Initialize output grad |
| 198 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H; |
| 199 |
H.resize(fieldInfo_->numFields); |
| 200 |
for (int i = 0; i < d; ++i) { |
| 201 |
H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv); |
| 202 |
} |
| 203 |
H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp); |
| 204 |
// Get components of the control |
| 205 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V, Z; |
| 206 |
FieldUtils::splitFieldCoeff<Real>(V, v_coeff, fieldInfo_); |
| 207 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 208 |
// Create storage |
| 209 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Zval, alpha, Vval, Vgrad, aVval; |
| 210 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 211 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 212 |
Vval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 213 |
aVval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 214 |
Vgrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 215 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 216 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 0); |
| 217 |
for (int i = 0; i < d; ++i) { |
| 218 |
Vval->initialize(); |
| 219 |
Vgrad->initialize(); |
| 220 |
aVval->initialize(); |
| 221 |
// Evaluate on FE basis |
| 222 |
feVel_->evaluateValue(Vval, V[i]); |
| 223 |
feVel_->evaluateGradient(Vgrad, V[i]); |
| 224 |
// Scale |
| 225 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aVval, *alpha, *Vval); |
| 226 |
Intrepid::RealSpaceTools<Real>::scale(*Vgrad, viscosity_); |
| 227 |
// Integrate |
| 228 |
Intrepid::FunctionSpaceTools::integrate<Real>(*H[i], |
| 229 |
*Vgrad, |
| 230 |
*(feVel_->gradNdetJ()), |
| 231 |
Intrepid::COMP_CPP, false); |
| 232 |
Intrepid::FunctionSpaceTools::integrate<Real>(*H[i], |
| 233 |
*aVval, |
| 234 |
*(feVel_->NdetJ()), |
| 235 |
Intrepid::COMP_CPP, true); |
| 236 |
} |
| 237 |
FieldUtils::combineFieldCoeff<Real>(hess, H, fieldInfo_); |
| 238 |
} |
| 239 |
|
| 240 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 241 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 242 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 243 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 244 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 245 |
// Get relevant dimensions |
| 246 |
const int c = feVel_->gradN()->dimension(0); |
| 247 |
const int fv = feVel_->gradN()->dimension(1); |
| 248 |
const int fp = fePrs_->gradN()->dimension(1); |
| 249 |
const int p = feVel_->gradN()->dimension(2); |
| 250 |
const int d = feVel_->gradN()->dimension(3); |
| 251 |
// Initialize output grad |
| 252 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H; |
| 253 |
H.resize(fieldInfo_->numFields); |
| 254 |
for (int i = 0; i < d; ++i) { |
| 255 |
H[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fv); |
| 256 |
} |
| 257 |
H[d] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fp); |
| 258 |
// Get components of the control |
| 259 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V, U, Z; |
| 260 |
FieldUtils::splitFieldCoeff<Real>(V, v_coeff, fieldInfoCtrl_); |
| 261 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 262 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 263 |
// Create storage |
| 264 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Zval, alpha, Uval, aUval, Vval, aVval; |
| 265 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 266 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 267 |
Uval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 268 |
aUval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 269 |
Vval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 270 |
aVval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 271 |
feCtrl_->evaluateValue(Vval, V[0]); |
| 272 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 273 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 1); |
| 274 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aVval, *alpha, *Vval); |
| 275 |
for (int i = 0; i < d; ++i) { |
| 276 |
Uval->initialize(); |
| 277 |
aUval->initialize(); |
| 278 |
// Evaluate on FE basis |
| 279 |
feVel_->evaluateValue(Uval, U[i]); |
| 280 |
// Scale |
| 281 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUval, *aVval, *Uval); |
| 282 |
// Integrate |
| 283 |
Intrepid::FunctionSpaceTools::integrate<Real>(*H[i], |
| 284 |
*aUval, |
| 285 |
*(feVel_->NdetJ()), |
| 286 |
Intrepid::COMP_CPP, false); |
| 287 |
} |
| 288 |
FieldUtils::combineFieldCoeff<Real>(hess, H, fieldInfo_); |
| 289 |
} |
| 290 |
|
| 291 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 292 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 293 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 294 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 295 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 296 |
// Get relevant dimensions |
| 297 |
const int c = feVel_->gradN()->dimension(0); |
| 298 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 299 |
const int p = feVel_->gradN()->dimension(2); |
| 300 |
const int d = feVel_->gradN()->dimension(3); |
| 301 |
// Initialize output grad |
| 302 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H; |
| 303 |
H.resize(fieldInfoCtrl_->numFields); |
| 304 |
H[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 305 |
// Get components of the control |
| 306 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V, U, Z; |
| 307 |
FieldUtils::splitFieldCoeff<Real>(V, v_coeff, fieldInfo_); |
| 308 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 309 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 310 |
// Create storage |
| 311 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Zval, alpha, Uval, aUval, aUVval, Vval; |
| 312 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 313 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 314 |
Uval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 315 |
aUval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 316 |
aUVval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 317 |
Vval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 318 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 319 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 1); |
| 320 |
for (int i = 0; i < d; ++i) { |
| 321 |
Vval->initialize(); |
| 322 |
Uval->initialize(); |
| 323 |
aUval->initialize(); |
| 324 |
aUVval->initialize(); |
| 325 |
// Evaluate on FE basis |
| 326 |
feVel_->evaluateValue(Vval, V[i]); |
| 327 |
feVel_->evaluateValue(Uval, U[i]); |
| 328 |
// Scale |
| 329 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUval, *alpha, *Uval); |
| 330 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUVval, *aUval, *Vval); |
| 331 |
// Integrate |
| 332 |
Intrepid::FunctionSpaceTools::integrate<Real>(*H[0], |
| 333 |
*aUVval, |
| 334 |
*(feCtrl_->NdetJ()), |
| 335 |
Intrepid::COMP_CPP, true); |
| 336 |
} |
| 337 |
FieldUtils::combineFieldCoeff<Real>(hess, H, fieldInfoCtrl_); |
| 338 |
} |
| 339 |
|
| 340 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 341 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 342 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 343 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 344 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 345 |
// Get relevant dimensions |
| 346 |
const int c = feVel_->gradN()->dimension(0); |
| 347 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 348 |
const int p = feVel_->gradN()->dimension(2); |
| 349 |
const int d = feVel_->gradN()->dimension(3); |
| 350 |
// Initialize output grad |
| 351 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> H; |
| 352 |
H.resize(fieldInfoCtrl_->numFields); |
| 353 |
H[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 354 |
// Get components of the control |
| 355 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> V, U, Z; |
| 356 |
FieldUtils::splitFieldCoeff<Real>(V, v_coeff, fieldInfoCtrl_); |
| 357 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 358 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoCtrl_); |
| 359 |
// Create storage |
| 360 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Zval, alpha, Uval, aUval, aU2val, Vval, aVval; |
| 361 |
Zval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 362 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 363 |
Uval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 364 |
aUval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 365 |
aU2val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 366 |
Vval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 367 |
aVval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 368 |
feCtrl_->evaluateValue(Vval, V[0]); |
| 369 |
feCtrl_->evaluateValue(Zval, Z[0]); |
| 370 |
imp_->compute(alpha, Zval, feVel_->cubPts(), 2); |
| 371 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aVval, *alpha, *Vval); |
| 372 |
for (int i = 0; i < d; ++i) { |
| 373 |
Uval->initialize(); |
| 374 |
aUval->initialize(); |
| 375 |
aU2val->initialize(); |
| 376 |
// Evaluate on FE basis |
| 377 |
feVel_->evaluateValue(Uval, U[i]); |
| 378 |
// Scale |
| 379 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aUval, *aVval, *Uval); |
| 380 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*aU2val, *aUval, *Uval); |
| 381 |
// Integrate |
| 382 |
Intrepid::FunctionSpaceTools::integrate<Real>(*H[0], |
| 383 |
*aU2val, |
| 384 |
*(feCtrl_->NdetJ()), |
| 385 |
Intrepid::COMP_CPP, true); |
| 386 |
} |
| 387 |
Intrepid::RealSpaceTools<Real>::scale(*H[0], static_cast<Real>(0.5)); |
| 388 |
FieldUtils::combineFieldCoeff<Real>(hess, H, fieldInfoCtrl_); |
| 389 |
} |
| 390 |
|
| 391 |
}; // QoI_Power_NavierStokes |
| 392 |
|
| 393 |
template <class Real> |
| 394 |
class QoI_Volume_NavierStokes : public QoI<Real> { |
| 395 |
private: |
| 396 |
const ROL::Ptr<FE<Real>> fe_; |
| 397 |
const ROL::Ptr<const FieldUtils::FieldInfo> fieldInfo_; |
| 398 |
|
| 399 |
ROL::Ptr<Intrepid::FieldContainer<Real>> weight_; |
| 400 |
Real volFraction_; |
| 401 |
|
| 402 |
public: |
| 403 |
QoI_Volume_NavierStokes(ROL::ParameterList &list, |
| 404 |
const ROL::Ptr<FE<Real>> &fe, |
| 405 |
const ROL::Ptr<const FieldUtils::FieldInfo> &fieldInfo) |
| 406 |
: fe_(fe), fieldInfo_(fieldInfo) { |
| 407 |
const Real one(1); |
| 408 |
volFraction_ = list.sublist("Problem").get("Volume Fraction",0.5); |
| 409 |
const int c = fe_->cubPts()->dimension(0); |
| 410 |
const int p = fe_->cubPts()->dimension(1); |
| 411 |
weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 412 |
weight_->initialize(one); |
| 413 |
} |
| 414 |
|
| 415 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val, |
| 416 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 417 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 418 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 419 |
// Get relevant dimensions |
| 420 |
const int c = fe_->cubPts()->dimension(0); |
| 421 |
const int p = fe_->cubPts()->dimension(1); |
| 422 |
// Initialize output val |
| 423 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 424 |
// Get components of the control |
| 425 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> Z; |
| 426 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfo_); |
| 427 |
// Evaluate on FE basis |
| 428 |
ROL::Ptr<Intrepid::FieldContainer<Real>> Z0; |
| 429 |
Z0 = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 430 |
fe_->evaluateValue(Z0, Z[0]); |
| 431 |
// Integrate the density minus volume fraction |
| 432 |
for (int i = 0; i < c; ++i) { |
| 433 |
for (int j = 0; j < p; ++j) { |
| 434 |
(*Z0)(i,j) -= volFraction_; |
| 435 |
} |
| 436 |
} |
| 437 |
fe_->computeIntegral(val,weight_,Z0,true); |
| 438 |
return static_cast<Real>(0); |
| 439 |
} |
| 440 |
|
| 441 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 442 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 443 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 444 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 445 |
throw Exception::Zero(">>> QoI_Volume_NavierStokes::gradient_1 is zero."); |
| 446 |
} |
| 447 |
|
| 448 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 449 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 450 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 451 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 452 |
// Get relevant dimensions |
| 453 |
const int c = fe_->cubPts()->dimension(0); |
| 454 |
const int f = fe_->N()->dimension(1); |
| 455 |
// Initialize output grad |
| 456 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> G; |
| 457 |
G.resize(fieldInfo_->numFields); |
| 458 |
G[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 459 |
// Integrate density |
| 460 |
Intrepid::FunctionSpaceTools::integrate<Real>(*G[0], |
| 461 |
*weight_, |
| 462 |
*(fe_->NdetJ()), |
| 463 |
Intrepid::COMP_CPP, false); |
| 464 |
FieldUtils::combineFieldCoeff(grad, G, fieldInfo_); |
| 465 |
} |
| 466 |
|
| 467 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 468 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 469 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 470 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 471 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 472 |
throw Exception::Zero(">>> QoI_Volume_NavierStokes::HessVec_11 is zero."); |
| 473 |
} |
| 474 |
|
| 475 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 476 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 477 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 478 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 479 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 480 |
throw Exception::Zero(">>> QoI_Volume_NavierStokes::HessVec_12 is zero."); |
| 481 |
} |
| 482 |
|
| 483 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 484 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 485 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 486 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 487 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 488 |
throw Exception::Zero(">>> QoI_Volume_NavierStokes::HessVec_21 is zero."); |
| 489 |
} |
| 490 |
|
| 491 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 492 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 493 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 494 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 495 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 496 |
throw Exception::Zero(">>> QoI_Volume_NavierStokes::HessVec_22 is zero."); |
| 497 |
} |
| 498 |
|
| 499 |
}; // QoI_Volume_NavierStokes |
| 500 |
|
| 501 |
#endif |