| 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_CONSTRAINT_VOLUME_SimOpt_H |
| 11 |
#define ROL_PDEOPT_ELASTICITYSIMP_CONSTRAINT_VOLUME_SimOpt_H |
| 12 |
|
| 13 |
#include "ROL_Constraint_SimOpt.hpp" |
| 14 |
#include "ROL_TpetraMultiVector.hpp" |
| 15 |
#include "ROL_StdVector.hpp" |
| 16 |
#include "Amesos2.hpp" |
| 17 |
|
| 18 |
template<class Real> |
| 19 |
class EqualityConstraint_PDEOPT_ElasticitySIMP_Volume_SimOpt : public ROL::Constraint_SimOpt<Real> { |
| 20 |
private: |
| 21 |
|
| 22 |
Real volFrac_; |
| 23 |
|
| 24 |
public: |
| 25 |
|
| 26 |
EqualityConstraint_PDEOPT_ElasticitySIMP_Volume_SimOpt(const ROL::Ptr<ElasticitySIMPOperators<Real> > &data, |
| 27 |
const Teuchos::RCP<Teuchos::ParameterList> &parlist) { |
| 28 |
|
| 29 |
volFrac_ = parlist->sublist("ElasticityTopoOpt").get("volfrac", 0.5); |
| 30 |
} |
| 31 |
|
| 32 |
using ROL::Constraint_SimOpt<Real>::value; |
| 33 |
void value(ROL::Vector<Real> &c, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) |
| 34 |
{ |
| 35 |
ROL::Ptr<std::vector<Real> > cp = (dynamic_cast<ROL::StdVector<Real>&>(c)).getVector(); |
| 36 |
ROL::Ptr<const Tpetra::MultiVector<> > zp = (dynamic_cast<const ROL::TpetraMultiVector<Real>&>(z)).getVector(); |
| 37 |
ROL::Ptr<Tpetra::MultiVector<> > unit = ROL::makePtr<Tpetra::MultiVector<>>(zp->getMap(), 1, true); |
| 38 |
unit->putScalar(1.0); |
| 39 |
Teuchos::Array<Real> sumZ(1, 0); |
| 40 |
zp->dot(*unit, sumZ); |
| 41 |
(*cp)[0] = sumZ[0] - 400*volFrac_; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
void applyJacobian_1(ROL::Vector<Real> &jv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, |
| 46 |
const ROL::Vector<Real> &z, Real &tol) |
| 47 |
{ |
| 48 |
jv.zero(); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
void applyJacobian_2(ROL::Vector<Real> &jv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, |
| 53 |
const ROL::Vector<Real> &z, Real &tol) |
| 54 |
{ |
| 55 |
ROL::Ptr<std::vector<Real> > jvp = (dynamic_cast<ROL::StdVector<Real>&>(jv)).getVector(); |
| 56 |
ROL::Ptr<const Tpetra::MultiVector<> > vp = (dynamic_cast<const ROL::TpetraMultiVector<Real>&>(v)).getVector(); |
| 57 |
ROL::Ptr<Tpetra::MultiVector<> > unit = ROL::makePtr<Tpetra::MultiVector<>>(vp->getMap(), 1, true); |
| 58 |
unit->putScalar(1.0); |
| 59 |
Teuchos::Array<Real> sumV(1, 0); |
| 60 |
vp->dot(*unit, sumV); |
| 61 |
(*jvp)[0] = sumV[0]; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
void applyAdjointJacobian_1(ROL::Vector<Real> &ajv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, |
| 66 |
const ROL::Vector<Real> &z, Real &tol) |
| 67 |
{ |
| 68 |
ajv.zero(); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
void applyAdjointJacobian_2(ROL::Vector<Real> &ajv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, |
| 73 |
const ROL::Vector<Real> &z, Real &tol) |
| 74 |
{ |
| 75 |
ROL::Ptr<Tpetra::MultiVector<> > ajvp = (dynamic_cast<ROL::TpetraMultiVector<Real>&>(ajv)).getVector(); |
| 76 |
ROL::Ptr<const std::vector<Real> > vp = (dynamic_cast<const ROL::StdVector<Real>&>(v)).getVector(); |
| 77 |
ajvp->putScalar(1.0); |
| 78 |
ajvp->scale((*vp)[0]); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
void applyAdjointHessian_11(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, |
| 83 |
const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) |
| 84 |
{ |
| 85 |
ahwv.zero(); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
void applyAdjointHessian_12(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, |
| 90 |
const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) |
| 91 |
{ |
| 92 |
ahwv.zero(); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
void applyAdjointHessian_21(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, |
| 97 |
const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) |
| 98 |
{ |
| 99 |
ahwv.zero(); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
void applyAdjointHessian_22(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, |
| 104 |
const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) |
| 105 |
{ |
| 106 |
ahwv.zero(); |
| 107 |
} |
| 108 |
|
| 109 |
}; |
| 110 |
|
| 111 |
#endif |