| 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_HPP |
| 15 |
#define PDEOPT_QOI_L2TRACKING_POISSON_BOLTZMANN_HPP |
| 16 |
|
| 17 |
#include "../TOOLS/qoi.hpp" |
| 18 |
#include "pde_poisson_boltzmann.hpp" |
| 19 |
|
| 20 |
template <class Real> |
| 21 |
class QoI_L2Tracking_Poisson_Boltzmann : public QoI<Real> { |
| 22 |
private: |
| 23 |
ROL::Ptr<FE<Real> > fe_; |
| 24 |
|
| 25 |
ROL::Ptr<Intrepid::FieldContainer<Real> > target_; |
| 26 |
|
| 27 |
Real targetFunc(const std::vector<Real> & x) const { |
| 28 |
int size = x.size(); |
| 29 |
Real val(0); |
| 30 |
for (int i = 0; i < size; ++i) { |
| 31 |
val += x[i]*x[i]; |
| 32 |
} |
| 33 |
return val; |
| 34 |
} |
| 35 |
|
| 36 |
public: |
| 37 |
QoI_L2Tracking_Poisson_Boltzmann(const ROL::Ptr<FE<Real> > &fe) : fe_(fe) { |
| 38 |
int c = fe_->cubPts()->dimension(0); |
| 39 |
int p = fe_->cubPts()->dimension(1); |
| 40 |
int d = fe_->cubPts()->dimension(2); |
| 41 |
std::vector<Real> pt(d); |
| 42 |
target_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 43 |
for (int i = 0; i < c; ++i) { |
| 44 |
for (int j = 0; j < p; ++j) { |
| 45 |
for (int k = 0; k < d; ++k) { |
| 46 |
pt[k] = (*fe_->cubPts())(i,j,k); |
| 47 |
} |
| 48 |
(*target_)(i,j) = targetFunc(pt); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 54 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 55 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 56 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 57 |
// Get relevant dimensions |
| 58 |
int c = u_coeff->dimension(0); |
| 59 |
int p = fe_->cubPts()->dimension(1); |
| 60 |
// Initialize output val |
| 61 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 62 |
// Evaluate state on FE basis |
| 63 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval = |
| 64 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 65 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 66 |
// Compute difference between state and target |
| 67 |
Intrepid::RealSpaceTools<Real>::subtract(*valU_eval,*target_); |
| 68 |
// Compute squared L2-norm of diff |
| 69 |
fe_->computeIntegral(val,valU_eval,valU_eval); |
| 70 |
// Scale by one half |
| 71 |
Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5)); |
| 72 |
return static_cast<Real>(0); |
| 73 |
} |
| 74 |
|
| 75 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 76 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 77 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 78 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 79 |
// Get relevant dimensions |
| 80 |
int c = u_coeff->dimension(0); |
| 81 |
int p = fe_->cubPts()->dimension(1); |
| 82 |
int f = fe_->N()->dimension(1); |
| 83 |
// Initialize output grad |
| 84 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 85 |
// Evaluate state on FE basis |
| 86 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valU_eval = |
| 87 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 88 |
fe_->evaluateValue(valU_eval, u_coeff); |
| 89 |
// Compute difference between state and target |
| 90 |
Intrepid::RealSpaceTools<Real>::subtract(*valU_eval,*target_); |
| 91 |
// Compute gradient of squared L2-norm of diff |
| 92 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 93 |
*valU_eval, |
| 94 |
*(fe_->NdetJ()), |
| 95 |
Intrepid::COMP_CPP, false); |
| 96 |
} |
| 97 |
|
| 98 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 99 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 100 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 101 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 102 |
throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::gradient_2 is zero."); |
| 103 |
} |
| 104 |
|
| 105 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 106 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 107 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 108 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 109 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 110 |
int c = v_coeff->dimension(0); |
| 111 |
int p = fe_->cubPts()->dimension(1); |
| 112 |
int f = fe_->N()->dimension(1); |
| 113 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval = |
| 114 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 115 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 116 |
fe_->evaluateValue(valV_eval, v_coeff); |
| 117 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 118 |
*valV_eval, |
| 119 |
*(fe_->NdetJ()), |
| 120 |
Intrepid::COMP_CPP, false); |
| 121 |
} |
| 122 |
|
| 123 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 124 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 125 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 126 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 127 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 128 |
throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::HessVec_12 is zero."); |
| 129 |
} |
| 130 |
|
| 131 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 132 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 133 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 134 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 135 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 136 |
throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::HessVec_21 is zero."); |
| 137 |
} |
| 138 |
|
| 139 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 140 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 141 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 142 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 143 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 144 |
throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::HessVec_22 is zero."); |
| 145 |
} |
| 146 |
|
| 147 |
}; // QoI_L2Tracking |
| 148 |
|
| 149 |
template <class Real> |
| 150 |
class QoI_L2Penalty_Poisson_Boltzmann : public QoI<Real> { |
| 151 |
private: |
| 152 |
ROL::Ptr<FE<Real> > fe_; |
| 153 |
|
| 154 |
public: |
| 155 |
QoI_L2Penalty_Poisson_Boltzmann(const ROL::Ptr<FE<Real> > &fe) : fe_(fe) {} |
| 156 |
|
| 157 |
Real value(ROL::Ptr<Intrepid::FieldContainer<Real> > & val, |
| 158 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 159 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 160 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 161 |
// Get relevant dimensions |
| 162 |
int c = z_coeff->dimension(0); |
| 163 |
int p = fe_->cubPts()->dimension(1); |
| 164 |
// Initialize output val |
| 165 |
val = ROL::makePtr<Intrepid::FieldContainer<Real>>(c); |
| 166 |
// Build local state tracking term |
| 167 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval = |
| 168 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 169 |
fe_->evaluateValue(valZ_eval, z_coeff); |
| 170 |
fe_->computeIntegral(val,valZ_eval,valZ_eval); |
| 171 |
Intrepid::RealSpaceTools<Real>::scale(*val,static_cast<Real>(0.5)); |
| 172 |
return static_cast<Real>(0); |
| 173 |
} |
| 174 |
|
| 175 |
void gradient_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 176 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 177 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 178 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 179 |
throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::gradient_1 is zero."); |
| 180 |
} |
| 181 |
|
| 182 |
void gradient_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & grad, |
| 183 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 184 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 185 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 186 |
// Get relevant dimensions |
| 187 |
int c = z_coeff->dimension(0); |
| 188 |
int p = fe_->cubPts()->dimension(1); |
| 189 |
int f = fe_->N()->dimension(1); |
| 190 |
// Initialize output grad |
| 191 |
grad = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 192 |
// Build local gradient of state tracking term |
| 193 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valZ_eval = |
| 194 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 195 |
fe_->evaluateValue(valZ_eval, z_coeff); |
| 196 |
Intrepid::FunctionSpaceTools::integrate<Real>(*grad, |
| 197 |
*valZ_eval, |
| 198 |
*(fe_->NdetJ()), |
| 199 |
Intrepid::COMP_CPP, false); |
| 200 |
} |
| 201 |
|
| 202 |
void HessVec_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 203 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 204 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 205 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 206 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 207 |
throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::HessVec_11 is zero."); |
| 208 |
} |
| 209 |
|
| 210 |
void HessVec_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 211 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 212 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 213 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 214 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 215 |
throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::HessVec_12 is zero."); |
| 216 |
} |
| 217 |
|
| 218 |
void HessVec_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 219 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 220 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 221 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 222 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 223 |
throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::HessVec_21 is zero."); |
| 224 |
} |
| 225 |
|
| 226 |
void HessVec_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 227 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & v_coeff, |
| 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 |
int c = v_coeff->dimension(0); |
| 232 |
int p = fe_->cubPts()->dimension(1); |
| 233 |
int f = fe_->N()->dimension(1); |
| 234 |
ROL::Ptr<Intrepid::FieldContainer<Real> > valV_eval = |
| 235 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 236 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 237 |
fe_->evaluateValue(valV_eval, v_coeff); |
| 238 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 239 |
*valV_eval, |
| 240 |
*(fe_->NdetJ()), |
| 241 |
Intrepid::COMP_CPP, false); |
| 242 |
} |
| 243 |
|
| 244 |
}; // QoI_L2Penalty |
| 245 |
|
| 246 |
template <class Real> |
| 247 |
class StdObjective_Poisson_Boltzmann : public ROL::StdObjective<Real> { |
| 248 |
private: |
| 249 |
Real alpha_; |
| 250 |
|
| 251 |
public: |
| 252 |
StdObjective_Poisson_Boltzmann(Teuchos::ParameterList &parlist) { |
| 253 |
alpha_ = parlist.sublist("Poisson Boltzmann Objective Function").get("Control Penalty",1.e-4); |
| 254 |
} |
| 255 |
|
| 256 |
Real value(const std::vector<Real> &x, Real &tol) { |
| 257 |
return x[0] + alpha_*x[1]; |
| 258 |
} |
| 259 |
|
| 260 |
void gradient(std::vector<Real> &g, const std::vector<Real> &x, Real &tol) { |
| 261 |
const Real one(1); |
| 262 |
g[0] = one; |
| 263 |
g[1] = alpha_; |
| 264 |
} |
| 265 |
|
| 266 |
void hessVec(std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol) { |
| 267 |
const Real zero(0); |
| 268 |
hv[0] = zero; |
| 269 |
hv[1] = zero; |
| 270 |
} |
| 271 |
|
| 272 |
}; // OBJ_SCALAR |
| 273 |
|
| 274 |
#endif |