| 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_L2TRACKING_POISSON_BOLTZMANN_EX02_HPP |
| 15 |
#define PDEOPT_QOI_L2TRACKING_POISSON_BOLTZMANN_EX02_HPP |
| 16 |
|
| 17 |
#include "../TOOLS/qoi.hpp" |
| 18 |
#include "doping.hpp" |
| 19 |
#include "pde_poisson_boltzmann_ex02.hpp" |
| 20 |
|
| 21 |
template <class Real> |
| 22 |
class QoI_State_Cost_1_Poisson_Boltzmann : public QoI<Real> { |
| 23 |
private: |
| 24 |
const ROL::Ptr<FE<Real> > fe_vol_; |
| 25 |
const std::vector<std::vector<ROL::Ptr<FE<Real> > > > fe_bdry_; |
| 26 |
const std::vector<std::vector<std::vector<int> > > bdryCellLocIds_; |
| 27 |
|
| 28 |
ROL::Ptr<Intrepid::FieldContainer<Real> > getBoundaryCoeff( |
| 29 |
const Intrepid::FieldContainer<Real> & cell_coeff, |
| 30 |
const int sideSet, const int locSideId) const { |
| 31 |
std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][locSideId]; |
| 32 |
const int numCellsSide = bdryCellLocId.size(); |
| 33 |
const int f = fe_vol_->N()->dimension(1); |
| 34 |
|
| 35 |
ROL::Ptr<Intrepid::FieldContainer<Real > > bdry_coeff = |
| 36 |
ROL::makePtr<Intrepid::FieldContainer<Real >>(numCellsSide, f); |
| 37 |
for (int i = 0; i < numCellsSide; ++i) { |
| 38 |
for (int j = 0; j < f; ++j) { |
| 39 |
(*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j); |
| 40 |
} |
| 41 |
} |
| 42 |
return bdry_coeff; |
| 43 |
} |
| 44 |
|
| 45 |
public: |
| 46 |
QoI_State_Cost_1_Poisson_Boltzmann(const ROL::Ptr<FE<Real> > &fe_vol, |
| 47 |
const std::vector<std::vector<ROL::Ptr<FE<Real> > > > &fe_bdry, |
| 48 |
const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds, |
| 49 |
Teuchos::ParameterList &parlist) |
| 50 |
: fe_vol_(fe_vol), fe_bdry_(fe_bdry), bdryCellLocIds_(bdryCellLocIds) {} |
| 51 |
|
| 52 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 53 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 54 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 55 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 56 |
const int c = fe_vol_->gradN()->dimension(0); |
| 57 |
const int d = fe_vol_->gradN()->dimension(3); |
| 58 |
// Initialize output val |
| 59 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 60 |
// Compute cost integral |
| 61 |
const int numSideSets = bdryCellLocIds_.size(); |
| 62 |
for (int i = 0; i < numSideSets; ++i) { |
| 63 |
if ( i == 3 ) { |
| 64 |
const int numLocSides = bdryCellLocIds_[i].size(); |
| 65 |
for (int j = 0; j < numLocSides; ++j) { |
| 66 |
const int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 67 |
if ( numCellsSide ) { |
| 68 |
const int numCubPerSide = fe_bdry_[i][j]->cubPts()->dimension(1); |
| 69 |
// Evaluate control on FE basis |
| 70 |
ROL::Ptr<Intrepid::FieldContainer<Real> > u_coeff_bdry |
| 71 |
= getBoundaryCoeff(*u_coeff, i, j); |
| 72 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval |
| 73 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide, d); |
| 74 |
fe_bdry_[i][j]->evaluateGradient(gradU_eval, u_coeff_bdry); |
| 75 |
// Compute cost |
| 76 |
ROL::Ptr<Intrepid::FieldContainer<Real> > costU |
| 77 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 78 |
ROL::Ptr<Intrepid::FieldContainer<Real> > weightU |
| 79 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 80 |
for (int k = 0; k < numCellsSide; ++k) { |
| 81 |
for (int l = 0; l < numCubPerSide; ++l) { |
| 82 |
(*costU)(k,l) = (*gradU_eval)(k,l,1); |
| 83 |
(*weightU)(k,l) = static_cast<Real>(1); |
| 84 |
} |
| 85 |
} |
| 86 |
// Integrate cell cost |
| 87 |
ROL::Ptr<Intrepid::FieldContainer<Real> > intVal |
| 88 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide); |
| 89 |
fe_bdry_[i][j]->computeIntegral(intVal,costU,weightU); |
| 90 |
// Add to integral value |
| 91 |
for (int k = 0; k < numCellsSide; ++k) { |
| 92 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 93 |
(*val)(cidx) += (*intVal)(k); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
return static_cast<Real>(0); |
| 100 |
} |
| 101 |
|
| 102 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 103 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 104 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 105 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 106 |
const int c = fe_vol_->gradN()->dimension(0); |
| 107 |
const int f = fe_vol_->gradN()->dimension(1); |
| 108 |
// Initialize output val |
| 109 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 110 |
// Compute cost integral |
| 111 |
const int numSideSets = bdryCellLocIds_.size(); |
| 112 |
for (int i = 0; i < numSideSets; ++i) { |
| 113 |
if ( i == 3 ) { |
| 114 |
const int numLocSides = bdryCellLocIds_[i].size(); |
| 115 |
for (int j = 0; j < numLocSides; ++j) { |
| 116 |
const int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 117 |
if ( numCellsSide ) { |
| 118 |
const int numCubPerSide = fe_bdry_[i][j]->cubPts()->dimension(1); |
| 119 |
// Compute cost |
| 120 |
ROL::Ptr<Intrepid::FieldContainer<Real> > weightU |
| 121 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 122 |
for (int k = 0; k < numCellsSide; ++k) { |
| 123 |
for (int l = 0; l < numCubPerSide; ++l) { |
| 124 |
(*weightU)(k,l) = static_cast<Real>(1); |
| 125 |
} |
| 126 |
} |
| 127 |
// Compute gradient of squared L2-norm of diff |
| 128 |
ROL::Ptr<Intrepid::FieldContainer<Real> > intGrad |
| 129 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, f); |
| 130 |
Intrepid::FunctionSpaceTools::integrate<Real>(*intGrad, |
| 131 |
*weightU, |
| 132 |
*(fe_bdry_[i][j]->DNDdetJ(1)), |
| 133 |
Intrepid::COMP_CPP, false); |
| 134 |
// Add to integral value |
| 135 |
for (int k = 0; k < numCellsSide; ++k) { |
| 136 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 137 |
for (int l = 0; l < f; ++l) { |
| 138 |
(*grad)(cidx,l) += (*intGrad)(k,l); |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 148 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 149 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 150 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 151 |
throw Exception::Zero(">>> QoI_ControlCost::gradient_2 is zero."); |
| 152 |
} |
| 153 |
|
| 154 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 155 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 156 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 157 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 158 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 159 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_11 is zero."); |
| 160 |
} |
| 161 |
|
| 162 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 163 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 164 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 165 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 166 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 167 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_12 is zero."); |
| 168 |
} |
| 169 |
|
| 170 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 171 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 172 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 173 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 174 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 175 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_21 is zero."); |
| 176 |
} |
| 177 |
|
| 178 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 179 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 180 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 181 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 182 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 183 |
throw Exception::Zero(">>> QoI_ControlCost::HessVec_22 is zero."); |
| 184 |
} |
| 185 |
|
| 186 |
}; // QoI_State_Cost_2_Poisson_Boltzmann |
| 187 |
|
| 188 |
template <class Real> |
| 189 |
class QoI_State_Cost_2_Poisson_Boltzmann : public QoI<Real> { |
| 190 |
private: |
| 191 |
ROL::Ptr<FE<Real> > fe_; |
| 192 |
|
| 193 |
ROL::Ptr<Intrepid::FieldContainer<Real> > target_; |
| 194 |
|
| 195 |
Real targetFunc(const std::vector<Real> & x) const { |
| 196 |
return static_cast<Real>(1); |
| 197 |
// int size = x.size(); |
| 198 |
// Real val(0); |
| 199 |
// for (int i = 0; i < size; ++i) { |
| 200 |
// val += x[i]*x[i]; |
| 201 |
// } |
| 202 |
// return val; |
| 203 |
} |
| 204 |
|
| 205 |
public: |
| 206 |
QoI_State_Cost_2_Poisson_Boltzmann(const ROL::Ptr<FE<Real> > &fe) : fe_(fe) { |
| 207 |
int c = fe_->cubPts()->dimension(0); |
| 208 |
int p = fe_->cubPts()->dimension(1); |
| 209 |
int d = fe_->cubPts()->dimension(2); |
| 210 |
std::vector<Real> pt(d); |
| 211 |
target_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 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 |
pt[k] = (*fe_->cubPts())(i,j,k); |
| 216 |
} |
| 217 |
(*target_)(i,j) = targetFunc(pt); |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 223 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 224 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 225 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 226 |
// Get relevant dimensions |
| 227 |
int c = u_coeff->dimension(0); |
| 228 |
int p = fe_->cubPts()->dimension(1); |
| 229 |
// Initialize output val |
| 230 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 231 |
// Evaluate state on FE basis |
| 232 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval = |
| 233 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 234 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 235 |
// Compute difference between state and target |
| 236 |
Intrepid::RealSpaceTools<Real>::subtract(*valU_eval,*target_); |
| 237 |
// Compute squared L2-norm of diff |
| 238 |
fe_->computeIntegral(val,valU_eval,valU_eval); |
| 239 |
// Scale by one half |
| 240 |
Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5)); |
| 241 |
return static_cast<Real>(0); |
| 242 |
} |
| 243 |
|
| 244 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 245 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 246 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 247 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 248 |
// Get relevant dimensions |
| 249 |
int c = u_coeff->dimension(0); |
| 250 |
int p = fe_->cubPts()->dimension(1); |
| 251 |
int f = fe_->N()->dimension(1); |
| 252 |
// Initialize output grad |
| 253 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 254 |
// Evaluate state on FE basis |
| 255 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval = |
| 256 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 257 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 258 |
// Compute difference between state and target |
| 259 |
Intrepid::RealSpaceTools<Real>::subtract(*valU_eval,*target_); |
| 260 |
// Compute gradient of squared L2-norm of diff |
| 261 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 262 |
*valU_eval, |
| 263 |
*(fe_->NdetJ()), |
| 264 |
Intrepid::COMP_CPP, false); |
| 265 |
} |
| 266 |
|
| 267 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 268 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 269 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 270 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 271 |
throw Exception::Zero(">>> QoI_State_Cost_Poisson_Boltzmann::gradient_2 is zero."); |
| 272 |
} |
| 273 |
|
| 274 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 275 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 276 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 277 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 278 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 279 |
int c = v_coeff->dimension(0); |
| 280 |
int p = fe_->cubPts()->dimension(1); |
| 281 |
int f = fe_->N()->dimension(1); |
| 282 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval = |
| 283 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 284 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 285 |
fe_->evaluateValue(valV_eval, v_coeff); |
| 286 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 287 |
*valV_eval, |
| 288 |
*(fe_->NdetJ()), |
| 289 |
Intrepid::COMP_CPP, false); |
| 290 |
} |
| 291 |
|
| 292 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 293 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 294 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 295 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 296 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 297 |
throw Exception::Zero(">>> QoI_State_Cost_Poisson_Boltzmann::HessVec_12 is zero."); |
| 298 |
} |
| 299 |
|
| 300 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 301 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 302 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 303 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 304 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 305 |
throw Exception::Zero(">>> QoI_State_Cost_Poisson_Boltzmann::HessVec_21 is zero."); |
| 306 |
} |
| 307 |
|
| 308 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 309 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 310 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 311 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 312 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 313 |
throw Exception::Zero(">>> QoI_State_Cost_Poisson_Boltzmann::HessVec_22 is zero."); |
| 314 |
} |
| 315 |
|
| 316 |
}; // QoI_State_Cost |
| 317 |
|
| 318 |
template <class Real> |
| 319 |
class QoI_Control_Cost_1_Poisson_Boltzmann : public QoI<Real> { |
| 320 |
private: |
| 321 |
const ROL::Ptr<FE<Real> > fe_; |
| 322 |
ROL::Ptr<Intrepid::FieldContainer<Real> > target_; |
| 323 |
|
| 324 |
public: |
| 325 |
QoI_Control_Cost_1_Poisson_Boltzmann(const ROL::Ptr<FE<Real> > &fe, |
| 326 |
const ROL::Ptr<Doping<Real> > &dope) |
| 327 |
: fe_(fe) { |
| 328 |
// Compute reference doping profile |
| 329 |
const int c = fe_->gradN()->dimension(0); |
| 330 |
const int p = fe_->gradN()->dimension(2); |
| 331 |
const int d = fe_->gradN()->dimension(3); |
| 332 |
std::vector<Real> pt(d); |
| 333 |
target_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 334 |
for (int i = 0; i < c; ++i) { |
| 335 |
for (int j = 0; j < p; ++j) { |
| 336 |
for (int k = 0; k < d; ++k) { |
| 337 |
pt[k] = (*fe_->cubPts())(i,j,k); |
| 338 |
} |
| 339 |
(*target_)(i,j) = dope->evaluate(pt); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 345 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 346 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 347 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 348 |
// Get relevant dimensions |
| 349 |
const int c = fe_->gradN()->dimension(0); |
| 350 |
const int p = fe_->gradN()->dimension(2); |
| 351 |
// Initialize output val |
| 352 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 353 |
// Evaluate state on FE basis |
| 354 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval = |
| 355 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 356 |
fe_->evaluateValue(valZ_eval, z_coeff); |
| 357 |
// Compute difference between control and target |
| 358 |
Intrepid::RealSpaceTools<Real>::subtract(*valZ_eval,*target_); |
| 359 |
// Compute squared L2-norm of diff |
| 360 |
fe_->computeIntegral(val,valZ_eval,valZ_eval); |
| 361 |
// Scale by one half |
| 362 |
Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5)); |
| 363 |
return static_cast<Real>(0); |
| 364 |
} |
| 365 |
|
| 366 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 367 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 368 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 369 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 370 |
throw Exception::Zero(">>> QoI_Control_Cost_1_Poisson_Boltzmann::gradient_1 is zero."); |
| 371 |
} |
| 372 |
|
| 373 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 374 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 375 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 376 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 377 |
// Get relevant dimensions |
| 378 |
const int c = fe_->gradN()->dimension(0); |
| 379 |
const int f = fe_->gradN()->dimension(1); |
| 380 |
const int p = fe_->gradN()->dimension(2); |
| 381 |
// Initialize output grad |
| 382 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 383 |
// Evaluate state on FE basis |
| 384 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval = |
| 385 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 386 |
fe_->evaluateValue(valZ_eval, z_coeff); |
| 387 |
// Compute difference between control and target |
| 388 |
Intrepid::RealSpaceTools<Real>::subtract(*valZ_eval,*target_); |
| 389 |
// Compute gradient of squared L2-norm of diff |
| 390 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 391 |
*valZ_eval, |
| 392 |
*(fe_->NdetJ()), |
| 393 |
Intrepid::COMP_CPP, false); |
| 394 |
} |
| 395 |
|
| 396 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 397 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 398 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 399 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 400 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 401 |
throw Exception::Zero(">>> QoI_Control_Cost_1_Poisson_Boltzmann::HessVec_11 is zero."); |
| 402 |
} |
| 403 |
|
| 404 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 405 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 406 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 407 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 408 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 409 |
throw Exception::Zero(">>> QoI_Control_Cost_1_Poisson_Boltzmann::HessVec_12 is zero."); |
| 410 |
} |
| 411 |
|
| 412 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 413 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 414 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 415 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 416 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 417 |
throw Exception::Zero(">>> QoI_Control_Cost_1_Poisson_Boltzmann::HessVec_21 is zero."); |
| 418 |
} |
| 419 |
|
| 420 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 421 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 422 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 423 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 424 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 425 |
const int c = fe_->gradN()->dimension(0); |
| 426 |
const int f = fe_->gradN()->dimension(1); |
| 427 |
const int p = fe_->gradN()->dimension(2); |
| 428 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval = |
| 429 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 430 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 431 |
fe_->evaluateValue(valV_eval, v_coeff); |
| 432 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 433 |
*valV_eval, |
| 434 |
*(fe_->NdetJ()), |
| 435 |
Intrepid::COMP_CPP, false); |
| 436 |
} |
| 437 |
|
| 438 |
}; // QoI_Control_Cost_1 |
| 439 |
|
| 440 |
template <class Real> |
| 441 |
class QoI_Control_Cost_2_Poisson_Boltzmann : public QoI<Real> { |
| 442 |
private: |
| 443 |
ROL::Ptr<FE<Real> > fe_; |
| 444 |
|
| 445 |
public: |
| 446 |
QoI_Control_Cost_2_Poisson_Boltzmann(const ROL::Ptr<FE<Real> > &fe) : fe_(fe) {} |
| 447 |
|
| 448 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 449 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 450 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 451 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 452 |
// Get relevant dimensions |
| 453 |
const int c = fe_->gradN()->dimension(0); |
| 454 |
const int p = fe_->gradN()->dimension(2); |
| 455 |
const int d = fe_->gradN()->dimension(3); |
| 456 |
// Initialize output val |
| 457 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 458 |
// Evaluate state on FE basis |
| 459 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradZ_eval = |
| 460 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 461 |
fe_->evaluateGradient(gradZ_eval, z_coeff); |
| 462 |
// Compute squared L2-norm of grad |
| 463 |
fe_->computeIntegral(val,gradZ_eval,gradZ_eval); |
| 464 |
// Scale by one half |
| 465 |
Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5)); |
| 466 |
return static_cast<Real>(0); |
| 467 |
} |
| 468 |
|
| 469 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 470 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 471 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 472 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 473 |
throw Exception::Zero(">>> QoI_Control_Cost_2_Poisson_Boltzmann::gradient_1 is zero."); |
| 474 |
} |
| 475 |
|
| 476 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 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 |
// Get relevant dimensions |
| 481 |
const int c = fe_->gradN()->dimension(0); |
| 482 |
const int f = fe_->gradN()->dimension(1); |
| 483 |
const int p = fe_->gradN()->dimension(2); |
| 484 |
const int d = fe_->gradN()->dimension(3); |
| 485 |
// Initialize output grad |
| 486 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 487 |
// Evaluate state on FE basis |
| 488 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradZ_eval = |
| 489 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 490 |
fe_->evaluateGradient(gradZ_eval, z_coeff); |
| 491 |
// Compute gradient of squared L2-norm of gradient |
| 492 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 493 |
*gradZ_eval, |
| 494 |
*(fe_->gradNdetJ()), |
| 495 |
Intrepid::COMP_CPP, false); |
| 496 |
} |
| 497 |
|
| 498 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 499 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 500 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 501 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 502 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 503 |
throw Exception::Zero(">>> QoI_Control_Cost_2_Poisson_Boltzmann::HessVec_11 is zero."); |
| 504 |
} |
| 505 |
|
| 506 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 507 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 508 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 509 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 510 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 511 |
throw Exception::Zero(">>> QoI_Control_Cost_2_Poisson_Boltzmann::HessVec_12 is zero."); |
| 512 |
} |
| 513 |
|
| 514 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 515 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 516 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 517 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 518 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 519 |
throw Exception::Zero(">>> QoI_Control_Cost_2_Poisson_Boltzmann::HessVec_21 is zero."); |
| 520 |
} |
| 521 |
|
| 522 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 523 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 524 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 525 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 526 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 527 |
const int c = fe_->gradN()->dimension(0); |
| 528 |
const int f = fe_->gradN()->dimension(1); |
| 529 |
const int p = fe_->gradN()->dimension(2); |
| 530 |
const int d = fe_->gradN()->dimension(3); |
| 531 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradV_eval = |
| 532 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 533 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 534 |
fe_->evaluateGradient(gradV_eval, v_coeff); |
| 535 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 536 |
*gradV_eval, |
| 537 |
*(fe_->gradNdetJ()), |
| 538 |
Intrepid::COMP_CPP, false); |
| 539 |
} |
| 540 |
|
| 541 |
}; // QoI_Control_Cost_2 |
| 542 |
|
| 543 |
template <class Real> |
| 544 |
class StdObjective_Poisson_Boltzmann : public ROL::StdObjective<Real> { |
| 545 |
private: |
| 546 |
const Real J_, w1_, w2_, w3_; |
| 547 |
|
| 548 |
public: |
| 549 |
StdObjective_Poisson_Boltzmann(const Real J, const Real w1, const Real w2, const Real w3) |
| 550 |
: J_(J), w1_(w1), w2_(w2), w3_(w3) {} |
| 551 |
|
| 552 |
Real value(const std::vector<Real> &x, Real &tol) { |
| 553 |
const Real half(0.5); |
| 554 |
return half*w1_*std::pow(x[0]-J_,2) + w2_*x[1] + w3_*x[2]; |
| 555 |
} |
| 556 |
|
| 557 |
void gradient(std::vector<Real> &g, const std::vector<Real> &x, Real &tol) { |
| 558 |
g[0] = w1_*(x[0]-J_); |
| 559 |
g[1] = w2_; |
| 560 |
g[2] = w3_; |
| 561 |
} |
| 562 |
|
| 563 |
void hessVec(std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol) { |
| 564 |
const Real zero(0); |
| 565 |
hv[0] = w1_*v[0]; |
| 566 |
hv[1] = zero; |
| 567 |
hv[2] = zero; |
| 568 |
} |
| 569 |
|
| 570 |
}; // OBJ_SCALAR |
| 571 |
|
| 572 |
#endif |