43 #ifndef PANZER_SCATTER_RESIDUAL_EPETRA_SG_IMPL_HPP
44 #define PANZER_SCATTER_RESIDUAL_EPETRA_SG_IMPL_HPP
46 #include "Panzer_config.hpp"
51 #include "Phalanx_DataLayout_MDALayout.hpp"
53 #include "Epetra_Vector.h"
54 #include "Epetra_Map.h"
55 #include "Epetra_CrsMatrix.h"
61 template<
typename TRAITS,
typename LO,
typename GO>
66 : globalIndexer_(indexer)
67 , globalDataKey_(
"Residual Scatter Container")
68 , useDiscreteAdjoint_(useDiscreteAdjoint)
72 std::string scatterName = p.
get<std::string>(
"Scatter Name");
77 const std::vector<std::string>& names =
88 for (std::size_t eq = 0; eq < names.size(); ++eq) {
89 scatterFields_[eq] = PHX::MDField<ScalarT,Cell,NODE>(names[eq],dl);
96 this->addEvaluatedField(*scatterHolder_);
98 if (p.
isType<std::string>(
"Global Data Key"))
99 globalDataKey_ = p.
get<std::string>(
"Global Data Key");
101 this->setName(scatterName+
" Scatter Residual (SGResidual)");
105 template<
typename TRAITS,
typename LO,
typename GO>
116 template<
typename TRAITS,
typename LO,
typename GO>
125 std::string fieldName = fieldMap_->find(
scatterFields_[fd].fieldTag().name())->second;
126 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
134 template<
typename TRAITS,
typename LO,
typename GO>
138 std::vector<GO> GIDs;
139 std::vector<int> LIDs;
142 std::string blockId = this->wda(workset).block_id;
143 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
155 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
156 std::size_t cellLocalId = localCellIds[worksetCellIndex];
158 globalIndexer_->getElementGIDs(cellLocalId,GIDs,blockId);
161 LIDs.resize(GIDs.size());
162 for(std::size_t i=0;i<GIDs.size();i++)
163 LIDs[i] = map.
LID(GIDs[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);
180 for(itr=sgEpetraContainer->
begin();itr!=sgEpetraContainer->
end();++itr,++stochIndex)
181 (*(*itr)->get_f())[lid] += field.coeff(stochIndex);
191 template<
typename TRAITS,
typename LO,
typename GO>
196 : globalIndexer_(indexer)
197 , globalDataKey_(
"Residual Scatter Container")
198 , useDiscreteAdjoint_(useDiscreteAdjoint)
202 std::string scatterName = p.
get<std::string>(
"Scatter Name");
207 const std::vector<std::string>& names =
218 for (std::size_t eq = 0; eq < names.size(); ++eq) {
219 scatterFields_[eq] = PHX::MDField<ScalarT,Cell,NODE>(names[eq],dl);
226 this->addEvaluatedField(*scatterHolder_);
228 if (p.
isType<std::string>(
"Global Data Key"))
229 globalDataKey_ = p.
get<std::string>(
"Global Data Key");
230 if (p.
isType<
bool>(
"Use Discrete Adjoint"))
231 useDiscreteAdjoint = p.
get<
bool>(
"Use Discrete Adjoint");
236 if(useDiscreteAdjoint)
239 this->setName(scatterName+
" Scatter Residual (SGJacobian)");
243 template<
typename TRAITS,
typename LO,
typename GO>
254 template<
typename TRAITS,
typename LO,
typename GO>
263 std::string fieldName = fieldMap_->find(
scatterFields_[fd].fieldTag().name())->second;
264 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
272 template<
typename TRAITS,
typename LO,
typename GO>
276 std::vector<int> rLIDs, cLIDs;
277 std::vector<double> jacRow;
280 std::string blockId = this->wda(workset).block_id;
281 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
292 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
293 std::size_t cellLocalId = localCellIds[worksetCellIndex];
295 rLIDs = globalIndexer_->getElementLIDs(cellLocalId);
299 for(std::size_t fieldIndex = 0; fieldIndex <
scatterFields_.size(); fieldIndex++) {
300 int fieldNum = fieldIds_[fieldIndex];
301 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
304 for(std::size_t rowBasisNum = 0; rowBasisNum < elmtOffset.size(); rowBasisNum++) {
306 int rowOffset = elmtOffset[rowBasisNum];
307 int row = rLIDs[rowOffset];
312 for(itr=sgEpetraContainer->
begin();itr!=sgEpetraContainer->
end();++itr,++stochIndex) {
318 r->SumIntoMyValue(row,0,scatterField.val().coeff(stochIndex));
321 jacRow.resize(scatterField.size());
323 if(useDiscreteAdjoint_) {
325 jacRow.resize(scatterField.size());
327 for(
int sensIndex=0;sensIndex<scatterField.size();++sensIndex)
328 jacRow[sensIndex] = scatterField.fastAccessDx(sensIndex).coeff(stochIndex);
331 for(std::size_t c=0;c<cLIDs.size();c++)
336 for(
int sensIndex=0;sensIndex<scatterField.size();++sensIndex)
337 jacRow[sensIndex] = scatterField.fastAccessDx(sensIndex).coeff(stochIndex);
CoeffVector::iterator end()
panzer::Traits::SGResidual::ScalarT ScalarT
std::vector< PHX::MDField< const ScalarT, panzer::Cell, panzer::Point > > scatterFields_
panzer::Traits::SGJacobian::ScalarT ScalarT
T & get(const std::string &name, T def_value)
CoeffVector::iterator begin()
PHX::MDField< ScalarT, Cell, IP > field
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)
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
bool isType(const std::string &name) const
CoeffVector::iterator iterator
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)