11 #ifndef __Panzer_ScatterDirichletResidual_BlockedEpetra_Hessian_impl_hpp__
12 #define __Panzer_ScatterDirichletResidual_BlockedEpetra_Hessian_impl_hpp__
15 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
26 template<
typename TRAITS,
typename LO,
typename GO>
32 : rowIndexers_(rIndexers)
33 , colIndexers_(cIndexers)
34 , globalDataKey_(
"Residual Scatter Container")
36 std::string scatterName = p.
get<std::string>(
"Scatter Name");
41 const std::vector<std::string>& names =
50 side_subcell_dim_ = p.
get<
int>(
"Side Subcell Dimension");
51 local_side_id_ = p.
get<
int>(
"Local Side ID");
54 scatterFields_.resize(names.size());
55 for (std::size_t eq = 0; eq < names.size(); ++eq) {
59 this->addDependentField(scatterFields_[eq]);
62 checkApplyBC_ = p.
get<
bool>(
"Check Apply BC");
64 applyBC_.resize(names.size());
65 for (std::size_t eq = 0; eq < names.size(); ++eq) {
67 this->addDependentField(applyBC_[eq]);
72 this->addEvaluatedField(*scatterHolder_);
74 if (p.
isType<std::string>(
"Global Data Key"))
75 globalDataKey_ = p.
get<std::string>(
"Global Data Key");
77 if(colIndexers_.size()==0)
78 colIndexers_ = rowIndexers_;
80 this->setName(scatterName+
" Scatter Dirichlet Residual : BlockedEpetra (Hessian)");
83 template<
typename TRAITS,
typename LO,
typename GO>
89 indexerIds_.resize(scatterFields_.size());
90 subFieldIds_.resize(scatterFields_.size());
93 for(std::size_t fd=0;fd<scatterFields_.size();++fd) {
95 std::string fieldName = fieldMap_->find(scatterFields_[fd].fieldTag().name())->second;
98 subFieldIds_[fd] = rowIndexers_[indexerIds_[fd]]->getFieldNum(fieldName);
102 num_nodes = scatterFields_[0].extent(1);
103 num_eq = scatterFields_.size();
106 template<
typename TRAITS,
typename LO,
typename GO>
113 using Teuchos::rcp_dynamic_cast;
117 = rcp_dynamic_cast<
const BLOC>(d.gedc->getDataObject(
"Dirichlet Counter"),
true);
123 blockContainer = rcp_dynamic_cast<
const BLOC>(d.gedc->getDataObject(globalDataKey_),
true);
129 template<
typename TRAITS,
typename LO,
typename GO>
136 using Teuchos::ptrFromRef;
137 using Teuchos::rcp_dynamic_cast;
139 using Thyra::SpmdVectorBase;
142 std::string blockId = this->
wda(workset).block_id;
143 const std::vector<std::size_t> & localCellIds = this->
wda(workset).cell_local_ids;
145 int numFieldBlocks = Teuchos::as<int>(colIndexers_.size());
147 std::vector<int> blockOffsets;
157 for(std::size_t fieldIndex = 0; fieldIndex < scatterFields_.size(); fieldIndex++) {
158 int rowIndexer = indexerIds_[fieldIndex];
159 int subFieldNum = subFieldIds_[fieldIndex];
163 rcp_dynamic_cast<SpmdVectorBase<double> >(dirichletCounter_->getNonconstVectorBlock(rowIndexer))
164 ->getNonconstLocalData(ptrFromRef(local_dc));
166 auto subRowIndexer = rowIndexers_[rowIndexer];
167 auto subIndicePair = subRowIndexer->getGIDFieldOffsets_closure(blockId,subFieldNum, side_subcell_dim_, local_side_id_);
168 const std::vector<int> & subElmtOffset = subIndicePair.first;
169 const std::vector<int> & subBasisIdMap = subIndicePair.second;
172 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
173 std::size_t cellLocalId = localCellIds[worksetCellIndex];
175 auto rLIDs = subRowIndexer->getElementLIDs(cellLocalId);
178 for(std::size_t basis=0;basis<subElmtOffset.size();basis++) {
179 int offset = subElmtOffset[basis];
180 int lid = rLIDs[offset];
184 int basisId = subBasisIdMap[basis];
187 if (!applyBC_[fieldIndex](worksetCellIndex,basisId))
191 for(
int colIndexer=0;colIndexer<numFieldBlocks;colIndexer++) {
192 int start = blockOffsets[colIndexer];
193 int end = blockOffsets[colIndexer+1];
199 std::pair<int,int> blockIndex = std::make_pair(rowIndexer,colIndexer);
200 Teuchos::RCP<Epetra_CrsMatrix> subJac = jacEpetraBlocks[blockIndex];
202 if(subJac==Teuchos::null) {
211 jacEpetraBlocks[blockIndex] = subJac;
215 int * rowIndices = 0;
216 double * rowValues = 0;
220 for(
int i=0;i<numEntries;i++)
224 const ScalarT scatterField = (scatterFields_[fieldIndex])(worksetCellIndex,basisId);
229 std::vector<double> jacRow(scatterField.size(),0.0);
231 for(
int sensIndex=0;sensIndex<scatterField.size();++sensIndex)
232 jacRow[sensIndex] = scatterField.fastAccessDx(sensIndex).fastAccessDx(0);
234 for(
int colIndexer=0;colIndexer<numFieldBlocks;colIndexer++) {
235 int start = blockOffsets[colIndexer];
236 int end = blockOffsets[colIndexer+1];
241 auto subColIndexer = colIndexers_[colIndexer];
242 auto cLIDs = subColIndexer->getElementLIDs(cellLocalId);
247 std::pair<int,int> blockIndex = std::make_pair(rowIndexer,colIndexer);
248 Teuchos::RCP<Epetra_CrsMatrix> subJac = jacEpetraBlocks[blockIndex];
251 if(subJac==Teuchos::null) {
260 jacEpetraBlocks[blockIndex] = subJac;
264 int err = subJac->
ReplaceMyValues(lid, end-start, &jacRow[start],&cLIDs[0]);
266 std::stringstream ss;
267 ss <<
"Failed inserting row: " <<
" (" << lid <<
"): ";
268 for(
int i=0;i<end-start;i++)
269 ss << cLIDs[i] <<
" ";
271 ss <<
"Into block " << rowIndexer <<
", " << colIndexer << std::endl;
273 ss <<
"scatter field = ";
274 scatterFields_[fieldIndex].print(ss);
T & get(const std::string &name, T def_value)
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
panzer::Traits::Hessian::ScalarT ScalarT
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
void computeBlockOffsets(const std::string &blockId, const std::vector< Teuchos::RCP< GlobalIndexer >> &ugis, std::vector< int > &blockOffsets)
int ExtractMyRowView(int MyRow, int &NumEntries, double *&Values, int *&Indices) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void evaluateFields(typename TRAITS::EvalData d)
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< const GlobalIndexer >> &ugis)
ScatterDirichletResidual_BlockedEpetra(const Teuchos::ParameterList &p)
virtual void preEvaluate(typename Traits::PreEvalData d)=0
bool isType(const std::string &name) const
WorksetDetailsAccessor wda
#define TEUCHOS_ASSERT(assertion_test)
int ReplaceMyValues(int MyRow, int NumEntries, const double *Values, const int *Indices)