| 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 pde.hpp |
| 11 |
\brief Implements the local PDE interface for the Stefan_Boltzmann control problem. |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef PDEOPT_PDE_STOCH_STEFAN_BOLTZMANN_HPP |
| 15 |
#define PDEOPT_PDE_STOCH_STEFAN_BOLTZMANN_HPP |
| 16 |
|
| 17 |
#include "../TOOLS/pde.hpp" |
| 18 |
#include "../TOOLS/fe.hpp" |
| 19 |
|
| 20 |
#include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" |
| 21 |
#include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" |
| 22 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 23 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 24 |
#include "Intrepid_CellTools.hpp" |
| 25 |
|
| 26 |
#include "ROL_Ptr.hpp" |
| 27 |
#include "Teuchos_LAPACK.hpp" |
| 28 |
|
| 29 |
template <class Real> |
| 30 |
class StochasticStefanBoltzmannPDE : public PDE<Real> { |
| 31 |
private: |
| 32 |
|
| 33 |
// Finite element basis information |
| 34 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > basisPtr_; |
| 35 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > basisPtrs_; |
| 36 |
// Cell cubature information |
| 37 |
ROL::Ptr<Intrepid::Cubature<Real> > cellCub_; |
| 38 |
ROL::Ptr<Intrepid::Cubature<Real> > bdryCub_; |
| 39 |
// Cell node information |
| 40 |
ROL::Ptr<Intrepid::FieldContainer<Real> > volCellNodes_; |
| 41 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > bdryCellNodes_; |
| 42 |
std::vector<std::vector<std::vector<int> > > bdryCellLocIds_; |
| 43 |
// Finite element definition |
| 44 |
ROL::Ptr<FE<Real> > fe_vol_; |
| 45 |
std::vector<std::vector<ROL::Ptr<FE<Real> > > > fe_bdry_; |
| 46 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 47 |
std::vector<std::vector<int> > fidx_; |
| 48 |
|
| 49 |
const Real scale_; |
| 50 |
Real xmid_; |
| 51 |
Real engTemp_; |
| 52 |
Real airTemp_; |
| 53 |
Real H2OTemp_; |
| 54 |
Real advMag_; |
| 55 |
Real SBscale_; |
| 56 |
Real nonLin_; |
| 57 |
|
| 58 |
public: |
| 59 |
|
| 60 |
StochasticStefanBoltzmannPDE(Teuchos::ParameterList &parlist) : scale_(1) { |
| 61 |
xmid_ = parlist.sublist("Geometry").get<Real>("Step height"); |
| 62 |
engTemp_ = parlist.sublist("Problem").get("Engine: Ambient Temperature",450.0); |
| 63 |
airTemp_ = parlist.sublist("Problem").get("Air: Ambient Temperature",293.0); |
| 64 |
H2OTemp_ = parlist.sublist("Problem").get("Water: Ambient Temperature",303.0); |
| 65 |
advMag_ = parlist.sublist("Problem").get("Advection Magnitude",6.3); |
| 66 |
bool useSB = parlist.sublist("Problem").get("Use Stefan-Boltzmann",true); |
| 67 |
SBscale_ = (useSB) ? static_cast<Real>(1) : static_cast<Real>(0); |
| 68 |
bool useND = parlist.sublist("Problem").get("Use Nonlinear Conductivities",true); |
| 69 |
nonLin_ = (useND) ? static_cast<Real>(1) : static_cast<Real>(0); |
| 70 |
// Finite element fields. |
| 71 |
int basisOrder = parlist.sublist("Problem").get("Basis Order",1); |
| 72 |
if (basisOrder == 1) { |
| 73 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real> >>(); |
| 74 |
} |
| 75 |
else if (basisOrder == 2) { |
| 76 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real> >>(); |
| 77 |
} |
| 78 |
basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_); |
| 79 |
// Quadrature rules. |
| 80 |
shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis |
| 81 |
Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory |
| 82 |
int cubDegree = parlist.sublist("Problem").get("Volume Cubature Degree",2); // set cubature degree, e.g., 2 |
| 83 |
cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature |
| 84 |
|
| 85 |
int d = cellType.getDimension(); |
| 86 |
shards::CellTopology bdryCellType = cellType.getCellTopologyData(d-1, 0); |
| 87 |
int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",2); // set cubature degree, e.g., 2 |
| 88 |
bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree); |
| 89 |
} |
| 90 |
|
| 91 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real> > & res, |
| 92 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 93 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 94 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 95 |
// GET DIMENSIONS |
| 96 |
int c = fe_vol_->gradN()->dimension(0); |
| 97 |
int f = fe_vol_->gradN()->dimension(1); |
| 98 |
int p = fe_vol_->gradN()->dimension(2); |
| 99 |
int d = fe_vol_->gradN()->dimension(3); |
| 100 |
// INITIALIZE RESIDUAL |
| 101 |
res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 102 |
// EVALUATE STATE ON FE BASIS |
| 103 |
ROL::Ptr<Intrepid::FieldContainer<Real> > U_eval = |
| 104 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 105 |
fe_vol_->evaluateValue(U_eval, u_coeff); |
| 106 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval = |
| 107 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 108 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 109 |
// COMPUTE CONSTANT PDE COEFFICIENTS |
| 110 |
ROL::Ptr<Intrepid::FieldContainer<Real> > V |
| 111 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 112 |
ROL::Ptr<Intrepid::FieldContainer<Real> > rhs |
| 113 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 114 |
computeCoefficients(V,rhs,z_param); |
| 115 |
// COMPUTE DIFFUSIVITY |
| 116 |
ROL::Ptr<Intrepid::FieldContainer<Real> > kappa |
| 117 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 118 |
computeDiffusivity(kappa,U_eval,0); |
| 119 |
// MULTIPLY kappa * grad(U) |
| 120 |
Intrepid::FieldContainer<Real> kappa_gradU(c, p, d); |
| 121 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(kappa_gradU, |
| 122 |
*kappa, |
| 123 |
*gradU_eval); |
| 124 |
// INTEGRATE (kappa * grad(U)) . grad(N) |
| 125 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 126 |
kappa_gradU, |
| 127 |
*(fe_vol_->gradNdetJ()), |
| 128 |
Intrepid::COMP_CPP, false); |
| 129 |
// MULTIPLY V . grad(U) |
| 130 |
Intrepid::FieldContainer<Real> V_gradU(c, p); |
| 131 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(V_gradU, |
| 132 |
*V, |
| 133 |
*gradU_eval); |
| 134 |
// INTEGRATE (V . grad(U)) * N |
| 135 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 136 |
V_gradU, |
| 137 |
*(fe_vol_->NdetJ()), |
| 138 |
Intrepid::COMP_CPP, true); |
| 139 |
// ADD RHS TO RESIDUAL |
| 140 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 141 |
*rhs, |
| 142 |
(*fe_vol_->NdetJ()), |
| 143 |
Intrepid::COMP_CPP, true); |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
// APPLY NEUMANN CONDITIONS: Sideset 3, 6 |
| 148 |
// ---> Nothing to do |
| 149 |
int numLocalSideIds(0); |
| 150 |
// APPLY STEFAN-BOLTZMANN CONDITIONS: Sideset 1, 2, 4, 5 |
| 151 |
std::vector<int> sidesets = {1, 2, 4, 5}; |
| 152 |
for (int i = 0; i < 4; ++i) { |
| 153 |
numLocalSideIds = bdryCellLocIds_[sidesets[i]].size(); |
| 154 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 155 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 156 |
int numCellsSide = bdryCellLocIds_[sidesets[i]][j].size(); |
| 157 |
if (numCellsSide) { |
| 158 |
// Get U coefficients on Stefan-Boltzmann boundary |
| 159 |
ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry |
| 160 |
= getBoundaryCoeff(*u_coeff, sidesets[i], j); |
| 161 |
// Evaluate U on FE basis |
| 162 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry |
| 163 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 164 |
fe_bdry_[sidesets[i]][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 165 |
// Compute Stefan-Boltzmann residual |
| 166 |
ROL::Ptr< Intrepid::FieldContainer<Real> > sb_valU |
| 167 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 168 |
computeStefanBoltzmann(sb_valU,valU_eval_bdry,sidesets[i],j,0); |
| 169 |
Intrepid::FieldContainer<Real> sbRes(numCellsSide, f); |
| 170 |
Intrepid::FunctionSpaceTools::integrate<Real>(sbRes, |
| 171 |
*sb_valU, |
| 172 |
*(fe_bdry_[sidesets[i]][j]->NdetJ()), |
| 173 |
Intrepid::COMP_CPP, false); |
| 174 |
// Add Stefan-Boltzmann residual to volume residual |
| 175 |
for (int k = 0; k < numCellsSide; ++k) { |
| 176 |
int cidx = bdryCellLocIds_[sidesets[i]][j][k]; |
| 177 |
for (int l = 0; l < f; ++l) { |
| 178 |
(*res)(cidx,l) += sbRes(k,l); |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
// APPLY ROBIN CONTROLS: Sideset 0 |
| 185 |
int sideset = 0; |
| 186 |
numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 187 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 188 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 189 |
int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 190 |
if (numCellsSide) { |
| 191 |
// Get U coefficients on Robin boundary |
| 192 |
ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry |
| 193 |
= getBoundaryCoeff(*u_coeff, sideset, j); |
| 194 |
// Evaluate U on FE basis |
| 195 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry |
| 196 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 197 |
fe_bdry_[sideset][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 198 |
// Compute Stefan-Boltzmann residual |
| 199 |
ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal |
| 200 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 201 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valZ_eval_bdry; |
| 202 |
if (z_coeff != ROL::nullPtr) { |
| 203 |
// Get Z coefficients on Robin boundary |
| 204 |
ROL::Ptr<Intrepid::FieldContainer<Real > > z_coeff_bdry |
| 205 |
= getBoundaryCoeff(*z_coeff, sideset, j); |
| 206 |
// Evaluate Z on FE basis |
| 207 |
valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 208 |
fe_bdry_[sideset][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry); |
| 209 |
} |
| 210 |
else { |
| 211 |
valZ_eval_bdry = ROL::nullPtr; |
| 212 |
} |
| 213 |
computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,sideset,j,0); |
| 214 |
Intrepid::FieldContainer<Real> robinRes(numCellsSide, f); |
| 215 |
Intrepid::FunctionSpaceTools::integrate<Real>(robinRes, |
| 216 |
*robinVal, |
| 217 |
*(fe_bdry_[sideset][j]->NdetJ()), |
| 218 |
Intrepid::COMP_CPP, false); |
| 219 |
// Add Stefan-Boltzmann residual to volume residual |
| 220 |
for (int k = 0; k < numCellsSide; ++k) { |
| 221 |
int cidx = bdryCellLocIds_[sideset][j][k]; |
| 222 |
for (int l = 0; l < f; ++l) { |
| 223 |
(*res)(cidx,l) += robinRes(k,l); |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
// // APPLY DIRICHLET CONTROLS: Sideset 0 |
| 229 |
// int sideset = 0; |
| 230 |
// numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 231 |
// for (int j = 0; j < numLocalSideIds; ++j) { |
| 232 |
// int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 233 |
// int numBdryDofs = fidx_[j].size(); |
| 234 |
// for (int k = 0; k < numCellsSide; ++k) { |
| 235 |
// int cidx = bdryCellLocIds_[sideset][j][k]; |
| 236 |
// for (int l = 0; l < numBdryDofs; ++l) { |
| 237 |
// (*res)(cidx,fidx_[j][l]) |
| 238 |
// = (*u_coeff)(cidx,fidx_[j][l]) - (*z_coeff)(cidx,fidx_[j][l]); |
| 239 |
// } |
| 240 |
// } |
| 241 |
// } |
| 242 |
} |
| 243 |
|
| 244 |
void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac, |
| 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 DIMENSIONS |
| 249 |
int c = fe_vol_->gradN()->dimension(0); |
| 250 |
int f = fe_vol_->gradN()->dimension(1); |
| 251 |
int p = fe_vol_->gradN()->dimension(2); |
| 252 |
int d = fe_vol_->gradN()->dimension(3); |
| 253 |
// INITILAIZE JACOBIAN |
| 254 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 255 |
// EVALUATE STATE ON FE BASIS |
| 256 |
ROL::Ptr<Intrepid::FieldContainer<Real> > U_eval = |
| 257 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 258 |
fe_vol_->evaluateValue(U_eval, u_coeff); |
| 259 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval = |
| 260 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 261 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 262 |
// COMPUTE CONSTNAT PDE COEFFICIENTS |
| 263 |
ROL::Ptr<Intrepid::FieldContainer<Real> > V |
| 264 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 265 |
ROL::Ptr<Intrepid::FieldContainer<Real> > rhs |
| 266 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 267 |
computeCoefficients(V,rhs,z_param); |
| 268 |
// COMPUTE DIFFUSIVITY |
| 269 |
ROL::Ptr<Intrepid::FieldContainer<Real> > kappa |
| 270 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 271 |
computeDiffusivity(kappa,U_eval,0); |
| 272 |
ROL::Ptr<Intrepid::FieldContainer<Real> > d_kappa |
| 273 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 274 |
computeDiffusivity(d_kappa,U_eval,1); |
| 275 |
// MULTIPLY kappa * grad(N) |
| 276 |
Intrepid::FieldContainer<Real> kappa_gradN(c, f, p, d); |
| 277 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataField<Real>(kappa_gradN, |
| 278 |
*kappa, |
| 279 |
*(fe_vol_->gradN())); |
| 280 |
// INTEGRATE (kappa * grad(N)) . grad(N) |
| 281 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 282 |
kappa_gradN, |
| 283 |
*(fe_vol_->gradNdetJ()), |
| 284 |
Intrepid::COMP_CPP, false); |
| 285 |
// MULTIPLY d_kappa * grad(U) |
| 286 |
Intrepid::FieldContainer<Real> d_kappa_gradU(c, p, d); |
| 287 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(d_kappa_gradU, |
| 288 |
*d_kappa, |
| 289 |
*gradU_eval); |
| 290 |
// MULTIPLY (d_kappa * grad(U)) . grad(N) |
| 291 |
Intrepid::FieldContainer<Real> d_kappa_gradU_gradN(c, f, p); |
| 292 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(d_kappa_gradU_gradN, |
| 293 |
d_kappa_gradU, |
| 294 |
*(fe_vol_->gradNdetJ())); |
| 295 |
// INTEGRATE (d_kappa * grad(U)) . grad(N) * N |
| 296 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 297 |
d_kappa_gradU_gradN, |
| 298 |
*(fe_vol_->N()), |
| 299 |
Intrepid::COMP_CPP, true); |
| 300 |
// MULTIPLY V . grad(N) |
| 301 |
Intrepid::FieldContainer<Real> V_gradN(c, f, p); |
| 302 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(V_gradN, |
| 303 |
*V, |
| 304 |
*(fe_vol_->gradN())); |
| 305 |
// INTEGRATE (V . grad(U)) * N |
| 306 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 307 |
*(fe_vol_->NdetJ()), |
| 308 |
V_gradN, |
| 309 |
Intrepid::COMP_CPP, true); |
| 310 |
|
| 311 |
// APPLY NEUMANN CONDITIONS: Sideset 3, 6 |
| 312 |
// ---> Nothing to do |
| 313 |
int numLocalSideIds(0); |
| 314 |
// APPLY STEFAN-BOLTZMANN CONDITIONS: Sideset 1, 2, 4, 5 |
| 315 |
std::vector<int> sidesets = {1, 2, 4, 5}; |
| 316 |
for (int i = 0; i < 4; ++i) { |
| 317 |
numLocalSideIds = bdryCellLocIds_[sidesets[i]].size(); |
| 318 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 319 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 320 |
int numCellsSide = bdryCellLocIds_[sidesets[i]][j].size(); |
| 321 |
if (numCellsSide) { |
| 322 |
// Get U coefficients on Stefan-Boltzmann boundary |
| 323 |
ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry |
| 324 |
= getBoundaryCoeff(*u_coeff, sidesets[i], j); |
| 325 |
// Evaluate U on FE basis |
| 326 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry |
| 327 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 328 |
fe_bdry_[sidesets[i]][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 329 |
// Compute Stefan-Boltzmann residual |
| 330 |
ROL::Ptr< Intrepid::FieldContainer<Real> > sb_derivU |
| 331 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 332 |
computeStefanBoltzmann(sb_derivU,valU_eval_bdry,sidesets[i],j,1); |
| 333 |
Intrepid::FieldContainer<Real> sb_derivU_N(numCellsSide, f, numCubPerSide); |
| 334 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(sb_derivU_N, |
| 335 |
*sb_derivU, |
| 336 |
*(fe_bdry_[sidesets[i]][j]->N())); |
| 337 |
Intrepid::FieldContainer<Real> sbJac(numCellsSide, f, f); |
| 338 |
Intrepid::FunctionSpaceTools::integrate<Real>(sbJac, |
| 339 |
sb_derivU_N, |
| 340 |
*(fe_bdry_[sidesets[i]][j]->NdetJ()), |
| 341 |
Intrepid::COMP_CPP, false); |
| 342 |
// Add Stefan-Boltzmann residual to volume residual |
| 343 |
for (int k = 0; k < numCellsSide; ++k) { |
| 344 |
int cidx = bdryCellLocIds_[sidesets[i]][j][k]; |
| 345 |
for (int l = 0; l < f; ++l) { |
| 346 |
for (int m = 0; m < f; ++m) { |
| 347 |
(*jac)(cidx,l,m) += sbJac(k,l,m); |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
// APPLY ROBIN CONTROL: Sideset 0 |
| 355 |
int sideset = 0; |
| 356 |
numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 357 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 358 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 359 |
int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 360 |
if (numCellsSide) { |
| 361 |
// Get U coefficients on Robin boundary |
| 362 |
ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry |
| 363 |
= getBoundaryCoeff(*u_coeff, sideset, j); |
| 364 |
// Evaluate U on FE basis |
| 365 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry |
| 366 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 367 |
fe_bdry_[sideset][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 368 |
// Compute Stefan-Boltzmann residual |
| 369 |
ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal |
| 370 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 371 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valZ_eval_bdry; |
| 372 |
if (z_coeff != ROL::nullPtr) { |
| 373 |
// Get Z coefficients on Robin boundary |
| 374 |
ROL::Ptr<Intrepid::FieldContainer<Real > > z_coeff_bdry |
| 375 |
= getBoundaryCoeff(*z_coeff, sideset, j); |
| 376 |
// Evaluate Z on FE basis |
| 377 |
valZ_eval_bdry = ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 378 |
fe_bdry_[sideset][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry); |
| 379 |
} |
| 380 |
else { |
| 381 |
valZ_eval_bdry = ROL::nullPtr; |
| 382 |
} |
| 383 |
computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,sideset,j,1,1); |
| 384 |
Intrepid::FieldContainer<Real> robinVal_N(numCellsSide, f, numCubPerSide); |
| 385 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal_N, |
| 386 |
*robinVal, |
| 387 |
*(fe_bdry_[sideset][j]->N())); |
| 388 |
Intrepid::FieldContainer<Real> robinJac(numCellsSide, f, f); |
| 389 |
Intrepid::FunctionSpaceTools::integrate<Real>(robinJac, |
| 390 |
robinVal_N, |
| 391 |
*(fe_bdry_[sideset][j]->NdetJ()), |
| 392 |
Intrepid::COMP_CPP, false); |
| 393 |
// Add Stefan-Boltzmann residual to volume residual |
| 394 |
for (int k = 0; k < numCellsSide; ++k) { |
| 395 |
int cidx = bdryCellLocIds_[sideset][j][k]; |
| 396 |
for (int l = 0; l < f; ++l) { |
| 397 |
for (int m = 0; m < f; ++m) { |
| 398 |
(*jac)(cidx,l,m) += robinJac(k,l,m); |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
// // APPLY DIRICHLET CONDITIONS: Sideset 0 |
| 405 |
// int sideset = 0; |
| 406 |
// numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 407 |
// for (int j = 0; j < numLocalSideIds; ++j) { |
| 408 |
// int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 409 |
// int numBdryDofs = fidx_[j].size(); |
| 410 |
// for (int k = 0; k < numCellsSide; ++k) { |
| 411 |
// int cidx = bdryCellLocIds_[sideset][j][k]; |
| 412 |
// for (int l = 0; l < numBdryDofs; ++l) { |
| 413 |
// for (int m = 0; m < f; ++m) { |
| 414 |
// (*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0); |
| 415 |
// } |
| 416 |
// (*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1); |
| 417 |
// } |
| 418 |
// } |
| 419 |
// } |
| 420 |
} |
| 421 |
|
| 422 |
void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & jac, |
| 423 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 424 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 425 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 426 |
if (z_coeff != ROL::nullPtr) { |
| 427 |
// GET DIMENSIONS |
| 428 |
int c = fe_vol_->gradN()->dimension(0); |
| 429 |
int f = fe_vol_->gradN()->dimension(1); |
| 430 |
// INITILAIZE JACOBIAN |
| 431 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 432 |
// APPLY ROBIN CONTROL: Sideset 0 |
| 433 |
int sideset = 0; |
| 434 |
int numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 435 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 436 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 437 |
int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 438 |
if (numCellsSide) { |
| 439 |
// Get U coefficients on Robin boundary |
| 440 |
ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry |
| 441 |
= getBoundaryCoeff(*u_coeff, sideset, j); |
| 442 |
// Get Z coefficients on Robin boundary |
| 443 |
ROL::Ptr<Intrepid::FieldContainer<Real > > z_coeff_bdry |
| 444 |
= getBoundaryCoeff(*z_coeff, sideset, j); |
| 445 |
// Evaluate U on FE basis |
| 446 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry |
| 447 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 448 |
fe_bdry_[sideset][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 449 |
// Evaluate Z on FE basis |
| 450 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valZ_eval_bdry |
| 451 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 452 |
fe_bdry_[sideset][j]->evaluateValue(valZ_eval_bdry, z_coeff_bdry); |
| 453 |
// Compute Stefan-Boltzmann residual |
| 454 |
ROL::Ptr< Intrepid::FieldContainer<Real> > robinVal |
| 455 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 456 |
computeRobin(robinVal,valU_eval_bdry,valZ_eval_bdry,sideset,j,1,2); |
| 457 |
Intrepid::FieldContainer<Real> robinVal_N(numCellsSide, f, numCubPerSide); |
| 458 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(robinVal_N, |
| 459 |
*robinVal, |
| 460 |
*(fe_bdry_[sideset][j]->N())); |
| 461 |
Intrepid::FieldContainer<Real> robinJac(numCellsSide, f, f); |
| 462 |
Intrepid::FunctionSpaceTools::integrate<Real>(robinJac, |
| 463 |
robinVal_N, |
| 464 |
*(fe_bdry_[sideset][j]->NdetJ()), |
| 465 |
Intrepid::COMP_CPP, false); |
| 466 |
// Add Stefan-Boltzmann residual to volume residual |
| 467 |
for (int k = 0; k < numCellsSide; ++k) { |
| 468 |
int cidx = bdryCellLocIds_[sideset][j][k]; |
| 469 |
for (int l = 0; l < f; ++l) { |
| 470 |
for (int m = 0; m < f; ++m) { |
| 471 |
(*jac)(cidx,l,m) += robinJac(k,l,m); |
| 472 |
} |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
else { |
| 479 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Jacobian_2): Jacobian_2 is zero."); |
| 480 |
} |
| 481 |
// // APPLY DIRICHLET CONTROLS: Sideset 0 |
| 482 |
// int sideset = 0; |
| 483 |
// int numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 484 |
// for (int j = 0; j < numLocalSideIds; ++j) { |
| 485 |
// int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 486 |
// int numBdryDofs = fidx_[j].size(); |
| 487 |
// for (int k = 0; k < numCellsSide; ++k) { |
| 488 |
// int cidx = bdryCellLocIds_[sideset][j][k]; |
| 489 |
// for (int l = 0; l < numBdryDofs; ++l) { |
| 490 |
// (*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(-1); |
| 491 |
// } |
| 492 |
// } |
| 493 |
// } |
| 494 |
} |
| 495 |
|
| 496 |
void Jacobian_3(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & jac, |
| 497 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 498 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 499 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 500 |
if (z_param != ROL::nullPtr) { |
| 501 |
// GET DIMENSIONS |
| 502 |
int c = fe_vol_->gradN()->dimension(0); |
| 503 |
int f = fe_vol_->gradN()->dimension(1); |
| 504 |
int p = fe_vol_->gradN()->dimension(2); |
| 505 |
int d = fe_vol_->gradN()->dimension(3); |
| 506 |
// INITIALIZE RESIDUAL |
| 507 |
jac.resize(z_param->size(), ROL::nullPtr); |
| 508 |
jac[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 509 |
// EVALUATE STATE ON FE BASIS |
| 510 |
ROL::Ptr<Intrepid::FieldContainer<Real> > U_eval = |
| 511 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 512 |
fe_vol_->evaluateValue(U_eval, u_coeff); |
| 513 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval = |
| 514 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 515 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 516 |
ROL::Ptr<std::vector<Real> > one = ROL::makePtr<std::vector<Real>>(z_param->size(), 1); |
| 517 |
// COMPUTE CONSTANT PDE COEFFICIENTS |
| 518 |
ROL::Ptr<Intrepid::FieldContainer<Real> > V |
| 519 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 520 |
ROL::Ptr<Intrepid::FieldContainer<Real> > rhs |
| 521 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 522 |
computeCoefficients(V,rhs,one); |
| 523 |
// MULTIPLY V . grad(U) |
| 524 |
Intrepid::FieldContainer<Real> V_gradU(c, p); |
| 525 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(V_gradU, |
| 526 |
*V, |
| 527 |
*gradU_eval); |
| 528 |
// INTEGRATE (V . grad(U)) * N |
| 529 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac[0], |
| 530 |
V_gradU, |
| 531 |
*(fe_vol_->NdetJ()), |
| 532 |
Intrepid::COMP_CPP, true); |
| 533 |
} |
| 534 |
else{ |
| 535 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Jacobian_3): Jacobian_3 is zero."); |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 540 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 541 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 542 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 543 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 544 |
// GET DIMENSIONS |
| 545 |
int c = fe_vol_->gradN()->dimension(0); |
| 546 |
int f = fe_vol_->gradN()->dimension(1); |
| 547 |
int p = fe_vol_->gradN()->dimension(2); |
| 548 |
int d = fe_vol_->gradN()->dimension(3); |
| 549 |
// INITILAIZE JACOBIAN |
| 550 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 551 |
ROL::Ptr<Intrepid::FieldContainer<Real> > l_coeff_dbc |
| 552 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(*l_coeff); |
| 553 |
// // APPLY DIRICHLET CONDITIONS TO LAGRANGE MULTIPLIERS: Sideset 0 |
| 554 |
// int sideset = 0; |
| 555 |
// int numLocalSideIds = bdryCellLocIds_[sideset].size(); |
| 556 |
// for (int j = 0; j < numLocalSideIds; ++j) { |
| 557 |
// int numCellsSide = bdryCellLocIds_[sideset][j].size(); |
| 558 |
// int numBdryDofs = fidx_[j].size(); |
| 559 |
// for (int k = 0; k < numCellsSide; ++k) { |
| 560 |
// int cidx = bdryCellLocIds_[sideset][j][k]; |
| 561 |
// for (int l = 0; l < numBdryDofs; ++l) { |
| 562 |
// (*l_coeff_dbc)(cidx,fidx_[j][l]) = static_cast<Real>(0); |
| 563 |
// } |
| 564 |
// } |
| 565 |
// } |
| 566 |
// EVALUATE STATE ON FE BASIS |
| 567 |
ROL::Ptr<Intrepid::FieldContainer<Real> > U_eval = |
| 568 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 569 |
fe_vol_->evaluateValue(U_eval, u_coeff); |
| 570 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradU_eval = |
| 571 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 572 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 573 |
ROL::Ptr<Intrepid::FieldContainer<Real> > gradL_eval = |
| 574 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 575 |
fe_vol_->evaluateGradient(gradL_eval, l_coeff_dbc); |
| 576 |
// COMPUTE DIFFUSIVITY |
| 577 |
ROL::Ptr<Intrepid::FieldContainer<Real> > d1_kappa |
| 578 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 579 |
computeDiffusivity(d1_kappa,U_eval,1); |
| 580 |
ROL::Ptr<Intrepid::FieldContainer<Real> > d2_kappa |
| 581 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 582 |
computeDiffusivity(d2_kappa,U_eval,2); |
| 583 |
// MULTIPLY d1_kappa * grad(L) |
| 584 |
Intrepid::FieldContainer<Real> d1_kappa_gradL(c, p, d); |
| 585 |
Intrepid::FunctionSpaceTools::tensorMultiplyDataData<Real>(d1_kappa_gradL, |
| 586 |
*d1_kappa, |
| 587 |
*gradL_eval); |
| 588 |
// MULTIPLY (d_1kappa * grad(L)) . grad(N)det(J) |
| 589 |
Intrepid::FieldContainer<Real> d1_kappa_gradL_gradNdetJ(c, f, p); |
| 590 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(d1_kappa_gradL_gradNdetJ, |
| 591 |
d1_kappa_gradL, |
| 592 |
*(fe_vol_->gradNdetJ())); |
| 593 |
// INTEGRATE (d1_kappa * grad(L)) . grad(N) * N |
| 594 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 595 |
*(fe_vol_->N()), |
| 596 |
d1_kappa_gradL_gradNdetJ, |
| 597 |
Intrepid::COMP_CPP, false); |
| 598 |
// MULTIPLY d1_kappa * grad(L) . grad(N) |
| 599 |
Intrepid::FieldContainer<Real> d1_kappa_gradL_gradN(c, f, p); |
| 600 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(d1_kappa_gradL_gradN, |
| 601 |
d1_kappa_gradL, |
| 602 |
*(fe_vol_->gradN())); |
| 603 |
// INTEGRATE (d1_kappa * grad(L)) . grad(N) * N |
| 604 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 605 |
d1_kappa_gradL_gradN, |
| 606 |
*(fe_vol_->NdetJ()), |
| 607 |
Intrepid::COMP_CPP, true); |
| 608 |
// MULTIPLY grad(U) . grad(L) |
| 609 |
Intrepid::FieldContainer<Real> gradU_gradL(c, p); |
| 610 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(gradU_gradL, |
| 611 |
*gradU_eval, |
| 612 |
*gradL_eval); |
| 613 |
// MULTIPLY d2_kappa * grad(U) . grad(L) |
| 614 |
Intrepid::FieldContainer<Real> d2_kappa_gradU_gradL(c, p); |
| 615 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(d2_kappa_gradU_gradL, |
| 616 |
*d2_kappa, |
| 617 |
gradU_gradL); |
| 618 |
// MULTIPLY d2_kappa * grad(U) . grad(L) * N |
| 619 |
Intrepid::FieldContainer<Real> d2_kappa_gradU_gradL_N(c, f, p); |
| 620 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(d2_kappa_gradU_gradL_N, |
| 621 |
d2_kappa_gradU_gradL, |
| 622 |
*(fe_vol_->N())); |
| 623 |
// INTEGRATE (d2_kappa * grad(U) . grad(L) ) * N * N |
| 624 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 625 |
d2_kappa_gradU_gradL_N, |
| 626 |
*(fe_vol_->NdetJ()), |
| 627 |
Intrepid::COMP_CPP, true); |
| 628 |
// APPLY NEUMANN CONDITIONS: Sideset 3, 6 |
| 629 |
// ---> Nothing to do |
| 630 |
// APPLY STEFAN-BOLTZMANN CONDITIONS: Sideset 1, 2, 4, 5 |
| 631 |
std::vector<int> sidesets = {1, 2, 4, 5}; |
| 632 |
for (int i = 0; i < 4; ++i) { |
| 633 |
int numLocalSideIds = bdryCellLocIds_[sidesets[i]].size(); |
| 634 |
const int numCubPerSide = bdryCub_->getNumPoints(); |
| 635 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 636 |
int numCellsSide = bdryCellLocIds_[sidesets[i]][j].size(); |
| 637 |
if (numCellsSide) { |
| 638 |
// Get U coefficients on Stefan-Boltzmann boundary |
| 639 |
ROL::Ptr<Intrepid::FieldContainer<Real > > u_coeff_bdry |
| 640 |
= getBoundaryCoeff(*u_coeff, sidesets[i], j); |
| 641 |
ROL::Ptr<Intrepid::FieldContainer<Real > > l_coeff_bdry |
| 642 |
= getBoundaryCoeff(*l_coeff_dbc, sidesets[i], j); |
| 643 |
// Evaluate U on FE basis |
| 644 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valU_eval_bdry |
| 645 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 646 |
fe_bdry_[sidesets[i]][j]->evaluateValue(valU_eval_bdry, u_coeff_bdry); |
| 647 |
ROL::Ptr<Intrepid::FieldContainer<Real > > valL_eval_bdry |
| 648 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 649 |
fe_bdry_[sidesets[i]][j]->evaluateValue(valL_eval_bdry, l_coeff_bdry); |
| 650 |
// Compute Stefan-Boltzmann residual |
| 651 |
ROL::Ptr< Intrepid::FieldContainer<Real> > sb_derivU |
| 652 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(numCellsSide, numCubPerSide); |
| 653 |
computeStefanBoltzmann(sb_derivU,valU_eval_bdry,sidesets[i],j,2); |
| 654 |
Intrepid::FieldContainer<Real> sb_derivU_L(numCellsSide, numCubPerSide); |
| 655 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(sb_derivU_L, |
| 656 |
*sb_derivU, |
| 657 |
*valL_eval_bdry); |
| 658 |
Intrepid::FieldContainer<Real> sb_derivU_L_N(numCellsSide, f, numCubPerSide); |
| 659 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(sb_derivU_L_N, |
| 660 |
sb_derivU_L, |
| 661 |
*(fe_bdry_[sidesets[i]][j]->N())); |
| 662 |
Intrepid::FieldContainer<Real> sbHess(numCellsSide, f, f); |
| 663 |
Intrepid::FunctionSpaceTools::integrate<Real>(sbHess, |
| 664 |
sb_derivU_L_N, |
| 665 |
*(fe_bdry_[sidesets[i]][j]->NdetJ()), |
| 666 |
Intrepid::COMP_CPP, false); |
| 667 |
// Add Stefan-Boltzmann residual to volume residual |
| 668 |
for (int k = 0; k < numCellsSide; ++k) { |
| 669 |
int cidx = bdryCellLocIds_[sidesets[i]][j][k]; |
| 670 |
for (int l = 0; l < f; ++l) { |
| 671 |
for (int m = 0; m < f; ++m) { |
| 672 |
(*hess)(cidx,l,m) += sbHess(k,l,m); |
| 673 |
} |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
} |
| 678 |
} |
| 679 |
// APPLY ROBIN CONTROL: Sideset 0 |
| 680 |
// --> Nothing to do |
| 681 |
} |
| 682 |
|
| 683 |
void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 684 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 685 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 686 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 687 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 688 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_12): Hessian is zero."); |
| 689 |
} |
| 690 |
|
| 691 |
void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 692 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 693 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 694 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 695 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 696 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_21): Hessian is zero."); |
| 697 |
} |
| 698 |
|
| 699 |
void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real> > & hess, |
| 700 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 701 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 702 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 703 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 704 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_22): Hessian is zero."); |
| 705 |
} |
| 706 |
|
| 707 |
void Hessian_13(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 708 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 709 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 710 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 711 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 712 |
if ( z_param != ROL::nullPtr ) { |
| 713 |
// GET DIMENSIONS |
| 714 |
int c = fe_vol_->gradN()->dimension(0); |
| 715 |
int f = fe_vol_->gradN()->dimension(1); |
| 716 |
int p = fe_vol_->gradN()->dimension(2); |
| 717 |
int d = fe_vol_->gradN()->dimension(3); |
| 718 |
// INITILAIZE HESSIAN |
| 719 |
hess.resize(z_param->size(),ROL::nullPtr); |
| 720 |
hess[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 721 |
// EVALUATE STATE ON FE BASIS |
| 722 |
ROL::Ptr<Intrepid::FieldContainer<Real> > L_eval = |
| 723 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 724 |
fe_vol_->evaluateValue(L_eval, l_coeff); |
| 725 |
// COMPUTE CONSTANT PDE COEFFICIENTS |
| 726 |
ROL::Ptr<Intrepid::FieldContainer<Real> > V |
| 727 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 728 |
ROL::Ptr<Intrepid::FieldContainer<Real> > rhs |
| 729 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 730 |
ROL::Ptr<std::vector<Real> > one = ROL::makePtr<std::vector<Real>>(z_param->size(), 1); |
| 731 |
computeCoefficients(V,rhs,one); |
| 732 |
// MULTIPLY V . grad(N) |
| 733 |
Intrepid::FieldContainer<Real> V_gradN(c, f, p); |
| 734 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(V_gradN, |
| 735 |
*V, |
| 736 |
*(fe_vol_->gradNdetJ())); |
| 737 |
// INTEGRATE (V . grad(U)) * N |
| 738 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess[0], |
| 739 |
*L_eval, |
| 740 |
V_gradN, |
| 741 |
Intrepid::COMP_CPP, false); |
| 742 |
} |
| 743 |
else { |
| 744 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_13): Hessian_13 is zero."); |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
void Hessian_23(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 749 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 750 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 751 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 752 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 753 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_23): Hessian_23 is zero."); |
| 754 |
} |
| 755 |
|
| 756 |
void Hessian_31(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 757 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 758 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 759 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 760 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 761 |
if ( z_param != ROL::nullPtr ) { |
| 762 |
// GET DIMENSIONS |
| 763 |
int c = fe_vol_->gradN()->dimension(0); |
| 764 |
int f = fe_vol_->gradN()->dimension(1); |
| 765 |
int p = fe_vol_->gradN()->dimension(2); |
| 766 |
int d = fe_vol_->gradN()->dimension(3); |
| 767 |
// INITILAIZE HESSIAN |
| 768 |
hess.resize(z_param->size(),ROL::nullPtr); |
| 769 |
hess[0] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 770 |
// EVALUATE STATE ON FE BASIS |
| 771 |
ROL::Ptr<Intrepid::FieldContainer<Real> > L_eval = |
| 772 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 773 |
fe_vol_->evaluateValue(L_eval, l_coeff); |
| 774 |
// COMPUTE CONSTANT PDE COEFFICIENTS |
| 775 |
ROL::Ptr<Intrepid::FieldContainer<Real> > V |
| 776 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 777 |
ROL::Ptr<Intrepid::FieldContainer<Real> > rhs |
| 778 |
= ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 779 |
ROL::Ptr<std::vector<Real> > one = ROL::makePtr<std::vector<Real>>(z_param->size(), 1); |
| 780 |
computeCoefficients(V,rhs,one); |
| 781 |
// MULTIPLY V . grad(N) |
| 782 |
Intrepid::FieldContainer<Real> V_gradN(c, f, p); |
| 783 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(V_gradN, |
| 784 |
*V, |
| 785 |
*(fe_vol_->gradNdetJ())); |
| 786 |
// INTEGRATE (V . grad(U)) * N |
| 787 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess[0], |
| 788 |
*L_eval, |
| 789 |
V_gradN, |
| 790 |
Intrepid::COMP_CPP, false); |
| 791 |
} |
| 792 |
else { |
| 793 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_31): Hessian_31 is zero."); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
void Hessian_32(std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > & hess, |
| 798 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 799 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 800 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 801 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 802 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_32): Hessian_32 is zero."); |
| 803 |
} |
| 804 |
|
| 805 |
void Hessian_33(std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > & hess, |
| 806 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & l_coeff, |
| 807 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & u_coeff, |
| 808 |
const ROL::Ptr<const Intrepid::FieldContainer<Real> > & z_coeff = ROL::nullPtr, |
| 809 |
const ROL::Ptr<const std::vector<Real> > & z_param = ROL::nullPtr) { |
| 810 |
throw Exception::Zero(">>> (StochasticStefanBoltzmannPDE::Hessian_33): Hessian_33 is zero."); |
| 811 |
} |
| 812 |
|
| 813 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) { |
| 814 |
// GET DIMENSIONS |
| 815 |
int c = fe_vol_->N()->dimension(0); |
| 816 |
int f = fe_vol_->N()->dimension(1); |
| 817 |
// INITIALIZE RIESZ |
| 818 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 819 |
*riesz = *fe_vol_->stiffMat(); |
| 820 |
Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat())); |
| 821 |
} |
| 822 |
|
| 823 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real> > & riesz) { |
| 824 |
// riesz = fe_vol_->stiffMat(); |
| 825 |
// Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat())); |
| 826 |
throw Exception::NotImplemented(">>> (StochasticStefanBoltzmannPDE::RieszMap2): Not implemented."); |
| 827 |
// GET DIMENSIONS |
| 828 |
int c = fe_vol_->N()->dimension(0); |
| 829 |
int f = fe_vol_->N()->dimension(1); |
| 830 |
// INITIALIZE RIESZ |
| 831 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 832 |
*riesz = *fe_vol_->massMat(); |
| 833 |
} |
| 834 |
|
| 835 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real> > > > getFields(void) { |
| 836 |
return basisPtrs_; |
| 837 |
} |
| 838 |
|
| 839 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real> > &volCellNodes, |
| 840 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real> > > > &bdryCellNodes, |
| 841 |
const std::vector<std::vector<std::vector<int> > > &bdryCellLocIds ) { |
| 842 |
volCellNodes_ = volCellNodes; |
| 843 |
bdryCellNodes_ = bdryCellNodes; |
| 844 |
bdryCellLocIds_ = bdryCellLocIds; |
| 845 |
// Finite element definition |
| 846 |
fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_); |
| 847 |
// Set local boundary DOFs |
| 848 |
fidx_ = fe_vol_->getBoundaryDofs(); |
| 849 |
// Construct boundary FEs |
| 850 |
const int numSidesets = bdryCellNodes.size(); |
| 851 |
fe_bdry_.resize(numSidesets); |
| 852 |
for(int i = 0; i < numSidesets; ++i) { |
| 853 |
int numLocSides = bdryCellNodes[i].size(); |
| 854 |
fe_bdry_[i].resize(numLocSides); |
| 855 |
for (int j = 0; j < numLocSides; ++j) { |
| 856 |
if (bdryCellNodes_[i][j] != ROL::nullPtr) { |
| 857 |
fe_bdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes_[i][j],basisPtr_,bdryCub_,j); |
| 858 |
} |
| 859 |
} |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
const ROL::Ptr<FE<Real> > getVolFE(void) const { |
| 864 |
return fe_vol_; |
| 865 |
} |
| 866 |
|
| 867 |
const std::vector<ROL::Ptr<FE<Real> > > getBdryFE(const int sideset) const { |
| 868 |
return fe_bdry_[sideset]; |
| 869 |
} |
| 870 |
|
| 871 |
const std::vector<std::vector<int> > getBdryCellLocIds(const int sideset) const { |
| 872 |
return bdryCellLocIds_[sideset]; |
| 873 |
} |
| 874 |
|
| 875 |
private: |
| 876 |
|
| 877 |
/***************************************************************************/ |
| 878 |
/************** EVALUATE PDE COEFFICIENTS AT DOF COORDINATES ***************/ |
| 879 |
/***************************************************************************/ |
| 880 |
Real evaluateDiffusivity(const Real u, const std::vector<Real> & x, const int deriv = 0) const { |
| 881 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 882 |
const int size_w = 11, size_a = 9; |
| 883 |
if ( x[1] < xmid_ ) { |
| 884 |
// Water Thermal Conductivity: 0.5818 at 280K and 0.6797 at 370K |
| 885 |
std::vector<Real> param_w(size_w,0); |
| 886 |
for (int i = 0; i < size_w; ++i) { |
| 887 |
Real pi = (static_cast<int>(param.size()) > i ? param[i] : static_cast<Real>(0.5)); |
| 888 |
param_w[i] = 0.01*pi; |
| 889 |
} |
| 890 |
std::vector<Real> c(3,0); |
| 891 |
getWaterCoeff(c,param_w); |
| 892 |
Real val = c[0] + nonLin_*(c[1] * u + c[2] * u * u); |
| 893 |
const Real min = 0.1; |
| 894 |
if ( deriv == 1 ) { |
| 895 |
return (val < min ? static_cast<Real>(0) : nonLin_*(c[1] + static_cast<Real>(2)*c[2]*u)); |
| 896 |
} |
| 897 |
if ( deriv == 2 ) { |
| 898 |
return (val < min ? static_cast<Real>(0) : nonLin_*(static_cast<Real>(2)*c[2])); |
| 899 |
} |
| 900 |
return (val < min ? min : c[0] + nonLin_*(c[1] * u + c[2] * u * u)); |
| 901 |
} |
| 902 |
else { |
| 903 |
// Aluminum Thermal Conductivity: 236 at 273K and 240 at 400K |
| 904 |
std::vector<Real> param_a(size_a,0); |
| 905 |
for (int i = 0; i < size_a; ++i) { |
| 906 |
Real pi = (static_cast<int>(param.size()) > size_w+i ? param[size_w+i] : static_cast<Real>(0.5)); |
| 907 |
param_a[i] = pi; |
| 908 |
} |
| 909 |
std::vector<Real> c(5,0); |
| 910 |
getAluminumCoeff(c,param_a); |
| 911 |
Real u2 = u*u, u3 = u2*u, u4 = u3*u; |
| 912 |
Real val = c[0] + nonLin_*(c[1]*u + c[2]*u2 + c[3]*u3 + c[4]*u4); |
| 913 |
const Real min = 100.0; |
| 914 |
if ( deriv == 1 ) { |
| 915 |
return (val < min ? static_cast<Real>(0) : |
| 916 |
nonLin_*(c[1] + static_cast<Real>(2)*c[2]*u |
| 917 |
+ static_cast<Real>(3)*c[3]*u2 |
| 918 |
+ static_cast<Real>(4)*c[4]*u3)); |
| 919 |
} |
| 920 |
if ( deriv == 2 ) { |
| 921 |
return (val < min ? static_cast<Real>(0) : |
| 922 |
nonLin_*(static_cast<Real>(2)*c[2] + static_cast<Real>(6)*c[3]*u |
| 923 |
+ static_cast<Real>(12)*c[4]*u2)); |
| 924 |
} |
| 925 |
return (val < min ? min : c[0] + nonLin_*(c[1]*u + c[2]*u2 + c[3]*u3 + c[4]*u4)); |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
void evaluateVelocity(std::vector<Real> &adv, const std::vector<Real> &x, const std::vector<Real> &z_param) const { |
| 930 |
if ( x[1] < xmid_ ) { |
| 931 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 932 |
Real p20 = (param.size() > 20 ? param[20] : static_cast<Real>(0.5)); |
| 933 |
const Real min = static_cast<Real>(0.1)*xmid_; |
| 934 |
const Real max = static_cast<Real>(0.9)*xmid_; |
| 935 |
const Real x1 = static_cast<Real>(0.5)*((max-min)*p20 + (max+min)); |
| 936 |
const Real mag = ((x[1] < x1) ? x[1]/x1 : (xmid_-x[1])/(xmid_-x1)); |
| 937 |
adv[0] = -z_param[0]*mag; |
| 938 |
adv[1] = static_cast<Real>(0); |
| 939 |
} |
| 940 |
else { |
| 941 |
adv[0] = static_cast<Real>(0); |
| 942 |
adv[1] = static_cast<Real>(0); |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
Real evaluateRHS(const std::vector<Real> &x) const { |
| 947 |
return static_cast<Real>(0); |
| 948 |
} |
| 949 |
|
| 950 |
Real evaluateStefanBoltzmann(const Real u, const std::vector<Real> &x, |
| 951 |
const int sideset, const int locSideId, |
| 952 |
const int deriv = 0) const { |
| 953 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 954 |
// sig is the Stefan-Boltzmann constant |
| 955 |
// c1 is sig times the emissivity [0.5,1.5] |
| 956 |
// c2 is the ambient temperature away from the aluminum |
| 957 |
// c3 is the thermal convectivity of air (5), oil (40), and water (440) |
| 958 |
Real c1(0), c2(0), c3(0), sig(5.67e-8); |
| 959 |
if ( sideset == 2 ) { |
| 960 |
Real p21 = (param.size()>21 ? param[21] : static_cast<Real>(0.5)); |
| 961 |
Real p22 = (param.size()>22 ? param[22] : static_cast<Real>(0.5)); |
| 962 |
Real p23 = (param.size()>23 ? param[23] : static_cast<Real>(0.5)); |
| 963 |
c1 = SBscale_ * sig * (static_cast<Real>(0.09) + static_cast<Real>(5.e-3) * p21); |
| 964 |
c2 = airTemp_ + static_cast<Real>(0.02*airTemp_) * p22; |
| 965 |
c3 = static_cast<Real>(5) + static_cast<Real>(0.5) * p23; |
| 966 |
} |
| 967 |
else if ( sideset == 4 || sideset == 5 ) { |
| 968 |
Real p24 = (param.size()>24 ? param[24] : static_cast<Real>(0.5)); |
| 969 |
Real p25 = (param.size()>25 ? param[25] : static_cast<Real>(0.5)); |
| 970 |
Real p26 = (param.size()>26 ? param[26] : static_cast<Real>(0.5)); |
| 971 |
c1 = SBscale_ * sig * (static_cast<Real>(0.09) + static_cast<Real>(5.e-3) * p24); |
| 972 |
c2 = engTemp_ + static_cast<Real>(0.2)*engTemp_ * p25; |
| 973 |
c3 = static_cast<Real>(40) + static_cast<Real>(2) * p26; |
| 974 |
} |
| 975 |
else if ( sideset == 1 ) { |
| 976 |
Real p27 = (param.size()>27 ? param[27] : static_cast<Real>(0.5)); |
| 977 |
Real p28 = (param.size()>28 ? param[28] : static_cast<Real>(0.5)); |
| 978 |
Real p29 = (param.size()>29 ? param[29] : static_cast<Real>(0.5)); |
| 979 |
c1 = SBscale_ * sig * (static_cast<Real>(0.09) + static_cast<Real>(5.e-3) * p27); |
| 980 |
c2 = H2OTemp_ + static_cast<Real>(0.05)*H2OTemp_ * (p28 + static_cast<Real>(1)); |
| 981 |
c3 = static_cast<Real>(440) + static_cast<Real>(20) * p29; |
| 982 |
} |
| 983 |
if ( deriv == 1 ) { |
| 984 |
return c1 * static_cast<Real>(4) * std::pow(u,3) + c3; |
| 985 |
} |
| 986 |
if ( deriv == 2 ) { |
| 987 |
return c1 * static_cast<Real>(4) * static_cast<Real>(3) * std::pow(u,2); |
| 988 |
} |
| 989 |
return c1 * (std::pow(u,4) - std::pow(c2,4)) + c3 * (u - c2); |
| 990 |
} |
| 991 |
|
| 992 |
Real evaluateRobin(const Real u, const Real z, const std::vector<Real> &x, |
| 993 |
const int sideset, const int locSideId, |
| 994 |
const int deriv = 0, const int component = 1) const { |
| 995 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 996 |
Real p30 = (param.size()>30 ? param[30] : static_cast<Real>(0.5)); |
| 997 |
// c is the thermal convectivity of water (440) |
| 998 |
Real c = static_cast<Real>(440) + static_cast<Real>(20) * p30; |
| 999 |
if ( deriv == 1 ) { |
| 1000 |
return (component==1) ? c : -c; |
| 1001 |
} |
| 1002 |
if ( deriv > 1 ) { |
| 1003 |
return static_cast<Real>(0); |
| 1004 |
} |
| 1005 |
return c * (u - z); |
| 1006 |
} |
| 1007 |
|
| 1008 |
Real evaluateRobin(const Real u, const std::vector<Real> &x, |
| 1009 |
const int sideset, const int locSideId, |
| 1010 |
const int deriv = 0, const int component = 1) const { |
| 1011 |
const std::vector<Real> param = PDE<Real>::getParameter(); |
| 1012 |
Real p31 = (param.size()>31 ? param[31] : static_cast<Real>(0.5)); |
| 1013 |
// c is the thermal convectivity of water (440) |
| 1014 |
Real c = static_cast<Real>(440) + static_cast<Real>(20) * p31; |
| 1015 |
if ( deriv == 1 ) { |
| 1016 |
return (component==1) ? c : static_cast<Real>(0); |
| 1017 |
} |
| 1018 |
if ( deriv > 1 ) { |
| 1019 |
return static_cast<Real>(0); |
| 1020 |
} |
| 1021 |
return c * (u - static_cast<Real>(293)); |
| 1022 |
} |
| 1023 |
|
| 1024 |
/***************************************************************************/ |
| 1025 |
/************** COMPUTE PDE COEFFICIENTS AT DOFS ***************************/ |
| 1026 |
/***************************************************************************/ |
| 1027 |
void computeDiffusivity(ROL::Ptr<Intrepid::FieldContainer<Real> > &kappa, |
| 1028 |
const ROL::Ptr<Intrepid::FieldContainer<Real> > &u, |
| 1029 |
const int deriv = 0 ) const { |
| 1030 |
// GET DIMENSIONS |
| 1031 |
int c = fe_vol_->gradN()->dimension(0); |
| 1032 |
int p = fe_vol_->gradN()->dimension(2); |
| 1033 |
int d = fe_vol_->gradN()->dimension(3); |
| 1034 |
std::vector<Real> pt(d); |
| 1035 |
for (int i = 0; i < c; ++i) { |
| 1036 |
for (int j = 0; j < p; ++j) { |
| 1037 |
for ( int k = 0; k < d; ++k) { |
| 1038 |
pt[k] = (*fe_vol_->cubPts())(i,j,k); |
| 1039 |
} |
| 1040 |
// Compute diffusivity |
| 1041 |
(*kappa)(i,j) = scale_*evaluateDiffusivity((*u)(i,j),pt,deriv); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
void computeCoefficients(ROL::Ptr<Intrepid::FieldContainer<Real> > &V, |
| 1047 |
ROL::Ptr<Intrepid::FieldContainer<Real> > &rhs, |
| 1048 |
const ROL::Ptr<const std::vector<Real> > &z_param = ROL::nullPtr) const { |
| 1049 |
// GET DIMENSIONS |
| 1050 |
int c = fe_vol_->gradN()->dimension(0); |
| 1051 |
int p = fe_vol_->gradN()->dimension(2); |
| 1052 |
int d = fe_vol_->gradN()->dimension(3); |
| 1053 |
std::vector<Real> pt(d), adv(d); |
| 1054 |
for (int i = 0; i < c; ++i) { |
| 1055 |
for (int j = 0; j < p; ++j) { |
| 1056 |
for ( int k = 0; k < d; ++k) { |
| 1057 |
pt[k] = (*fe_vol_->cubPts())(i,j,k); |
| 1058 |
} |
| 1059 |
// Compute advection velocity field V |
| 1060 |
if (z_param != ROL::nullPtr) { |
| 1061 |
evaluateVelocity(adv,pt,*z_param); |
| 1062 |
} |
| 1063 |
else { |
| 1064 |
std::vector<Real> param = {advMag_}; |
| 1065 |
evaluateVelocity(adv,pt,param); |
| 1066 |
} |
| 1067 |
for (int k = 0; k < d; ++k) { |
| 1068 |
(*V)(i,j,k) = scale_*adv[k]; |
| 1069 |
} |
| 1070 |
// Compute forcing term f |
| 1071 |
(*rhs)(i,j) = -scale_*evaluateRHS(pt); |
| 1072 |
} |
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
void computeStefanBoltzmann(ROL::Ptr<Intrepid::FieldContainer<Real> > &sb, |
| 1077 |
const ROL::Ptr<Intrepid::FieldContainer<Real> > &u, |
| 1078 |
const int sideset, |
| 1079 |
const int locSideId, |
| 1080 |
const int deriv = 0) const { |
| 1081 |
const int c = u->dimension(0); |
| 1082 |
const int p = u->dimension(1); |
| 1083 |
const int d = fe_vol_->gradN()->dimension(3); |
| 1084 |
std::vector<Real> pt(d); |
| 1085 |
for (int i = 0; i < c; ++i) { |
| 1086 |
for (int j = 0; j < p; ++j) { |
| 1087 |
for (int k = 0; k < d; ++k) { |
| 1088 |
pt[k] = (*fe_bdry_[sideset][locSideId]->cubPts())(i,j,k); |
| 1089 |
} |
| 1090 |
(*sb)(i,j) = evaluateStefanBoltzmann((*u)(i,j),pt,sideset,locSideId,deriv); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
void computeRobin(ROL::Ptr<Intrepid::FieldContainer<Real> > &robin, |
| 1096 |
const ROL::Ptr<Intrepid::FieldContainer<Real> > &u, |
| 1097 |
const ROL::Ptr<Intrepid::FieldContainer<Real> > &z, |
| 1098 |
const int sideset, |
| 1099 |
const int locSideId, |
| 1100 |
const int deriv = 0, |
| 1101 |
const int component = 1) const { |
| 1102 |
const int c = u->dimension(0); |
| 1103 |
const int p = u->dimension(1); |
| 1104 |
const int d = fe_vol_->gradN()->dimension(3); |
| 1105 |
std::vector<Real> pt(d); |
| 1106 |
for (int i = 0; i < c; ++i) { |
| 1107 |
for (int j = 0; j < p; ++j) { |
| 1108 |
for (int k = 0; k < d; ++k) { |
| 1109 |
pt[k] = (*fe_bdry_[sideset][locSideId]->cubPts())(i,j,k); |
| 1110 |
} |
| 1111 |
if (z != ROL::nullPtr) { |
| 1112 |
(*robin)(i,j) = evaluateRobin((*u)(i,j),(*z)(i,j),pt,sideset,locSideId,deriv,component); |
| 1113 |
} |
| 1114 |
else { |
| 1115 |
(*robin)(i,j) = evaluateRobin((*u)(i,j),pt,sideset,locSideId,deriv,component); |
| 1116 |
} |
| 1117 |
} |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
/***************************************************************************/ |
| 1122 |
/************** EXTRACT COEFFICIENTS ON BOUNDARY ***************************/ |
| 1123 |
/***************************************************************************/ |
| 1124 |
ROL::Ptr<Intrepid::FieldContainer<Real> > getBoundaryCoeff( |
| 1125 |
const Intrepid::FieldContainer<Real> & cell_coeff, |
| 1126 |
int sideSet, int cell) const { |
| 1127 |
std::vector<int> bdryCellLocId = bdryCellLocIds_[sideSet][cell]; |
| 1128 |
const int numCellsSide = bdryCellLocId.size(); |
| 1129 |
const int f = basisPtr_->getCardinality(); |
| 1130 |
|
| 1131 |
ROL::Ptr<Intrepid::FieldContainer<Real > > bdry_coeff = |
| 1132 |
ROL::makePtr<Intrepid::FieldContainer<Real >>(numCellsSide, f); |
| 1133 |
for (int i = 0; i < numCellsSide; ++i) { |
| 1134 |
for (int j = 0; j < f; ++j) { |
| 1135 |
(*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
return bdry_coeff; |
| 1139 |
} |
| 1140 |
|
| 1141 |
/***************************************************************************/ |
| 1142 |
/************** COMPUTE LEAST SQUARES COEFFICIENTS *************************/ |
| 1143 |
/***************************************************************************/ |
| 1144 |
void getAluminumCoeff(std::vector<Real> &c, const std::vector<Real> ¶m) const { |
| 1145 |
const std::vector<Real> Ta = {273, 300, 350, 400, 500, 600, 700, 800, 900}; |
| 1146 |
const std::vector<Real> Ka = {236, 237, 240, 240, 237, 232, 226, 220, 213}; |
| 1147 |
Teuchos::LAPACK<int,Real> lapack; |
| 1148 |
const char trans = 'N'; |
| 1149 |
const int m = Ta.size(); |
| 1150 |
const int n = 5; |
| 1151 |
const int nrhs = 1; |
| 1152 |
const int lda = m; |
| 1153 |
const int ldb = m; |
| 1154 |
std::vector<Real> A(m*n,1); |
| 1155 |
std::vector<Real> b(m,1); |
| 1156 |
for (int i = 0; i < m; ++i) { |
| 1157 |
b[i] = Ka[i] + param[i]; |
| 1158 |
for (int j = 0; j < n; ++j) { |
| 1159 |
A[j*m + i] = std::pow(Ta[i],j); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
const int lwork = n + m; |
| 1163 |
std::vector<Real> work(lwork,0); |
| 1164 |
int info; |
| 1165 |
lapack.GELS(trans,m,n,nrhs,&A[0],lda,&b[0],ldb,&work[0],lwork,&info); |
| 1166 |
c.clear(); c.resize(n,0); |
| 1167 |
for (int i = 0; i < n; ++i) { |
| 1168 |
c[i] = b[i]; |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
void getWaterCoeff(std::vector<Real> &c, const std::vector<Real> ¶m) const { |
| 1173 |
const std::vector<Real> Tw = {270, 280, 290, 300, 310, 320, 330, 340, 350, 370, 400}; |
| 1174 |
const std::vector<Real> Kw = {0.5551, 0.5818, 0.5918, 0.6084, 0.6233, 0.6367, 0.6485, 0.6587, 0.6673, 0.6797, 0.6864}; |
| 1175 |
Teuchos::LAPACK<int,Real> lapack; |
| 1176 |
const char trans = 'N'; |
| 1177 |
const int m = Tw.size(); |
| 1178 |
const int n = 3; |
| 1179 |
const int nrhs = 1; |
| 1180 |
const int lda = m; |
| 1181 |
const int ldb = m; |
| 1182 |
std::vector<Real> A(m*n,1); |
| 1183 |
std::vector<Real> b(m,1); |
| 1184 |
for (int i = 0; i < m; ++i) { |
| 1185 |
b[i] = Kw[i] + param[i]; |
| 1186 |
for (int j = 0; j < n; ++j) { |
| 1187 |
A[j*m + i] = std::pow(Tw[i],j); |
| 1188 |
} |
| 1189 |
} |
| 1190 |
const int lwork = n + m; |
| 1191 |
std::vector<Real> work(lwork,0); |
| 1192 |
int info; |
| 1193 |
lapack.GELS(trans,m,n,nrhs,&A[0],lda,&b[0],ldb,&work[0],lwork,&info); |
| 1194 |
c.clear(); c.resize(n,0); |
| 1195 |
for (int i = 0; i < n; ++i) { |
| 1196 |
c[i] = b[i]; |
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
}; // PDE_stefan_boltzmann |
| 1201 |
|
| 1202 |
#endif |