// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /*! \file pde.hpp \brief Implements the local PDE interface for the obstacle problem. */ #ifndef PDE_POISSON_HPP #define PDE_POISSON_HPP #include "../TOOLS/pde.hpp" #include "../TOOLS/fe.hpp" #include "Intrepid_HGRAD_QUAD_C1_FEM.hpp" #include "Intrepid_HGRAD_QUAD_C2_FEM.hpp" #include "Intrepid_DefaultCubatureFactory.hpp" #include "Intrepid_FunctionSpaceTools.hpp" #include "Intrepid_CellTools.hpp" #include "ROL_Ptr.hpp" template class PDE_Obstacle : public PDE { private: // Finite element basis information ROL::Ptr > > basisPtr_; std::vector > > > basisPtrs_; // Cell cubature information ROL::Ptr > cellCub_; // Cell node information ROL::Ptr > volCellNodes_; // Finite element definition ROL::Ptr > fe_vol_; // Load term ROL::Ptr > load_; Real coeff_; // Use Riesz map for state variables? bool useStateRiesz_; Real evaluateLoad(const std::vector &coord) const { return static_cast(2)*coeff_; } public: PDE_Obstacle(Teuchos::ParameterList &parlist) { // Finite element fields. int basisOrder = parlist.sublist("Problem").get("Basis Order",1); if (basisOrder == 1) { basisPtr_ = ROL::makePtr >>(); } else if (basisOrder == 2) { basisPtr_ = ROL::makePtr >>(); } basisPtrs_.clear(); basisPtrs_.push_back(basisPtr_); // Quadrature rules. shards::CellTopology cellType = basisPtr_->getBaseCellTopology(); // get the cell type from any basis Intrepid::DefaultCubatureFactory cubFactory; // create cubature factory int cubDegree = parlist.sublist("Problem").get("Cubature Degree", 2); // set cubature degree, e.g., 2 cellCub_ = cubFactory.create(cellType, cubDegree); // create default cubature coeff_ = parlist.sublist("Problem").get("Load Magnitude", 1.0); // Pointwise load magnitude useStateRiesz_ = parlist.sublist("Problem").get("Use State Riesz Map", true); // use Riesz map for state variables? } void residual(ROL::Ptr > & res, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { // GET DIMENSIONS int c = fe_vol_->gradN()->dimension(0); int f = fe_vol_->gradN()->dimension(1); int p = fe_vol_->gradN()->dimension(2); int d = fe_vol_->gradN()->dimension(3); // INITIALIZE RESIDUAL res = ROL::makePtr>(c, f); // COMPUTE STIFFNESS TERM ROL::Ptr > gradU_eval = ROL::makePtr>(c, p, d); fe_vol_->evaluateGradient(gradU_eval, u_coeff); Intrepid::FunctionSpaceTools::integrate(*res, *gradU_eval, *(fe_vol_->gradNdetJ()), Intrepid::COMP_CPP, false); // // ADD MASS TERM // ROL::Ptr > valU_eval // = ROL::makePtr>(c, p); // fe_vol_->evaluateValue(valU_eval, u_coeff); // Intrepid::FunctionSpaceTools::integrate(*res, // *valU_eval, // *(fe_vol_->NdetJ()), // Intrepid::COMP_CPP, // true); // ADD LOAD TERM Intrepid::FunctionSpaceTools::integrate(*res, *load_, *(fe_vol_->NdetJ()), Intrepid::COMP_CPP, true); } void Jacobian_1(ROL::Ptr > & jac, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { // GET DIMENSIONS int c = fe_vol_->gradN()->dimension(0); int f = fe_vol_->gradN()->dimension(1); // INITIALIZE JACOBIAN jac = ROL::makePtr>(c, f, f); // COMPUTE STIFFNESS TERM *jac = *fe_vol_->stiffMat(); // // ADD MASS TERM // Intrepid::RealSpaceTools::add(*jac, *fe_vol_->massMat()); } void Hessian_11(ROL::Ptr > & hess, const ROL::Ptr > & l_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> (PDE_Obstacle::Hessian_11): Hessian is zero."); } void RieszMap_1(ROL::Ptr > & riesz) { // Optionally disable Riesz map ... if (!useStateRiesz_) { throw Exception::NotImplemented(">>> (PDE_Obstacle::RieszMap_1): Not implemented."); } // ...otherwise ... int c = fe_vol_->N()->dimension(0); int f = fe_vol_->N()->dimension(1); // INITIALIZE RIESZ MAP riesz = ROL::makePtr>(c, f, f); *riesz = *fe_vol_->stiffMat(); Intrepid::RealSpaceTools::add(*riesz,*(fe_vol_->massMat())); } std::vector > > > getFields() { return basisPtrs_; } void setCellNodes(const ROL::Ptr > &volCellNodes, const std::vector > > > &bdryCellNodes, const std::vector > > &bdryCellLocIds) { volCellNodes_ = volCellNodes; // Finite element definition. fe_vol_ = ROL::makePtr>(volCellNodes_,basisPtr_,cellCub_); // Compute load function computeLoad(); } void computeLoad(void) { int c = fe_vol_->gradN()->dimension(0); int p = fe_vol_->gradN()->dimension(2); int d = fe_vol_->gradN()->dimension(3); std::vector coord(d); load_ = ROL::makePtr>(c,p); for (int i = 0; i < c; ++i) { for (int j = 0; j < p; ++j) { for (int k = 0; k < d; ++k) { coord[k] = (*fe_vol_->cubPts())(i,j,k); } (*load_)(i,j) = -evaluateLoad(coord); } } } const ROL::Ptr > getFE(void) const { return fe_vol_; } const ROL::Ptr > getCellNodes(void) const { return volCellNodes_; } }; // PDE_Obstacle #endif