42 const Teuchos::RCP<const panzer::GlobalIndexer> & ,
43 const Teuchos::ParameterList& p)
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;
71 for (std::size_t eq = 0; eq < names.size(); ++eq) {
72 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
78 checkApplyBC_ = p.isParameter(
"Check Apply BC") ? p.get<
bool>(
"Check Apply BC") :
false;
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]);
90 if (p.isType<std::string>(
"Global Data Key"))
93 this->setName(scatterName+
" Scatter Residual");
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();
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++) {
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
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);
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);
215 (*dirichletCounter_)[lid] = 1.0;
230 const Teuchos::RCP<const panzer::GlobalIndexer> & ,
231 const Teuchos::ParameterList& p)
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;
259 for (std::size_t eq = 0; eq < names.size(); ++eq) {
260 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
266 checkApplyBC_ = p.isParameter(
"Check Apply BC") ? p.get<
bool>(
"Check Apply BC") :
false;
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]);
278 if (p.isType<std::string>(
"Global Data Key"))
281 this->setName(scatterName+
" Scatter Tangent");
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);
320 Teuchos::RCP<EpetraLinearObjContainer> epetraContainer
321 = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(d.gedc->getDataObject(
"Dirichlet Counter"),
true);
328 using Teuchos::rcp_dynamic_cast;
331 std::vector<std::string> activeParameters =
332 rcp_dynamic_cast<ParameterList_GlobalEvaluationData>(d.gedc->getDataObject(
"PARAMETER_NAMES"))->getActiveParameters();
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();
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();
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++) {
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
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);
402 for(
int d=0;d<value.size();d++) {
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);
429 for(
int d=0;d<value.size();d++) {
435 (*dirichletCounter_)[lid] = 1.0;
449 const Teuchos::RCP<const panzer::GlobalIndexer> & cIndexer,
450 const Teuchos::ParameterList& p)
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;
475 for (std::size_t eq = 0; eq < names.size(); ++eq) {
476 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
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]);
494 if (p.isType<std::string>(
"Global Data Key"))
497 if (p.isType<
bool>(
"Preserve Diagonal"))
500 this->setName(scatterName+
" Scatter Residual (Jacobian)");
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);
540 Teuchos::RCP<GlobalEvaluationData> dataContainer = d.gedc->getDataObject(
"Dirichlet Counter");
541 Teuchos::RCP<EpetraLinearObjContainer> epetraContainer = Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(dataContainer,
true);
553 Kokkos::View<const int*, Kokkos::LayoutRight, PHX::Device> cLIDs, rLIDs;
556 const Teuchos::RCP<const panzer::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();
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;
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++) {
597 const std::pair<std::vector<int>,std::vector<int> > & indicePair
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++) {
625 if(row!=rowIndices[i])
634 const ScalarT scatterField = (scatterFields_h[fieldIndex])(worksetCellIndex,basisId);
637 (*r)[row] = scatterField.val();
640 (*dirichletCounter_)[row] = 1.0;
644 std::vector<double> jacRow(scatterField.size(),0.0);
647 int err = Jac->ReplaceMyValues(row, gidCount, scatterField.dx(),
648 &colLIDs_h(cellLocalId,0));
649 TEUCHOS_ASSERT(err==0);