70 const Teuchos::ParameterList& p)
74 std::string scatterName = p.get<std::string>(
"Scatter Name");
76 Teuchos::rcp(
new PHX::Tag<ScalarT>(scatterName,Teuchos::rcp(
new PHX::MDALayout<Dummy>(0))));
79 const std::vector<std::string>& names =
80 *(p.get< Teuchos::RCP< std::vector<std::string> > >(
"Dependent Names"));
83 fieldMap_ = p.get< Teuchos::RCP< std::map<std::string,std::string> > >(
"Dependent Map");
86 scatterIC_ = p.isParameter(
"Scatter Initial Condition") ? p.get<
bool>(
"Scatter Initial Condition") :
false;
88 Teuchos::RCP<PHX::DataLayout> dl = (!
scatterIC_) ?
89 p.get< Teuchos::RCP<panzer::PureBasis> >(
"Basis")->functional :
90 p.get< Teuchos::RCP<const panzer::PureBasis> >(
"Basis")->functional ;
98 for (std::size_t eq = 0; eq < names.size(); ++eq) {
99 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
105 checkApplyBC_ = p.isParameter(
"Check Apply BC") ? p.get<
bool>(
"Check Apply BC") :
false;
108 for (std::size_t eq = 0; eq < names.size(); ++eq) {
109 applyBC_[eq] = PHX::MDField<const bool,Cell,NODE>(std::string(
"APPLY_BC_")+
fieldMap_->find(names[eq])->second,dl);
110 this->addDependentField(
applyBC_[eq]);
117 if (p.isType<std::string>(
"Global Data Key"))
120 this->setName(scatterName+
" Scatter Residual");
172 std::vector<GO> GIDs;
173 std::vector<LO> LIDs;
176 std::string blockId = this->
wda(workset).block_id;
177 const std::vector<std::size_t> & localCellIds = this->
wda(workset).cell_local_ids;
179 Teuchos::RCP<typename LOC::VectorType> r = (!
scatterIC_) ?
183 Teuchos::ArrayRCP<double> r_array = r->get1dViewNonConst();
194 for(std::size_t fieldIndex = 0; fieldIndex <
scatterFields_.size(); fieldIndex++) {
196 auto scatterFields_h = Kokkos::create_mirror_view(
scatterFields_[fieldIndex].get_static_view());
197 Kokkos::deep_copy(scatterFields_h,
scatterFields_[fieldIndex].get_static_view());
200 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
201 std::size_t cellLocalId = localCellIds[worksetCellIndex];
206 LIDs.resize(GIDs.size());
207 for(std::size_t i=0;i<GIDs.size();i++)
208 LIDs[i] = r->getMap()->getLocalElement(GIDs[i]);
212 const std::pair<std::vector<int>,std::vector<int> > & indicePair
214 const std::vector<int> & elmtOffset = indicePair.first;
215 const std::vector<int> & basisIdMap = indicePair.second;
218 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
219 int offset = elmtOffset[basis];
220 LO lid = LIDs[offset];
224 int basisId = basisIdMap[basis];
227 if (!
applyBC_[fieldIndex](worksetCellIndex,basisId))
230 r_array[lid] = scatterFields_h(worksetCellIndex,basisId);
237 const std::vector<int> & elmtOffset =
globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
240 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
241 int offset = elmtOffset[basis];
242 LO lid = LIDs[offset];
246 r_array[lid] = scatterFields_h(worksetCellIndex,basis);
264 const Teuchos::ParameterList& p)
268 std::string scatterName = p.get<std::string>(
"Scatter Name");
270 Teuchos::rcp(
new PHX::Tag<ScalarT>(scatterName,Teuchos::rcp(
new PHX::MDALayout<Dummy>(0))));
273 const std::vector<std::string>& names =
274 *(p.get< Teuchos::RCP< std::vector<std::string> > >(
"Dependent Names"));
277 fieldMap_ = p.get< Teuchos::RCP< std::map<std::string,std::string> > >(
"Dependent Map");
280 scatterIC_ = p.isParameter(
"Scatter Initial Condition") ? p.get<
bool>(
"Scatter Initial Condition") :
false;
282 Teuchos::RCP<PHX::DataLayout> dl = (!
scatterIC_) ?
283 p.get< Teuchos::RCP<panzer::PureBasis> >(
"Basis")->functional :
284 p.get< Teuchos::RCP<const panzer::PureBasis> >(
"Basis")->functional ;
292 for (std::size_t eq = 0; eq < names.size(); ++eq) {
293 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
299 checkApplyBC_ = p.isParameter(
"Check Apply BC") ? p.get<
bool>(
"Check Apply BC") :
false;
302 for (std::size_t eq = 0; eq < names.size(); ++eq) {
303 applyBC_[eq] = PHX::MDField<const bool,Cell,NODE>(std::string(
"APPLY_BC_")+
fieldMap_->find(names[eq])->second,dl);
304 this->addDependentField(
applyBC_[eq]);
311 if (p.isType<std::string>(
"Global Data Key"))
314 this->setName(scatterName+
" Scatter Tangent");
346 Teuchos::RCP<LinearObjContainer> loc = Teuchos::rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(d.gedc->getDataObject(
globalDataKey_),
true)->getGhostedLOC();
353 Teuchos::RCP<LOC> tpetraContainer
354 = Teuchos::rcp_dynamic_cast<LOC>(d.gedc->getDataObject(
"Dirichlet Counter"),
true);
361 using Teuchos::rcp_dynamic_cast;
364 std::vector<std::string> activeParameters =
365 rcp_dynamic_cast<ParameterList_GlobalEvaluationData>(d.gedc->getDataObject(
"PARAMETER_NAMES"))->getActiveParameters();
370 for(std::size_t i=0;i<activeParameters.size();i++) {
371 RCP<typename LOC::VectorType> vec =
372 rcp_dynamic_cast<LOC>(d.gedc->getDataObject(activeParameters[i]),
true)->get_f();
373 Teuchos::ArrayRCP<double> vec_array = vec->get1dViewNonConst();
383 std::vector<GO> GIDs;
384 std::vector<LO> LIDs;
387 std::string blockId = this->
wda(workset).block_id;
388 const std::vector<std::size_t> & localCellIds = this->
wda(workset).cell_local_ids;
390 Teuchos::RCP<typename LOC::VectorType> r = (!
scatterIC_) ?
394 Teuchos::ArrayRCP<double> r_array = r->get1dViewNonConst();
404 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
405 std::size_t cellLocalId = localCellIds[worksetCellIndex];
410 LIDs.resize(GIDs.size());
411 for(std::size_t i=0;i<GIDs.size();i++)
412 LIDs[i] = r->getMap()->getLocalElement(GIDs[i]);
415 for(std::size_t fieldIndex = 0; fieldIndex <
scatterFields_.size(); fieldIndex++) {
420 const std::pair<std::vector<int>,std::vector<int> > & indicePair
422 const std::vector<int> & elmtOffset = indicePair.first;
423 const std::vector<int> & basisIdMap = indicePair.second;
426 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
427 int offset = elmtOffset[basis];
428 LO lid = LIDs[offset];
432 int basisId = basisIdMap[basis];
435 if (!
applyBC_[fieldIndex](worksetCellIndex,basisId))
446 for(
int d=0;d<value.size();d++) {
455 const std::vector<int> & elmtOffset =
globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
458 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
459 int offset = elmtOffset[basis];
460 LO lid = LIDs[offset];
472 for(
int d=0;d<value.size();d++) {
491 const Teuchos::ParameterList& p)
495 std::string scatterName = p.get<std::string>(
"Scatter Name");
497 Teuchos::rcp(
new PHX::Tag<ScalarT>(scatterName,Teuchos::rcp(
new PHX::MDALayout<Dummy>(0))));
500 const std::vector<std::string>& names =
501 *(p.get< Teuchos::RCP< std::vector<std::string> > >(
"Dependent Names"));
504 fieldMap_ = p.get< Teuchos::RCP< std::map<std::string,std::string> > >(
"Dependent Map");
506 Teuchos::RCP<PHX::DataLayout> dl =
507 p.get< Teuchos::RCP<panzer::PureBasis> >(
"Basis")->functional;
514 for (std::size_t eq = 0; eq < names.size(); ++eq) {
515 scatterFields_[eq] = PHX::MDField<const ScalarT,Cell,NODE>(names[eq],dl);
524 for (std::size_t eq = 0; eq < names.size(); ++eq) {
525 applyBC_[eq] = PHX::MDField<const bool,Cell,NODE>(std::string(
"APPLY_BC_")+
fieldMap_->find(names[eq])->second,dl);
526 this->addDependentField(
applyBC_[eq]);
533 if (p.isType<std::string>(
"Global Data Key"))
536 this->setName(scatterName+
" Scatter Residual (Jacobian)");
588 std::vector<GO> GIDs;
591 std::string blockId = this->
wda(workset).block_id;
592 const std::vector<std::size_t> & localCellIds = this->
wda(workset).cell_local_ids;
597 Teuchos::ArrayRCP<double> r_array = r->get1dViewNonConst();
607 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
608 Kokkos::deep_copy(LIDs_h, LIDs);
610 for(std::size_t fieldIndex = 0; fieldIndex <
scatterFields_.size(); fieldIndex++) {
612 auto scatterFields_h = Kokkos::create_mirror_view(
scatterFields_[fieldIndex].get_static_view());
613 Kokkos::deep_copy(scatterFields_h,
scatterFields_[fieldIndex].get_static_view());
614 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
615 std::size_t cellLocalId = localCellIds[worksetCellIndex];
620 const std::pair<std::vector<int>,std::vector<int> > & indicePair
622 const std::vector<int> & elmtOffset = indicePair.first;
623 const std::vector<int> & basisIdMap = indicePair.second;
626 for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
627 int offset = elmtOffset[basis];
628 int lid = LIDs_h(cellLocalId, offset);
632 int basisId = basisIdMap[basis];
635 if (!
applyBC_[fieldIndex](worksetCellIndex,basisId))
640 std::size_t sz = Jac->getNumEntriesInLocalRow(lid);
641 std::size_t numEntries = 0;
642 typename LOC::CrsMatrixType::nonconst_local_inds_host_view_type rowIndices(
"indices", sz);
643 typename LOC::CrsMatrixType::nonconst_values_host_view_type rowValues(
"values", sz);
646 Jac->getLocalRowCopy(lid,rowIndices,rowValues,numEntries);
648 for(std::size_t i=0;i<numEntries;i++)
651 Jac->replaceLocalValues(lid,rowIndices,rowValues);
654 GO gid = GIDs[offset];
655 const ScalarT scatterField = scatterFields_h(worksetCellIndex,basisId);
657 r_array[lid] = scatterField.val();
661 std::vector<double> jacRow(scatterField.size(),0.0);
663 for(
int sensIndex=0;sensIndex<scatterField.size();++sensIndex)
664 jacRow[sensIndex] = scatterField.fastAccessDx(sensIndex);
665 TEUCHOS_ASSERT(jacRow.size()==GIDs.size());
667 Jac->replaceGlobalValues(gid, GIDs, jacRow);