11#ifndef PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_IMPL_HPP
12#define PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_IMPL_HPP
17#include "PanzerDiscFE_config.hpp"
19#include "Phalanx_Evaluator_Macros.hpp"
20#include "Phalanx_MDField.hpp"
21#include "Phalanx_DataLayout_MDALayout.hpp"
27#include "Thyra_DefaultProductVector.hpp"
28#include "Thyra_SpmdVectorBase.hpp"
29#include "Thyra_ProductVectorBase.hpp"
31#include "Teuchos_ArrayRCP.hpp"
38template<
typename EvalT,
typename Traits>
42 const Teuchos::RCP<FunctionalScatterBase> & functionalScatter)
44 , scatterObj_(functionalScatter)
52 RCP<PHX::DataLayout> dl_dummy = rcp(
new PHX::MDALayout<panzer::Dummy>(0));
57 RCP<PHX::DataLayout> dl_cell = rcp(
new PHX::MDALayout<panzer::Cell>(cd.
numCells()));
58 cellIntegral_ = PHX::MDField<const ScalarT,panzer::Cell>(name,dl_cell);
61 std::string n =
"Functional Response Scatter: " + name;
65template<
typename EvalT,
typename Traits>
68 const std::string & responseName,
70 const Teuchos::RCP<FunctionalScatterBase> & functionalScatter)
71 : responseName_(responseName)
72 , scatterObj_(functionalScatter)
80 RCP<PHX::DataLayout> dl_dummy = rcp(
new PHX::MDALayout<panzer::Dummy>(0));
85 RCP<PHX::DataLayout> dl_cell = rcp(
new PHX::MDALayout<panzer::Cell>(cd.
numCells()));
86 cellIntegral_ = PHX::MDField<const ScalarT,panzer::Cell>(integrandName,dl_cell);
89 std::string n =
"Functional Response Scatter: " + responseName;
93template<
typename EvalT,
typename Traits>
98 responseObj_ = Teuchos::rcp_dynamic_cast<Response_Functional<EvalT> >(
103template<
typename EvalT,
typename Traits>
107 auto cellIntegral_h = Kokkos::create_mirror_view ( cellIntegral_.get_static_view());
108 Kokkos::deep_copy(cellIntegral_h, cellIntegral_.get_static_view());
110 responseObj_->value += cellIntegral_h(i);
119 using Teuchos::rcp_dynamic_cast;
120 using Thyra::SpmdVectorBase;
123 TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
124 TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
126 RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
128 std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
129 for(
int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
131 Teuchos::ArrayRCP<double> local_dgdx;
132 RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
133 dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
135 TEUCHOS_ASSERT(!local_dgdx.is_null());
137 local_dgdxs.push_back(local_dgdx);
140 scatterObj_->scatterDerivative(cellIntegral_,d,this->wda,local_dgdxs);
143#ifdef Panzer_BUILD_HESSIAN_SUPPORT
149 using Teuchos::rcp_dynamic_cast;
150 using Thyra::SpmdVectorBase;
153 TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
154 TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
156 RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
158 std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
159 for(
int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
161 Teuchos::ArrayRCP<double> local_dgdx;
162 RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
163 dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
165 TEUCHOS_ASSERT(!local_dgdx.is_null());
167 local_dgdxs.push_back(local_dgdx);
171 scatterObj_->scatterHessian(cellIntegral_,d,this->wda,local_dgdxs);
Data for determining cell topology and dimensionality.
std::size_t numCells() const
static std::string buildLookupName(const std::string &responseName)
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_
ResponseScatterEvaluator_Functional(const std::string &name, const CellData &cd, const Teuchos::RCP< FunctionalScatterBase > &functionalScatter)
A constructor with concrete arguments instead of a parameter list.
int num_cells
DEPRECATED - use: numCells()
User-defined data passed to PHX::Evaluator::preEvaluate(), called once before each residual/Jacobian ...
Teuchos::RCP< GlobalEvaluationDataContainer > gedc
Container of global (non-cell-local) data, e.g. distributed vectors needed by gather/scatter evaluato...