| 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_poisson_topOpt.hpp |
| 11 |
\brief Implements the local PDE interface for the Poisson |
| 12 |
topology optimization problem. |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifndef PDE_POISSON_TOPOPT_HPP |
| 16 |
#define PDE_POISSON_TOPOPT_HPP |
| 17 |
|
| 18 |
#include "../../TOOLS/pde.hpp" |
| 19 |
#include "../../TOOLS/fe.hpp" |
| 20 |
#include "../../TOOLS/Intrepid_HGRAD_C0_FEM.hpp" |
| 21 |
|
| 22 |
#include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" |
| 23 |
#include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" |
| 24 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 25 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 26 |
#include "Intrepid_RealSpaceTools.hpp" |
| 27 |
#include "Intrepid_CellTools.hpp" |
| 28 |
|
| 29 |
#include "ROL_Ptr.hpp" |
| 30 |
|
| 31 |
template <class Real> |
| 32 |
class PDE_Poisson_TopOpt : public PDE<Real> { |
| 33 |
private: |
| 34 |
// Finite element basis information |
| 35 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtr_; |
| 36 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrs_; |
| 37 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtrDens_; |
| 38 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrsDens_; |
| 39 |
// Cell cubature information |
| 40 |
ROL::Ptr<Intrepid::Cubature<Real>> cellCub_; |
| 41 |
// Cell node information |
| 42 |
ROL::Ptr<Intrepid::FieldContainer<Real>> volCellNodes_; |
| 43 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellNodes_; |
| 44 |
std::vector<std::vector<std::vector<int>>> bdryCellLocIds_; |
| 45 |
// Finite element definition |
| 46 |
ROL::Ptr<FE<Real>> fe_vol_, fe_dens_; |
| 47 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 48 |
std::vector<std::vector<int>> fidx_; |
| 49 |
// Coordinates of degrees freedom on boundary cells. |
| 50 |
// Indexing: [sideset number][local side id](cell number, value at dof) |
| 51 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellDofValues_; |
| 52 |
// Force function evaluated at cubature points |
| 53 |
ROL::Ptr<Intrepid::FieldContainer<Real>> force_eval_; |
| 54 |
ROL::Ptr<Intrepid::FieldContainer<Real>> nforce_eval_; |
| 55 |
// Inputs |
| 56 |
Real minConductivity_; |
| 57 |
Real SIMPpower_; |
| 58 |
|
| 59 |
bool getFields2called_; |
| 60 |
|
| 61 |
Real ForceFunc(const std::vector<Real> &x) const { |
| 62 |
return static_cast<Real>(0.01); |
| 63 |
} |
| 64 |
|
| 65 |
Real dirichletFunc(const std::vector<Real> & coords, const int sideset, const int locSideId) const { |
| 66 |
return static_cast<Real>(0); |
| 67 |
} |
| 68 |
|
| 69 |
public: |
| 70 |
PDE_Poisson_TopOpt(Teuchos::ParameterList &parlist) : getFields2called_(false) { |
| 71 |
// Finite element fields. |
| 72 |
int basisOrder = parlist.sublist("Problem").get("Order of FE discretization",1); |
| 73 |
int basisOrderDens = parlist.sublist("Problem").get("Density Basis Order",0); |
| 74 |
TEUCHOS_TEST_FOR_EXCEPTION(basisOrder > 2 || basisOrder < 1, std::invalid_argument, |
| 75 |
">>> PDE-OPT/topopt/poisson/pde_poisson_topOpt.hpp: Basis order is not 1 or 2!"); |
| 76 |
TEUCHOS_TEST_FOR_EXCEPTION(basisOrderDens > 1 || basisOrderDens < 0, std::invalid_argument, |
| 77 |
">>> PDE-OPT/topopt/poisson/pde_poisson_topOpt.hpp: Basis order is not 0 or 1!"); |
| 78 |
if (basisOrder == 1) |
| 79 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real,Intrepid::FieldContainer<Real>>>(); |
| 80 |
else if (basisOrder == 2) |
| 81 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real,Intrepid::FieldContainer<Real>>>(); |
| 82 |
if (basisOrderDens == 1) |
| 83 |
basisPtrDens_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real,Intrepid::FieldContainer<Real>>>(); |
| 84 |
else |
| 85 |
basisPtrDens_ = ROL::makePtr<Intrepid::Basis_HGRAD_C0_FEM<Real,Intrepid::FieldContainer<Real>>>(); |
| 86 |
basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_); |
| 87 |
basisPtrsDens_.clear(); basisPtrsDens_.push_back(basisPtrDens_); // Density component |
| 88 |
// Quadrature rules. |
| 89 |
shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis |
| 90 |
Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory |
| 91 |
int cubDegree = parlist.sublist("Problem").get("Cubature Degree",2); // set cubature degree, e.g., 2 |
| 92 |
cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature |
| 93 |
|
| 94 |
minConductivity_ = parlist.sublist("Problem").get("Minimum Conductivity",1.e-3); |
| 95 |
SIMPpower_ = parlist.sublist("Problem").get("SIMP Power",3.0); |
| 96 |
} |
| 97 |
|
| 98 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> & res, |
| 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 |
const Real one(1); |
| 103 |
// Get dimensions |
| 104 |
const int c = fe_vol_->gradN()->dimension(0); |
| 105 |
const int f = fe_vol_->gradN()->dimension(1); |
| 106 |
const int p = fe_vol_->gradN()->dimension(2); |
| 107 |
const int d = fe_vol_->gradN()->dimension(3); |
| 108 |
// Initialize residual storage |
| 109 |
res = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 110 |
// Temporary storage |
| 111 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, gradU_eval, KgradU; |
| 112 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 113 |
gradU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 114 |
KgradU = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 115 |
// Build SIMP density at cubature points |
| 116 |
fe_dens_->evaluateValue(valZ_eval, z_coeff); |
| 117 |
for (int i = 0; i < c; ++i) { |
| 118 |
for (int j = 0; j < p; ++j) { |
| 119 |
(*valZ_eval)(i,j) = minConductivity_ |
| 120 |
+ (one - minConductivity_) * std::pow((*valZ_eval)(i,j),SIMPpower_); |
| 121 |
} |
| 122 |
} |
| 123 |
// Build flux function |
| 124 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 125 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*KgradU, |
| 126 |
*valZ_eval, |
| 127 |
*gradU_eval); |
| 128 |
// Integrate stiffness term |
| 129 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 130 |
*KgradU, |
| 131 |
*(fe_vol_->gradNdetJ()), |
| 132 |
Intrepid::COMP_CPP, false); |
| 133 |
// Add force term |
| 134 |
Intrepid::FunctionSpaceTools::integrate<Real>(*res, |
| 135 |
*nforce_eval_, |
| 136 |
*(fe_vol_->NdetJ()), |
| 137 |
Intrepid::COMP_CPP, true); |
| 138 |
// Apply Dirichlet boundary conditions |
| 139 |
int numSideSets = bdryCellLocIds_.size(); |
| 140 |
if (numSideSets > 0) { |
| 141 |
for (int i = 0; i < numSideSets; ++i) { |
| 142 |
if (i==2) { |
| 143 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 144 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 145 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 146 |
int numBdryDofs = fidx_[j].size(); |
| 147 |
for (int k = 0; k < numCellsSide; ++k) { |
| 148 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 149 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 150 |
(*res)(cidx,fidx_[j][l]) = (*u_coeff)(cidx,fidx_[j][l]) - (*bdryCellDofValues_[i][j])(k,fidx_[j][l]); |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 160 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 161 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 162 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 163 |
const Real one(1); |
| 164 |
// Get dimensions |
| 165 |
const int c = fe_vol_->gradN()->dimension(0); |
| 166 |
const int f = fe_vol_->gradN()->dimension(1); |
| 167 |
const int p = fe_vol_->gradN()->dimension(2); |
| 168 |
const int d = fe_vol_->gradN()->dimension(3); |
| 169 |
// Initialize Jacobian storage |
| 170 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 171 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, KgradN; |
| 172 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 173 |
KgradN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p, d); |
| 174 |
// Build density-dependent conductivity function |
| 175 |
fe_dens_->evaluateValue(valZ_eval, z_coeff); |
| 176 |
for (int i = 0; i < c; ++i) { |
| 177 |
for (int j = 0; j < p; ++j) { |
| 178 |
(*valZ_eval)(i,j) = minConductivity_ |
| 179 |
+ (one - minConductivity_) * std::pow((*valZ_eval)(i,j),SIMPpower_); |
| 180 |
} |
| 181 |
} |
| 182 |
// Build flux function |
| 183 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*KgradN, |
| 184 |
*valZ_eval, |
| 185 |
*(fe_vol_->gradN())); |
| 186 |
// Integrate stiffness term |
| 187 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 188 |
*KgradN, |
| 189 |
*(fe_vol_->gradNdetJ()), |
| 190 |
Intrepid::COMP_CPP, false); |
| 191 |
|
| 192 |
// Apply Dirichlet boundary conditions |
| 193 |
int numSideSets = bdryCellLocIds_.size(); |
| 194 |
if (numSideSets > 0) { |
| 195 |
for (int i = 0; i < numSideSets; ++i) { |
| 196 |
if (i==2) { |
| 197 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 198 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 199 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 200 |
int numBdryDofs = fidx_[j].size(); |
| 201 |
for (int k = 0; k < numCellsSide; ++k) { |
| 202 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 203 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 204 |
for (int m = 0; m < f; ++m) { |
| 205 |
(*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0); |
| 206 |
} |
| 207 |
(*jac)(cidx,fidx_[j][l],fidx_[j][l]) = static_cast<Real>(1); |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & jac, |
| 217 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 218 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 219 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 220 |
const Real one(1); |
| 221 |
// Get dimensions |
| 222 |
const int c = fe_vol_->gradN()->dimension(0); |
| 223 |
const int f = fe_vol_->gradN()->dimension(1); |
| 224 |
const int fd = fe_dens_->gradN()->dimension(1); |
| 225 |
const int p = fe_vol_->gradN()->dimension(2); |
| 226 |
const int d = fe_vol_->gradN()->dimension(3); |
| 227 |
// Initialize Jacobian storage |
| 228 |
jac = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, fd); |
| 229 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, gradU_eval, dKN, gradUgradN; |
| 230 |
// Temporary storage |
| 231 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 232 |
gradU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 233 |
dKN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, p); |
| 234 |
gradUgradN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 235 |
// Build density-dependent conductivity function |
| 236 |
fe_dens_->evaluateValue(valZ_eval, z_coeff); |
| 237 |
for (int i = 0; i < c; ++i) { |
| 238 |
for (int j = 0; j < p; ++j) { |
| 239 |
(*valZ_eval)(i,j) = SIMPpower_*(one - minConductivity_) |
| 240 |
* std::pow((*valZ_eval)(i,j),SIMPpower_-one); |
| 241 |
} |
| 242 |
} |
| 243 |
// Build derivative of conductivity function |
| 244 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*dKN, |
| 245 |
*valZ_eval, |
| 246 |
*(fe_dens_->N())); |
| 247 |
// Integrate stiffness term |
| 248 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 249 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*gradUgradN, |
| 250 |
*gradU_eval, |
| 251 |
(*fe_vol_->gradNdetJ())); |
| 252 |
Intrepid::FunctionSpaceTools::integrate<Real>(*jac, |
| 253 |
*gradUgradN, |
| 254 |
*dKN, |
| 255 |
Intrepid::COMP_CPP, false); |
| 256 |
|
| 257 |
// Apply Dirichlet boundary conditions |
| 258 |
int numSideSets = bdryCellLocIds_.size(); |
| 259 |
if (numSideSets > 0) { |
| 260 |
for (int i = 0; i < numSideSets; ++i) { |
| 261 |
if (i==2) { |
| 262 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 263 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 264 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 265 |
int numBdryDofs = fidx_[j].size(); |
| 266 |
for (int k = 0; k < numCellsSide; ++k) { |
| 267 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 268 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 269 |
for (int m=0; m < f; ++m) { |
| 270 |
(*jac)(cidx,fidx_[j][l],m) = static_cast<Real>(0); |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 281 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 282 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 283 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 284 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 285 |
throw Exception::Zero(">>> (PDE_Poisson_TopOpt::Hessian_11): Zero Hessian."); |
| 286 |
} |
| 287 |
|
| 288 |
void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 289 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 290 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 291 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 292 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 293 |
const Real one(1); |
| 294 |
// Get dimensions |
| 295 |
const int c = fe_vol_->gradN()->dimension(0); |
| 296 |
const int f = fe_vol_->gradN()->dimension(1); |
| 297 |
const int fd = fe_dens_->gradN()->dimension(1); |
| 298 |
const int p = fe_vol_->gradN()->dimension(2); |
| 299 |
const int d = fe_vol_->gradN()->dimension(3); |
| 300 |
// Initialize Hessian storage |
| 301 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, f); |
| 302 |
// Temporary storage |
| 303 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, l0_coeff, dKN, gradL_eval, gradLgradN; |
| 304 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 305 |
l0_coeff = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 306 |
dKN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, p); |
| 307 |
gradL_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 308 |
gradLgradN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 309 |
// Build density-dependent conductivity function |
| 310 |
fe_dens_->evaluateValue(valZ_eval, z_coeff); |
| 311 |
for (int i = 0; i < c; ++i) { |
| 312 |
for (int j = 0; j < p; ++j) { |
| 313 |
(*valZ_eval)(i,j) = SIMPpower_*(one - minConductivity_) |
| 314 |
* std::pow((*valZ_eval)(i,j),SIMPpower_-one); |
| 315 |
} |
| 316 |
} |
| 317 |
// Apply Dirichlet conditions to the multipliers. |
| 318 |
*l0_coeff = *l_coeff; |
| 319 |
int numSideSets = bdryCellLocIds_.size(); |
| 320 |
if (numSideSets > 0) { |
| 321 |
for (int i = 0; i < numSideSets; ++i) { |
| 322 |
if (i==2) { |
| 323 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 324 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 325 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 326 |
int numBdryDofs = fidx_[j].size(); |
| 327 |
for (int k = 0; k < numCellsSide; ++k) { |
| 328 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 329 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 330 |
(*l0_coeff)(cidx,fidx_[j][l]) = static_cast<Real>(0); |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
// Build derivative of conductivity function |
| 338 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*dKN, |
| 339 |
*valZ_eval, |
| 340 |
*(fe_dens_->N())); |
| 341 |
// Integrate stiffness term |
| 342 |
fe_vol_->evaluateGradient(gradL_eval, l0_coeff); |
| 343 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*gradLgradN, |
| 344 |
*gradL_eval, |
| 345 |
(*fe_vol_->gradNdetJ())); |
| 346 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 347 |
*dKN, |
| 348 |
*gradLgradN, |
| 349 |
Intrepid::COMP_CPP, false); |
| 350 |
} |
| 351 |
|
| 352 |
void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 353 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 354 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 355 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 356 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 357 |
const Real one(1); |
| 358 |
// Get dimensions |
| 359 |
const int c = fe_vol_->gradN()->dimension(0); |
| 360 |
const int f = fe_vol_->gradN()->dimension(1); |
| 361 |
const int fd = fe_dens_->gradN()->dimension(1); |
| 362 |
const int p = fe_vol_->gradN()->dimension(2); |
| 363 |
const int d = fe_vol_->gradN()->dimension(3); |
| 364 |
// Initialize Hessian storage |
| 365 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, fd); |
| 366 |
// Temporary storage |
| 367 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, l0_coeff, dKN, gradL_eval, gradLgradN; |
| 368 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 369 |
l0_coeff = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 370 |
dKN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, p); |
| 371 |
gradL_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 372 |
gradLgradN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 373 |
// Build density-dependent conductivity function |
| 374 |
fe_vol_->evaluateValue(valZ_eval, z_coeff); |
| 375 |
for (int i = 0; i < c; ++i) { |
| 376 |
for (int j = 0; j < p; ++j) { |
| 377 |
(*valZ_eval)(i,j) = SIMPpower_*(one - minConductivity_) |
| 378 |
* std::pow((*valZ_eval)(i,j),SIMPpower_-one); |
| 379 |
} |
| 380 |
} |
| 381 |
// Apply Dirichlet conditions to the multipliers. |
| 382 |
*l0_coeff = *l_coeff; |
| 383 |
int numSideSets = bdryCellLocIds_.size(); |
| 384 |
if (numSideSets > 0) { |
| 385 |
for (int i = 0; i < numSideSets; ++i) { |
| 386 |
if (i==2) { |
| 387 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 388 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 389 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 390 |
int numBdryDofs = fidx_[j].size(); |
| 391 |
for (int k = 0; k < numCellsSide; ++k) { |
| 392 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 393 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 394 |
(*l0_coeff)(cidx,fidx_[j][l]) = static_cast<Real>(0); |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
// Build derivative of conductivity function |
| 402 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*dKN, |
| 403 |
*valZ_eval, |
| 404 |
*(fe_dens_->N())); |
| 405 |
// Integrate stiffness term |
| 406 |
fe_vol_->evaluateGradient(gradL_eval, l0_coeff); |
| 407 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*gradLgradN, |
| 408 |
*gradL_eval, |
| 409 |
(*fe_vol_->gradNdetJ())); |
| 410 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 411 |
*gradLgradN, |
| 412 |
*dKN, |
| 413 |
Intrepid::COMP_CPP, false); |
| 414 |
} |
| 415 |
|
| 416 |
void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real>> & hess, |
| 417 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & l_coeff, |
| 418 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & u_coeff, |
| 419 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> & z_coeff = ROL::nullPtr, |
| 420 |
const ROL::Ptr<const std::vector<Real>> & z_param = ROL::nullPtr) { |
| 421 |
const Real one(1), two(2); |
| 422 |
// Get dimensions |
| 423 |
const int c = fe_vol_->gradN()->dimension(0); |
| 424 |
const int f = fe_vol_->gradN()->dimension(1); |
| 425 |
const int fd = fe_dens_->gradN()->dimension(1); |
| 426 |
const int p = fe_vol_->gradN()->dimension(2); |
| 427 |
const int d = fe_vol_->gradN()->dimension(3); |
| 428 |
// Initialize Hessian storage |
| 429 |
hess = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, fd); |
| 430 |
// Temporary storage |
| 431 |
ROL::Ptr<Intrepid::FieldContainer<Real>> valZ_eval, l0_coeff, dKN, gradU_eval, gradL_eval, gradUgradL, NgradUgradL; |
| 432 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 433 |
l0_coeff = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 434 |
dKN = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, p); |
| 435 |
gradU_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 436 |
gradL_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 437 |
gradUgradL = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 438 |
NgradUgradL = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, p); |
| 439 |
// Build density-dependent conductivity function |
| 440 |
fe_dens_->evaluateValue(valZ_eval, z_coeff); |
| 441 |
for (int i = 0; i < c; ++i) { |
| 442 |
for (int j = 0; j < p; ++j) { |
| 443 |
(*valZ_eval)(i,j) = SIMPpower_ * (SIMPpower_ - one)*(one - minConductivity_) |
| 444 |
* std::pow((*valZ_eval)(i,j),SIMPpower_-two); |
| 445 |
} |
| 446 |
} |
| 447 |
// Apply Dirichlet conditions to the multipliers. |
| 448 |
*l0_coeff = *l_coeff; |
| 449 |
int numSideSets = bdryCellLocIds_.size(); |
| 450 |
if (numSideSets > 0) { |
| 451 |
for (int i = 0; i < numSideSets; ++i) { |
| 452 |
if (i==2) { |
| 453 |
int numLocalSideIds = bdryCellLocIds_[i].size(); |
| 454 |
for (int j = 0; j < numLocalSideIds; ++j) { |
| 455 |
int numCellsSide = bdryCellLocIds_[i][j].size(); |
| 456 |
int numBdryDofs = fidx_[j].size(); |
| 457 |
for (int k = 0; k < numCellsSide; ++k) { |
| 458 |
int cidx = bdryCellLocIds_[i][j][k]; |
| 459 |
for (int l = 0; l < numBdryDofs; ++l) { |
| 460 |
(*l0_coeff)(cidx,fidx_[j][l]) = static_cast<Real>(0); |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
// Build derivative of conductivity function |
| 468 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*dKN, |
| 469 |
*valZ_eval, |
| 470 |
*(fe_dens_->N())); |
| 471 |
// Integrate stiffness term |
| 472 |
fe_vol_->evaluateGradient(gradU_eval, u_coeff); |
| 473 |
fe_vol_->evaluateGradient(gradL_eval, l0_coeff); |
| 474 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(*gradUgradL, |
| 475 |
*gradU_eval, |
| 476 |
*gradL_eval); |
| 477 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*NgradUgradL, |
| 478 |
*gradUgradL, |
| 479 |
*(fe_dens_->NdetJ())); |
| 480 |
Intrepid::FunctionSpaceTools::integrate<Real>(*hess, |
| 481 |
*dKN, |
| 482 |
*NgradUgradL, |
| 483 |
Intrepid::COMP_CPP, false); |
| 484 |
} |
| 485 |
|
| 486 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 487 |
// GET DIMENSIONS |
| 488 |
int c = fe_vol_->N()->dimension(0); |
| 489 |
int f = fe_vol_->N()->dimension(1); |
| 490 |
// INITIALIZE RIESZ |
| 491 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 492 |
*riesz = *fe_vol_->stiffMat(); |
| 493 |
Intrepid::RealSpaceTools<Real>::add(*riesz,*(fe_vol_->massMat())); |
| 494 |
} |
| 495 |
|
| 496 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 497 |
// GET DIMENSIONS |
| 498 |
int c = fe_dens_->N()->dimension(0); |
| 499 |
int f = fe_dens_->N()->dimension(1); |
| 500 |
// INITIALIZE RIESZ |
| 501 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, f); |
| 502 |
*riesz = *fe_dens_->massMat(); |
| 503 |
} |
| 504 |
|
| 505 |
// This must be called before getFields2 |
| 506 |
void setDensityFields(const std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> &basisPtrs) { |
| 507 |
TEUCHOS_TEST_FOR_EXCEPTION(getFields2called_, std::invalid_argument, |
| 508 |
">>> PDE-OPT/topo-opt/elasticity/src/pde_elasticity.hpp: Must call before getFields2!"); |
| 509 |
|
| 510 |
basisPtrDens_ = basisPtrs[0]; |
| 511 |
basisPtrsDens_ = basisPtrs; |
| 512 |
} |
| 513 |
|
| 514 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() { |
| 515 |
return basisPtrs_; |
| 516 |
} |
| 517 |
|
| 518 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields2() { |
| 519 |
getFields2called_ = true; |
| 520 |
return basisPtrsDens_; |
| 521 |
} |
| 522 |
|
| 523 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes, |
| 524 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 525 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 526 |
volCellNodes_ = volCellNodes; |
| 527 |
bdryCellNodes_ = bdryCellNodes; |
| 528 |
bdryCellLocIds_ = bdryCellLocIds; |
| 529 |
// Finite element definition. |
| 530 |
fe_vol_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_); |
| 531 |
fe_dens_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtrDens_,cellCub_,false); |
| 532 |
fidx_ = fe_vol_->getBoundaryDofs(); |
| 533 |
computeForce(); |
| 534 |
computeDirichlet(); |
| 535 |
} |
| 536 |
|
| 537 |
void computeForce(void) { |
| 538 |
int c = fe_vol_->cubPts()->dimension(0); |
| 539 |
int p = fe_vol_->cubPts()->dimension(1); |
| 540 |
int d = fe_vol_->cubPts()->dimension(2); |
| 541 |
std::vector<Real> pt(d,0); |
| 542 |
force_eval_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 543 |
nforce_eval_ = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,p); |
| 544 |
for (int i = 0; i < c; ++i) { |
| 545 |
for (int j = 0; j < p; ++j) { |
| 546 |
for (int k = 0; k < d; ++k) { |
| 547 |
pt[k] = (*fe_vol_->cubPts())(i,j,k); |
| 548 |
} |
| 549 |
(*force_eval_)(i,j) = ForceFunc(pt); |
| 550 |
(*nforce_eval_)(i,j) = -(*force_eval_)(i,j); |
| 551 |
} |
| 552 |
} |
| 553 |
} |
| 554 |
|
| 555 |
void computeDirichlet(void) { |
| 556 |
// Compute Dirichlet values at DOFs. |
| 557 |
int d = basisPtr_->getBaseCellTopology().getDimension(); |
| 558 |
int numSidesets = bdryCellLocIds_.size(); |
| 559 |
bdryCellDofValues_.resize(numSidesets); |
| 560 |
for (int i=0; i<numSidesets; ++i) { |
| 561 |
int numLocSides = bdryCellLocIds_[i].size(); |
| 562 |
bdryCellDofValues_[i].resize(numLocSides); |
| 563 |
for (int j=0; j<numLocSides; ++j) { |
| 564 |
int c = bdryCellLocIds_[i][j].size(); |
| 565 |
int f = basisPtr_->getCardinality(); |
| 566 |
bdryCellDofValues_[i][j] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f); |
| 567 |
ROL::Ptr<Intrepid::FieldContainer<Real>> coords = |
| 568 |
ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, d); |
| 569 |
if (c > 0) { |
| 570 |
fe_vol_->computeDofCoords(coords, bdryCellNodes_[i][j]); |
| 571 |
} |
| 572 |
for (int k=0; k<c; ++k) { |
| 573 |
for (int l=0; l<f; ++l) { |
| 574 |
std::vector<Real> dofpoint(d); |
| 575 |
for (int m=0; m<d; ++m) { |
| 576 |
dofpoint[m] = (*coords)(k, l, m); |
| 577 |
} |
| 578 |
(*bdryCellDofValues_[i][j])(k, l) = dirichletFunc(dofpoint, i, j); |
| 579 |
} |
| 580 |
} |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
const ROL::Ptr<FE<Real>> getFE(void) const { |
| 586 |
return fe_vol_; |
| 587 |
} |
| 588 |
|
| 589 |
const ROL::Ptr<FE<Real>> getDensityFE(void) const { |
| 590 |
return fe_dens_; |
| 591 |
} |
| 592 |
|
| 593 |
const ROL::Ptr<Intrepid::FieldContainer<Real>> getForce(void) const { |
| 594 |
return force_eval_; |
| 595 |
} |
| 596 |
|
| 597 |
}; // PDE_Poisson |
| 598 |
|
| 599 |
#endif |