| 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 |
#ifndef ROL_PDEOPT_ELASTICITYSIMP_OPERATORS_H |
| 11 |
#define ROL_PDEOPT_ELASTICITYSIMP_OPERATORS_H |
| 12 |
|
| 13 |
#include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" |
| 14 |
#include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" |
| 15 |
#include "../TOOLS/elasticitySIMP.hpp" |
| 16 |
|
| 17 |
template<class Real> |
| 18 |
class ElasticitySIMPOperators : public ElasticitySIMP <Real> { |
| 19 |
private: |
| 20 |
using GO = typename Tpetra::Map<>::global_ordinal_type; |
| 21 |
|
| 22 |
Real volFrac_; |
| 23 |
|
| 24 |
public: |
| 25 |
|
| 26 |
ElasticitySIMPOperators(const ROL::Ptr<const Teuchos::Comm<int> > &comm, |
| 27 |
const Teuchos::RCP<Teuchos::ParameterList> &parlist, |
| 28 |
const ROL::Ptr<std::ostream> &outStream) { |
| 29 |
ElasticitySIMPOperators_Initialize(comm, parlist, outStream); |
| 30 |
this->SetSIMPParallelStructure(); |
| 31 |
this->SetUpLocalIntrepidArrays(); |
| 32 |
this->ComputeLocalSystemMats(true); |
| 33 |
//Setup DBC information, do not specify any bc sides, use coordinates to determine the BC instead |
| 34 |
std::vector<GO> dbc_side {}; |
| 35 |
this->SetUpMyDBCInfo(true, dbc_side); |
| 36 |
this->process_loading_information(parlist); |
| 37 |
//With new modification on boundary traction, ComputeLocalForceVec should go after SetUpMyBCInfo and process_loading_information |
| 38 |
//this->AssembleSystemGraph(); |
| 39 |
this->AssembleSystemGraph(); |
| 40 |
this->AssembleSystemMats(); |
| 41 |
this->ComputeLocalForceVec(); |
| 42 |
this->AssembleRHSVector(); |
| 43 |
this->EnforceDBC(); |
| 44 |
this->ConstructSolvers(); |
| 45 |
} |
| 46 |
|
| 47 |
void ElasticitySIMPOperators_Initialize(const ROL::Ptr<const Teuchos::Comm<int> > &comm, |
| 48 |
const Teuchos::RCP<Teuchos::ParameterList> &parlist, |
| 49 |
const ROL::Ptr<std::ostream> &outStream) { |
| 50 |
ElasticitySIMP<Real>::ElasticitySIMP_Initialize(comm, parlist, outStream); |
| 51 |
volFrac_ = parlist->sublist("ElasticityTopoOpt").get<Real>("Volume Fraction"); |
| 52 |
this->initDensity_ = volFrac_; |
| 53 |
} |
| 54 |
|
| 55 |
// construct solvers with new material |
| 56 |
void constructSolverWithNewMaterial(void) { |
| 57 |
bool ifInit = false; |
| 58 |
{ |
| 59 |
#ifdef ROL_TIMERS |
| 60 |
Teuchos::TimeMonitor LocalTimer(*SolverUpdateTime_example_PDEOPT_TOOLS_PDEFEM_GLOB); |
| 61 |
#endif |
| 62 |
this->ComputeLocalSystemMats(ifInit); |
| 63 |
this->AssembleSystemMats(); |
| 64 |
this->MatrixRemoveDBC(); |
| 65 |
} |
| 66 |
this->ConstructSolvers(); |
| 67 |
} |
| 68 |
// |
| 69 |
|
| 70 |
ROL::Ptr<Intrepid::FieldContainer<int> > getPosCell(void) const { |
| 71 |
return this->meshMgr_->getPosCell(); |
| 72 |
} |
| 73 |
|
| 74 |
void ApplyMatAToVec(ROL::Ptr<Tpetra::MultiVector<> > &Ju, |
| 75 |
const ROL::Ptr<const Tpetra::MultiVector<> > &u) { |
| 76 |
this->matA_dirichlet_->apply(*u, *Ju); |
| 77 |
} |
| 78 |
|
| 79 |
void ApplyJacobian1ToVec(ROL::Ptr<Tpetra::MultiVector<> > &Ju, |
| 80 |
const ROL::Ptr<const Tpetra::MultiVector<> > &u) { |
| 81 |
#ifdef ROL_TIMERS |
| 82 |
Teuchos::TimeMonitor LocalTimer(*ConstraintDerivativeTime_example_PDEOPT_TOOLS_PDEFEM_GLOB); |
| 83 |
#endif |
| 84 |
this->matA_dirichlet_->apply(*u, *Ju); |
| 85 |
// Jv is myUniqueMap_ |
| 86 |
// u is myUniqueMap_ |
| 87 |
// v should be myCellMap_ |
| 88 |
// |
| 89 |
/* |
| 90 |
ROL::Ptr<Tpetra::MultiVector<> > Ju_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 91 |
ROL::Ptr<Tpetra::MultiVector<> > u_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 92 |
Tpetra::Import<> importer(u->getMap(), u_overlap->getMap()); |
| 93 |
u_overlap->doImport(*u, importer, Tpetra::REPLACE); |
| 94 |
//simply apply matrix to a vector, no need to apply EBC to the vec |
| 95 |
//this-> ApplyBCToVec (u_overlap); |
| 96 |
Teuchos::ArrayRCP<const Real> uData = u_overlap->get1dView(); |
| 97 |
|
| 98 |
Real SIMPScale(0), sum(0), zero(0); |
| 99 |
Intrepid::FieldContainer<Real> localDisp(this->numLocalDofs_); |
| 100 |
|
| 101 |
for(int i=0; i<this->numCells_; i++) { |
| 102 |
SIMPScale = this->SIMPmaterial_[i]->getSIMPScaleFactor(); |
| 103 |
localDisp.initialize(zero); |
| 104 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 105 |
localDisp(j) = uData[u_overlap->getMap()->getLocalElement(this->cellDofs_(this->myCellIds_[i], j))]; |
| 106 |
} |
| 107 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 108 |
if(this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],j))) { |
| 109 |
Ju_overlap -> replaceGlobalValue(this->cellDofs_(this->myCellIds_[i], j), 0, localDisp(j)); |
| 110 |
} |
| 111 |
else { |
| 112 |
sum = zero; |
| 113 |
for(int k=0; k<this->numLocalDofs_; k++) { |
| 114 |
if( !this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],k)) ) { |
| 115 |
sum += SIMPScale * (*this->gradgradMats0_)(i, j, k) * localDisp(k); |
| 116 |
} |
| 117 |
} |
| 118 |
Ju_overlap -> sumIntoGlobalValue(this->cellDofs_(this->myCellIds_[i], j), 0, sum); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
Tpetra::Export<> exporter(Ju_overlap->getMap(), Ju->getMap()); |
| 124 |
//Ju->doExport(*Ju_overlap, exporter, Tpetra::REPLACE); |
| 125 |
Ju->doExport(*Ju_overlap, exporter, Tpetra::ADD); |
| 126 |
*/ |
| 127 |
} |
| 128 |
|
| 129 |
void ApplyInverseJacobian1ToVec(ROL::Ptr<Tpetra::MultiVector<> > &InvJu, |
| 130 |
const ROL::Ptr<const Tpetra::MultiVector<> > &u, |
| 131 |
const bool ifTrans) { |
| 132 |
//Ju is matA->getDomainMap(); |
| 133 |
#ifdef ROL_TIMERS |
| 134 |
Teuchos::TimeMonitor LocalTimer(*LUSubstitutionTime_example_PDEOPT_TOOLS_PDEFEM_GLOB); |
| 135 |
#endif |
| 136 |
this->getSolver(ifTrans)->setB(u); |
| 137 |
this->getSolver(ifTrans)->setX(InvJu); |
| 138 |
this->getSolver(ifTrans)->solve(); |
| 139 |
} |
| 140 |
|
| 141 |
void ApplyJacobian2ToVec(ROL::Ptr<Tpetra::MultiVector<> > &Jv, |
| 142 |
const ROL::Ptr<const Tpetra::MultiVector<> > &u, |
| 143 |
const ROL::Ptr<const Tpetra::MultiVector<> > &v) { |
| 144 |
// Jv is myUniqueMap_ |
| 145 |
// u is myUniqueMap_ |
| 146 |
// v should be myCellMap_ |
| 147 |
// |
| 148 |
#ifdef ROL_TIMERS |
| 149 |
Teuchos::TimeMonitor LocalTimer(*ConstraintDerivativeTime_example_PDEOPT_TOOLS_PDEFEM_GLOB); |
| 150 |
#endif |
| 151 |
ROL::Ptr<Tpetra::MultiVector<> > Jv_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 152 |
ROL::Ptr<Tpetra::MultiVector<> > u_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 153 |
Tpetra::Import<> importer(u->getMap(), u_overlap->getMap()); |
| 154 |
u_overlap->doImport(*u, importer, Tpetra::REPLACE); |
| 155 |
//apply BC here, KU |
| 156 |
this->ApplyBCToVec (u_overlap); |
| 157 |
Teuchos::ArrayRCP<const Real> uData = u_overlap->get1dView(); |
| 158 |
|
| 159 |
ROL::Ptr<Tpetra::MultiVector<> > v_local = ROL::makePtr<Tpetra::MultiVector<>>(this->myCellMap_, 1, true); |
| 160 |
Tpetra::Export<> exporter1(v->getMap(), this->myCellMap_); |
| 161 |
v_local->doExport(*v, exporter1, Tpetra::REPLACE); |
| 162 |
Teuchos::ArrayRCP<const Real> vData = v_local->get1dView(); |
| 163 |
|
| 164 |
Real SIMPDScale(0), localV(0), sum(0), zero(0); |
| 165 |
Intrepid::FieldContainer<Real> localDisp(this->numLocalDofs_); |
| 166 |
|
| 167 |
for(int i=0; i<this->numCells_; i++) { |
| 168 |
SIMPDScale = this->SIMPmaterial_[i]->getSIMPFirstDerivativeScaleFactor(); |
| 169 |
localV = vData[v_local->getMap()->getLocalElement(this->myCellIds_[i])]; |
| 170 |
|
| 171 |
localDisp.initialize(zero); |
| 172 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 173 |
localDisp(j) = uData[u_overlap->getMap()->getLocalElement(this->cellDofs_(this->myCellIds_[i], j))]; |
| 174 |
} |
| 175 |
|
| 176 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 177 |
if(this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],j))) { |
| 178 |
Jv_overlap -> replaceGlobalValue(this->cellDofs_(this->myCellIds_[i], j), 0, localDisp(j)); |
| 179 |
} |
| 180 |
else { |
| 181 |
sum = zero; |
| 182 |
for(int k=0; k<this->numLocalDofs_; k++) { |
| 183 |
if( !this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],k)) ) { |
| 184 |
sum += localV * SIMPDScale * (*this->gradgradMats0_)(i, j, k) * localDisp(k); |
| 185 |
} |
| 186 |
} |
| 187 |
Jv_overlap -> sumIntoGlobalValue(this->cellDofs_(this->myCellIds_[i], j), 0, sum); |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
Tpetra::Export<> exporter2(Jv_overlap->getMap(), Jv->getMap()); |
| 192 |
//Jv->doExport(*Jv_overlap, exporter2, Tpetra::REPLACE); |
| 193 |
Jv->doExport(*Jv_overlap, exporter2, Tpetra::ADD); |
| 194 |
} |
| 195 |
|
| 196 |
void ApplyAdjointJacobian2ToVec (ROL::Ptr<Tpetra::MultiVector<> > &Jv, |
| 197 |
const ROL::Ptr<const Tpetra::MultiVector<> > &u, |
| 198 |
const ROL::Ptr<const Tpetra::MultiVector<> > &v) { |
| 199 |
// Jv is myCellMap_ |
| 200 |
// u should be myUniqueMap_ |
| 201 |
// v should be myUniqueMap_ |
| 202 |
// |
| 203 |
#ifdef ROL_TIMERS |
| 204 |
Teuchos::TimeMonitor LocalTimer(*ConstraintDerivativeTime_example_PDEOPT_TOOLS_PDEFEM_GLOB); |
| 205 |
#endif |
| 206 |
ROL::Ptr<Tpetra::MultiVector<> > u_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 207 |
Tpetra::Import<> importer1(u->getMap(), u_overlap->getMap()); |
| 208 |
u_overlap->doImport(*u, importer1, Tpetra::REPLACE); |
| 209 |
//only apply BC to u |
| 210 |
this->ApplyBCToVec (u_overlap); |
| 211 |
Teuchos::ArrayRCP<const Real> uData = u_overlap->get1dView(); |
| 212 |
|
| 213 |
ROL::Ptr<Tpetra::MultiVector<> > v_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 214 |
Tpetra::Import<> importer2(v->getMap(), v_overlap->getMap()); |
| 215 |
v_overlap->doImport(*v, importer2, Tpetra::REPLACE); |
| 216 |
//ApplyBCToVec (v_overlap); |
| 217 |
Teuchos::ArrayRCP<const Real> vData = v_overlap->get1dView(); |
| 218 |
|
| 219 |
Intrepid::FieldContainer<Real> u_local(this->numLocalDofs_); |
| 220 |
Intrepid::FieldContainer<Real> v_local(this->numLocalDofs_); |
| 221 |
|
| 222 |
Real SIMPDScale(0), sum(0), zero(0); |
| 223 |
for(int i=0; i<this->numCells_; i++) { |
| 224 |
SIMPDScale = this->SIMPmaterial_[i]->getSIMPFirstDerivativeScaleFactor(); |
| 225 |
u_local.initialize(zero); |
| 226 |
v_local.initialize(zero); |
| 227 |
|
| 228 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 229 |
u_local(j) = uData[u_overlap->getMap()->getLocalElement(this->cellDofs_(this->myCellIds_[i], j))]; |
| 230 |
v_local(j) = vData[v_overlap->getMap()->getLocalElement(this->cellDofs_(this->myCellIds_[i], j))]; |
| 231 |
} |
| 232 |
|
| 233 |
sum = zero; |
| 234 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 235 |
if(this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],j))) { |
| 236 |
sum += u_local(j) * v_local(j); |
| 237 |
} |
| 238 |
else { |
| 239 |
for(int k=0; k<this->numLocalDofs_; k++) { |
| 240 |
if( !this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],k)) ) { |
| 241 |
sum += SIMPDScale * (*this->gradgradMats0_)(i, j, k) * v_local(j) * u_local(k); |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
//put value into myDensityDerivative_ |
| 247 |
Jv -> replaceGlobalValue(this->myCellIds_[i], 0, sum); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
void ApplyAdjointHessian22ToVec(ROL::Ptr<Tpetra::MultiVector<> > &Hvw, |
| 252 |
const ROL::Ptr<const Tpetra::MultiVector<> > &u, |
| 253 |
const ROL::Ptr<const Tpetra::MultiVector<> > &v, |
| 254 |
const ROL::Ptr<const Tpetra::MultiVector<> > &w) { |
| 255 |
// Hvw is myCellMap_ |
| 256 |
// u should be myUniqueMap_ |
| 257 |
// v should be myCellMap_ |
| 258 |
// w shluld be myUniqueMapi_ |
| 259 |
// |
| 260 |
#ifdef ROL_TIMERS |
| 261 |
Teuchos::TimeMonitor LocalTimer(*ConstraintDerivativeTime_example_PDEOPT_TOOLS_PDEFEM_GLOB); |
| 262 |
#endif |
| 263 |
ROL::Ptr<Tpetra::MultiVector<> > u_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 264 |
Tpetra::Import<> importer1(u->getMap(), u_overlap->getMap()); |
| 265 |
u_overlap->doImport(*u, importer1, Tpetra::REPLACE); |
| 266 |
//only apply BC to U |
| 267 |
this->ApplyBCToVec (u_overlap); |
| 268 |
Teuchos::ArrayRCP<const Real> uData = u_overlap->get1dView(); |
| 269 |
|
| 270 |
Tpetra::Export<> exporter(v->getMap(), this->myCellMap_); |
| 271 |
ROL::Ptr<Tpetra::MultiVector<> > v_local = ROL::makePtr<Tpetra::MultiVector<>>(this->myCellMap_, 1, true); |
| 272 |
v_local->doExport(*v, exporter, Tpetra::REPLACE); |
| 273 |
Teuchos::ArrayRCP<const Real> vData = v_local->get1dView(); |
| 274 |
|
| 275 |
ROL::Ptr<Tpetra::MultiVector<> > w_overlap = ROL::makePtr<Tpetra::MultiVector<>>(this->myOverlapMap_, 1, true); |
| 276 |
Tpetra::Import<> importer2(w->getMap(), w_overlap->getMap()); |
| 277 |
w_overlap->doImport(*w, importer2, Tpetra::REPLACE); |
| 278 |
//ApplyBCToVec (w_overlap); |
| 279 |
Teuchos::ArrayRCP<const Real> wData = w_overlap->get1dView(); |
| 280 |
|
| 281 |
Intrepid::FieldContainer<Real> u_local(this->numLocalDofs_); |
| 282 |
Intrepid::FieldContainer<Real> w_local(this->numLocalDofs_); |
| 283 |
|
| 284 |
Real SIMPDDScale(0), localV(0), sum(0), zero(0); |
| 285 |
|
| 286 |
for(int i=0; i<this->numCells_; i++) { |
| 287 |
SIMPDDScale = this->SIMPmaterial_[i]->getSIMPSecondDerivativeScaleFactor(); |
| 288 |
localV = vData[v_local->getMap()->getLocalElement(this->myCellIds_[i])]; |
| 289 |
|
| 290 |
u_local.initialize(zero); |
| 291 |
w_local.initialize(zero); |
| 292 |
|
| 293 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 294 |
u_local(j) = uData[u_overlap->getMap()->getLocalElement(this->cellDofs_(this->myCellIds_[i], j))]; |
| 295 |
w_local(j) = wData[w_overlap->getMap()->getLocalElement(this->cellDofs_(this->myCellIds_[i], j))]; |
| 296 |
} |
| 297 |
|
| 298 |
sum = zero; |
| 299 |
for(int j=0; j<this->numLocalDofs_; j++) { |
| 300 |
if(this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],j))) { |
| 301 |
sum += u_local(j) * w_local(j); |
| 302 |
} |
| 303 |
else { |
| 304 |
for(int k=0; k<this->numLocalDofs_; k++) { |
| 305 |
if( !this->check_myGlobalDof_on_boundary(this->cellDofs_(this->myCellIds_[i],k)) ) { |
| 306 |
sum += localV * SIMPDDScale * (*this->gradgradMats0_)(i, j, k) * w_local(j) * u_local(k); |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
//put value into myDensityDerivative_ |
| 312 |
Hvw -> replaceGlobalValue(this->myCellIds_[i], 0, sum); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
}; // class ElasticitySIMPOperators |
| 317 |
|
| 318 |
#endif |