// @HEADER // ***************************************************************************** // Panzer: A partial differential equation assembly // engine for strongly coupled complex multiphysics systems // // Copyright 2011 NTESS and the Panzer contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_HPP #define PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_HPP #include #include #include "PanzerDiscFE_config.hpp" #include "Panzer_Dimension.hpp" #include "Panzer_CellData.hpp" #include "Panzer_Response_Functional.hpp" #include "Panzer_GlobalIndexer.hpp" #include "Panzer_GlobalIndexer_Utilities.hpp" #include "Phalanx_Evaluator_Macros.hpp" #include "Phalanx_MDField.hpp" #include "Panzer_Evaluator_WithBaseImpl.hpp" namespace panzer { class FunctionalScatterBase { public: virtual ~FunctionalScatterBase() {} virtual void scatterDerivative(const PHX::MDField & cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor& wda, const std::vector > & dgdx) const = 0; #ifdef Panzer_BUILD_HESSIAN_SUPPORT virtual void scatterHessian(const PHX::MDField & cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor& wda, const std::vector > & d2gdx2) const = 0; #endif }; template class FunctionalScatter : public FunctionalScatterBase { public: FunctionalScatter(const Teuchos::RCP & globalIndexer) { if(globalIndexer!=Teuchos::null) ugis_.push_back(globalIndexer); } FunctionalScatter(const std::vector > & ugis) : ugis_(ugis) {} void scatterDerivative(const PHX::MDField & cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor& wda, const std::vector > & dgdx) const; #ifdef Panzer_BUILD_HESSIAN_SUPPORT void scatterHessian(const PHX::MDField & cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor& wda, const std::vector > & d2gdx2) const; #endif private: std::vector > ugis_; }; /** This class handles responses with values aggregated * on each finite element cell. */ template class ResponseScatterEvaluator_Functional : public panzer::EvaluatorWithBaseImpl, public PHX::EvaluatorDerived { public: //! A constructor with concrete arguments instead of a parameter list. ResponseScatterEvaluator_Functional(const std::string & name,const CellData & cd, const Teuchos::RCP & functionalScatter); ResponseScatterEvaluator_Functional(const std::string & integrandName,const std::string & responseName,const CellData & cd, const Teuchos::RCP & functionalScatter); void evaluateFields(typename Traits::EvalData d); void preEvaluate(typename Traits::PreEvalData d); private: typedef typename EvalT::ScalarT ScalarT; std::string responseName_; Teuchos::RCP > responseObj_; Teuchos::RCP scatterHolder_; // dummy target PHX::MDField cellIntegral_; // holds cell integrals Teuchos::RCP scatterObj_; }; template void FunctionalScatter::scatterDerivative(const PHX::MDField & cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor& wda, const std::vector > & dgdx) const { // for convenience pull out some objects from workset std::string blockId = wda(workset).block_id; std::vector blockOffsets; computeBlockOffsets(blockId,ugis_,blockOffsets); TEUCHOS_ASSERT(dgdx.size()==ugis_.size()); auto cellIntegral_h = Kokkos::create_mirror_view(cellIntegral.get_view()); Kokkos::deep_copy(cellIntegral_h, cellIntegral.get_view()); const std::vector & localCellIds = wda(workset).cell_local_ids; for(std::size_t b=0;bgetLIDs(); auto LIDs_h = Kokkos::create_mirror_view(LIDs); Kokkos::deep_copy(LIDs_h, LIDs); Teuchos::ArrayRCP dgdx_b = dgdx[b]; // scatter operation for each cell in workset for(std::size_t worksetCellIndex=0;worksetCellIndex void FunctionalScatter::scatterHessian(const PHX::MDField & cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor& wda, const std::vector > & d2gdx2) const { PHX::View LIDs; // for convenience pull out some objects from workset std::string blockId = wda(workset).block_id; std::vector blockOffsets; computeBlockOffsets(blockId,ugis_,blockOffsets); TEUCHOS_ASSERT(d2gdx2.size()==ugis_.size()); // scatter operation for each cell in workset const std::vector & localCellIds = wda(workset).cell_local_ids; for(std::size_t worksetCellIndex=0;worksetCellIndexgetElementLIDs(cellLocalId); Teuchos::ArrayRCP d2gdx2_b = d2gdx2[b]; // loop over basis functions for(std::size_t i=0;i