// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef ROL_FRACTIONALCONSTRAINT_H #define ROL_FRACTIONALCONSTRAINT_H #include "ROL_Constraint_SimOpt.hpp" #include "ROL_KrylovFactory.hpp" #include "fractional_operator.hpp" #include "fractional_vector.hpp" template class FractionalConstraint : public ROL::Constraint_SimOpt { private: const ROL::Ptr > pde_local_; const ROL::Ptr > pde_cylinder_; ROL::Ptr > assembler_local_; ROL::Ptr > assembler_cylinder_; ROL::Ptr > Klocal_, Blocal_, Mlocal_; ROL::Ptr > Kcylinder_, Mcylinder_; ROL::Ptr > Flocal_; ROL::Ptr > krylov_; ROL::Ptr > A_; ROL::Ptr > B_; ROL::Ptr > M_; ROL::Ptr > Vec_; ROL::Ptr > ulocal_; ROL::Ptr > zlocal_; ROL::Ptr > ucylinder_; ROL::Ptr > zcylinder_; Teuchos::ParameterList parlist_; Real fracPower_; bool isAssembled_; void assemble(const ROL::Vector &z) { if ( !isAssembled_ ) { // Assemble local components assembler_local_->assemblePDEJacobian1(Klocal_,pde_local_,ulocal_,zlocal_); assembler_local_->assemblePDEJacobian2(Blocal_,pde_local_,ulocal_,zlocal_); assembler_local_->assemblePDERieszMap1(Mlocal_,pde_local_); // Assemble cylinder components assembler_cylinder_->assemblePDEJacobian1(Kcylinder_,pde_cylinder_,ucylinder_,zcylinder_); assembler_cylinder_->assemblePDERieszMap1(Mcylinder_,pde_cylinder_); // Create fractional operator and vector A_ = ROL::makePtr>(Klocal_,Mlocal_,Kcylinder_,Mcylinder_); B_ = ROL::makePtr>(Blocal_,Mcylinder_->getGlobalNumCols()); M_ = ROL::makePtr>(Klocal_,Mlocal_,Kcylinder_,Mcylinder_,parlist_); isAssembled_ = true; } ROL::Ptr > zf = dynamic_cast&>(z).getVector(); assembler_local_->assemblePDEResidual(Flocal_,pde_local_,ulocal_,zf); Vec_ = ROL::makePtr>(Flocal_,Klocal_->getRowMap(),Mcylinder_->getGlobalNumCols(),fracPower_); } public: FractionalConstraint(const ROL::Ptr > & pde_local, const ROL::Ptr > & mesh_local, const ROL::Ptr > & comm_local, const ROL::Ptr > & pde_cylinder, const ROL::Ptr > & mesh_cylinder, const ROL::Ptr > & comm_cylinder, Teuchos::ParameterList & parlist, std::ostream & outStream = std::cout) : pde_local_(pde_local), pde_cylinder_(pde_cylinder), parlist_(parlist), isAssembled_(false) { assembler_local_ = ROL::makePtr>(pde_local_->getFields(), mesh_local, comm_local, parlist, outStream); assembler_local_->setCellNodes(*pde_local_); ulocal_ = assembler_local_->createStateVector(); zlocal_ = assembler_local_->createControlVector(); assembler_cylinder_ = ROL::makePtr>(pde_cylinder_->getFields(), mesh_cylinder, comm_cylinder, parlist, outStream); assembler_cylinder_->setCellNodes(*pde_cylinder_); ucylinder_ = assembler_cylinder_->createStateVector(); zcylinder_ = assembler_cylinder_->createControlVector(); krylov_ = ROL::KrylovFactory(parlist); fracPower_ = parlist.sublist("Problem").get("Fractional Power",0.5); } void setParameter(const std::vector ¶m) { ROL::Constraint_SimOpt::setParameter(param); pde_local_->setParameter(param); pde_cylinder_->setParameter(param); isAssembled_ = false; } void value(ROL::Vector &c, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); A_->apply(c,u,tol); c.axpy(static_cast(-1),*(Vec_->get())); } void applyJacobian_1(ROL::Vector &jv, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); A_->apply(jv,v,tol); } void applyJacobian_2(ROL::Vector &jv, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); B_->setTranspose(false); B_->apply(jv,v,tol); } void applyInverseJacobian_1(ROL::Vector &ijv, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); int iter(0), flag(0); krylov_->run(ijv,*A_,v,*M_,iter,flag); } void applyAdjointJacobian_1(ROL::Vector &ajv, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); A_->apply(ajv,v,tol); } void applyInverseAdjointJacobian_1(ROL::Vector &iajv, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); int iter(0), flag(0); krylov_->run(iajv,*A_,v,*M_,iter,flag); } void applyAdjointJacobian_2(ROL::Vector &ajv, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { assemble(z); B_->setTranspose(true); B_->apply(ajv,v,tol); } void applyAdjointHessian_11(ROL::Vector &ahwv, const ROL::Vector &w, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { ahwv.zero(); } void applyAdjointHessian_12(ROL::Vector &ahwv, const ROL::Vector &w, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { ahwv.zero(); } void applyAdjointHessian_21(ROL::Vector &ahwv, const ROL::Vector &w, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { ahwv.zero(); } void applyAdjointHessian_22(ROL::Vector &ahwv, const ROL::Vector &w, const ROL::Vector &v, const ROL::Vector &u, const ROL::Vector &z, Real &tol) { ahwv.zero(); } ROL::Ptr > getLocalAssembler(void) const { return assembler_local_; } ROL::Ptr > getCylinderAssembler(void) const { return assembler_cylinder_; } }; #endif