| 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_elasticity.hpp |
| 11 |
\brief Implements the local PDE interface for the structural topology |
| 12 |
optimization problem. |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifndef PDE_TOPO_OPT_ELASTICITY_HPP |
| 16 |
#define PDE_TOPO_OPT_ELASTICITY_HPP |
| 17 |
|
| 18 |
#include "../../../TOOLS/pde.hpp" |
| 19 |
#include "../../../TOOLS/fe.hpp" |
| 20 |
#include "../../../TOOLS/fieldhelper.hpp" |
| 21 |
#include "../../../TOOLS/Intrepid_HGRAD_C0_FEM.hpp" |
| 22 |
|
| 23 |
#include "dirichlet.hpp" |
| 24 |
#include "traction.hpp" |
| 25 |
#include "load.hpp" |
| 26 |
#include "materialtensor.hpp" |
| 27 |
|
| 28 |
#include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" |
| 29 |
#include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" |
| 30 |
#include "Intrepid_HGRAD_HEX_C1_FEM.hpp" |
| 31 |
#include "Intrepid_HGRAD_HEX_C2_FEM.hpp" |
| 32 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 33 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 34 |
#include "Intrepid_CellTools.hpp" |
| 35 |
|
| 36 |
#include "ROL_Ptr.hpp" |
| 37 |
|
| 38 |
template <class Real> |
| 39 |
class PDE_Elasticity : public PDE<Real> { |
| 40 |
private: |
| 41 |
// Finite element basis information |
| 42 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtr_; |
| 43 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrs_; |
| 44 |
ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>> basisPtrDens_; |
| 45 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> basisPtrsDens_; |
| 46 |
// Cell cubature information |
| 47 |
ROL::Ptr<Intrepid::Cubature<Real>> cellCub_; |
| 48 |
ROL::Ptr<Intrepid::Cubature<Real>> bdryCub_; |
| 49 |
// Cell node information |
| 50 |
ROL::Ptr<Intrepid::FieldContainer<Real>> volCellNodes_; |
| 51 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellNodes_; |
| 52 |
std::vector<std::vector<std::vector<int>>> bdryCellLocIds_; |
| 53 |
// Finite element definition |
| 54 |
ROL::Ptr<FE<Real>> fe_, feDens_; |
| 55 |
std::vector<std::vector<ROL::Ptr<FE<Real>>>> feBdry_; |
| 56 |
// Local degrees of freedom on boundary, for each side of the reference cell (first index). |
| 57 |
std::vector<std::vector<int>> fidx_; |
| 58 |
// Coordinates of degrees freedom on boundary cells. |
| 59 |
// Indexing: [sideset number][local side id](cell number, value at dof) |
| 60 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> bdryCellDofValues_; |
| 61 |
// Field pattern, offsets, etc. |
| 62 |
std::vector<std::vector<int>> fieldPattern_; // local Field/DOF pattern; set from DOF manager |
| 63 |
int numFields_; // number of fields (equations in the PDE) |
| 64 |
int numDofs_; // total number of degrees of freedom for all (local) fields |
| 65 |
std::vector<int> offset_; // for each field, a counting offset |
| 66 |
std::vector<int> numFieldDofs_; // for each field, number of degrees of freedom |
| 67 |
std::vector<std::vector<int>> fieldPatternDens_; // local Field/DOF pattern; set from DOF manager |
| 68 |
int numFieldsDens_; // number of fields (equations in the PDE) |
| 69 |
int numDofsDens_; // total number of degrees of freedom for all (local) fields |
| 70 |
std::vector<int> offsetDens_; // for each field, a counting offset |
| 71 |
std::vector<int> numFieldDofsDens_; // for each field, number of degrees of freedom |
| 72 |
|
| 73 |
ROL::Ptr<Load<Real>> load_; |
| 74 |
ROL::Ptr<MaterialTensor<Real>> matTensor_; |
| 75 |
ROL::Ptr<Dirichlet<Real>> dirichlet_; |
| 76 |
ROL::Ptr<Traction<Real>> traction_; |
| 77 |
ROL::Ptr<FieldUtils::FieldInfo> fieldInfo_, fieldInfoDens_; |
| 78 |
|
| 79 |
bool getFields2called_; |
| 80 |
|
| 81 |
public: |
| 82 |
PDE_Elasticity(Teuchos::ParameterList &parlist) : getFields2called_(false) { |
| 83 |
// Finite element fields. |
| 84 |
int basisOrder = parlist.sublist("Problem").get("Basis Order",1); |
| 85 |
int basisOrderDens = parlist.sublist("Problem").get("Density Basis Order",0); |
| 86 |
int cubDegree = parlist.sublist("Problem").get("Cubature Degree",4); |
| 87 |
int bdryCubDegree = parlist.sublist("Problem").get("Boundary Cubature Degree",2); |
| 88 |
int probDim = parlist.sublist("Problem").get("Problem Dimension",2); |
| 89 |
if (probDim > 3 || probDim < 2) { |
| 90 |
TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, |
| 91 |
">>> PDE-OPT/poisson/pde_poisson.hpp: Problem dimension is not 2 or 3!"); |
| 92 |
} |
| 93 |
if (basisOrder > 2 || basisOrder < 1) { |
| 94 |
TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, |
| 95 |
">>> PDE-OPT/poisson/pde_poisson.hpp: Basis order is not 1 or 2!"); |
| 96 |
} |
| 97 |
if (probDim == 2) { |
| 98 |
if (basisOrder == 1) { |
| 99 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 100 |
} |
| 101 |
else if (basisOrder == 2) { |
| 102 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C2_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 103 |
} |
| 104 |
if (basisOrderDens == 1) { |
| 105 |
basisPtrDens_ = ROL::makePtr<Intrepid::Basis_HGRAD_QUAD_C1_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 106 |
} |
| 107 |
else { |
| 108 |
basisPtrDens_ = ROL::makePtr<Intrepid::Basis_HGRAD_C0_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 109 |
} |
| 110 |
} |
| 111 |
else if (probDim == 3) { |
| 112 |
if (basisOrder == 1) { |
| 113 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_HEX_C1_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 114 |
} |
| 115 |
else if (basisOrder == 2) { |
| 116 |
basisPtr_ = ROL::makePtr<Intrepid::Basis_HGRAD_HEX_C2_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 117 |
} |
| 118 |
basisPtrDens_ = ROL::makePtr<Intrepid::Basis_HGRAD_HEX_C1_FEM<Real, Intrepid::FieldContainer<Real>>>(); |
| 119 |
} |
| 120 |
basisPtrs_.clear(); basisPtrsDens_.clear(); |
| 121 |
for (int i=0; i<probDim; ++i) { |
| 122 |
basisPtrs_.push_back(basisPtr_); // Displacement component |
| 123 |
} |
| 124 |
basisPtrsDens_.push_back(basisPtrDens_); // Density component |
| 125 |
|
| 126 |
// Quadrature rules. |
| 127 |
shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get cell type from basis |
| 128 |
Intrepid::DefaultCubatureFactory<Real> cubFactory; // create cubature factory |
| 129 |
cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature |
| 130 |
|
| 131 |
shards::CellTopology bdryCellType = cellType.getCellTopologyData(probDim-1, 0); |
| 132 |
bdryCub_ = cubFactory.create(bdryCellType, bdryCubDegree); |
| 133 |
|
| 134 |
matTensor_ = ROL::makePtr<MaterialTensor<Real>>(parlist.sublist("Problem")); |
| 135 |
std::string example = parlist.sublist("Problem").get("Example","Default"); |
| 136 |
load_ = ROL::makePtr<Load<Real>>(parlist.sublist("Problem"),example); |
| 137 |
traction_= ROL::makePtr<Traction<Real>>(parlist.sublist("Problem"),example); |
| 138 |
dirichlet_ = ROL::makePtr<Dirichlet<Real>>(parlist.sublist("Problem"),example); |
| 139 |
|
| 140 |
numDofs_ = 0; |
| 141 |
numFields_ = basisPtrs_.size(); |
| 142 |
offset_.resize(numFields_); |
| 143 |
numFieldDofs_.resize(numFields_); |
| 144 |
for (int i=0; i<numFields_; ++i) { |
| 145 |
if (i==0) { |
| 146 |
offset_[i] = 0; |
| 147 |
} |
| 148 |
else { |
| 149 |
offset_[i] = offset_[i-1] + basisPtrs_[i-1]->getCardinality(); |
| 150 |
} |
| 151 |
numFieldDofs_[i] = basisPtrs_[i]->getCardinality(); |
| 152 |
numDofs_ += numFieldDofs_[i]; |
| 153 |
} |
| 154 |
|
| 155 |
numDofsDens_ = 0; |
| 156 |
numFieldsDens_ = basisPtrsDens_.size(); |
| 157 |
offsetDens_.resize(numFieldsDens_); |
| 158 |
numFieldDofsDens_.resize(numFieldsDens_); |
| 159 |
for (int i=0; i<numFieldsDens_; ++i) { |
| 160 |
if (i==0) { |
| 161 |
offsetDens_[i] = 0; |
| 162 |
} |
| 163 |
else { |
| 164 |
offsetDens_[i] = offsetDens_[i-1] + basisPtrsDens_[i-1]->getCardinality(); |
| 165 |
} |
| 166 |
numFieldDofsDens_[i] = basisPtrsDens_[i]->getCardinality(); |
| 167 |
numDofsDens_ += numFieldDofsDens_[i]; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
void residual(ROL::Ptr<Intrepid::FieldContainer<Real>> &res, |
| 172 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 173 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 174 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 175 |
// Retrieve dimensions. |
| 176 |
int c = fe_->gradN()->dimension(0); |
| 177 |
int f = fe_->gradN()->dimension(1); |
| 178 |
int p = fe_->gradN()->dimension(2); |
| 179 |
int d = fe_->gradN()->dimension(3); |
| 180 |
int matd = matTensor_->getMatrixDim(); |
| 181 |
|
| 182 |
// Initialize residuals. |
| 183 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> R(d); |
| 184 |
for (int i=0; i<d; ++i) { |
| 185 |
R[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f); |
| 186 |
} |
| 187 |
|
| 188 |
// Split u_coeff into components. |
| 189 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, Z; |
| 190 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 191 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoDens_); |
| 192 |
|
| 193 |
// Evaluate/interpolate finite element fields on cells. |
| 194 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradDisp_eval(d); |
| 195 |
ROL::Ptr<Intrepid::FieldContainer<Real>> rho, valZ_eval, UMat, rhoUMat; |
| 196 |
rho = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 197 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 198 |
rhoUMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, matd); |
| 199 |
for (int i=0; i<d; ++i) { |
| 200 |
gradDisp_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 201 |
fe_->evaluateGradient(gradDisp_eval[i], U[i]); |
| 202 |
} |
| 203 |
feDens_->evaluateValue(valZ_eval, Z[0]); |
| 204 |
|
| 205 |
// EVALUATE MATERIAL TENSOR |
| 206 |
matTensor_->computeUmat(UMat, gradDisp_eval); |
| 207 |
matTensor_->computeDensity(rho, valZ_eval); |
| 208 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*rhoUMat, *rho, *UMat); |
| 209 |
for (int i=0; i<d; ++i) { |
| 210 |
Intrepid::FunctionSpaceTools::integrate<Real>(*R[i], |
| 211 |
*rhoUMat, // rho B U |
| 212 |
*matTensor_->CBdetJ(i), // B' C |
| 213 |
Intrepid::COMP_CPP, |
| 214 |
false); |
| 215 |
} |
| 216 |
|
| 217 |
// EVALUATE LOAD |
| 218 |
if (!load_->isNull()) { |
| 219 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> load(d); |
| 220 |
for (int i=0; i<d; ++i) { |
| 221 |
load[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 222 |
} |
| 223 |
load_->compute(load, fe_, PDE<Real>::getParameter(), static_cast<Real>(-1)); |
| 224 |
for (int i=0; i<d; ++i) { |
| 225 |
Intrepid::FunctionSpaceTools::integrate<Real>(*R[i], |
| 226 |
*load[i], // F |
| 227 |
*fe_->NdetJ(), // N |
| 228 |
Intrepid::COMP_CPP, |
| 229 |
true); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
// APPLY TRACTION CONDITIONS |
| 234 |
if (!traction_->isNull()) { |
| 235 |
traction_->apply(R, feBdry_, PDE<Real>::getParameter(), static_cast<Real>(-1)); |
| 236 |
} |
| 237 |
|
| 238 |
// APPLY DIRICHLET CONDITIONS |
| 239 |
dirichlet_->applyResidual(R,U); |
| 240 |
|
| 241 |
// Combine the residuals. |
| 242 |
FieldUtils::combineFieldCoeff<Real>(res, R, fieldInfo_); |
| 243 |
} |
| 244 |
|
| 245 |
void Jacobian_1(ROL::Ptr<Intrepid::FieldContainer<Real>> &jac, |
| 246 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 247 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 248 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 249 |
// Retrieve dimensions. |
| 250 |
int c = fe_->gradN()->dimension(0); |
| 251 |
int f = fe_->gradN()->dimension(1); |
| 252 |
int p = fe_->gradN()->dimension(2); |
| 253 |
int d = fe_->gradN()->dimension(3); |
| 254 |
int matd = matTensor_->getMatrixDim(); |
| 255 |
|
| 256 |
// Initialize Jacobians. |
| 257 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J(d); |
| 258 |
for (int i=0; i<d; ++i) { |
| 259 |
for (int j=0; j<d; ++j) { |
| 260 |
J[i].push_back(ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,f)); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
// Split z_coeff into components. |
| 265 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> Z; |
| 266 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoDens_); |
| 267 |
|
| 268 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> rhoBMat(d); |
| 269 |
ROL::Ptr<Intrepid::FieldContainer<Real>> rho, valZ_eval; |
| 270 |
rho = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 271 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 272 |
|
| 273 |
feDens_->evaluateValue(valZ_eval, Z[0]); |
| 274 |
matTensor_->computeDensity(rho, valZ_eval); |
| 275 |
for (int i=0; i<d; ++i) { |
| 276 |
rhoBMat[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p, matd); |
| 277 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*rhoBMat[i], *rho, *matTensor_->B(i)); |
| 278 |
} |
| 279 |
|
| 280 |
/*** Evaluate weak form of the Jacobian. ***/ |
| 281 |
for (int i=0; i<d; ++i) { |
| 282 |
for (int j=0; j<d; ++j) { |
| 283 |
Intrepid::FunctionSpaceTools::integrate<Real>(*J[i][j], |
| 284 |
*rhoBMat[i], // rho B |
| 285 |
*matTensor_->CBdetJ(j), // B' C |
| 286 |
Intrepid::COMP_CPP, |
| 287 |
false); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
// APPLY DIRICHLET CONDITIONS |
| 292 |
dirichlet_->applyJacobian1(J); |
| 293 |
|
| 294 |
// Combine the jacobians. |
| 295 |
FieldUtils::combineFieldCoeff<Real>(jac, J, fieldInfo_, fieldInfo_); |
| 296 |
} |
| 297 |
|
| 298 |
void Jacobian_2(ROL::Ptr<Intrepid::FieldContainer<Real>> &jac, |
| 299 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 300 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 301 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 302 |
// Retrieve dimensions. |
| 303 |
int c = fe_->gradN()->dimension(0); |
| 304 |
int f = fe_->gradN()->dimension(1); |
| 305 |
int fd = feDens_->gradN()->dimension(1); |
| 306 |
int p = fe_->gradN()->dimension(2); |
| 307 |
int d = fe_->gradN()->dimension(3); |
| 308 |
int matd = matTensor_->getMatrixDim(); |
| 309 |
|
| 310 |
// Initialize Jacobians. |
| 311 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J(d); |
| 312 |
for (int i=0; i<d; ++i) { |
| 313 |
J[i].push_back(ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,fd)); |
| 314 |
} |
| 315 |
|
| 316 |
// Split u_coeff into components. |
| 317 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, Z; |
| 318 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 319 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoDens_); |
| 320 |
|
| 321 |
// Evaluate/interpolate finite element fields on cells. |
| 322 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradDisp_eval(d), CBrhoUMat(d); |
| 323 |
ROL::Ptr<Intrepid::FieldContainer<Real>> rho, valZ_eval, UMat, rhoUMat; |
| 324 |
rho = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 325 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 326 |
rhoUMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, matd); |
| 327 |
for (int i=0; i<d; ++i) { |
| 328 |
CBrhoUMat[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 329 |
gradDisp_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 330 |
fe_->evaluateGradient(gradDisp_eval[i], U[i]); |
| 331 |
} |
| 332 |
feDens_->evaluateValue(valZ_eval, Z[0]); |
| 333 |
matTensor_->computeUmat(UMat, gradDisp_eval); |
| 334 |
matTensor_->computeDensity(rho, valZ_eval, 1); // first derivative |
| 335 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*rhoUMat, *rho, *UMat); |
| 336 |
|
| 337 |
for (int i=0; i<d; ++i) { |
| 338 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*CBrhoUMat[i], *rhoUMat, *matTensor_->CBdetJ(i)); |
| 339 |
} |
| 340 |
|
| 341 |
/*** Evaluate weak form of the residual. ***/ |
| 342 |
for (int i=0; i<d; ++i) { |
| 343 |
Intrepid::FunctionSpaceTools::integrate<Real>(*J[i][0], |
| 344 |
*CBrhoUMat[i], // B' C drho B U |
| 345 |
*feDens_->N() , // N |
| 346 |
Intrepid::COMP_CPP, |
| 347 |
false); |
| 348 |
} |
| 349 |
|
| 350 |
// APPLY DIRICHLET CONDITIONS |
| 351 |
dirichlet_->applyJacobian2(J); |
| 352 |
|
| 353 |
// Combine the jacobians. |
| 354 |
FieldUtils::combineFieldCoeff<Real>(jac, J, fieldInfo_, fieldInfoDens_); |
| 355 |
} |
| 356 |
|
| 357 |
void Hessian_11(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess, |
| 358 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &l_coeff, |
| 359 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 360 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 361 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 362 |
throw Exception::Zero(">>> (PDE_TopoOpt::Hessian_11): Hessian is zero."); |
| 363 |
} |
| 364 |
|
| 365 |
void Hessian_12(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess, |
| 366 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &l_coeff, |
| 367 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 368 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 369 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 370 |
// Retrieve dimensions. |
| 371 |
int c = fe_->gradN()->dimension(0); |
| 372 |
int f = fe_->gradN()->dimension(1); |
| 373 |
int fd = feDens_->gradN()->dimension(1); |
| 374 |
int p = fe_->gradN()->dimension(2); |
| 375 |
int d = fe_->gradN()->dimension(3); |
| 376 |
int matd = matTensor_->getMatrixDim(); |
| 377 |
|
| 378 |
// Initialize Hessians. |
| 379 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J(1); |
| 380 |
for (int i=0; i<d; ++i) { |
| 381 |
J[0].push_back(ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fd,f)); |
| 382 |
} |
| 383 |
|
| 384 |
// Split u_coeff into components. |
| 385 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> L, Z; |
| 386 |
FieldUtils::splitFieldCoeff<Real>(L, l_coeff, fieldInfo_); |
| 387 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoDens_); |
| 388 |
|
| 389 |
// Apply Dirichlet conditions to the multipliers. |
| 390 |
dirichlet_->applyMultiplier(L); |
| 391 |
|
| 392 |
// Evaluate/interpolate finite element fields on cells. |
| 393 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradDisp_eval(d), CBrhoLMat(d); |
| 394 |
ROL::Ptr<Intrepid::FieldContainer<Real>> rho, valZ_eval, LMat, rhoLMat; |
| 395 |
rho = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 396 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 397 |
rhoLMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, matd); |
| 398 |
for (int i=0; i<d; ++i) { |
| 399 |
CBrhoLMat[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 400 |
gradDisp_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 401 |
fe_->evaluateGradient(gradDisp_eval[i], L[i]); |
| 402 |
} |
| 403 |
feDens_->evaluateValue(valZ_eval, Z[0]); |
| 404 |
matTensor_->computeUmat(LMat, gradDisp_eval); |
| 405 |
matTensor_->computeDensity(rho, valZ_eval, 1); // first derivative |
| 406 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*rhoLMat, *rho, *LMat); |
| 407 |
|
| 408 |
for (int i=0; i<d; ++i) { |
| 409 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*CBrhoLMat[i], *rhoLMat, *matTensor_->CBdetJ(i)); |
| 410 |
} |
| 411 |
|
| 412 |
/*** Evaluate weak form of the residual. ***/ |
| 413 |
for (int i=0; i<d; ++i) { |
| 414 |
Intrepid::FunctionSpaceTools::integrate<Real>(*J[0][i], |
| 415 |
*feDens_->N(), // N |
| 416 |
*CBrhoLMat[i], // B' C drho B U |
| 417 |
Intrepid::COMP_CPP, |
| 418 |
false); |
| 419 |
} |
| 420 |
|
| 421 |
// Combine the Hessians. |
| 422 |
FieldUtils::combineFieldCoeff<Real>(hess, J, fieldInfoDens_, fieldInfo_); |
| 423 |
|
| 424 |
} |
| 425 |
|
| 426 |
void Hessian_21(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess, |
| 427 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &l_coeff, |
| 428 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 429 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 430 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 431 |
// Retrieve dimensions. |
| 432 |
int c = fe_->gradN()->dimension(0); |
| 433 |
int f = fe_->gradN()->dimension(1); |
| 434 |
int fd = feDens_->gradN()->dimension(1); |
| 435 |
int p = fe_->gradN()->dimension(2); |
| 436 |
int d = fe_->gradN()->dimension(3); |
| 437 |
int matd = matTensor_->getMatrixDim(); |
| 438 |
|
| 439 |
// Initialize Hessians. |
| 440 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J(d); |
| 441 |
for (int i=0; i<d; ++i) { |
| 442 |
J[i].push_back(ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,fd)); |
| 443 |
} |
| 444 |
|
| 445 |
// Split u_coeff into components. |
| 446 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> L, Z; |
| 447 |
FieldUtils::splitFieldCoeff<Real>(L, l_coeff, fieldInfo_); |
| 448 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoDens_); |
| 449 |
|
| 450 |
// Apply Dirichlet conditions to the multipliers. |
| 451 |
dirichlet_->applyMultiplier(L); |
| 452 |
|
| 453 |
// Evaluate/interpolate finite element fields on cells. |
| 454 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradDisp_eval(d), CBrhoLMat(d); |
| 455 |
ROL::Ptr<Intrepid::FieldContainer<Real>> rho, valZ_eval, LMat, rhoLMat; |
| 456 |
rho = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 457 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 458 |
rhoLMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, matd); |
| 459 |
for (int i=0; i<d; ++i) { |
| 460 |
CBrhoLMat[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, f, p); |
| 461 |
gradDisp_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 462 |
fe_->evaluateGradient(gradDisp_eval[i], L[i]); |
| 463 |
} |
| 464 |
feDens_->evaluateValue(valZ_eval, Z[0]); |
| 465 |
matTensor_->computeUmat(LMat, gradDisp_eval); |
| 466 |
matTensor_->computeDensity(rho, valZ_eval, 1); // first derivative |
| 467 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*rhoLMat, *rho, *LMat); |
| 468 |
|
| 469 |
for (int i=0; i<d; ++i) { |
| 470 |
Intrepid::FunctionSpaceTools::dotMultiplyDataField<Real>(*CBrhoLMat[i], *rhoLMat, *matTensor_->CBdetJ(i)); |
| 471 |
} |
| 472 |
|
| 473 |
/*** Evaluate weak form of the residual. ***/ |
| 474 |
for (int i=0; i<d; ++i) { |
| 475 |
Intrepid::FunctionSpaceTools::integrate<Real>(*J[i][0], |
| 476 |
*CBrhoLMat[i], // B' C drho B U |
| 477 |
*feDens_->N(), // N |
| 478 |
Intrepid::COMP_CPP, |
| 479 |
false); |
| 480 |
} |
| 481 |
|
| 482 |
// Combine the Hessians. |
| 483 |
FieldUtils::combineFieldCoeff(hess, J, fieldInfo_, fieldInfoDens_); |
| 484 |
} |
| 485 |
|
| 486 |
void Hessian_22(ROL::Ptr<Intrepid::FieldContainer<Real>> &hess, |
| 487 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &l_coeff, |
| 488 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &u_coeff, |
| 489 |
const ROL::Ptr<const Intrepid::FieldContainer<Real>> &z_coeff = ROL::nullPtr, |
| 490 |
const ROL::Ptr<const std::vector<Real>> &z_param = ROL::nullPtr) { |
| 491 |
// Retrieve dimensions. |
| 492 |
int c = fe_->gradN()->dimension(0); |
| 493 |
int fd = feDens_->gradN()->dimension(1); |
| 494 |
int p = fe_->gradN()->dimension(2); |
| 495 |
int d = fe_->gradN()->dimension(3); |
| 496 |
int matd = matTensor_->getMatrixDim(); |
| 497 |
|
| 498 |
// Initialize Hessians. |
| 499 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J(1); |
| 500 |
J[0].push_back(ROL::makePtr<Intrepid::FieldContainer<Real>>(c,fd,fd)); |
| 501 |
|
| 502 |
// Split u_coeff into components. |
| 503 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> U, L, Z; |
| 504 |
FieldUtils::splitFieldCoeff<Real>(U, u_coeff, fieldInfo_); |
| 505 |
FieldUtils::splitFieldCoeff<Real>(L, l_coeff, fieldInfo_); |
| 506 |
FieldUtils::splitFieldCoeff<Real>(Z, z_coeff, fieldInfoDens_); |
| 507 |
|
| 508 |
// Apply Dirichlet conditions to the multipliers. |
| 509 |
dirichlet_->applyMultiplier(L); |
| 510 |
|
| 511 |
// Evaluate/interpolate finite element fields on cells. |
| 512 |
std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>> gradDispU_eval(d), gradDispL_eval(d); |
| 513 |
ROL::Ptr<Intrepid::FieldContainer<Real>> rho, valZ_eval, UMat, LMat, rhoLMat, CUMat, CUrhoLMat, NCUrhoLMat; |
| 514 |
rho = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 515 |
valZ_eval = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 516 |
rhoLMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, matd); |
| 517 |
CUMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, matd); |
| 518 |
CUrhoLMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p); |
| 519 |
NCUrhoLMat = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, fd, p); |
| 520 |
for (int i=0; i<d; ++i) { |
| 521 |
gradDispU_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 522 |
fe_->evaluateGradient(gradDispU_eval[i], U[i]); |
| 523 |
gradDispL_eval[i] = ROL::makePtr<Intrepid::FieldContainer<Real>>(c, p, d); |
| 524 |
fe_->evaluateGradient(gradDispL_eval[i], L[i]); |
| 525 |
} |
| 526 |
feDens_->evaluateValue(valZ_eval, Z[0]); |
| 527 |
matTensor_->computeUmat(UMat, gradDispU_eval); |
| 528 |
matTensor_->computeUmat(LMat, gradDispL_eval); |
| 529 |
matTensor_->computeDensity(rho, valZ_eval, 2); // second derivative |
| 530 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataData<Real>(*rhoLMat, *rho, *LMat); |
| 531 |
matTensor_->applyTensor(CUMat, UMat); |
| 532 |
|
| 533 |
Intrepid::FunctionSpaceTools::dotMultiplyDataData<Real>(*CUrhoLMat, *rhoLMat, *CUMat); |
| 534 |
Intrepid::FunctionSpaceTools::scalarMultiplyDataField<Real>(*NCUrhoLMat, *CUrhoLMat, *feDens_->N()); |
| 535 |
|
| 536 |
/*** Evaluate weak form of the residual. ***/ |
| 537 |
Intrepid::FunctionSpaceTools::integrate<Real>(*J[0][0], |
| 538 |
*NCUrhoLMat, // N L' B' C ddrho B U |
| 539 |
*feDens_->NdetJ(), // N |
| 540 |
Intrepid::COMP_CPP, |
| 541 |
false); |
| 542 |
|
| 543 |
// Combine the Hessians. |
| 544 |
FieldUtils::combineFieldCoeff(hess, J, fieldInfoDens_, fieldInfoDens_); |
| 545 |
} |
| 546 |
|
| 547 |
void RieszMap_1(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 548 |
//throw Exception::NotImplemented(">>> (PDE_TopoOpt::RieszMap_1): Not implemented."); |
| 549 |
|
| 550 |
// Retrieve dimensions. |
| 551 |
int c = fe_->gradN()->dimension(0); |
| 552 |
int f = fe_->gradN()->dimension(1); |
| 553 |
int d = fe_->gradN()->dimension(3); |
| 554 |
|
| 555 |
// Initialize Jacobians. |
| 556 |
std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> J(d); |
| 557 |
for (int i=0; i<d; ++i) { |
| 558 |
for (int j=0; j<d; ++j) { |
| 559 |
J[i].push_back(ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,f)); |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
for (int i=0; i<d; ++i) { |
| 564 |
*(J[i][i]) = *(fe_->stiffMat()); |
| 565 |
Intrepid::RealSpaceTools<Real>::add(*(J[i][i]),*(fe_->massMat())); |
| 566 |
} |
| 567 |
|
| 568 |
// Combine the jacobians. |
| 569 |
FieldUtils::combineFieldCoeff<Real>(riesz, J, fieldInfo_, fieldInfo_); |
| 570 |
} |
| 571 |
|
| 572 |
void RieszMap_2(ROL::Ptr<Intrepid::FieldContainer<Real>> & riesz) { |
| 573 |
//throw Exception::NotImplemented(">>> (PDE_TopoOpt::RieszMap_2): Not implemented."); |
| 574 |
|
| 575 |
// Retrieve dimensions. |
| 576 |
int c = feDens_->gradN()->dimension(0); |
| 577 |
int f = feDens_->gradN()->dimension(1); |
| 578 |
|
| 579 |
riesz = ROL::makePtr<Intrepid::FieldContainer<Real>>(c,f,f); |
| 580 |
*(riesz) = *(feDens_->massMat()); |
| 581 |
} |
| 582 |
|
| 583 |
// This must be called before getFields2 |
| 584 |
void setDensityFields(const std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> &basisPtrs) { |
| 585 |
if (getFields2called_) { |
| 586 |
TEUCHOS_TEST_FOR_EXCEPTION(getFields2called_, std::invalid_argument, |
| 587 |
">>> PDE-OPT/topo-opt/elasticity/src/pde_elasticity.hpp: Must call before getFields2!"); |
| 588 |
} |
| 589 |
else { |
| 590 |
basisPtrDens_ = basisPtrs[0]; |
| 591 |
basisPtrsDens_ = basisPtrs; |
| 592 |
|
| 593 |
numDofsDens_ = 0; |
| 594 |
numFieldsDens_ = basisPtrsDens_.size(); |
| 595 |
offsetDens_.resize(numFieldsDens_); |
| 596 |
numFieldDofsDens_.resize(numFieldsDens_); |
| 597 |
for (int i=0; i<numFieldsDens_; ++i) { |
| 598 |
if (i==0) { |
| 599 |
offsetDens_[i] = 0; |
| 600 |
} |
| 601 |
else { |
| 602 |
offsetDens_[i] = offsetDens_[i-1] + basisPtrsDens_[i-1]->getCardinality(); |
| 603 |
} |
| 604 |
numFieldDofsDens_[i] = basisPtrsDens_[i]->getCardinality(); |
| 605 |
numDofsDens_ += numFieldDofsDens_[i]; |
| 606 |
} |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields() { |
| 611 |
return basisPtrs_; |
| 612 |
} |
| 613 |
|
| 614 |
std::vector<ROL::Ptr<Intrepid::Basis<Real, Intrepid::FieldContainer<Real>>>> getFields2() { |
| 615 |
getFields2called_ = true; |
| 616 |
return basisPtrsDens_; |
| 617 |
} |
| 618 |
|
| 619 |
void setCellNodes(const ROL::Ptr<Intrepid::FieldContainer<Real>> &volCellNodes, |
| 620 |
const std::vector<std::vector<ROL::Ptr<Intrepid::FieldContainer<Real>>>> &bdryCellNodes, |
| 621 |
const std::vector<std::vector<std::vector<int>>> &bdryCellLocIds) { |
| 622 |
volCellNodes_ = volCellNodes; |
| 623 |
bdryCellNodes_ = bdryCellNodes; |
| 624 |
bdryCellLocIds_ = bdryCellLocIds; |
| 625 |
// Finite element definition. |
| 626 |
fe_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtr_,cellCub_); |
| 627 |
feDens_ = ROL::makePtr<FE<Real>>(volCellNodes_,basisPtrDens_,cellCub_,false); |
| 628 |
fidx_ = fe_->getBoundaryDofs(); |
| 629 |
if (!traction_->isNull()) { |
| 630 |
traction_->setCellNodes(bdryCellNodes_,bdryCellLocIds_); |
| 631 |
} |
| 632 |
dirichlet_->setCellNodes(bdryCellNodes_,bdryCellLocIds_,fidx_); |
| 633 |
matTensor_->setFE(fe_); |
| 634 |
// Construct boundary FE |
| 635 |
int numSideSets = bdryCellLocIds_.size(); |
| 636 |
if (numSideSets > 0) { |
| 637 |
feBdry_.resize(numSideSets); |
| 638 |
for (int i = 0; i < numSideSets; ++i) { |
| 639 |
int numLocSides = bdryCellNodes[i].size(); |
| 640 |
feBdry_[i].resize(numLocSides); |
| 641 |
for (int j = 0; j < numLocSides; ++j) { |
| 642 |
if (bdryCellNodes[i][j] != ROL::nullPtr) { |
| 643 |
feBdry_[i][j] = ROL::makePtr<FE<Real>>(bdryCellNodes[i][j],basisPtr_,bdryCub_,j); |
| 644 |
} |
| 645 |
} |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
void setFieldPattern(const std::vector<std::vector<int>> &fieldPattern, |
| 651 |
const std::vector<std::vector<int>> &fieldPattern2) { |
| 652 |
fieldPattern_ = fieldPattern; |
| 653 |
fieldPatternDens_ = fieldPattern2; |
| 654 |
fieldInfo_ = ROL::makePtr<FieldUtils::FieldInfo>(numFields_, numDofs_, numFieldDofs_, fieldPattern_); |
| 655 |
fieldInfoDens_ = ROL::makePtr<FieldUtils::FieldInfo>(numFieldsDens_, numDofsDens_, numFieldDofsDens_, fieldPatternDens_); |
| 656 |
} |
| 657 |
|
| 658 |
const ROL::Ptr<FE<Real>> getStateFE(void) const { |
| 659 |
return fe_; |
| 660 |
} |
| 661 |
|
| 662 |
const ROL::Ptr<FE<Real>> getDensityFE(void) const { |
| 663 |
return feDens_; |
| 664 |
} |
| 665 |
|
| 666 |
const std::vector<std::vector<ROL::Ptr<FE<Real>>>> getBdryFE(void) const { |
| 667 |
return feBdry_; |
| 668 |
} |
| 669 |
|
| 670 |
const std::vector<std::vector<std::vector<int>>> getBdryCellLocIds(void) const { |
| 671 |
return bdryCellLocIds_; |
| 672 |
} |
| 673 |
|
| 674 |
const ROL::Ptr<FieldUtils::FieldInfo> getStateFieldInfo(void) const { |
| 675 |
return fieldInfo_; |
| 676 |
} |
| 677 |
|
| 678 |
const ROL::Ptr<FieldUtils::FieldInfo> getDensityFieldInfo(void) const { |
| 679 |
return fieldInfoDens_; |
| 680 |
} |
| 681 |
|
| 682 |
const ROL::Ptr<Load<Real>> getLoad(void) const { |
| 683 |
return load_; |
| 684 |
} |
| 685 |
|
| 686 |
const ROL::Ptr<Traction<Real>> getTraction(void) const { |
| 687 |
return traction_; |
| 688 |
} |
| 689 |
|
| 690 |
const ROL::Ptr<MaterialTensor<Real>> getMaterialTensor(void) const { |
| 691 |
return matTensor_; |
| 692 |
} |
| 693 |
|
| 694 |
}; // PDE_TopoOpt |
| 695 |
|
| 696 |
#endif |