42 const Teuchos::RCP<const panzer::GlobalIndexer> & ,
43 const Teuchos::ParameterList& p)
44 : globalIndexer_(indexer)
45 , globalDataKey_(
"Residual Scatter Container")
47 std::string scatterName = p.get<std::string>(
"Scatter Name");
49 Teuchos::rcp(
new PHX::Tag<ScalarT>(scatterName,Teuchos::rcp(
new PHX::MDALayout<Dummy>(0))));
52 const std::vector<std::string>& names =
53 *(p.get< Teuchos::RCP< std::vector<std::string> > >(
"Dependent Names"));
56 fieldMap_ = p.get< Teuchos::RCP< std::map<std::string,std::string> > >(
"Dependent Map");
59 scatterIC_ = p.isParameter(
"Scatter Initial Condition") ? p.get<
bool>(
"Scatter Initial Condition") :
false;
61 Teuchos::RCP<PHX::DataLayout> dl = (!scatterIC_) ?
62 p.get< Teuchos::RCP<panzer::PureBasis> >(
"Basis")->functional :
63 p.get< Teuchos::RCP<const panzer::PureBasis> >(
"Basis")->functional;
65 side_subcell_dim_ = p.get<
int>(
"Side Subcell Dimension");
66 local_side_id_ = p.get<
int>(
"Local Side ID");
70 scatterFields_.resize(names.size());
71 for (std::size_t eq = 0; eq < names.size(); ++eq) {
72 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
75 this->addDependentField(scatterFields_[eq]);
78 checkApplyBC_ = p.isParameter(
"Check Apply BC") ? p.get<
bool>(
"Check Apply BC") :
false;
80 applyBC_.resize(names.size());
81 for (std::size_t eq = 0; eq < names.size(); ++eq) {
82 applyBC_[eq] = PHX::MDField<const bool,Cell,NODE>(std::string(
"APPLY_BC_")+fieldMap_->find(names[eq])->second,dl);
83 this->addDependentField(applyBC_[eq]);
88 this->addEvaluatedField(*scatterHolder_);
90 if (p.isType<std::string>(
"Global Data Key"))
91 globalDataKey_ = p.get<std::string>(
"Global Data Key");
93 this->setName(scatterName+
" Scatter Residual");
121 epetraContainer_ = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(globalDataKey_));
123 if(epetraContainer_==Teuchos::null) {
125 Teuchos::RCP<LinearObjContainer> loc = Teuchos::rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(d.gedc->getDataObject(globalDataKey_),
true)->getGhostedLOC();
126 epetraContainer_ = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(loc);
128 dirichletCounter_ = Teuchos::null;
132 Teuchos::RCP<EpetraLinearObjContainer> epetraContainer
133 = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(
"Dirichlet Counter"),
true);
135 dirichletCounter_ = epetraContainer->get_f();
136 TEUCHOS_ASSERT(!Teuchos::is_null(dirichletCounter_));
146 std::string blockId = this->wda(workset).block_id;
147 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
149 Teuchos::RCP<const EpetraLinearObjContainer> epetraContainer = epetraContainer_;
150 Teuchos::RCP<Epetra_Vector> r = (!scatterIC_) ?
151 epetraContainer->get_f() :
152 epetraContainer->get_x();
159 auto LIDs = globalIndexer_->getLIDs();
160 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
161 Kokkos::deep_copy(LIDs_h, LIDs);
165 for(std::size_t fieldIndex = 0; fieldIndex < scatterFields_.size(); fieldIndex++) {
166 int fieldNum = fieldIds_[fieldIndex];
167 auto field = PHX::as_view(scatterFields_[fieldIndex]);
168 auto field_h = Kokkos::create_mirror_view(
field);
169 Kokkos::deep_copy(field_h,
field);
171 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
172 std::size_t cellLocalId = localCellIds[worksetCellIndex];
176 const std::pair<std::vector<int>,std::vector<int> > & indicePair
177 = globalIndexer_->getGIDFieldOffsets_closure(blockId,fieldNum, side_subcell_dim_, local_side_id_);
178 const std::vector<int> & elmtOffset = indicePair.first;
179 const std::vector<int> & basisIdMap = indicePair.second;
182 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
183 int offset = elmtOffset[basis];
184 int lid = LIDs_h(cellLocalId, offset);
188 int basisId = basisIdMap[basis];
191 if (!applyBC_[fieldIndex](worksetCellIndex,basisId))
194 (*r)[lid] = field_h(worksetCellIndex,basisId);
197 if(dirichletCounter_!=Teuchos::null)
198 (*dirichletCounter_)[lid] = 1.0;
202 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
205 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
206 int offset = elmtOffset[basis];
207 int lid = LIDs_h(cellLocalId, offset);
211 (*r)[lid] = field_h(worksetCellIndex,basis);
214 if(dirichletCounter_!=Teuchos::null)
215 (*dirichletCounter_)[lid] = 1.0;
230 const Teuchos::RCP<const panzer::GlobalIndexer> & ,
231 const Teuchos::ParameterList& p)
232 : globalIndexer_(indexer)
233 , globalDataKey_(
"Residual Scatter Container")
235 std::string scatterName = p.get<std::string>(
"Scatter Name");
237 Teuchos::rcp(
new PHX::Tag<ScalarT>(scatterName,Teuchos::rcp(
new PHX::MDALayout<Dummy>(0))));
240 const std::vector<std::string>& names =
241 *(p.get< Teuchos::RCP< std::vector<std::string> > >(
"Dependent Names"));
244 fieldMap_ = p.get< Teuchos::RCP< std::map<std::string,std::string> > >(
"Dependent Map");
247 scatterIC_ = p.isParameter(
"Scatter Initial Condition") ? p.get<
bool>(
"Scatter Initial Condition") :
false;
249 Teuchos::RCP<PHX::DataLayout> dl = (!scatterIC_) ?
250 p.get< Teuchos::RCP<panzer::PureBasis> >(
"Basis")->functional :
251 p.get< Teuchos::RCP<const panzer::PureBasis> >(
"Basis")->functional;
253 side_subcell_dim_ = p.get<
int>(
"Side Subcell Dimension");
254 local_side_id_ = p.get<
int>(
"Local Side ID");
258 scatterFields_.resize(names.size());
259 for (std::size_t eq = 0; eq < names.size(); ++eq) {
260 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
263 this->addDependentField(scatterFields_[eq]);
266 checkApplyBC_ = p.isParameter(
"Check Apply BC") ? p.get<
bool>(
"Check Apply BC") :
false;
268 applyBC_.resize(names.size());
269 for (std::size_t eq = 0; eq < names.size(); ++eq) {
270 applyBC_[eq] = PHX::MDField<const bool,Cell,NODE>(std::string(
"APPLY_BC_")+fieldMap_->find(names[eq])->second,dl);
271 this->addDependentField(applyBC_[eq]);
276 this->addEvaluatedField(*scatterHolder_);
278 if (p.isType<std::string>(
"Global Data Key"))
279 globalDataKey_ = p.get<std::string>(
"Global Data Key");
281 this->setName(scatterName+
" Scatter Tangent");
309 epetraContainer_ = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(globalDataKey_));
311 if(epetraContainer_==Teuchos::null) {
313 Teuchos::RCP<LinearObjContainer> loc = Teuchos::rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(d.gedc->getDataObject(globalDataKey_),
true)->getGhostedLOC();
314 epetraContainer_ = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(loc);
316 dirichletCounter_ = Teuchos::null;
320 Teuchos::RCP<EpetraLinearObjContainer> epetraContainer
321 = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(
"Dirichlet Counter"),
true);
323 dirichletCounter_ = epetraContainer->get_f();
324 TEUCHOS_ASSERT(!Teuchos::is_null(dirichletCounter_));
328 using Teuchos::rcp_dynamic_cast;
331 std::vector<std::string> activeParameters =
332 rcp_dynamic_cast<ParameterList_GlobalEvaluationData>(d.gedc->getDataObject(
"PARAMETER_NAMES"))->getActiveParameters();
335 TEUCHOS_ASSERT(!scatterIC_);
336 dfdp_vectors_.clear();
337 for(std::size_t i=0;i<activeParameters.size();i++) {
338 RCP<Epetra_Vector> vec = rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(activeParameters[i]),
true)->get_f();
339 dfdp_vectors_.push_back(vec);
349 std::string blockId = this->wda(workset).block_id;
350 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
352 Teuchos::RCP<const EpetraLinearObjContainer> epetraContainer = epetraContainer_;
353 Teuchos::RCP<Epetra_Vector> r = (!scatterIC_) ?
354 epetraContainer->get_f() :
355 epetraContainer->get_x();
362 auto LIDs = globalIndexer_->getLIDs();
363 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
364 Kokkos::deep_copy(LIDs_h, LIDs);
365 for(std::size_t fieldIndex = 0; fieldIndex < scatterFields_.size(); fieldIndex++) {
366 int fieldNum = fieldIds_[fieldIndex];
367 auto scatterField_h = Kokkos::create_mirror_view(scatterFields_[fieldIndex].get_static_view());
368 Kokkos::deep_copy(scatterField_h, scatterFields_[fieldIndex].get_static_view());
371 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
372 std::size_t cellLocalId = localCellIds[worksetCellIndex];
376 const std::pair<std::vector<int>,std::vector<int> > & indicePair
377 = globalIndexer_->getGIDFieldOffsets_closure(blockId,fieldNum, side_subcell_dim_, local_side_id_);
378 const std::vector<int> & elmtOffset = indicePair.first;
379 const std::vector<int> & basisIdMap = indicePair.second;
382 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
383 int offset = elmtOffset[basis];
384 int lid = LIDs_h(cellLocalId, offset);
388 int basisId = basisIdMap[basis];
391 if (!applyBC_[fieldIndex](worksetCellIndex,basisId))
394 ScalarT value = scatterField_h(worksetCellIndex,basisId);
399 for(std::size_t d=0;d<dfdp_vectors_.size();d++)
400 (*dfdp_vectors_[d])[lid] = 0.0;
402 for(
int d=0;d<value.size();d++) {
403 (*dfdp_vectors_[d])[lid] = value.fastAccessDx(d);
407 if(dirichletCounter_!=Teuchos::null)
408 (*dirichletCounter_)[lid] = 1.0;
412 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
415 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
416 int offset = elmtOffset[basis];
417 int lid = LIDs_h(cellLocalId, offset);
421 ScalarT value = scatterField_h(worksetCellIndex,basis);
426 for(std::size_t d=0;d<dfdp_vectors_.size();d++)
427 (*dfdp_vectors_[d])[lid] = 0.0;
429 for(
int d=0;d<value.size();d++) {
430 (*dfdp_vectors_[d])[lid] = value.fastAccessDx(d);
434 if(dirichletCounter_!=Teuchos::null)
435 (*dirichletCounter_)[lid] = 1.0;
449 const Teuchos::RCP<const panzer::GlobalIndexer> & cIndexer,
450 const Teuchos::ParameterList& p)
451 : globalIndexer_(indexer)
452 , colGlobalIndexer_(cIndexer)
453 , globalDataKey_(
"Residual Scatter Container")
454 , preserveDiagonal_(false)
456 std::string scatterName = p.get<std::string>(
"Scatter Name");
458 Teuchos::rcp(
new PHX::Tag<ScalarT>(scatterName,Teuchos::rcp(
new PHX::MDALayout<Dummy>(0))));
461 const std::vector<std::string>& names =
462 *(p.get< Teuchos::RCP< std::vector<std::string> > >(
"Dependent Names"));
465 fieldMap_ = p.get< Teuchos::RCP< std::map<std::string,std::string> > >(
"Dependent Map");
467 Teuchos::RCP<PHX::DataLayout> dl =
468 p.get< Teuchos::RCP<panzer::PureBasis> >(
"Basis")->functional;
470 side_subcell_dim_ = p.get<
int>(
"Side Subcell Dimension");
471 local_side_id_ = p.get<
int>(
"Local Side ID");
474 scatterFields_.resize(names.size());
475 for (std::size_t eq = 0; eq < names.size(); ++eq) {
476 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
479 this->addDependentField(scatterFields_[eq]);
482 checkApplyBC_ = p.get<
bool>(
"Check Apply BC");
484 applyBC_.resize(names.size());
485 for (std::size_t eq = 0; eq < names.size(); ++eq) {
486 applyBC_[eq] = PHX::MDField<const bool,Cell,NODE>(std::string(
"APPLY_BC_")+fieldMap_->find(names[eq])->second,dl);
487 this->addDependentField(applyBC_[eq]);
492 this->addEvaluatedField(*scatterHolder_);
494 if (p.isType<std::string>(
"Global Data Key"))
495 globalDataKey_ = p.get<std::string>(
"Global Data Key");
497 if (p.isType<
bool>(
"Preserve Diagonal"))
498 preserveDiagonal_ = p.get<
bool>(
"Preserve Diagonal");
500 this->setName(scatterName+
" Scatter Residual (Jacobian)");
529 epetraContainer_ = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(globalDataKey_));
531 if(epetraContainer_==Teuchos::null) {
533 Teuchos::RCP<LinearObjContainer> loc = Teuchos::rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(d.gedc->getDataObject(globalDataKey_),
true)->getGhostedLOC();
534 epetraContainer_ = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(loc,
true);
536 dirichletCounter_ = Teuchos::null;
540 Teuchos::RCP<GlobalEvaluationData> dataContainer = d.gedc->getDataObject(
"Dirichlet Counter");
541 Teuchos::RCP<EpetraLinearObjContainer> epetraContainer = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(dataContainer,
true);
543 dirichletCounter_ = epetraContainer->get_f();
544 TEUCHOS_ASSERT(!Teuchos::is_null(dirichletCounter_));
553 Kokkos::View<const int*, Kokkos::LayoutRight, PHX::Device> cLIDs, rLIDs;
555 bool useColumnIndexer = colGlobalIndexer_!=Teuchos::null;
556 const Teuchos::RCP<const panzer::GlobalIndexer>&
557 colGlobalIndexer = useColumnIndexer ? colGlobalIndexer_ : globalIndexer_;
560 std::string blockId = this->wda(workset).block_id;
561 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
563 Teuchos::RCP<const EpetraLinearObjContainer> epetraContainer = epetraContainer_;
564 TEUCHOS_ASSERT(epetraContainer!=Teuchos::null);
565 Teuchos::RCP<Epetra_Vector> r = epetraContainer->get_f();
566 Teuchos::RCP<Epetra_CrsMatrix> Jac = epetraContainer->get_A();
574 auto LIDs = globalIndexer_->getLIDs();
575 auto colLIDs = colGlobalIndexer->getLIDs();
576 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
577 auto colLIDs_h = Kokkos::create_mirror_view(colLIDs);
578 Kokkos::deep_copy(LIDs_h, LIDs);
579 Kokkos::deep_copy(colLIDs_h, colLIDs);
581 std::vector<
typename decltype(scatterFields_[0].get_static_view())::host_mirror_type> scatterFields_h;
582 for ( std::size_t i=0; i< scatterFields_.size(); ++i) {
583 scatterFields_h.push_back(Kokkos::create_mirror_view(scatterFields_[i].get_static_view()));
584 Kokkos::deep_copy(scatterFields_h[i], scatterFields_[i].get_static_view());
587 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
588 std::size_t cellLocalId = localCellIds[worksetCellIndex];
590 gidCount = colGlobalIndexer->getElementBlockGIDCount(blockId);
593 for(std::size_t fieldIndex = 0; fieldIndex < scatterFields_.size(); fieldIndex++) {
594 int fieldNum = fieldIds_[fieldIndex];
597 const std::pair<std::vector<int>,std::vector<int> > & indicePair
598 = globalIndexer_->getGIDFieldOffsets_closure(blockId,fieldNum, side_subcell_dim_, local_side_id_);
599 const std::vector<int> & elmtOffset = indicePair.first;
600 const std::vector<int> & basisIdMap = indicePair.second;
603 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
604 int offset = elmtOffset[basis];
605 int row = LIDs_h(cellLocalId, offset);
609 int basisId = basisIdMap[basis];
612 if (!applyBC_[fieldIndex](worksetCellIndex,basisId))
618 int * rowIndices = 0;
619 double * rowValues = 0;
621 Jac->ExtractMyRowView(row,numEntries,rowValues,rowIndices);
623 for(
int i=0;i<numEntries;i++) {
624 if(preserveDiagonal_) {
625 if(row!=rowIndices[i])
634 const ScalarT scatterField = (scatterFields_h[fieldIndex])(worksetCellIndex,basisId);
637 (*r)[row] = scatterField.val();
638 if(dirichletCounter_!=Teuchos::null) {
640 (*dirichletCounter_)[row] = 1.0;
644 std::vector<double> jacRow(scatterField.size(),0.0);
646 if(!preserveDiagonal_) {
647 int err = Jac->ReplaceMyValues(row, gidCount, scatterField.dx(),
648 &colLIDs_h(cellLocalId,0));
649 TEUCHOS_ASSERT(err==0);