| 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_FRACTIONALCONSTRAINT_H |
| 11 |
#define ROL_FRACTIONALCONSTRAINT_H |
| 12 |
|
| 13 |
#include "ROL_Constraint_SimOpt.hpp" |
| 14 |
#include "ROL_KrylovFactory.hpp" |
| 15 |
#include "fractional_operator.hpp" |
| 16 |
#include "fractional_vector.hpp" |
| 17 |
|
| 18 |
template <class Real> |
| 19 |
class FractionalConstraint : public ROL::Constraint_SimOpt<Real> { |
| 20 |
private: |
| 21 |
const ROL::Ptr<PDE<Real> > pde_local_; |
| 22 |
const ROL::Ptr<PDE<Real> > pde_cylinder_; |
| 23 |
|
| 24 |
ROL::Ptr<Assembler<Real> > assembler_local_; |
| 25 |
ROL::Ptr<Assembler<Real> > assembler_cylinder_; |
| 26 |
|
| 27 |
ROL::Ptr<Tpetra::CrsMatrix<> > Klocal_, Blocal_, Mlocal_; |
| 28 |
ROL::Ptr<Tpetra::CrsMatrix<> > Kcylinder_, Mcylinder_; |
| 29 |
ROL::Ptr<Tpetra::MultiVector<> > Flocal_; |
| 30 |
|
| 31 |
ROL::Ptr<ROL::Krylov<Real> > krylov_; |
| 32 |
|
| 33 |
ROL::Ptr<FractionalOperator<Real> > A_; |
| 34 |
ROL::Ptr<FractionalControlOperator<Real> > B_; |
| 35 |
ROL::Ptr<FractionalPreconditioner<Real> > M_; |
| 36 |
ROL::Ptr<FractionalVector<Real> > Vec_; |
| 37 |
|
| 38 |
ROL::Ptr<Tpetra::MultiVector<> > ulocal_; |
| 39 |
ROL::Ptr<Tpetra::MultiVector<> > zlocal_; |
| 40 |
ROL::Ptr<Tpetra::MultiVector<> > ucylinder_; |
| 41 |
ROL::Ptr<Tpetra::MultiVector<> > zcylinder_; |
| 42 |
|
| 43 |
Teuchos::ParameterList parlist_; |
| 44 |
|
| 45 |
Real fracPower_; |
| 46 |
|
| 47 |
bool isAssembled_; |
| 48 |
|
| 49 |
void assemble(const ROL::Vector<Real> &z) { |
| 50 |
if ( !isAssembled_ ) { |
| 51 |
// Assemble local components |
| 52 |
assembler_local_->assemblePDEJacobian1(Klocal_,pde_local_,ulocal_,zlocal_); |
| 53 |
assembler_local_->assemblePDEJacobian2(Blocal_,pde_local_,ulocal_,zlocal_); |
| 54 |
assembler_local_->assemblePDERieszMap1(Mlocal_,pde_local_); |
| 55 |
// Assemble cylinder components |
| 56 |
assembler_cylinder_->assemblePDEJacobian1(Kcylinder_,pde_cylinder_,ucylinder_,zcylinder_); |
| 57 |
assembler_cylinder_->assemblePDERieszMap1(Mcylinder_,pde_cylinder_); |
| 58 |
// Create fractional operator and vector |
| 59 |
A_ = ROL::makePtr<FractionalOperator<Real>>(Klocal_,Mlocal_,Kcylinder_,Mcylinder_); |
| 60 |
B_ = ROL::makePtr<FractionalControlOperator<Real>>(Blocal_,Mcylinder_->getGlobalNumCols()); |
| 61 |
M_ = ROL::makePtr<FractionalPreconditioner<Real>>(Klocal_,Mlocal_,Kcylinder_,Mcylinder_,parlist_); |
| 62 |
|
| 63 |
isAssembled_ = true; |
| 64 |
} |
| 65 |
ROL::Ptr<const Tpetra::MultiVector<> > zf |
| 66 |
= dynamic_cast<const ROL::TpetraMultiVector<Real>&>(z).getVector(); |
| 67 |
assembler_local_->assemblePDEResidual(Flocal_,pde_local_,ulocal_,zf); |
| 68 |
Vec_ = ROL::makePtr<FractionalVector<Real>>(Flocal_,Klocal_->getRowMap(),Mcylinder_->getGlobalNumCols(),fracPower_); |
| 69 |
} |
| 70 |
|
| 71 |
public: |
| 72 |
FractionalConstraint(const ROL::Ptr<PDE<Real> > & pde_local, |
| 73 |
const ROL::Ptr<MeshManager<Real> > & mesh_local, |
| 74 |
const ROL::Ptr<const Teuchos::Comm<int> > & comm_local, |
| 75 |
const ROL::Ptr<PDE<Real> > & pde_cylinder, |
| 76 |
const ROL::Ptr<MeshManager<Real> > & mesh_cylinder, |
| 77 |
const ROL::Ptr<const Teuchos::Comm<int> > & comm_cylinder, |
| 78 |
Teuchos::ParameterList & parlist, |
| 79 |
std::ostream & outStream = std::cout) |
| 80 |
: pde_local_(pde_local), pde_cylinder_(pde_cylinder), parlist_(parlist), isAssembled_(false) { |
| 81 |
assembler_local_ = ROL::makePtr<Assembler<Real>>(pde_local_->getFields(), |
| 82 |
mesh_local, |
| 83 |
comm_local, |
| 84 |
parlist, |
| 85 |
outStream); |
| 86 |
assembler_local_->setCellNodes(*pde_local_); |
| 87 |
ulocal_ = assembler_local_->createStateVector(); |
| 88 |
zlocal_ = assembler_local_->createControlVector(); |
| 89 |
assembler_cylinder_ = ROL::makePtr<Assembler<Real>>(pde_cylinder_->getFields(), |
| 90 |
mesh_cylinder, |
| 91 |
comm_cylinder, |
| 92 |
parlist, |
| 93 |
outStream); |
| 94 |
assembler_cylinder_->setCellNodes(*pde_cylinder_); |
| 95 |
ucylinder_ = assembler_cylinder_->createStateVector(); |
| 96 |
zcylinder_ = assembler_cylinder_->createControlVector(); |
| 97 |
krylov_ = ROL::KrylovFactory<Real>(parlist); |
| 98 |
|
| 99 |
fracPower_ = parlist.sublist("Problem").get("Fractional Power",0.5); |
| 100 |
} |
| 101 |
|
| 102 |
void setParameter(const std::vector<Real> ¶m) { |
| 103 |
ROL::Constraint_SimOpt<Real>::setParameter(param); |
| 104 |
pde_local_->setParameter(param); |
| 105 |
pde_cylinder_->setParameter(param); |
| 106 |
isAssembled_ = false; |
| 107 |
} |
| 108 |
|
| 109 |
void value(ROL::Vector<Real> &c, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 110 |
assemble(z); |
| 111 |
A_->apply(c,u,tol); |
| 112 |
c.axpy(static_cast<Real>(-1),*(Vec_->get())); |
| 113 |
} |
| 114 |
|
| 115 |
void applyJacobian_1(ROL::Vector<Real> &jv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 116 |
assemble(z); |
| 117 |
A_->apply(jv,v,tol); |
| 118 |
} |
| 119 |
|
| 120 |
void applyJacobian_2(ROL::Vector<Real> &jv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 121 |
assemble(z); |
| 122 |
B_->setTranspose(false); |
| 123 |
B_->apply(jv,v,tol); |
| 124 |
} |
| 125 |
|
| 126 |
void applyInverseJacobian_1(ROL::Vector<Real> &ijv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 127 |
assemble(z); |
| 128 |
int iter(0), flag(0); |
| 129 |
krylov_->run(ijv,*A_,v,*M_,iter,flag); |
| 130 |
} |
| 131 |
|
| 132 |
void applyAdjointJacobian_1(ROL::Vector<Real> &ajv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 133 |
assemble(z); |
| 134 |
A_->apply(ajv,v,tol); |
| 135 |
} |
| 136 |
|
| 137 |
void applyInverseAdjointJacobian_1(ROL::Vector<Real> &iajv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 138 |
assemble(z); |
| 139 |
int iter(0), flag(0); |
| 140 |
krylov_->run(iajv,*A_,v,*M_,iter,flag); |
| 141 |
} |
| 142 |
|
| 143 |
void applyAdjointJacobian_2(ROL::Vector<Real> &ajv, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 144 |
assemble(z); |
| 145 |
B_->setTranspose(true); |
| 146 |
B_->apply(ajv,v,tol); |
| 147 |
} |
| 148 |
|
| 149 |
void applyAdjointHessian_11(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 150 |
ahwv.zero(); |
| 151 |
} |
| 152 |
|
| 153 |
void applyAdjointHessian_12(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 154 |
ahwv.zero(); |
| 155 |
} |
| 156 |
|
| 157 |
void applyAdjointHessian_21(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 158 |
ahwv.zero(); |
| 159 |
} |
| 160 |
|
| 161 |
void applyAdjointHessian_22(ROL::Vector<Real> &ahwv, const ROL::Vector<Real> &w, const ROL::Vector<Real> &v, const ROL::Vector<Real> &u, const ROL::Vector<Real> &z, Real &tol) { |
| 162 |
ahwv.zero(); |
| 163 |
} |
| 164 |
|
| 165 |
ROL::Ptr<Assembler<Real> > getLocalAssembler(void) const { |
| 166 |
return assembler_local_; |
| 167 |
} |
| 168 |
|
| 169 |
ROL::Ptr<Assembler<Real> > getCylinderAssembler(void) const { |
| 170 |
return assembler_cylinder_; |
| 171 |
} |
| 172 |
}; |
| 173 |
|
| 174 |
#endif |