| 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 OBJ_DARCY_HPP |
| 15 |
#define OBJ_DARCY_HPP |
| 16 |
|
| 17 |
#include "../../../../TOOLS/qoi.hpp" |
| 18 |
#include "pde_darcy.hpp" |
| 19 |
#include "permeability.hpp" |
| 20 |
|
| 21 |
|
| 22 |
template <class Real> |
| 23 |
class QoI_VelocityTracking_Darcy : public QoI<Real> { |
| 24 |
private: |
| 25 |
const ROL::Ptr<FE<Real>> fePrs_, feCtrl_; |
| 26 |
const ROL::Ptr<Permeability<Real>> perm_; |
| 27 |
ROL::Ptr<Intrepid::FieldContainer<Real>> target_, weight_; |
| 28 |
Real rad_, yvel_, frac_, twpow_; |
| 29 |
bool onlyAxial_; |
| 30 |
|
| 31 |
Real xTarget(const std::vector<Real> &x) const { |
| 32 |
const Real X = x[0], Y = x[1]; |
| 33 |
//return xWeight(x) ? -X*Y/(rad_*rad_-Y*Y) : zero; |
| 34 |
//return xWeight(x) ? -X*Y/std::sqrt(rad_*rad_-Y*Y) : zero; |
| 35 |
//return polyWeight(x) * (-X*Y/std::sqrt(rad_*rad_-Y*Y)); |
| 36 |
//return -X*Y/std::sqrt(rad_*rad_-Y*Y); |
| 37 |
return -X*Y/((rad_*rad_-Y*Y)*(rad_*rad_-Y*Y)); |
| 38 |
} |
| 39 |
|
| 40 |
Real yTarget(const std::vector<Real> &x) const { |
| 41 |
const Real one(1), Y = x[1]; |
| 42 |
//return yWeight(x) ? one : zero; |
| 43 |
//return yWeight(x) ? std::sqrt(rad_*rad_-Y*Y) : zero; |
| 44 |
//return polyWeight(x) * std::sqrt(rad_*rad_-Y*Y); |
| 45 |
//return std::sqrt(rad_*rad_-Y*Y); |
| 46 |
return one/(rad_*rad_-Y*Y); |
| 47 |
} |
| 48 |
|
| 49 |
Real xWeight(const std::vector<Real> &x) const { |
| 50 |
return yWeight(x); |
| 51 |
} |
| 52 |
|
| 53 |
Real yWeight(const std::vector<Real> &x) const { |
| 54 |
//const Real zero(0), one(1), Y = x[1]; |
| 55 |
//return (std::abs(Y) <= frac_*rad_ ? one : zero); |
| 56 |
return polyWeight(x); |
| 57 |
} |
| 58 |
|
| 59 |
Real polyWeight(const std::vector<Real> &x) const { |
| 60 |
const Real zero(0), one(1), Y = x[1], p = twpow_; |
| 61 |
const Real yTOP = 9.976339196; |
| 62 |
const Real yBOT = -yTOP; |
| 63 |
Real val = 0, at = 0, bt = 0; |
| 64 |
at = one / std::pow(-yTOP,p); |
| 65 |
bt = one / std::pow(-yBOT,p); |
| 66 |
if (Y > zero) { |
| 67 |
val = at*std::pow(Y-yTOP,p); |
| 68 |
} else { |
| 69 |
val = bt*std::pow(Y-yBOT,p); |
| 70 |
} |
| 71 |
//std::cout << Y << " " << val << std::endl; |
| 72 |
return val; |
| 73 |
} |
| 74 |
|
| 75 |
public: |
| 76 |
QoI_VelocityTracking_Darcy(Teuchos::ParameterList &list, |
| 77 |
const ROL::Ptr<FE<Real>> &fePrs, |
| 78 |
const ROL::Ptr<FE<Real>> &feCtrl, |
| 79 |
const ROL::Ptr<Permeability<Real>> &perm) |
| 80 |
: fePrs_(fePrs), feCtrl_(feCtrl), perm_(perm) { |
| 81 |
rad_ = list.sublist("Problem").get("Diffuser Radius",5.0); |
| 82 |
yvel_ = list.sublist("Problem").get("Target Axial Velocity",15.0); |
| 83 |
frac_ = list.sublist("Problem").get("Integration Domain Fraction",0.95); |
| 84 |
onlyAxial_ = list.sublist("Problem").get("Only Use Axial Velocity",false); |
| 85 |
twpow_ = list.sublist("Problem").get("Target Weighting Power",0.0); |
| 86 |
Real xWScal = list.sublist("Problem").get("Radial Tracking Scale",1.0); |
| 87 |
Real yWScal = list.sublist("Problem").get("Axial Tracking Scale",1.0); |
| 88 |
bool useNorm = list.sublist("Problem").get("Use Normalized Misfit",false); |
| 89 |
useNorm = onlyAxial_ ? false : useNorm; |
| 90 |
xWScal = onlyAxial_ ? static_cast<Real>(0) : xWScal; |
| 91 |
const int c = fePrs_->gradN()->dimension(0); |
| 92 |
const int p = fePrs_->gradN()->dimension(2); |
| 93 |
const int d = fePrs_->gradN()->dimension(3); |
| 94 |
target_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 95 |
weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 96 |
std::vector<Real> x(2); |
| 97 |
for (int i = 0; i < c; ++i) { |
| 98 |
for (int j = 0; j < p; ++j) { |
| 99 |
x[0] = (*fePrs_->cubPts())(i,j,0); |
| 100 |
x[1] = (*fePrs_->cubPts())(i,j,1); |
| 101 |
(*target_)(i,j,0) = xTarget(x); |
| 102 |
(*target_)(i,j,1) = yTarget(x); |
| 103 |
if (useNorm && yWeight(x)) { |
| 104 |
xWScal = static_cast<Real>(1) |
| 105 |
/(std::pow((*target_)(i,j,0),2) + std::pow((*target_)(i,j,1),2)); |
| 106 |
yWScal = xWScal; |
| 107 |
} |
| 108 |
(*weight_)(i,j,0) = x[0] * xWScal * xWeight(x); |
| 109 |
(*weight_)(i,j,1) = x[0] * yWScal * yWeight(x); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val, |
| 115 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 116 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 117 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 118 |
// Get relevant dimensions |
| 119 |
const int c = fePrs_->gradN()->dimension(0); |
| 120 |
const int p = fePrs_->gradN()->dimension(2); |
| 121 |
const int d = fePrs_->gradN()->dimension(3); |
| 122 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 123 |
// Initialize output val |
| 124 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 125 |
// Compute cost integral |
| 126 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, valZ, alpha, vel, wvel; |
| 127 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 128 |
vel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 129 |
wvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 130 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 131 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 132 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 133 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 134 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 135 |
|
| 136 |
for (int i = 0; i < c; ++i) { |
| 137 |
for (int j = 0; j < p; ++j) { |
| 138 |
for (int k = 0; k < d; ++k) { |
| 139 |
(*vel)(i,j,k) = (*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k); |
| 140 |
(*wvel)(i,j,k) = (*weight_)(i,j,k)*(*vel)(i,j,k); |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
fePrs_->computeIntegral(val,vel,wvel); |
| 146 |
// Scale by one half |
| 147 |
Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5)); |
| 148 |
return static_cast<Real>(0); |
| 149 |
} |
| 150 |
|
| 151 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 152 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 153 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 154 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 155 |
// Get relevant dimensions |
| 156 |
const int c = fePrs_->gradN()->dimension(0); |
| 157 |
const int f = fePrs_->gradN()->dimension(1); |
| 158 |
const int p = fePrs_->gradN()->dimension(2); |
| 159 |
const int d = fePrs_->gradN()->dimension(3); |
| 160 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 161 |
// Initialize output grad |
| 162 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 163 |
// Compute cost integral |
| 164 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, valZ, alpha, awvel; |
| 165 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 166 |
awvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 167 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 168 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 169 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 170 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 171 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 172 |
|
| 173 |
for (int i = 0; i < c; ++i) { |
| 174 |
for (int j = 0; j < p; ++j) { |
| 175 |
for (int k = 0; k < d; ++k) { |
| 176 |
(*awvel)(i,j,k) = (*weight_)(i,j,k)*((*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k)) |
| 177 |
*(*alpha)(i,j); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 183 |
*awvel, |
| 184 |
*(fePrs_->gradNdetJ()), |
| 185 |
Intrepid::COMP_CPP, false); |
| 186 |
} |
| 187 |
|
| 188 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 189 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 190 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 191 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 192 |
// Get relevant dimensions |
| 193 |
const int c = fePrs_->gradN()->dimension(0); |
| 194 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 195 |
const int p = fePrs_->gradN()->dimension(2); |
| 196 |
const int d = fePrs_->gradN()->dimension(3); |
| 197 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 198 |
// Initialize output grad |
| 199 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 200 |
// Compute cost integral |
| 201 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, valZ, alpha, dalpha, deriv; |
| 202 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 203 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 204 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 205 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 206 |
deriv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 207 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 208 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 209 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 210 |
perm_->compute(dalpha, valZ, fePrs_->cubPts(), 1); |
| 211 |
|
| 212 |
for (int i = 0; i < c; ++i) { |
| 213 |
for (int j = 0; j < p; ++j) { |
| 214 |
for (int k = 0; k < d; ++k) { |
| 215 |
(*deriv)(i,j) += (*weight_)(i,j,k)*((*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k)) |
| 216 |
*(*dalpha)(i,j)*(*gradU)(i,j,k); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 222 |
*deriv, |
| 223 |
*feCtrl_->NdetJ(), |
| 224 |
Intrepid::COMP_CPP, false); |
| 225 |
} |
| 226 |
|
| 227 |
std::vector<Real> gradient_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & grad, |
| 228 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 229 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 230 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 231 |
if (z_param != ROL::nullPtr) { |
| 232 |
// Get relevant dimensions |
| 233 |
const int c = fePrs_->gradN()->dimension(0); |
| 234 |
const int p = fePrs_->gradN()->dimension(2); |
| 235 |
const int d = fePrs_->gradN()->dimension(3); |
| 236 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 237 |
// Initialize output val |
| 238 |
std::vector<Real> g_param(d,static_cast<Real>(0)); |
| 239 |
grad.clear(); grad.resize(d); |
| 240 |
for (int i = 0; i < d; ++i) |
| 241 |
grad[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 242 |
// Compute cost integral |
| 243 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, wvel, valZ, alpha; |
| 244 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 245 |
wvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 246 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 247 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 248 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 249 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 250 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 251 |
|
| 252 |
for (int i = 0; i < c; ++i) { |
| 253 |
for (int j = 0; j < p; ++j) { |
| 254 |
for (int k = 0; k < d; ++k) { |
| 255 |
(*wvel)(i,j,k) = (*weight_)(i,j,k)*((*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k)); |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
fePrs_->computeIntegral(grad[0],wvel,target_); |
| 261 |
|
| 262 |
return g_param; |
| 263 |
} |
| 264 |
else { |
| 265 |
throw Exception::Zero(">>> QoI_VelocityTracking_Darcy::gradient_3 is zero."); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 270 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 271 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 272 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 273 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 274 |
// Get relevant dimensions |
| 275 |
const int c = fePrs_->gradN()->dimension(0); |
| 276 |
const int f = fePrs_->gradN()->dimension(1); |
| 277 |
const int p = fePrs_->gradN()->dimension(2); |
| 278 |
const int d = fePrs_->gradN()->dimension(3); |
| 279 |
// Initialize output hess |
| 280 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 281 |
// Compute cost integral |
| 282 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradV, awvel, valZ, alpha; |
| 283 |
gradV = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 284 |
awvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 285 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 286 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 287 |
fePrs_->evaluateGradient(gradV, v_coeff); |
| 288 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 289 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 290 |
|
| 291 |
for (int i = 0; i < c; ++i) { |
| 292 |
for (int j = 0; j < p; ++j) { |
| 293 |
for (int k = 0; k < d; ++k) { |
| 294 |
(*awvel)(i,j,k) = (*alpha)(i,j)*(*alpha)(i,j)*(*weight_)(i,j,k)*(*gradV)(i,j,k); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 300 |
*awvel, |
| 301 |
*(fePrs_->gradNdetJ()), |
| 302 |
Intrepid::COMP_CPP, false); |
| 303 |
} |
| 304 |
|
| 305 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 306 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 307 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 308 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 309 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 310 |
// Get relevant dimensions |
| 311 |
const int c = fePrs_->gradN()->dimension(0); |
| 312 |
const int f = fePrs_->gradN()->dimension(1); |
| 313 |
const int p = fePrs_->gradN()->dimension(2); |
| 314 |
const int d = fePrs_->gradN()->dimension(3); |
| 315 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 316 |
// Initialize output grad |
| 317 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 318 |
// Compute cost integral |
| 319 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, valZ, alpha, awvel, dalpha, valV; |
| 320 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 321 |
awvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 322 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 323 |
valV = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 324 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 325 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 326 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 327 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 328 |
feCtrl_->evaluateValue(valV, v_coeff); |
| 329 |
perm_->compute( alpha, valZ, fePrs_->cubPts(), 0); |
| 330 |
perm_->compute(dalpha, valZ, fePrs_->cubPts(), 1); |
| 331 |
|
| 332 |
for (int i = 0; i < c; ++i) { |
| 333 |
for (int j = 0; j < p; ++j) { |
| 334 |
for (int k = 0; k < d; ++k) { |
| 335 |
(*awvel)(i,j,k) = static_cast<Real>(2)*(*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k); |
| 336 |
(*awvel)(i,j,k) *= (*weight_)(i,j,k)*(*dalpha)(i,j)*(*valV)(i,j); |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 342 |
*awvel, |
| 343 |
*fePrs_->gradNdetJ(), |
| 344 |
Intrepid::COMP_CPP, false); |
| 345 |
} |
| 346 |
|
| 347 |
void HessVec_13(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 348 |
const ROL::Ptr<const std::vector<Real>> & v_param, |
| 349 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 350 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 351 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 352 |
if (z_param != ROL::nullPtr) { |
| 353 |
// Get relevant dimensions |
| 354 |
const int c = fePrs_->gradN()->dimension(0); |
| 355 |
const int f = fePrs_->gradN()->dimension(1); |
| 356 |
const int p = fePrs_->gradN()->dimension(2); |
| 357 |
const int d = fePrs_->gradN()->dimension(3); |
| 358 |
// Initialize output val |
| 359 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 360 |
// Compute cost integral |
| 361 |
ROL::Ptr<Intrepid::FieldContainer<Real>> wvel, valZ, alpha; |
| 362 |
wvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 363 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 364 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 365 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 366 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 367 |
|
| 368 |
for (int i = 0; i < c; ++i) { |
| 369 |
for (int j = 0; j < p; ++j) { |
| 370 |
for (int k = 0; k < d; ++k) { |
| 371 |
(*wvel)(i,j,k) = (*weight_)(i,j,k)*(*alpha)(i,j)*(*target_)(i,j,k)*(*v_param)[0]; |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 377 |
*wvel, |
| 378 |
*fePrs_->gradNdetJ(), |
| 379 |
Intrepid::COMP_CPP, false); |
| 380 |
} |
| 381 |
else { |
| 382 |
throw Exception::NotImplemented(">>> HessVec_13 not implemented."); |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 387 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 388 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 389 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 390 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 391 |
// Get relevant dimensions |
| 392 |
const int c = fePrs_->gradN()->dimension(0); |
| 393 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 394 |
const int p = fePrs_->gradN()->dimension(2); |
| 395 |
const int d = fePrs_->gradN()->dimension(3); |
| 396 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 397 |
// Initialize output grad |
| 398 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 399 |
// Compute cost integral |
| 400 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, gradV, valZ, alpha, dalpha, deriv; |
| 401 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 402 |
gradV = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 403 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 404 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 405 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 406 |
deriv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 407 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 408 |
fePrs_->evaluateGradient(gradV, v_coeff); |
| 409 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 410 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 411 |
perm_->compute(dalpha, valZ, fePrs_->cubPts(), 1); |
| 412 |
|
| 413 |
for (int i = 0; i < c; ++i) { |
| 414 |
for (int j = 0; j < p; ++j) { |
| 415 |
for (int k = 0; k < d; ++k) { |
| 416 |
(*deriv)(i,j) += (*weight_)(i,j,k)*((*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k)) |
| 417 |
*(*dalpha)(i,j)*(*gradV)(i,j,k); |
| 418 |
(*deriv)(i,j) += (*weight_)(i,j,k)*(*dalpha)(i,j)*(*gradU)(i,j,k)*(*alpha)(i,j)*(*gradV)(i,j,k); |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 424 |
*deriv, |
| 425 |
*feCtrl_->NdetJ(), |
| 426 |
Intrepid::COMP_CPP, false); |
| 427 |
} |
| 428 |
|
| 429 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 430 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 431 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 432 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 433 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 434 |
// Get relevant dimensions |
| 435 |
const int c = fePrs_->gradN()->dimension(0); |
| 436 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 437 |
const int p = fePrs_->gradN()->dimension(2); |
| 438 |
const int d = fePrs_->gradN()->dimension(3); |
| 439 |
Real yvel = (z_param == ROL::nullPtr) ? yvel_ : (*z_param)[0]; |
| 440 |
// Initialize output hess |
| 441 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 442 |
// Compute cost integral |
| 443 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, valZ, alpha, dalpha, ddalpha, valV, deriv; |
| 444 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 445 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 446 |
valV = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 447 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 448 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 449 |
ddalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 450 |
deriv = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 451 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 452 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 453 |
feCtrl_->evaluateValue(valV, v_coeff); |
| 454 |
perm_->compute( alpha, valZ, fePrs_->cubPts(), 0); |
| 455 |
perm_->compute( dalpha, valZ, fePrs_->cubPts(), 1); |
| 456 |
perm_->compute(ddalpha, valZ, fePrs_->cubPts(), 2); |
| 457 |
|
| 458 |
for (int i = 0; i < c; ++i) { |
| 459 |
for (int j = 0; j < p; ++j) { |
| 460 |
for (int k = 0; k < d; ++k) { |
| 461 |
(*deriv)(i,j) += (*weight_)(i,j,k)*((*alpha)(i,j)*(*gradU)(i,j,k)+yvel*(*target_)(i,j,k)) |
| 462 |
*(*ddalpha)(i,j)*(*valV)(i,j)*(*gradU)(i,j,k); |
| 463 |
(*deriv)(i,j) += (*weight_)(i,j,k)*(*dalpha)(i,j)*(*gradU)(i,j,k) |
| 464 |
*(*dalpha)(i,j)*(*valV)(i,j)*(*gradU)(i,j,k); |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 470 |
*deriv, |
| 471 |
*feCtrl_->NdetJ(), |
| 472 |
Intrepid::COMP_CPP, false); |
| 473 |
} |
| 474 |
|
| 475 |
void HessVec_23(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 476 |
const ROL::Ptr<const std::vector<Real>> & v_param, |
| 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 |
if (z_param != ROL::nullPtr) { |
| 481 |
// Get relevant dimensions |
| 482 |
const int c = fePrs_->gradN()->dimension(0); |
| 483 |
const int fc = feCtrl_->N()->dimension(1); |
| 484 |
const int p = fePrs_->gradN()->dimension(2); |
| 485 |
const int d = fePrs_->gradN()->dimension(3); |
| 486 |
// Initialize output val |
| 487 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 488 |
// Compute cost integral |
| 489 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, wvel, valZ, dalpha; |
| 490 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 491 |
wvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 492 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 493 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 494 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 495 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 496 |
perm_->compute(dalpha, valZ, fePrs_->cubPts(), 1); |
| 497 |
|
| 498 |
for (int i = 0; i < c; ++i) { |
| 499 |
for (int j = 0; j < p; ++j) { |
| 500 |
for (int k = 0; k < d; ++k) { |
| 501 |
(*wvel)(i,j) += (*weight_)(i,j,k)*(*dalpha)(i,j)*(*gradU)(i,j,k)*(*target_)(i,j,k)*(*v_param)[0]; |
| 502 |
} |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 507 |
*wvel, |
| 508 |
*feCtrl_->NdetJ(), |
| 509 |
Intrepid::COMP_CPP, false); |
| 510 |
} |
| 511 |
else { |
| 512 |
throw Exception::Zero(">>> QoI_VelocityTracking_Darcy::HessVec_23 is zero."); |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
std::vector<Real> HessVec_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 517 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 518 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 519 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 520 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 521 |
if (z_param != ROL::nullPtr) { |
| 522 |
// Get relevant dimensions |
| 523 |
const int c = fePrs_->gradN()->dimension(0); |
| 524 |
const int p = fePrs_->gradN()->dimension(2); |
| 525 |
const int d = fePrs_->gradN()->dimension(3); |
| 526 |
// Initialize output val |
| 527 |
std::vector<Real> h_param(d,static_cast<Real>(0)); |
| 528 |
hess.clear(); hess.resize(d); |
| 529 |
for (int k = 0; k < d; ++k) |
| 530 |
hess[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 531 |
// Compute cost integral |
| 532 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradV, wvel, valZ, alpha; |
| 533 |
gradV = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 534 |
wvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 535 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 536 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 537 |
fePrs_->evaluateGradient(gradV, v_coeff); |
| 538 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 539 |
perm_->compute(alpha, valZ, fePrs_->cubPts(), 0); |
| 540 |
|
| 541 |
for (int i = 0; i < c; ++i) { |
| 542 |
for (int j = 0; j < p; ++j) { |
| 543 |
for (int k = 0; k < d; ++k) { |
| 544 |
(*wvel)(i,j,k) = (*weight_)(i,j,k)*(*alpha)(i,j)*(*gradV)(i,j,k); |
| 545 |
} |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
fePrs_->computeIntegral(hess[0],wvel,target_); |
| 550 |
|
| 551 |
return h_param; |
| 552 |
} |
| 553 |
else { |
| 554 |
throw Exception::Zero(">>> QoI_VelocityTracking_Darcy::HessVec_31 is zero."); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
std::vector<Real> HessVec_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 559 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 560 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 561 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 562 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 563 |
if (z_param != ROL::nullPtr) { |
| 564 |
// Get relevant dimensions |
| 565 |
const int c = fePrs_->gradN()->dimension(0); |
| 566 |
const int p = fePrs_->gradN()->dimension(2); |
| 567 |
const int d = fePrs_->gradN()->dimension(3); |
| 568 |
// Initialize output val |
| 569 |
std::vector<Real> h_param(d,static_cast<Real>(0)); |
| 570 |
hess.clear(); hess.resize(d); |
| 571 |
for (int k = 0; k < d; ++k) |
| 572 |
hess[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 573 |
// Compute cost integral |
| 574 |
ROL::Ptr<Intrepid::FieldContainer<Real>> gradU, wvel, valZ, valV, dalpha; |
| 575 |
gradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 576 |
wvel = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 577 |
valZ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 578 |
valV = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 579 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 580 |
fePrs_->evaluateGradient(gradU, u_coeff); |
| 581 |
feCtrl_->evaluateValue(valZ, z_coeff); |
| 582 |
feCtrl_->evaluateValue(valV, v_coeff); |
| 583 |
perm_->compute(dalpha, valZ, fePrs_->cubPts(), 1); |
| 584 |
|
| 585 |
for (int i = 0; i < c; ++i) { |
| 586 |
for (int j = 0; j < p; ++j) { |
| 587 |
for (int k = 0; k < d; ++k) { |
| 588 |
(*wvel)(i,j,k) = (*weight_)(i,j,k)*(*dalpha)(i,j)*(*gradU)(i,j,k)*(*valV)(i,j); |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
fePrs_->computeIntegral(hess[0],wvel,target_); |
| 594 |
|
| 595 |
return h_param; |
| 596 |
} |
| 597 |
else { |
| 598 |
throw Exception::Zero(">>> QoI_VelocityTracking_Darcy::HessVec_32 is zero."); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
std::vector<Real> HessVec_33(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 603 |
const ROL::Ptr<const std::vector<Real>> & v_param, |
| 604 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 605 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 606 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 607 |
if (z_param != ROL::nullPtr) { |
| 608 |
// Get relevant dimensions |
| 609 |
const int c = fePrs_->gradN()->dimension(0); |
| 610 |
const int p = fePrs_->gradN()->dimension(2); |
| 611 |
const int d = fePrs_->gradN()->dimension(3); |
| 612 |
// Initialize output val |
| 613 |
std::vector<Real> h_param(d,static_cast<Real>(0)); |
| 614 |
hess.clear(); hess.resize(d); |
| 615 |
for (int k = 0; k < d; ++k) |
| 616 |
hess[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 617 |
// Compute cost integral |
| 618 |
ROL::Ptr<Intrepid::FieldContainer<Real>> wtarget; |
| 619 |
wtarget = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p,d); |
| 620 |
for (int i = 0; i < c; ++i) { |
| 621 |
for (int j = 0; j < p; ++j) { |
| 622 |
for (int k = 0; k < d; ++k) { |
| 623 |
(*wtarget)(i,j,k) = (*weight_)(i,j,k)*(*target_)(i,j,k); |
| 624 |
} |
| 625 |
} |
| 626 |
} |
| 627 |
fePrs_->computeIntegral(hess[0],wtarget,target_); |
| 628 |
Intrepid::RealSpaceTools<Real>::scale(*hess[0],(*v_param)[0]); |
| 629 |
|
| 630 |
return h_param; |
| 631 |
} |
| 632 |
else { |
| 633 |
throw Exception::Zero(">>> QoI_VelocityTracking_Darcy::HessVec_33 is zero."); |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
}; // QoI_VelocityTracking_Darcy |
| 638 |
|
| 639 |
|
| 640 |
/* |
| 641 |
template <class Real> |
| 642 |
class QoI_Velocity_Darcy : public QoI<Real> { |
| 643 |
private: |
| 644 |
const ROL::Ptr<FE<Real>> fePrs_, feCtrl_; |
| 645 |
const std::vector<ROL::Ptr<FE<Real>>> fePrsBdry_, feCtrlBdry_; |
| 646 |
const std::vector<std::vector<int>> bdryCellLocIds_; |
| 647 |
const ROL::Ptr<Permeability<Real>> perm_; |
| 648 |
std::vector<Real> target_; |
| 649 |
bool onlyAxial_; |
| 650 |
|
| 651 |
ROL::Ptr<Intrepid::FieldContainer<Real>> getBoundaryCoeff( |
| 652 |
const Intrepid::FieldContainer<Real> & cell_coeff, |
| 653 |
int locSideId, |
| 654 |
const ROL::Ptr<FE<Real>> &fe) const { |
| 655 |
std::vector<int> bdryCellLocId = bdryCellLocIds_[locSideId]; |
| 656 |
const int numCellsSide = bdryCellLocId.size(); |
| 657 |
const int f = fe->N()->dimension(1); |
| 658 |
|
| 659 |
ROL::Ptr<Intrepid::FieldContainer<Real>> bdry_coeff = |
| 660 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 661 |
for (int i = 0; i < numCellsSide; ++i) { |
| 662 |
for (int j = 0; j < f; ++j) { |
| 663 |
(*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j); |
| 664 |
} |
| 665 |
} |
| 666 |
return bdry_coeff; |
| 667 |
} |
| 668 |
|
| 669 |
public: |
| 670 |
QoI_Velocity_Darcy(Teuchos::ParameterList &list, |
| 671 |
const ROL::Ptr<FE<Real>> &fePrs, |
| 672 |
const ROL::Ptr<FE<Real>> &feCtrl, |
| 673 |
const std::vector<ROL::Ptr<FE<Real>>> &fePrsBdry, |
| 674 |
const std::vector<ROL::Ptr<FE<Real>>> &feCtrlBdry, |
| 675 |
const std::vector<std::vector<int>> &bdryCellLocIds, |
| 676 |
const ROL::Ptr<Permeability<Real>> &perm) |
| 677 |
: fePrs_(fePrs), feCtrl_(feCtrl), |
| 678 |
fePrsBdry_(fePrsBdry), feCtrlBdry_(feCtrlBdry), |
| 679 |
bdryCellLocIds_(bdryCellLocIds), |
| 680 |
perm_(perm) { |
| 681 |
target_.clear(); target_.resize(2); |
| 682 |
target_[0] = list.sublist("Problem").get("Target Radial Velocity",0.0); |
| 683 |
target_[1] = list.sublist("Problem").get("Target Axial Velocity",-15.0); |
| 684 |
onlyAxial_ = list.sublist("Problem").get("Only Use Axial Velocity",false); |
| 685 |
} |
| 686 |
|
| 687 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real>> & val, |
| 688 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 689 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 690 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 691 |
// Get relevant dimensions |
| 692 |
const int c = fePrs_->gradN()->dimension(0); |
| 693 |
const int d = fePrs_->gradN()->dimension(3); |
| 694 |
// Initialize output val |
| 695 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 696 |
// Compute cost integral |
| 697 |
std::vector<Real> target = (z_param == ROL::nullPtr) ? target_ : *z_param; |
| 698 |
const int numLocSides = bdryCellLocIds_.size(); |
| 699 |
for (int l = 0; l < numLocSides; ++l) { |
| 700 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 701 |
if ( numCellsSide ) { |
| 702 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 703 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry, valU_eval, valZ_eval, alpha, intVal; |
| 704 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 705 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 706 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 707 |
intVal = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide); |
| 708 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 709 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 710 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 711 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 712 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 713 |
for (int i = 0; i < numCellsSide; ++i) { |
| 714 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 715 |
for (int k = 0; k < d; ++k) { |
| 716 |
(*valU_eval)(i,j,k) *= -(*alpha)(i,j); |
| 717 |
if (k==0 && onlyAxial_) (*valU_eval)(i,j,k) = static_cast<Real>(0); |
| 718 |
else (*valU_eval)(i,j,k) -= target[k]; |
| 719 |
} |
| 720 |
} |
| 721 |
} |
| 722 |
fePrsBdry_[l]->computeIntegral(intVal,valU_eval,valU_eval,true); |
| 723 |
// Add to integral value |
| 724 |
for (int i = 0; i < numCellsSide; ++i) { |
| 725 |
int cidx = bdryCellLocIds_[l][i]; |
| 726 |
(*val)(cidx) += static_cast<Real>(0.5)*(*intVal)(i); |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
return static_cast<Real>(0); |
| 731 |
} |
| 732 |
|
| 733 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 734 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 735 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 736 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 737 |
// Get relevant dimensions |
| 738 |
const int c = fePrs_->gradN()->dimension(0); |
| 739 |
const int f = fePrs_->gradN()->dimension(1); |
| 740 |
const int d = fePrs_->gradN()->dimension(3); |
| 741 |
// Initialize output grad |
| 742 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 743 |
// Compute cost integral |
| 744 |
std::vector<Real> target = (z_param == ROL::nullPtr) ? target_ : *z_param; |
| 745 |
const int numLocSides = bdryCellLocIds_.size(); |
| 746 |
for (int l = 0; l < numLocSides; ++l) { |
| 747 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 748 |
if ( numCellsSide ) { |
| 749 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 750 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry, valU_eval, valZ_eval, alpha, intGrad; |
| 751 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 752 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 753 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 754 |
intGrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 755 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 756 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 757 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 758 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 759 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 760 |
for (int i = 0; i < numCellsSide; ++i) { |
| 761 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 762 |
for (int k = 0; k < d; ++k) { |
| 763 |
(*valU_eval)(i,j,k) *= -(*alpha)(i,j); |
| 764 |
if (k==0 && onlyAxial_) (*valU_eval)(i,j,k) = static_cast<Real>(0); |
| 765 |
else (*valU_eval)(i,j,k) -= target[k]; |
| 766 |
(*valU_eval)(i,j,k) *= -(*alpha)(i,j); |
| 767 |
} |
| 768 |
} |
| 769 |
} |
| 770 |
// Compute gradient of squared L2-norm of diff |
| 771 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad, |
| 772 |
*valU_eval, |
| 773 |
*fePrsBdry_[l]->gradNdetJ(), |
| 774 |
Intrepid::COMP_CPP, false); |
| 775 |
// Add to integral value |
| 776 |
for (int i = 0; i < numCellsSide; ++i) { |
| 777 |
int cidx = bdryCellLocIds_[l][i]; |
| 778 |
for (int j = 0; j < f; ++j) { |
| 779 |
(*grad)(cidx,j) += (*intGrad)(i,j); |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & grad, |
| 787 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 788 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 789 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 790 |
// Get relevant dimensions |
| 791 |
const int c = fePrs_->gradN()->dimension(0); |
| 792 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 793 |
const int d = fePrs_->gradN()->dimension(3); |
| 794 |
// Initialize output grad |
| 795 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 796 |
// Compute cost integral |
| 797 |
std::vector<Real> target = (z_param == ROL::nullPtr) ? target_ : *z_param; |
| 798 |
const int numLocSides = bdryCellLocIds_.size(); |
| 799 |
for (int l = 0; l < numLocSides; ++l) { |
| 800 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 801 |
if ( numCellsSide ) { |
| 802 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 803 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry; |
| 804 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, valZ_eval, alpha, dalpha; |
| 805 |
ROL::Ptr<Intrepid::FieldContainer<Real>> integrand, intGrad; |
| 806 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 807 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 808 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 809 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 810 |
integrand = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 811 |
intGrad = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fc); |
| 812 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 813 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 814 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 815 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 816 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 817 |
perm_->compute(dalpha, valZ_eval, fePrsBdry_[l]->cubPts(), 1); |
| 818 |
Real dalphaU(0), misfit(0); |
| 819 |
for (int i = 0; i < numCellsSide; ++i) { |
| 820 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 821 |
for (int k = 0; k < d; ++k) { |
| 822 |
dalphaU = -(*dalpha)(i,j) * (*valU_eval)(i,j,k); |
| 823 |
if (k==0 && onlyAxial_) misfit = static_cast<Real>(0); |
| 824 |
else misfit = -(*alpha)(i,j) * (*valU_eval)(i,j,k) - target[k]; |
| 825 |
(*integrand)(i,j) += dalphaU * misfit; |
| 826 |
} |
| 827 |
} |
| 828 |
} |
| 829 |
// Compute gradient of squared L2-norm of diff |
| 830 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad, |
| 831 |
*integrand, |
| 832 |
*feCtrlBdry_[l]->NdetJ(), |
| 833 |
Intrepid::COMP_CPP, false); |
| 834 |
// Add to integral value |
| 835 |
for (int i = 0; i < numCellsSide; ++i) { |
| 836 |
int cidx = bdryCellLocIds_[l][i]; |
| 837 |
for (int j = 0; j < fc; ++j) { |
| 838 |
(*grad)(cidx,j) += (*intGrad)(i,j); |
| 839 |
} |
| 840 |
} |
| 841 |
} |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
std::vector<Real> gradient_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & grad, |
| 846 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 847 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 848 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 849 |
if (z_param != ROL::nullPtr) { |
| 850 |
// Get relevant dimensions |
| 851 |
const int c = fePrs_->gradN()->dimension(0); |
| 852 |
const int d = fePrs_->gradN()->dimension(3); |
| 853 |
// Initialize output val |
| 854 |
std::vector<Real> g_param(d,static_cast<Real>(0)); |
| 855 |
grad.clear(); grad.resize(d); |
| 856 |
for (int k = 0; k < d; ++k) |
| 857 |
grad[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 858 |
// Compute cost integral |
| 859 |
const int numLocSides = bdryCellLocIds_.size(); |
| 860 |
for (int l = 0; l < numLocSides; ++l) { |
| 861 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 862 |
if ( numCellsSide ) { |
| 863 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 864 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> intVal(d); |
| 865 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry, valU_eval, valZ_eval, integrand, weight, alpha; |
| 866 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 867 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 868 |
integrand = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 869 |
weight = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 870 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 871 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 872 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 873 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 874 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 875 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 876 |
for (int k = 0; k < d; ++k) { |
| 877 |
intVal[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide); |
| 878 |
if ((k==0 && !onlyAxial_) || k==1) { |
| 879 |
integrand->initialize(); |
| 880 |
for (int i = 0; i < numCellsSide; ++i) { |
| 881 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 882 |
(*weight)(i,j) = static_cast<Real>(1); |
| 883 |
(*integrand)(i,j) = (*z_param)[k] + (*alpha)(i,j) * (*valU_eval)(i,j,k); |
| 884 |
} |
| 885 |
} |
| 886 |
fePrsBdry_[l]->computeIntegral(intVal[k],weight,integrand,true); |
| 887 |
} |
| 888 |
} |
| 889 |
// Add to integral value |
| 890 |
for (int k = 0; k < d; ++k) { |
| 891 |
for (int i = 0; i < numCellsSide; ++i) { |
| 892 |
int cidx = bdryCellLocIds_[l][i]; |
| 893 |
(*grad[k])(cidx) += (*intVal[k])(i); |
| 894 |
} |
| 895 |
} |
| 896 |
} |
| 897 |
} |
| 898 |
return g_param; |
| 899 |
} |
| 900 |
else { |
| 901 |
throw Exception::Zero(">>> QoI_Velocity_Darcy::gradient_3 is zero."); |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 906 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 907 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 908 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 909 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 910 |
// Get relevant dimensions |
| 911 |
const int c = fePrs_->gradN()->dimension(0); |
| 912 |
const int f = fePrs_->gradN()->dimension(1); |
| 913 |
const int d = fePrs_->gradN()->dimension(3); |
| 914 |
// Initialize output grad |
| 915 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 916 |
// Compute cost integral |
| 917 |
const int numLocSides = bdryCellLocIds_.size(); |
| 918 |
for (int l = 0; l < numLocSides; ++l) { |
| 919 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 920 |
if ( numCellsSide ) { |
| 921 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 922 |
ROL::Ptr<Intrepid::FieldContainer<Real>> v_coeff_bdry, z_coeff_bdry , valV_eval, valZ_eval, alpha, intHess; |
| 923 |
valV_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 924 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 925 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 926 |
intHess = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 927 |
v_coeff_bdry = getBoundaryCoeff(*v_coeff, l, fePrs_); |
| 928 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 929 |
fePrsBdry_[l]->evaluateGradient(valV_eval, v_coeff_bdry); |
| 930 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 931 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 932 |
for (int i = 0; i < numCellsSide; ++i) { |
| 933 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 934 |
for (int k = 0; k < d; ++k) { |
| 935 |
(*valV_eval)(i,j,k) *= (-(*alpha)(i,j)) * (-(*alpha)(i,j)); |
| 936 |
if (k==0 && onlyAxial_) (*valV_eval)(i,j,k) = static_cast<Real>(0); |
| 937 |
} |
| 938 |
} |
| 939 |
} |
| 940 |
// Compute hessian of squared L2-norm of diff |
| 941 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intHess, |
| 942 |
*valV_eval, |
| 943 |
*(fePrsBdry_[l]->gradNdetJ()), |
| 944 |
Intrepid::COMP_CPP, false); |
| 945 |
// Add to integral value |
| 946 |
for (int i = 0; i < numCellsSide; ++i) { |
| 947 |
int cidx = bdryCellLocIds_[l][i]; |
| 948 |
for (int j = 0; j < f; ++j) { |
| 949 |
(*hess)(cidx,j) += (*intHess)(i,j); |
| 950 |
} |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 957 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 958 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 959 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 960 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 961 |
// Get relevant dimensions |
| 962 |
const int c = fePrs_->gradN()->dimension(0); |
| 963 |
const int f = fePrs_->gradN()->dimension(1); |
| 964 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 965 |
const int d = fePrs_->gradN()->dimension(3); |
| 966 |
// Initialize output grad |
| 967 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 968 |
// Compute cost integral |
| 969 |
std::vector<Real> target = (z_param == ROL::nullPtr) ? target_ : *z_param; |
| 970 |
const int numLocSides = bdryCellLocIds_.size(); |
| 971 |
for (int l = 0; l < numLocSides; ++l) { |
| 972 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 973 |
if ( numCellsSide ) { |
| 974 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 975 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry, v_coeff_bdry; |
| 976 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, valZ_eval, valV_eval; |
| 977 |
ROL::Ptr<Intrepid::FieldContainer<Real>> alpha, dalpha, integrand, intHess; |
| 978 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 979 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 980 |
valV_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 981 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 982 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 983 |
integrand = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 984 |
intHess = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 985 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 986 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 987 |
v_coeff_bdry = getBoundaryCoeff(*v_coeff, l, feCtrl_); |
| 988 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 989 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 990 |
feCtrlBdry_[l]->evaluateValue(valV_eval, v_coeff_bdry); |
| 991 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 992 |
perm_->compute(dalpha, valZ_eval, fePrsBdry_[l]->cubPts(), 1); |
| 993 |
Real dalphaV(0), misfit(0), dmisfit(0); |
| 994 |
for (int i = 0; i < numCellsSide; ++i) { |
| 995 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 996 |
for (int k = 0; k < d; ++k) { |
| 997 |
dalphaV = -(*dalpha)(i,j) * (*valV_eval)(i,j); |
| 998 |
if (k==0 && onlyAxial_) { |
| 999 |
misfit = static_cast<Real>(0); |
| 1000 |
dmisfit = static_cast<Real>(0); |
| 1001 |
} |
| 1002 |
else { |
| 1003 |
misfit = -(*alpha)(i,j)*(*valU_eval)(i,j,k) - target[k]; |
| 1004 |
dmisfit = -(*alpha)(i,j)*(*valU_eval)(i,j,k); |
| 1005 |
} |
| 1006 |
(*integrand)(i,j,k) = dalphaV * (misfit + dmisfit); |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
// Compute gradient of squared L2-norm of diff |
| 1011 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intHess, |
| 1012 |
*integrand, |
| 1013 |
*fePrsBdry_[l]->gradNdetJ(), |
| 1014 |
Intrepid::COMP_CPP, false); |
| 1015 |
// Add to integral value |
| 1016 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1017 |
int cidx = bdryCellLocIds_[l][i]; |
| 1018 |
for (int j = 0; j < f; ++j) { |
| 1019 |
(*hess)(cidx,j) += (*intHess)(i,j); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
void HessVec_13(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 1027 |
const ROL::Ptr<const std::vector<Real>> & v_param, |
| 1028 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1029 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1030 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1031 |
if (z_param != ROL::nullPtr) { |
| 1032 |
// Get relevant dimensions |
| 1033 |
const int c = fePrs_->gradN()->dimension(0); |
| 1034 |
const int f = fePrs_->gradN()->dimension(1); |
| 1035 |
const int d = fePrs_->gradN()->dimension(3); |
| 1036 |
// Initialize output grad |
| 1037 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 1038 |
// Compute cost integral |
| 1039 |
const int numLocSides = bdryCellLocIds_.size(); |
| 1040 |
for (int l = 0; l < numLocSides; ++l) { |
| 1041 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 1042 |
if ( numCellsSide ) { |
| 1043 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 1044 |
ROL::Ptr<Intrepid::FieldContainer<Real>> z_coeff_bdry, valZ_eval, alpha, weight, intHess; |
| 1045 |
weight = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 1046 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1047 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1048 |
intHess = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 1049 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 1050 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 1051 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 1052 |
for (int k = 0; k < d; ++k) { |
| 1053 |
if ((k==0 && !onlyAxial_) || k==1) { |
| 1054 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1055 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 1056 |
(*weight)(i,j,k) = (*v_param)[k] * (-(*alpha)(i,j)); |
| 1057 |
} |
| 1058 |
} |
| 1059 |
// Compute gradient of squared L2-norm of diff |
| 1060 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intHess, |
| 1061 |
*weight, |
| 1062 |
*fePrsBdry_[l]->gradNdetJ(), |
| 1063 |
Intrepid::COMP_CPP, false); |
| 1064 |
// Add to integral value |
| 1065 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1066 |
int cidx = bdryCellLocIds_[l][i]; |
| 1067 |
for (int j = 0; j < f; ++j) { |
| 1068 |
(*hess)(cidx,j) += (*intHess)(i,j); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
} |
| 1073 |
} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
else { |
| 1077 |
throw Exception::NotImplemented(">>> HessVec_13 not implemented."); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 1082 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 1083 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1084 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1085 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1086 |
// Get relevant dimensions |
| 1087 |
const int c = fePrs_->gradN()->dimension(0); |
| 1088 |
const int f = fePrs_->gradN()->dimension(1); |
| 1089 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 1090 |
const int d = fePrs_->gradN()->dimension(3); |
| 1091 |
// Initialize output grad |
| 1092 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 1093 |
// Compute cost integral |
| 1094 |
std::vector<Real> target = (z_param == ROL::nullPtr) ? target_ : *z_param; |
| 1095 |
const int numLocSides = bdryCellLocIds_.size(); |
| 1096 |
for (int l = 0; l < numLocSides; ++l) { |
| 1097 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 1098 |
if ( numCellsSide ) { |
| 1099 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 1100 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry, v_coeff_bdry; |
| 1101 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, valZ_eval, valV_eval; |
| 1102 |
ROL::Ptr<Intrepid::FieldContainer<Real>> alpha, dalpha, integrand, intHess; |
| 1103 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 1104 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1105 |
valV_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 1106 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1107 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1108 |
integrand = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1109 |
intHess = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fc); |
| 1110 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 1111 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 1112 |
v_coeff_bdry = getBoundaryCoeff(*v_coeff, l, fePrs_); |
| 1113 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 1114 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 1115 |
fePrsBdry_[l]->evaluateGradient(valV_eval, v_coeff_bdry); |
| 1116 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 1117 |
perm_->compute(dalpha, valZ_eval, fePrsBdry_[l]->cubPts(), 1); |
| 1118 |
Real dalphaV(0), misfit(0), dmisfit(0); |
| 1119 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1120 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 1121 |
for (int k = 0; k < d; ++k) { |
| 1122 |
dalphaV = -(*dalpha)(i,j) * (*valV_eval)(i,j,k); |
| 1123 |
if (k==0 && onlyAxial_) { |
| 1124 |
misfit = static_cast<Real>(0); |
| 1125 |
dmisfit = static_cast<Real>(0); |
| 1126 |
} |
| 1127 |
else { |
| 1128 |
misfit = -(*alpha)(i,j)*(*valU_eval)(i,j,k) - target[k]; |
| 1129 |
dmisfit = -(*alpha)(i,j)*(*valU_eval)(i,j,k); |
| 1130 |
} |
| 1131 |
(*integrand)(i,j) += dalphaV * (misfit + dmisfit); |
| 1132 |
} |
| 1133 |
} |
| 1134 |
} |
| 1135 |
// Compute gradient of squared L2-norm of diff |
| 1136 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intHess, |
| 1137 |
*integrand, |
| 1138 |
*feCtrlBdry_[l]->NdetJ(), |
| 1139 |
Intrepid::COMP_CPP, false); |
| 1140 |
// Add to integral value |
| 1141 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1142 |
int cidx = bdryCellLocIds_[l][i]; |
| 1143 |
for (int j = 0; j < fc; ++j) { |
| 1144 |
(*hess)(cidx,j) += (*intHess)(i,j); |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 1152 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 1153 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1154 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1155 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1156 |
// Get relevant dimensions |
| 1157 |
const int c = fePrs_->gradN()->dimension(0); |
| 1158 |
const int f = fePrs_->gradN()->dimension(1); |
| 1159 |
const int fc = feCtrl_->gradN()->dimension(1); |
| 1160 |
const int d = fePrs_->gradN()->dimension(3); |
| 1161 |
// Initialize output grad |
| 1162 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fc); |
| 1163 |
// Compute cost integral |
| 1164 |
std::vector<Real> target = (z_param == ROL::nullPtr) ? target_ : *z_param; |
| 1165 |
const int numLocSides = bdryCellLocIds_.size(); |
| 1166 |
for (int l = 0; l < numLocSides; ++l) { |
| 1167 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 1168 |
if ( numCellsSide ) { |
| 1169 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 1170 |
ROL::Ptr<Intrepid::FieldContainer<Real>> u_coeff_bdry, z_coeff_bdry, v_coeff_bdry; |
| 1171 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, valZ_eval, valV_eval; |
| 1172 |
ROL::Ptr<Intrepid::FieldContainer<Real>> alpha, dalpha, ddalpha, integrand, intHess; |
| 1173 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 1174 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1175 |
valV_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1176 |
alpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1177 |
dalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1178 |
ddalpha = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1179 |
integrand = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1180 |
intHess = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, fc); |
| 1181 |
u_coeff_bdry = getBoundaryCoeff(*u_coeff, l, fePrs_); |
| 1182 |
z_coeff_bdry = getBoundaryCoeff(*z_coeff, l, feCtrl_); |
| 1183 |
v_coeff_bdry = getBoundaryCoeff(*v_coeff, l, feCtrl_); |
| 1184 |
fePrsBdry_[l]->evaluateGradient(valU_eval, u_coeff_bdry); |
| 1185 |
feCtrlBdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 1186 |
feCtrlBdry_[l]->evaluateValue(valV_eval, v_coeff_bdry); |
| 1187 |
perm_->compute(alpha, valZ_eval, fePrsBdry_[l]->cubPts(), 0); |
| 1188 |
perm_->compute(dalpha, valZ_eval, fePrsBdry_[l]->cubPts(), 1); |
| 1189 |
perm_->compute(ddalpha, valZ_eval, fePrsBdry_[l]->cubPts(), 2); |
| 1190 |
Real dalphaV(0), misfit(0), dmisfit(0), ddalphaV(0); |
| 1191 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1192 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 1193 |
for (int k = 0; k < d; ++k) { |
| 1194 |
dalphaV = -(*dalpha)(i,j) * (*valV_eval)(i,j) * (*valU_eval)(i,j,k); |
| 1195 |
ddalphaV = -(*ddalpha)(i,j) * (*valV_eval)(i,j) * (*valU_eval)(i,j,k); |
| 1196 |
if (k==0 && onlyAxial_) { |
| 1197 |
misfit = static_cast<Real>(0); |
| 1198 |
dmisfit = static_cast<Real>(0); |
| 1199 |
} |
| 1200 |
else { |
| 1201 |
misfit = -(*alpha)(i,j)*(*valU_eval)(i,j,k) - target[k]; |
| 1202 |
dmisfit = -(*dalpha)(i,j)*(*valU_eval)(i,j,k); |
| 1203 |
} |
| 1204 |
(*integrand)(i,j) += dalphaV * dmisfit + ddalphaV * misfit; |
| 1205 |
} |
| 1206 |
} |
| 1207 |
} |
| 1208 |
// Compute gradient of squared L2-norm of diff |
| 1209 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intHess, |
| 1210 |
*integrand, |
| 1211 |
*feCtrlBdry_[l]->NdetJ(), |
| 1212 |
Intrepid::COMP_CPP, false); |
| 1213 |
// Add to integral value |
| 1214 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1215 |
int cidx = bdryCellLocIds_[l][i]; |
| 1216 |
for (int j = 0; j < fc; ++j) { |
| 1217 |
(*hess)(cidx,j) += (*intHess)(i,j); |
| 1218 |
} |
| 1219 |
} |
| 1220 |
} |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
void HessVec_23(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 1225 |
const ROL::Ptr<const std::vector<Real>> & v_param, |
| 1226 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1227 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1228 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1229 |
throw Exception::Zero(">>> QoI_Velocity_Darcy::HessVec_23 is zero."); |
| 1230 |
} |
| 1231 |
|
| 1232 |
std::vector<Real> HessVec_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 1233 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & v_coeff, |
| 1234 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1235 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1236 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1237 |
if (z_param != ROL::nullPtr) { |
| 1238 |
// Get relevant dimensions |
| 1239 |
const int c = fePrs_->gradN()->dimension(0); |
| 1240 |
const int d = fePrs_->gradN()->dimension(3); |
| 1241 |
// Initialize output val |
| 1242 |
std::vector<Real> h_param(d,static_cast<Real>(0)); |
| 1243 |
hess.clear(); hess.resize(d); |
| 1244 |
for (int k = 0; k < d; ++k) |
| 1245 |
hess[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 1246 |
// Compute cost integral |
| 1247 |
const int numLocSides = bdryCellLocIds_.size(); |
| 1248 |
for (int l = 0; l < numLocSides; ++l) { |
| 1249 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 1250 |
if ( numCellsSide ) { |
| 1251 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 1252 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> intVal(d); |
| 1253 |
ROL::Ptr<Intrepid::FieldContainer<Real>> v_coeff_bdry, valV_eval, weight; |
| 1254 |
valV_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1255 |
weight = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1256 |
for (int k = 0; k < d; ++k) { |
| 1257 |
intVal[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide); |
| 1258 |
if ((k==0 && !onlyAxial_) || k==1) { |
| 1259 |
v_coeff_bdry = getBoundaryCoeff(*v_coeff, l, fePrs_); |
| 1260 |
valV_eval->initialize(); |
| 1261 |
fePrsBdry_[l]->evaluateValue(valV_eval, v_coeff_bdry); |
| 1262 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1263 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 1264 |
(*weight)(i,j) = static_cast<Real>(1); |
| 1265 |
(*valV_eval)(i,j) *= static_cast<Real>(-1); |
| 1266 |
} |
| 1267 |
} |
| 1268 |
fePrsBdry_[l]->computeIntegral(intVal[k],weight,valV_eval,true); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
// Add to integral value |
| 1272 |
for (int k = 0; k < d; ++k) { |
| 1273 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1274 |
int cidx = bdryCellLocIds_[l][i]; |
| 1275 |
(*hess[k])(cidx) += (*intVal[k])(i); |
| 1276 |
} |
| 1277 |
} |
| 1278 |
} |
| 1279 |
} |
| 1280 |
return h_param; |
| 1281 |
} |
| 1282 |
else { |
| 1283 |
throw Exception::Zero(">>> QoI_Velocity_Darcy::HessVec_31 is zero."); |
| 1284 |
} |
| 1285 |
} |
| 1286 |
|
| 1287 |
std::vector<Real> HessVec_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 1288 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 1289 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1290 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1291 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1292 |
throw Exception::Zero(">>> HessVec_32 is zero."); |
| 1293 |
} |
| 1294 |
|
| 1295 |
std::vector<Real> HessVec_33(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> & hess, |
| 1296 |
const ROL::Ptr<const std::vector<Real>> & v_param, |
| 1297 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 1298 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 1299 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 1300 |
if (z_param != ROL::nullPtr) { |
| 1301 |
// Get relevant dimensions |
| 1302 |
const int c = fePrs_->gradN()->dimension(0); |
| 1303 |
const int d = fePrs_->gradN()->dimension(3); |
| 1304 |
// Initialize output val |
| 1305 |
std::vector<Real> h_param(d,static_cast<Real>(0)); |
| 1306 |
hess.clear(); hess.resize(d); |
| 1307 |
for (int k = 0; k < d; ++k) |
| 1308 |
hess[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 1309 |
// Compute cost integral |
| 1310 |
const int numLocSides = bdryCellLocIds_.size(); |
| 1311 |
for (int l = 0; l < numLocSides; ++l) { |
| 1312 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 1313 |
if ( numCellsSide ) { |
| 1314 |
const int numCubPerSide = fePrsBdry_[l]->cubPts()->dimension(1); |
| 1315 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> intVal(d); |
| 1316 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valU_eval, weight; |
| 1317 |
valU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1318 |
weight = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 1319 |
for (int k = 0; k < d; ++k) { |
| 1320 |
intVal[k] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide); |
| 1321 |
if ((k==0 && !onlyAxial_) || k==1) { |
| 1322 |
valU_eval->initialize(); |
| 1323 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1324 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 1325 |
(*weight)(i,j) = static_cast<Real>(1); |
| 1326 |
(*valU_eval)(i,j) = (*v_param)[k]; |
| 1327 |
} |
| 1328 |
} |
| 1329 |
fePrsBdry_[l]->computeIntegral(intVal[k],weight,valU_eval,true); |
| 1330 |
} |
| 1331 |
} |
| 1332 |
// Add to integral value |
| 1333 |
for (int k = 0; k < d; ++k) { |
| 1334 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1335 |
int cidx = bdryCellLocIds_[l][i]; |
| 1336 |
(*hess[k])(cidx) += (*intVal[k])(i); |
| 1337 |
} |
| 1338 |
} |
| 1339 |
} |
| 1340 |
} |
| 1341 |
return h_param; |
| 1342 |
} |
| 1343 |
else { |
| 1344 |
throw Exception::Zero(">>> QoI_Velocity_Darcy::HessVec_33 is zero."); |
| 1345 |
} |
| 1346 |
} |
| 1347 |
|
| 1348 |
}; // QoI_Velocity_Darcy |
| 1349 |
*/ |
| 1350 |
|
| 1351 |
#endif |