| 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_STOCHASTIC_STEFAN_BOLTZMANN_HPP |
| 15 |
#define PDEOPT_QOI_STOCHASTIC_STEFAN_BOLTZMANN_HPP |
| 16 |
|
| 17 |
#include "../TOOLS/qoi.hpp" |
| 18 |
#include "pde_stoch_stefan_boltzmann.hpp" |
| 19 |
|
| 20 |
template <class Real> |
| 21 |
class QoI_StateCost : public QoI<Real> { |
| 22 |
private: |
| 23 |
const ROL::Ptr<FE<Real> > fe_; |
| 24 |
ROL::Ptr<Intrepid::FieldContainer<Real> > weight_; |
| 25 |
Real T_; |
| 26 |
Real rate_; |
| 27 |
bool exp_; |
| 28 |
Real xmid_; |
| 29 |
Real vol_; |
| 30 |
|
| 31 |
Real weightFunc(const std::vector<Real> & x) const { |
| 32 |
return ((x[1] < xmid_) ? static_cast<Real>(0) : static_cast<Real>(1)); |
| 33 |
} |
| 34 |
|
| 35 |
Real cost(const Real u, const int deriv = 0) const { |
| 36 |
if ( exp_ ) { |
| 37 |
if ( deriv == 1 ) { |
| 38 |
return std::exp(rate_ * (u - T_)) / vol_; |
| 39 |
} |
| 40 |
if ( deriv == 2 ) { |
| 41 |
return rate_ * std::exp(rate_ * (u - T_)) / vol_; |
| 42 |
} |
| 43 |
return (std::exp(rate_ * (u - T_)) - static_cast<Real>(1)) / (rate_ * vol_); |
| 44 |
} |
| 45 |
else { |
| 46 |
if ( u > T_ ) { |
| 47 |
if ( deriv == 0 ) { |
| 48 |
return static_cast<Real>(0.5)*(u-T_)*(u-T_)/vol_; |
| 49 |
} |
| 50 |
if ( deriv == 1 ) { |
| 51 |
return (u-T_)/vol_; |
| 52 |
} |
| 53 |
if ( deriv == 2 ) { |
| 54 |
return static_cast<Real>(1)/vol_; |
| 55 |
} |
| 56 |
} |
| 57 |
return static_cast<Real>(0); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public: |
| 62 |
QoI_StateCost(const ROL::Ptr<FE<Real> > &fe, |
| 63 |
Teuchos::ParameterList &parlist) : fe_(fe) { |
| 64 |
T_ = parlist.sublist("Problem").get("Desired engine temperature",373.0); |
| 65 |
exp_ = parlist.sublist("Problem").get("Use exponential engine cost model",false); |
| 66 |
rate_ = parlist.sublist("Problem").get("Exponential engine cost rate",1.0); |
| 67 |
|
| 68 |
xmid_ = parlist.sublist("Geometry").get("Step height",0.5); |
| 69 |
Real height = parlist.sublist("Geometry").get("Channel height",1.0); |
| 70 |
Real width = parlist.sublist("Geometry").get("Channel width",5.0); |
| 71 |
vol_ = (height - xmid_) * width; |
| 72 |
|
| 73 |
int c = fe_->cubPts()->dimension(0); |
| 74 |
int p = fe_->cubPts()->dimension(1); |
| 75 |
int d = fe_->cubPts()->dimension(2); |
| 76 |
std::vector<Real> pt(d); |
| 77 |
weight_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 78 |
for (int i = 0; i < c; ++i) { |
| 79 |
for (int j = 0; j < p; ++j) { |
| 80 |
for (int k = 0; k < d; ++k) { |
| 81 |
pt[k] = (*fe_->cubPts())(i,j,k); |
| 82 |
} |
| 83 |
(*weight_)(i,j) = weightFunc(pt); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 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 = fe_->gradN()->dimension(0); |
| 94 |
const int p = fe_->gradN()->dimension(2); |
| 95 |
// Initialize output val |
| 96 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 97 |
// Evaluate state on FE basis |
| 98 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval |
| 99 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 100 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 101 |
// Compute cost |
| 102 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costU |
| 103 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 104 |
for (int i = 0; i < c; ++i) { |
| 105 |
for (int j = 0; j < p; ++j) { |
| 106 |
(*costU)(i,j) = cost((*valU_eval)(i,j),0); |
| 107 |
} |
| 108 |
} |
| 109 |
// Compute squared L2-norm of diff |
| 110 |
fe_->computeIntegral(val,costU,weight_); |
| 111 |
return static_cast<Real>(0); |
| 112 |
} |
| 113 |
|
| 114 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 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 = fe_->gradN()->dimension(0); |
| 120 |
const int f = fe_->gradN()->dimension(1); |
| 121 |
const int p = fe_->gradN()->dimension(2); |
| 122 |
// Initialize output grad |
| 123 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 124 |
// Evaluate state on FE basis |
| 125 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval |
| 126 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 127 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 128 |
// Compute cost |
| 129 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costU |
| 130 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 131 |
for (int i = 0; i < c; ++i) { |
| 132 |
for (int j = 0; j < p; ++j) { |
| 133 |
(*costU)(i,j) = cost((*valU_eval)(i,j),1); |
| 134 |
} |
| 135 |
} |
| 136 |
// Multiply cost and weight |
| 137 |
Intrepid::FieldContainer<Real> WcostU(c, p); |
| 138 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(WcostU, |
| 139 |
*weight_, |
| 140 |
*costU); |
| 141 |
// Compute gradient of squared L2-norm of diff |
| 142 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 143 |
WcostU, |
| 144 |
*(fe_->NdetJ()), |
| 145 |
Intrepid::COMP_CPP, false); |
| 146 |
} |
| 147 |
|
| 148 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 149 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 150 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 151 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 152 |
throw Exception::Zero(">>> QoI_StateCost::gradient_2 is zero."); |
| 153 |
} |
| 154 |
|
| 155 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 156 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 157 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 158 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 159 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 160 |
// Get relevant dimensions |
| 161 |
const int c = fe_->gradN()->dimension(0); |
| 162 |
const int f = fe_->gradN()->dimension(1); |
| 163 |
const int p = fe_->gradN()->dimension(2); |
| 164 |
// Initialize output grad |
| 165 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 166 |
// Evaluate state on FE basis |
| 167 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval |
| 168 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 169 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 170 |
// Evaluate direction on FE basis |
| 171 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval |
| 172 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 173 |
fe_->evaluateValue(valV_eval, v_coeff); |
| 174 |
// Compute cost |
| 175 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costU |
| 176 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 177 |
for (int i = 0; i < c; ++i) { |
| 178 |
for (int j = 0; j < p; ++j) { |
| 179 |
(*costU)(i,j) = cost((*valU_eval)(i,j),2); |
| 180 |
} |
| 181 |
} |
| 182 |
// Multiply cost and weight |
| 183 |
Intrepid::FieldContainer<Real> WcostU(c, p); |
| 184 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(WcostU, |
| 185 |
*weight_, |
| 186 |
*costU); |
| 187 |
// Multiply weighted cost and direction |
| 188 |
Intrepid::FieldContainer<Real> WcostUV(c, p); |
| 189 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(WcostUV, |
| 190 |
WcostU, |
| 191 |
*valV_eval); |
| 192 |
// Compute gradient of squared L2-norm of diff |
| 193 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 194 |
WcostUV, |
| 195 |
*(fe_->NdetJ()), |
| 196 |
Intrepid::COMP_CPP, false); |
| 197 |
} |
| 198 |
|
| 199 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 200 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 201 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 202 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 203 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 204 |
throw Exception::Zero(">>> QoI_StateCost::HessVec_12 is zero."); |
| 205 |
} |
| 206 |
|
| 207 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 208 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 209 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 210 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 211 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 212 |
throw Exception::Zero(">>> QoI_StateCost::HessVec_21 is zero."); |
| 213 |
} |
| 214 |
|
| 215 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 216 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 217 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 218 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 219 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 220 |
throw Exception::Zero(">>> QoI_StateCost::HessVec_22 is zero."); |
| 221 |
} |
| 222 |
|
| 223 |
}; // QoI_L2Tracking |
| 224 |
|
| 225 |
template <class Real> |
| 226 |
class QoI_ControlCost : public QoI<Real> { |
| 227 |
private: |
| 228 |
const ROL::Ptr<FE<Real> > fe_vol_; |
| 229 |
const std::vector<ROL::Ptr<FE<Real> > > fe_bdry_; |
| 230 |
const std::vector<std::vector<int> > bdryCellLocIds_; |
| 231 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > weight_; |
| 232 |
Real T_; |
| 233 |
bool exp_; |
| 234 |
Real rate1_; |
| 235 |
Real rate2_; |
| 236 |
Real area_; |
| 237 |
|
| 238 |
Real weightFunc(const std::vector<Real> & x) const { |
| 239 |
return static_cast<Real>(1); |
| 240 |
} |
| 241 |
|
| 242 |
Real cost(const Real z, const int deriv = 0) const { |
| 243 |
if ( exp_ ) { |
| 244 |
if ( deriv == 1 ) { |
| 245 |
return (std::exp(rate1_ * (z - T_)) - std::exp(rate2_ * (T_ - z))) / area_; |
| 246 |
} |
| 247 |
if ( deriv == 2 ) { |
| 248 |
return (rate1_ * std::exp(rate1_ * (z - T_)) |
| 249 |
+ rate2_ * std::exp(rate2_ * (T_ - z))) / area_; |
| 250 |
} |
| 251 |
return (std::exp(rate1_ * (z - T_)) - static_cast<Real>(1)) / (rate1_ * area_) |
| 252 |
+(std::exp(rate2_ * (T_ - z)) - static_cast<Real>(1)) / (rate2_ * area_); |
| 253 |
} |
| 254 |
else { |
| 255 |
if ( deriv == 0 ) { |
| 256 |
return static_cast<Real>(0.5)*(z-T_)*(z-T_)/area_; |
| 257 |
} |
| 258 |
if ( deriv == 1 ) { |
| 259 |
return (z-T_)/area_; |
| 260 |
} |
| 261 |
if ( deriv == 2 ) { |
| 262 |
return static_cast<Real>(1)/area_; |
| 263 |
} |
| 264 |
return static_cast<Real>(0); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
ROL::Ptr<Intrepid::FieldContainer<Real> > getBoundaryCoeff( |
| 269 |
const Intrepid::FieldContainer<Real> & cell_coeff, |
| 270 |
int locSideId) const { |
| 271 |
std::vector<int> bdryCellLocId = bdryCellLocIds_[locSideId]; |
| 272 |
const int numCellsSide = bdryCellLocId.size(); |
| 273 |
const int f = fe_vol_->N()->dimension(1); |
| 274 |
|
| 275 |
ROL::Ptr<Intrepid::FieldContainer<Real > > bdry_coeff = |
| 276 |
ROL::makePtr<Intrepid::FieldContainer<Real >>(numCellsSide, f); |
| 277 |
for (int i = 0; i < numCellsSide; ++i) { |
| 278 |
for (int j = 0; j < f; ++j) { |
| 279 |
(*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j); |
| 280 |
} |
| 281 |
} |
| 282 |
return bdry_coeff; |
| 283 |
} |
| 284 |
|
| 285 |
public: |
| 286 |
QoI_ControlCost(const ROL::Ptr<FE<Real> > &fe_vol, |
| 287 |
const std::vector<ROL::Ptr<FE<Real> > > &fe_bdry, |
| 288 |
const std::vector<std::vector<int> > &bdryCellLocIds, |
| 289 |
Teuchos::ParameterList &parlist) |
| 290 |
: fe_vol_(fe_vol), fe_bdry_(fe_bdry), bdryCellLocIds_(bdryCellLocIds) { |
| 291 |
T_ = parlist.sublist("Problem").get("Desired control temperature",293.0); |
| 292 |
exp_ = parlist.sublist("Problem").get("Use exponential control cost model",false); |
| 293 |
rate1_ = parlist.sublist("Problem").get("Exponential upper control cost rate",1.0); |
| 294 |
rate2_ = parlist.sublist("Problem").get("Exponential lower control cost rate",1.0); |
| 295 |
Real w1 = parlist.sublist("Geometry").get("Channel width",5.0); |
| 296 |
Real w2 = parlist.sublist("Geometry").get("Step width",1.0); |
| 297 |
area_ = w1 - w2; |
| 298 |
const int numLocSides = bdryCellLocIds_.size(); |
| 299 |
const int d = fe_vol_->gradN()->dimension(3); |
| 300 |
std::vector<Real> pt(d); |
| 301 |
weight_.resize(numLocSides); |
| 302 |
for (int l = 0; l < numLocSides; ++l) { |
| 303 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 304 |
if ( numCellsSide ) { |
| 305 |
const int numCubPerSide = fe_bdry_[l]->cubPts()->dimension(1); |
| 306 |
weight_[l] = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 307 |
for (int i = 0; i < numCellsSide; ++i) { |
| 308 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 309 |
for (int k = 0; k < d; ++k) { |
| 310 |
pt[k] = (*fe_bdry_[l]->cubPts())(i,j,k); |
| 311 |
} |
| 312 |
(*weight_[l])(i,j) = weightFunc(pt); |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 320 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 321 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 322 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 323 |
if ( z_coeff != ROL::nullPtr ) { |
| 324 |
const int c = fe_vol_->gradN()->dimension(0); |
| 325 |
// Initialize output val |
| 326 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 327 |
// Compute cost integral |
| 328 |
const int numLocSides = bdryCellLocIds_.size(); |
| 329 |
for (int l = 0; l < numLocSides; ++l) { |
| 330 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 331 |
if ( numCellsSide ) { |
| 332 |
const int numCubPerSide = fe_bdry_[l]->cubPts()->dimension(1); |
| 333 |
// Evaluate control on FE basis |
| 334 |
ROL::Ptr<Intrepid::FieldContainer<Real> > z_coeff_bdry |
| 335 |
= getBoundaryCoeff(*z_coeff, l); |
| 336 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval |
| 337 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 338 |
fe_bdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 339 |
// Compute cost |
| 340 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costZ |
| 341 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 342 |
for (int i = 0; i < numCellsSide; ++i) { |
| 343 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 344 |
(*costZ)(i,j) = cost((*valZ_eval)(i,j),0); |
| 345 |
} |
| 346 |
} |
| 347 |
// Integrate cell cost |
| 348 |
ROL::Ptr<Intrepid::FieldContainer<Real> > intVal |
| 349 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide); |
| 350 |
fe_bdry_[l]->computeIntegral(intVal,costZ,weight_[l]); |
| 351 |
// Add to integral value |
| 352 |
for (int i = 0; i < numCellsSide; ++i) { |
| 353 |
int cidx = bdryCellLocIds_[l][i]; |
| 354 |
(*val)(cidx) += (*intVal)(i); |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
else { |
| 360 |
throw Exception::Zero(">>> QoI_ControlCost: Value is zero."); |
| 361 |
} |
| 362 |
return static_cast<Real>(0); |
| 363 |
} |
| 364 |
|
| 365 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 366 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 367 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 368 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 369 |
throw Exception::Zero(">>> QoI_ControlCost::gradient_1 is zero."); |
| 370 |
} |
| 371 |
|
| 372 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 373 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 374 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 375 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 376 |
if ( z_coeff != ROL::nullPtr ) { |
| 377 |
const int c = fe_vol_->gradN()->dimension(0); |
| 378 |
const int f = fe_vol_->gradN()->dimension(1); |
| 379 |
// Initialize output val |
| 380 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 381 |
// Compute cost integral |
| 382 |
const int numLocSides = bdryCellLocIds_.size(); |
| 383 |
for (int l = 0; l < numLocSides; ++l) { |
| 384 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 385 |
if ( numCellsSide ) { |
| 386 |
const int numCubPerSide = fe_bdry_[l]->cubPts()->dimension(1); |
| 387 |
// Evaluate control on FE basis |
| 388 |
ROL::Ptr<Intrepid::FieldContainer<Real> > z_coeff_bdry |
| 389 |
= getBoundaryCoeff(*z_coeff, l); |
| 390 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval |
| 391 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 392 |
fe_bdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 393 |
// Compute cost |
| 394 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costZ |
| 395 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 396 |
for (int i = 0; i < numCellsSide; ++i) { |
| 397 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 398 |
(*costZ)(i,j) = cost((*valZ_eval)(i,j),1); |
| 399 |
} |
| 400 |
} |
| 401 |
// Multiply cost and weight |
| 402 |
Intrepid::FieldContainer<Real> WcostZ(numCellsSide, numCubPerSide); |
| 403 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(WcostZ, |
| 404 |
*(weight_[l]), |
| 405 |
*costZ); |
| 406 |
// Compute gradient of squared L2-norm of diff |
| 407 |
ROL::Ptr<Intrepid::FieldContainer<Real> > intGrad |
| 408 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 409 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad, |
| 410 |
WcostZ, |
| 411 |
*(fe_bdry_[l]->NdetJ()), |
| 412 |
Intrepid::COMP_CPP, false); |
| 413 |
// Add to integral value |
| 414 |
for (int i = 0; i < numCellsSide; ++i) { |
| 415 |
int cidx = bdryCellLocIds_[l][i]; |
| 416 |
for (int j = 0; j < f; ++j) { |
| 417 |
(*grad)(cidx,j) += (*intGrad)(i,j); |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
} |
| 423 |
else { |
| 424 |
throw Exception::Zero(">>> QoI_ControlCost: Gradient_2 is zero."); |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 429 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 430 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 431 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 432 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 433 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_11 is zero."); |
| 434 |
} |
| 435 |
|
| 436 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 437 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 438 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 439 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 440 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 441 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_12 is zero."); |
| 442 |
} |
| 443 |
|
| 444 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 445 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 446 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 447 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 448 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 449 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_21 is zero."); |
| 450 |
} |
| 451 |
|
| 452 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 453 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 454 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 455 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 456 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 457 |
if ( z_coeff != ROL::nullPtr ) { |
| 458 |
const int c = fe_vol_->gradN()->dimension(0); |
| 459 |
const int f = fe_vol_->gradN()->dimension(1); |
| 460 |
// Initialize output val |
| 461 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 462 |
// Compute cost integral |
| 463 |
const int numLocSides = bdryCellLocIds_.size(); |
| 464 |
for (int l = 0; l < numLocSides; ++l) { |
| 465 |
const int numCellsSide = bdryCellLocIds_[l].size(); |
| 466 |
if ( numCellsSide ) { |
| 467 |
const int numCubPerSide = fe_bdry_[l]->cubPts()->dimension(1); |
| 468 |
// Evaluate control on FE basis |
| 469 |
ROL::Ptr<Intrepid::FieldContainer<Real> > z_coeff_bdry |
| 470 |
= getBoundaryCoeff(*z_coeff, l); |
| 471 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval |
| 472 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 473 |
fe_bdry_[l]->evaluateValue(valZ_eval, z_coeff_bdry); |
| 474 |
// Evaluate direction on FE basis |
| 475 |
ROL::Ptr<Intrepid::FieldContainer<Real> > v_coeff_bdry |
| 476 |
= getBoundaryCoeff(*v_coeff, l); |
| 477 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval |
| 478 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 479 |
fe_bdry_[l]->evaluateValue(valV_eval, v_coeff_bdry); |
| 480 |
// Compute cost |
| 481 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costZ |
| 482 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 483 |
for (int i = 0; i < numCellsSide; ++i) { |
| 484 |
for (int j = 0; j < numCubPerSide; ++j) { |
| 485 |
(*costZ)(i,j) = cost((*valZ_eval)(i,j),2); |
| 486 |
} |
| 487 |
} |
| 488 |
// Multiply cost and weight |
| 489 |
Intrepid::FieldContainer<Real> WcostZ(numCellsSide, numCubPerSide); |
| 490 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(WcostZ, |
| 491 |
*(weight_[l]), |
| 492 |
*costZ); |
| 493 |
// Multiply weighted cost and direction |
| 494 |
Intrepid::FieldContainer<Real> WcostZV(numCellsSide, numCubPerSide); |
| 495 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(WcostZV, |
| 496 |
WcostZ, |
| 497 |
*valV_eval); |
| 498 |
// Compute hessian times a vector of cost |
| 499 |
ROL::Ptr<Intrepid::FieldContainer<Real> > intHess |
| 500 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 501 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intHess, |
| 502 |
WcostZV, |
| 503 |
*(fe_bdry_[l]->NdetJ()), |
| 504 |
Intrepid::COMP_CPP, false); |
| 505 |
// Add to integral value |
| 506 |
for (int i = 0; i < numCellsSide; ++i) { |
| 507 |
int cidx = bdryCellLocIds_[l][i]; |
| 508 |
for (int j = 0; j < f; ++j) { |
| 509 |
(*hess)(cidx,j) += (*intHess)(i,j); |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
} |
| 515 |
else { |
| 516 |
throw Exception::Zero(">>> QoI_ControlCost: HessVec_22 is zero."); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
}; // QoI_L2Penalty |
| 521 |
|
| 522 |
template <class Real> |
| 523 |
class QoI_AdvectionCost : public QoI<Real> { |
| 524 |
public: |
| 525 |
QoI_AdvectionCost(void) {} |
| 526 |
|
| 527 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 528 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 529 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 530 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 531 |
if ( z_param != ROL::nullPtr ) { |
| 532 |
const int size = z_param->size(); |
| 533 |
Real sum(0); |
| 534 |
for (int i = 0; i < size; ++i) { |
| 535 |
sum += std::pow((*z_param)[i], 2); |
| 536 |
} |
| 537 |
val = ROL::nullPtr; |
| 538 |
return static_cast<Real>(0.5)*sum; |
| 539 |
} |
| 540 |
return static_cast<Real>(0); |
| 541 |
} |
| 542 |
|
| 543 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 544 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 545 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 546 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 547 |
throw Exception::Zero(">>> QoI_AdvectionCost::gradient_1 is zero."); |
| 548 |
} |
| 549 |
|
| 550 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 551 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 552 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 553 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 554 |
throw Exception::Zero(">>> QoI_AdvectionCost::gradient_2 is zero."); |
| 555 |
} |
| 556 |
|
| 557 |
std::vector<Real> gradient_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & grad, |
| 558 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 559 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 560 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 561 |
if ( z_param != ROL::nullPtr ) { |
| 562 |
return *z_param; |
| 563 |
} |
| 564 |
else { |
| 565 |
throw Exception::Zero(">>> QoI_AdvectionCost::gradient_3 is zero."); |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 570 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 571 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 572 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 573 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 574 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_11 is zero."); |
| 575 |
} |
| 576 |
|
| 577 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 578 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 579 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 580 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 581 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 582 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_12 is zero."); |
| 583 |
} |
| 584 |
|
| 585 |
void HessVec_13(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 586 |
const ROL::Ptr<const std::vector<Real> > & v_param, |
| 587 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 588 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 589 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 590 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_13 is zero."); |
| 591 |
} |
| 592 |
|
| 593 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 594 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 595 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 596 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 597 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 598 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_21 is zero."); |
| 599 |
} |
| 600 |
|
| 601 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 602 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 603 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 604 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 605 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 606 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_22 is zero."); |
| 607 |
} |
| 608 |
|
| 609 |
void HessVec_23(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 610 |
const ROL::Ptr<const std::vector<Real> > & v_param, |
| 611 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 612 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 613 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 614 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_23 is zero."); |
| 615 |
} |
| 616 |
|
| 617 |
std::vector<Real> HessVec_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 618 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 619 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 620 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 621 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 622 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_31 is zero."); |
| 623 |
} |
| 624 |
|
| 625 |
std::vector<Real> HessVec_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 626 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 627 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 628 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 629 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 630 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_32 is zero."); |
| 631 |
} |
| 632 |
|
| 633 |
std::vector<Real> HessVec_33(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 634 |
const ROL::Ptr<const std::vector<Real> > & v_param, |
| 635 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 636 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 637 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 638 |
if ( z_param != ROL::nullPtr ) { |
| 639 |
return *v_param; |
| 640 |
} |
| 641 |
else { |
| 642 |
throw Exception::Zero(">>> QoI_AdvectionCost::HessVec_33 is zero."); |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
}; // QoI_Advection_Cost |
| 647 |
|
| 648 |
template <class Real> |
| 649 |
class StochasticStefanBoltzmannStdObjective : public ROL::StdObjective<Real> { |
| 650 |
private: |
| 651 |
Real alpha0_; |
| 652 |
Real alpha1_; |
| 653 |
|
| 654 |
public: |
| 655 |
StochasticStefanBoltzmannStdObjective(Teuchos::ParameterList &parlist) { |
| 656 |
alpha0_ = parlist.sublist("Problem").get("State Cost",1.0); |
| 657 |
alpha1_ = parlist.sublist("Problem").get("Control Cost",1.0); |
| 658 |
} |
| 659 |
|
| 660 |
Real value(const std::vector<Real> &x, Real &tol) { |
| 661 |
return alpha0_*x[0] + alpha1_*x[1]; |
| 662 |
} |
| 663 |
|
| 664 |
void gradient(std::vector<Real> &g, const std::vector<Real> &x, Real &tol) { |
| 665 |
g[0] = alpha0_; |
| 666 |
g[1] = alpha1_; |
| 667 |
} |
| 668 |
|
| 669 |
void hessVec(std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol) { |
| 670 |
const Real zero(0); |
| 671 |
hv[0] = zero; |
| 672 |
hv[1] = zero; |
| 673 |
} |
| 674 |
|
| 675 |
}; // OBJ_SCALAR |
| 676 |
|
| 677 |
template <class Real> |
| 678 |
class StochasticStefanBoltzmannStdObjective3 : public ROL::StdObjective<Real> { |
| 679 |
private: |
| 680 |
Real alpha0_; |
| 681 |
Real alpha1_; |
| 682 |
Real alpha2_; |
| 683 |
|
| 684 |
public: |
| 685 |
StochasticStefanBoltzmannStdObjective3(Teuchos::ParameterList &parlist) { |
| 686 |
alpha0_ = parlist.sublist("Problem").get("State Cost",1.0); |
| 687 |
alpha1_ = parlist.sublist("Problem").get("Control Cost",1.0); |
| 688 |
alpha2_ = parlist.sublist("Problem").get("Advection Cost",1.0); |
| 689 |
} |
| 690 |
|
| 691 |
Real value(const std::vector<Real> &x, Real &tol) { |
| 692 |
return alpha0_*x[0] + alpha1_*x[1] + alpha2_*x[2]; |
| 693 |
} |
| 694 |
|
| 695 |
void gradient(std::vector<Real> &g, const std::vector<Real> &x, Real &tol) { |
| 696 |
g[0] = alpha0_; |
| 697 |
g[1] = alpha1_; |
| 698 |
g[2] = alpha2_; |
| 699 |
} |
| 700 |
|
| 701 |
void hessVec(std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol) { |
| 702 |
const Real zero(0); |
| 703 |
hv[0] = zero; |
| 704 |
hv[1] = zero; |
| 705 |
hv[2] = zero; |
| 706 |
} |
| 707 |
|
| 708 |
}; // OBJ_SCALAR |
| 709 |
|
| 710 |
#endif |