11#ifndef PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_HPP
12#define PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_HPP
17#include "PanzerDiscFE_config.hpp"
24#include "Phalanx_Evaluator_Macros.hpp"
25#include "Phalanx_MDField.hpp"
52 virtual void scatterDerivative(
const PHX::MDField<const panzer::Traits::Jacobian::ScalarT,panzer::Cell> & cellIntegral,
55 const std::vector<Teuchos::ArrayRCP<double> > & dgdx)
const = 0;
57#ifdef Panzer_BUILD_HESSIAN_SUPPORT
65 virtual void scatterHessian(
const PHX::MDField<const panzer::Traits::Hessian::ScalarT,panzer::Cell> & cellIntegral,
68 const std::vector<Teuchos::ArrayRCP<double> > & d2gdx2)
const = 0;
77template <
typename LO,
typename GO>
83 if(globalIndexer!=Teuchos::null)
84 ugis_.push_back(globalIndexer);
92 void scatterDerivative(
const PHX::MDField<const panzer::Traits::Jacobian::ScalarT,panzer::Cell> & cellIntegral,
95 const std::vector<Teuchos::ArrayRCP<double> > & dgdx)
const;
97#ifdef Panzer_BUILD_HESSIAN_SUPPORT
99 void scatterHessian(
const PHX::MDField<const panzer::Traits::Hessian::ScalarT,panzer::Cell> & cellIntegral,
102 const std::vector<Teuchos::ArrayRCP<double> > & d2gdx2)
const;
108 std::vector<Teuchos::RCP<const panzer::GlobalIndexer> >
ugis_;
122template<
typename EvalT,
typename Traits>
124 public PHX::EvaluatorDerived<EvalT, Traits> {
135 const Teuchos::RCP<FunctionalScatterBase> & functionalScatter);
144 const Teuchos::RCP<FunctionalScatterBase> & functionalScatter);
166template <
typename LO,
typename GO>
170 const std::vector<Teuchos::ArrayRCP<double> > & dgdx)
const
173 std::string blockId = wda(workset).block_id;
175 std::vector<int> blockOffsets;
178 TEUCHOS_ASSERT(dgdx.size()==ugis_.size());
180 auto cellIntegral_h = Kokkos::create_mirror_view(cellIntegral.get_view());
181 Kokkos::deep_copy(cellIntegral_h, cellIntegral.get_view());
183 const std::vector<std::size_t> & localCellIds = wda(workset).cell_local_ids;
185 for(std::size_t b=0;b<ugis_.size();b++) {
186 int start = blockOffsets[b];
188 auto LIDs = ugis_[b]->getLIDs();
189 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
190 Kokkos::deep_copy(LIDs_h, LIDs);
192 Teuchos::ArrayRCP<double> dgdx_b = dgdx[b];
195 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
196 std::size_t cellLocalId = localCellIds[worksetCellIndex];
199 for(std::size_t i=0;i<LIDs_h.extent(1);i++) {
200 dgdx_b[LIDs_h(cellLocalId, i)] += cellIntegral_h(worksetCellIndex).dx(start+i);
206#ifdef Panzer_BUILD_HESSIAN_SUPPORT
207template <
typename LO,
typename GO>
211 const std::vector<Teuchos::ArrayRCP<double> > & d2gdx2)
const
213 PHX::View<const LO*> LIDs;
216 std::string blockId = wda(workset).block_id;
218 std::vector<int> blockOffsets;
221 TEUCHOS_ASSERT(d2gdx2.size()==ugis_.size());
224 const std::vector<std::size_t> & localCellIds = wda(workset).cell_local_ids;
225 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
226 std::size_t cellLocalId = localCellIds[worksetCellIndex];
228 for(std::size_t b=0;b<ugis_.size();b++) {
229 int start = blockOffsets[b];
231 LIDs = ugis_[b]->getElementLIDs(cellLocalId);
233 Teuchos::ArrayRCP<double> d2gdx2_b = d2gdx2[b];
236 for(std::size_t i=0;i<LIDs.size();i++) {
237 d2gdx2_b[LIDs[i]] += cellIntegral(worksetCellIndex).dx(start+i).dx(0);
Data for determining cell topology and dimensionality.
Wrapper to PHX::EvaluatorWithBaseImpl that implements Panzer-specific helpers.
Abstract interface for scattering a functional response's derivative back into global sensitivity vec...
virtual void scatterDerivative(const PHX::MDField< const panzer::Traits::Jacobian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &dgdx) const =0
Accumulates dg/dx contributions from one workset's cell integrals into the global gradient vector(s).
virtual ~FunctionalScatterBase()
virtual void scatterHessian(const PHX::MDField< const panzer::Traits::Hessian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &d2gdx2) const =0
Accumulates d2g/dx2 contributions from one workset's cell integrals into the global Hessian-vector pr...
Concrete FunctionalScatterBase that scatters using one or more panzer::GlobalIndexer objects.
std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > ugis_
One global indexer per block; a single entry for non-blocked problems.
FunctionalScatter(const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &ugis)
Construct for a blocked problem with one global indexer per block.
FunctionalScatter(const Teuchos::RCP< const panzer::GlobalIndexer > &globalIndexer)
Construct for a single global indexer (single-block problem); no-op if globalIndexer is null.
void scatterDerivative(const PHX::MDField< const panzer::Traits::Jacobian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &dgdx) const
Accumulates dg/dx contributions from one workset's cell integrals into the global gradient vector(s).
void scatterHessian(const PHX::MDField< const panzer::Traits::Hessian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &d2gdx2) const
Accumulates d2g/dx2 contributions from one workset's cell integrals into the global Hessian-vector pr...
Teuchos::RCP< FunctionalScatterBase > scatterObj_
Used to scatter derivative/Hessian information into the response's global vectors.
Teuchos::RCP< Response_Functional< EvalT > > responseObj_
The response object accumulated into by evaluateFields().
Teuchos::RCP< PHX::FieldTag > scatterHolder_
void preEvaluate(typename Traits::PreEvalData d)
Looks up the Response_Functional to accumulate into for the upcoming fill.
void evaluateFields(typename Traits::EvalData d)
Sums this workset's per-cell integrand values (and scatters derivatives, via scatterObj_) into the re...
PHX::MDField< const ScalarT, panzer::Cell > cellIntegral_
std::string responseName_
Name of the response this evaluator contributes to.
void computeBlockOffsets(const std::string &blockId, const std::vector< Teuchos::RCP< GlobalIndexer > > &ugis, std::vector< int > &blockOffsets)
User-defined data passed to PHX::Evaluator::preEvaluate(), called once before each residual/Jacobian ...