// @HEADER // ***************************************************************************** // Rapid Optimization Library (ROL) Package // // Copyright 2014 NTESS and the ROL contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /*! \file obj.hpp \brief Provides the interface for local (cell-based) objective function computations. */ #ifndef PDEOPT_QOI_L2TRACKING_POISSON_BOLTZMANN_HPP #define PDEOPT_QOI_L2TRACKING_POISSON_BOLTZMANN_HPP #include "../TOOLS/qoi.hpp" #include "pde_poisson_boltzmann.hpp" template class QoI_L2Tracking_Poisson_Boltzmann : public QoI { private: ROL::Ptr > fe_; ROL::Ptr > target_; Real targetFunc(const std::vector & x) const { int size = x.size(); Real val(0); for (int i = 0; i < size; ++i) { val += x[i]*x[i]; } return val; } public: QoI_L2Tracking_Poisson_Boltzmann(const ROL::Ptr > &fe) : fe_(fe) { int c = fe_->cubPts()->dimension(0); int p = fe_->cubPts()->dimension(1); int d = fe_->cubPts()->dimension(2); std::vector pt(d); target_ = 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) { pt[k] = (*fe_->cubPts())(i,j,k); } (*target_)(i,j) = targetFunc(pt); } } } Real value(ROL::Ptr > & val, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { // Get relevant dimensions int c = u_coeff->dimension(0); int p = fe_->cubPts()->dimension(1); // Initialize output val val = ROL::makePtr>(c); // Evaluate state on FE basis ROL::Ptr > valU_eval = ROL::makePtr>(c, p); fe_->evaluateValue(valU_eval, u_coeff); // Compute difference between state and target Intrepid::RealSpaceTools::subtract(*valU_eval,*target_); // Compute squared L2-norm of diff fe_->computeIntegral(val,valU_eval,valU_eval); // Scale by one half Intrepid::RealSpaceTools::scale(*val,static_cast(0.5)); return static_cast(0); } void gradient_1(ROL::Ptr > & grad, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { // Get relevant dimensions int c = u_coeff->dimension(0); int p = fe_->cubPts()->dimension(1); int f = fe_->N()->dimension(1); // Initialize output grad grad = ROL::makePtr>(c, f); // Evaluate state on FE basis ROL::Ptr > valU_eval = ROL::makePtr>(c, p); fe_->evaluateValue(valU_eval, u_coeff); // Compute difference between state and target Intrepid::RealSpaceTools::subtract(*valU_eval,*target_); // Compute gradient of squared L2-norm of diff Intrepid::FunctionSpaceTools::integrate(*grad, *valU_eval, *(fe_->NdetJ()), Intrepid::COMP_CPP, false); } void gradient_2(ROL::Ptr > & grad, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::gradient_2 is zero."); } void HessVec_11(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { int c = v_coeff->dimension(0); int p = fe_->cubPts()->dimension(1); int f = fe_->N()->dimension(1); ROL::Ptr > valV_eval = ROL::makePtr>(c, p); hess = ROL::makePtr>(c, f); fe_->evaluateValue(valV_eval, v_coeff); Intrepid::FunctionSpaceTools::integrate(*hess, *valV_eval, *(fe_->NdetJ()), Intrepid::COMP_CPP, false); } void HessVec_12(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::HessVec_12 is zero."); } void HessVec_21(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::HessVec_21 is zero."); } void HessVec_22(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Tracking_Poisson_Boltzmann::HessVec_22 is zero."); } }; // QoI_L2Tracking template class QoI_L2Penalty_Poisson_Boltzmann : public QoI { private: ROL::Ptr > fe_; public: QoI_L2Penalty_Poisson_Boltzmann(const ROL::Ptr > &fe) : fe_(fe) {} Real value(ROL::Ptr > & val, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { // Get relevant dimensions int c = z_coeff->dimension(0); int p = fe_->cubPts()->dimension(1); // Initialize output val val = ROL::makePtr>(c); // Build local state tracking term ROL::Ptr > valZ_eval = ROL::makePtr>(c, p); fe_->evaluateValue(valZ_eval, z_coeff); fe_->computeIntegral(val,valZ_eval,valZ_eval); Intrepid::RealSpaceTools::scale(*val,static_cast(0.5)); return static_cast(0); } void gradient_1(ROL::Ptr > & grad, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::gradient_1 is zero."); } void gradient_2(ROL::Ptr > & grad, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { // Get relevant dimensions int c = z_coeff->dimension(0); int p = fe_->cubPts()->dimension(1); int f = fe_->N()->dimension(1); // Initialize output grad grad = ROL::makePtr>(c, f); // Build local gradient of state tracking term ROL::Ptr > valZ_eval = ROL::makePtr>(c, p); fe_->evaluateValue(valZ_eval, z_coeff); Intrepid::FunctionSpaceTools::integrate(*grad, *valZ_eval, *(fe_->NdetJ()), Intrepid::COMP_CPP, false); } void HessVec_11(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::HessVec_11 is zero."); } void HessVec_12(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::HessVec_12 is zero."); } void HessVec_21(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { throw Exception::Zero(">>> QoI_L2Penalty_Poisson_Boltzmann::HessVec_21 is zero."); } void HessVec_22(ROL::Ptr > & hess, const ROL::Ptr > & v_coeff, const ROL::Ptr > & u_coeff, const ROL::Ptr > & z_coeff = ROL::nullPtr, const ROL::Ptr > & z_param = ROL::nullPtr) { int c = v_coeff->dimension(0); int p = fe_->cubPts()->dimension(1); int f = fe_->N()->dimension(1); ROL::Ptr > valV_eval = ROL::makePtr>(c, p); hess = ROL::makePtr>(c, f); fe_->evaluateValue(valV_eval, v_coeff); Intrepid::FunctionSpaceTools::integrate(*hess, *valV_eval, *(fe_->NdetJ()), Intrepid::COMP_CPP, false); } }; // QoI_L2Penalty template class StdObjective_Poisson_Boltzmann : public ROL::StdObjective { private: Real alpha_; public: StdObjective_Poisson_Boltzmann(Teuchos::ParameterList &parlist) { alpha_ = parlist.sublist("Poisson Boltzmann Objective Function").get("Control Penalty",1.e-4); } Real value(const std::vector &x, Real &tol) { return x[0] + alpha_*x[1]; } void gradient(std::vector &g, const std::vector &x, Real &tol) { const Real one(1); g[0] = one; g[1] = alpha_; } void hessVec(std::vector &hv, const std::vector &v, const std::vector &x, Real &tol) { const Real zero(0); hv[0] = zero; hv[1] = zero; } }; // OBJ_SCALAR #endif