// @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_TOPOOPT_MULTIMAT_HPP #define PDEOPT_QOI_TOPOOPT_MULTIMAT_HPP #include "../../../TOOLS/qoi.hpp" #include "pde_elasticity.hpp" template class QoI_Compliance_TopoOpt : public QoI { private: // Volumetric Information const ROL::Ptr> fe_; const ROL::Ptr> load_; // Boundary Information const std::vector>>> feBdry_; const std::vector>> bdryCellLocIds_; const ROL::Ptr> traction_; // Field Information const ROL::Ptr fieldInfo_; // QoI Scaling const Real scale_; ROL::Ptr> getBoundaryCoeff( const Intrepid::FieldContainer & cell_coeff, const int sideset, const int locSideId) const { std::vector bdryCellLocId = bdryCellLocIds_[sideset][locSideId]; const int numCellsSide = bdryCellLocId.size(); const int f = fe_->N()->dimension(1); ROL::Ptr> bdry_coeff = ROL::makePtr>(numCellsSide, f); for (int i = 0; i < numCellsSide; ++i) { for (int j = 0; j < f; ++j) { (*bdry_coeff)(i, j) = cell_coeff(bdryCellLocId[i], j); } } return bdry_coeff; } public: QoI_Compliance_TopoOpt(const ROL::Ptr> &fe, const ROL::Ptr> &load, const ROL::Ptr &fieldInfo, const Real scale = 1.0) : fe_(fe), load_(load), traction_(ROL::makePtr>()), fieldInfo_(fieldInfo), scale_(scale) {} QoI_Compliance_TopoOpt(const std::vector>>> &feBdry, const std::vector>> &bdryCellLocIds, const ROL::Ptr> &traction, const ROL::Ptr &fieldInfo, const Real scale = 1.0) : feBdry_(feBdry), load_(ROL::makePtr>()), bdryCellLocIds_(bdryCellLocIds), traction_(traction), fieldInfo_(fieldInfo), scale_(scale) {} QoI_Compliance_TopoOpt(const ROL::Ptr> &fe, const ROL::Ptr> &load, const std::vector>>> &feBdry, const std::vector>> &bdryCellLocIds, const ROL::Ptr> &traction, const ROL::Ptr &fieldInfo, const Real scale = 1.0) : fe_(fe), load_(load), feBdry_(feBdry), bdryCellLocIds_(bdryCellLocIds), traction_(traction), fieldInfo_(fieldInfo), scale_(scale) {} 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 = fe_->gradN()->dimension(0); int p = fe_->gradN()->dimension(2); int d = fe_->gradN()->dimension(3); // Initialize output val val = ROL::makePtr>(c); // Get components of the displacement std::vector>> U; FieldUtils::splitFieldCoeff(U, u_coeff, fieldInfo_); // Evaluate on FE basis std::vector>> valU_eval(d); for (int i=0; i>(c, p); fe_->evaluateValue(valU_eval[i], U[i]); } // Compute load integral if (!load_->isNull()) { std::vector > > load_eval(d); for (int i=0; i>(c, p); } load_->compute(load_eval, fe_, QoI::getParameter()); for (int i=0; icomputeIntegral(val,load_eval[i],valU_eval[i],true); } } // Compute traction integral if (!traction_->isNull()) { std::vector > > > > traction; traction_->compute(traction, feBdry_, QoI::getParameter()); const int numSideSets = bdryCellLocIds_.size(); if (numSideSets > 0) { for (int i = 0; i < numSideSets; ++i) { if (traction[i].size() > 0) { const int numLocalSideIds = bdryCellLocIds_[i].size(); for (int j = 0; j < numLocalSideIds; ++j) { const int numCellsSide = bdryCellLocIds_[i][j].size(); if (numCellsSide > 0 && traction[i][j].size() > 0) { const int numCubPerSide = feBdry_[i][j]->cubPts()->dimension(1); for (int k = 0; k < d; ++k) { // Evaluate i-component of state on FE basis ROL::Ptr > u_coeff_bdry = getBoundaryCoeff(*U[k], i, j); ROL::Ptr > valU_eval = ROL::makePtr>(numCellsSide, numCubPerSide); feBdry_[i][j]->evaluateValue(valU_eval, u_coeff_bdry); // Integrate cell traction compliance ROL::Ptr > intVal = ROL::makePtr>(numCellsSide); feBdry_[i][j]->computeIntegral(intVal,valU_eval,traction[i][j][k],false); // Add to integral value for (int l = 0; l < numCellsSide; ++l) { int cidx = bdryCellLocIds_[i][j][l]; (*val)(cidx) += (*intVal)(l); } } } } } } } } Intrepid::RealSpaceTools::scale(*val, scale_); 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 = fe_->gradN()->dimension(0); int f = fe_->gradN()->dimension(1); int p = fe_->gradN()->dimension(2); int d = fe_->gradN()->dimension(3); // Initialize output grad std::vector>> G(d); for (int i=0; i>(c, f); } // Compute load integral if (!load_->isNull()) { std::vector>> load_eval(d); for (int i=0; i>(c, p); } load_->compute(load_eval, fe_, QoI::getParameter()); for (int i=0; i(*G[i], *load_eval[i], *(fe_->NdetJ()), Intrepid::COMP_CPP, false); } } // Compute traction integral if (!traction_->isNull()) { traction_->apply(G, feBdry_, QoI::getParameter()); } // Multiply gradient by compliance scale for (int i=0; i::scale(*G[i], scale_); } FieldUtils::combineFieldCoeff(grad, G, fieldInfo_); } 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_Compliance_TopoOpt::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) { throw Exception::Zero(">>> QoI_Compliance_TopoOpt::HessVec_12 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_Compliance_TopoOpt::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_Compliance_TopoOpt::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_Compliance_TopoOpt::HessVec_22 is zero."); } }; // QoI_Compliance_TopoOpt #endif