11 #ifndef __Panzer_ScatterResidual_Epetra_Hessian_impl_hpp__
12 #define __Panzer_ScatterResidual_Epetra_Hessian_impl_hpp__
15 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
18 #include "Teuchos_Assert.hpp"
20 #include "Phalanx_DataLayout.hpp"
22 #include "Epetra_Map.h"
23 #include "Epetra_Vector.h"
24 #include "Epetra_CrsMatrix.h"
34 #include "Phalanx_DataLayout_MDALayout.hpp"
36 #include "Teuchos_FancyOStream.hpp"
42 template<
typename TRAITS,
typename LO,
typename GO>
47 bool useDiscreteAdjoint)
48 : globalIndexer_(indexer)
49 , colGlobalIndexer_(cIndexer)
50 , globalDataKey_(
"Residual Scatter Container")
51 , useDiscreteAdjoint_(useDiscreteAdjoint)
53 std::string scatterName = p.
get<std::string>(
"Scatter Name");
58 const std::vector<std::string>& names =
68 scatterFields_.resize(names.size());
69 for (std::size_t eq = 0; eq < names.size(); ++eq) {
73 this->addDependentField(scatterFields_[eq]);
77 this->addEvaluatedField(*scatterHolder_);
79 if (p.
isType<std::string>(
"Global Data Key"))
80 globalDataKey_ = p.
get<std::string>(
"Global Data Key");
81 if (p.
isType<
bool>(
"Use Discrete Adjoint"))
82 useDiscreteAdjoint = p.
get<
bool>(
"Use Discrete Adjoint");
85 if(useDiscreteAdjoint)
88 this->setName(scatterName+
" Scatter Residual Epetra (Jacobian)");
92 template<
typename TRAITS,
typename LO,
typename GO>
97 fieldIds_.resize(scatterFields_.size());
99 for(std::size_t fd=0;fd<scatterFields_.size();++fd) {
101 std::string fieldName = fieldMap_->find(scatterFields_[fd].fieldTag().name())->second;
102 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
107 template<
typename TRAITS,
typename LO,
typename GO>
114 if(epetraContainer_==Teuchos::null) {
122 template<
typename TRAITS,
typename LO,
typename GO>
130 std::vector<double> jacRow;
132 bool useColumnIndexer = colGlobalIndexer_!=Teuchos::null;
135 std::string blockId = this->wda(workset).block_id;
136 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
142 colGlobalIndexer = useColumnIndexer ? colGlobalIndexer_ : globalIndexer_;
150 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
151 std::size_t cellLocalId = localCellIds[worksetCellIndex];
154 auto initial_cLIDs = colGlobalIndexer->
getElementLIDs(cellLocalId);
156 for (
int i(0); i < static_cast<int>(initial_cLIDs.extent(0)); ++i)
157 cLIDs.push_back(initial_cLIDs(i));
159 const std::size_t other_cellLocalId = workset.other->cell_local_ids[worksetCellIndex];
160 auto other_cLIDs = colGlobalIndexer->
getElementLIDs(other_cellLocalId);
161 for (
int i(0); i < static_cast<int>(other_cLIDs.extent(0)); ++i)
162 cLIDs.push_back(other_cLIDs(i));
166 for(std::size_t fieldIndex = 0; fieldIndex < scatterFields_.size(); fieldIndex++) {
167 int fieldNum = fieldIds_[fieldIndex];
168 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
171 for(std::size_t rowBasisNum = 0; rowBasisNum < elmtOffset.size(); rowBasisNum++) {
172 const ScalarT scatterField = (scatterFields_[fieldIndex])(worksetCellIndex,rowBasisNum);
173 int rowOffset = elmtOffset[rowBasisNum];
174 int row = rLIDs[rowOffset];
177 jacRow.resize(scatterField.size());
179 for(
int sensIndex=0;sensIndex<scatterField.size();++sensIndex)
180 jacRow[sensIndex] = scatterField.fastAccessDx(sensIndex).fastAccessDx(0);
185 std::min(cLIDs.size(),
static_cast<size_t>(scatterField.size())),
const Kokkos::View< const panzer::LocalOrdinal *, Kokkos::LayoutRight, PHX::Device > getElementLIDs(panzer::LocalOrdinal localElmtId) const
T & get(const std::string &name, T def_value)
bool nonnull(const std::shared_ptr< T > &p)
panzer::Traits::Hessian::ScalarT ScalarT
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
T * ptrFromStlVector(std::vector< T > &v)
Pushes residual values into the residual vector for a Newton-based solve.
int SumIntoMyValues(int MyRow, int NumEntries, const double *Values, const int *Indices)
bool isType(const std::string &name) const
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)