49 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
51 const Teuchos::ParameterList& p)
54 hasTangentFields_(false)
63 using vvstring = std::vector<std::vector<std::string>>;
67 RCP<const PureBasis> basis = input.
getBasis();
79 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
80 this->addEvaluatedField(gatherFields_[fd]);
84 if (tangentFieldNames.size() > 0)
86 TEUCHOS_ASSERT(gatherFields_.size() == tangentFieldNames.size());
87 hasTangentFields_ =
true;
91 int numTangentFields(tangentFieldNames[fd].size());
92 tangentFields_[fd].resize(numTangentFields);
93 for (
int i(0); i < numTangentFields; ++i)
95 tangentFields_[fd][i] =
96 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
98 this->addDependentField(tangentFields_[fd][i]);
104 string firstName(
"<none>");
106 firstName = names[0];
107 string n(
"GatherSolution (BlockedEpetra): " + firstName +
" (" +
108 print<EvalT>() +
")");
150GatherSolution_BlockedEpetra<panzer::Traits::Residual, TRAITS, LO, GO>::
152 typename TRAITS::PreEvalData d)
154 using std::logic_error;
157 using Teuchos::rcp_dynamic_cast;
158 using Teuchos::typeName;
166 string post(useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X");
167 if (d.gedc->containsDataObject(globalDataKey_ + post))
169 ged = d.gedc->getDataObject(globalDataKey_ + post);
170 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
176 ged = d.gedc->getDataObject(globalDataKey_);
179 auto roGed = rcp_dynamic_cast<const BVROGED>(ged);
180 auto beLoc = rcp_dynamic_cast<const BELOC>(ged);
181 if (not roGed.is_null())
182 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
183 else if (not beLoc.is_null())
185 if (useTimeDerivativeSolutionVector_)
186 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_dxdt());
188 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_x());
189 TEUCHOS_TEST_FOR_EXCEPTION(x_.is_null(), logic_error,
"Gather " \
190 "Residual: Can't find the x_ vector in GEDC \"" << globalDataKey_ <<
191 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
207 typename TRAITS::EvalData workset)
213 using Teuchos::ArrayRCP;
214 using Teuchos::ptrFromRef;
216 using Teuchos::rcp_dynamic_cast;
218 using Thyra::SpmdVectorBase;
222 string blockId(this->wda(workset).block_id);
223 const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
224 int numFields(gatherFields_.size()), numCells(localCellIds.size());
227 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
229 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
230 auto field_h = Kokkos::create_mirror_view(
field.get_static_view());
232 int indexerId(indexerIds_[fieldInd]),
233 subFieldNum(subFieldIds_[fieldInd]);
236 ArrayRCP<const double> x;
237 Teuchos::RCP<const ReadOnlyVector_GlobalEvaluationData> xEvRoGed;
239 if(not x_.is_null()) {
240 rcp_dynamic_cast<SpmdVectorBase<double>>(x_->
241 getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
244 xEvRoGed = xBvRoGed_->getGEDBlock(indexerId);
247 auto subRowIndexer = indexers_[indexerId];
248 const vector<int>& elmtOffset =
249 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
250 int numBases(elmtOffset.size());
252 auto LIDs = subRowIndexer->getLIDs();
253 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
254 Kokkos::deep_copy(LIDs_h, LIDs);
257 for (
int cell(0); cell < numCells; ++cell)
259 LO cellLocalId = localCellIds[cell];
262 for (
int basis(0); basis < numBases; ++basis)
264 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
266 field_h(cell, basis) = (*xEvRoGed)[lid];
268 field_h(cell, basis) = x[lid];
271 Kokkos::deep_copy(
field.get_static_view(), field_h);
283 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
285 const Teuchos::ParameterList& p)
288 hasTangentFields_(false)
297 using vvstring = std::vector<std::vector<std::string>>;
301 RCP<const PureBasis> basis = input.
getBasis();
313 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
314 this->addEvaluatedField(gatherFields_[fd]);
318 if (tangentFieldNames.size() > 0)
320 TEUCHOS_ASSERT(gatherFields_.size() == tangentFieldNames.size());
321 hasTangentFields_ =
true;
325 int numTangentFields(tangentFieldNames[fd].size());
326 tangentFields_[fd].resize(numTangentFields);
327 for (
int i(0); i < numTangentFields; ++i)
329 tangentFields_[fd][i] =
330 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
332 this->addDependentField(tangentFields_[fd][i]);
338 string firstName(
"<none>");
340 firstName = names[0];
341 string n(
"GatherSolution Tangent (BlockedEpetra): " + firstName +
" (" +
342 print<EvalT>() +
")");
384 typename TRAITS::PreEvalData d)
386 using std::logic_error;
389 using Teuchos::rcp_dynamic_cast;
390 using Teuchos::typeName;
398 string post(useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X");
399 if (d.gedc->containsDataObject(globalDataKey_ + post))
401 ged = d.gedc->getDataObject(globalDataKey_ + post);
402 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
408 ged = d.gedc->getDataObject(globalDataKey_);
411 auto roGed = rcp_dynamic_cast<const BVROGED>(ged);
412 auto beLoc = rcp_dynamic_cast<const BELOC>(ged);
413 if (not roGed.is_null())
414 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
415 else if (not beLoc.is_null())
417 if (useTimeDerivativeSolutionVector_)
418 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_dxdt());
420 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_x());
421 TEUCHOS_TEST_FOR_EXCEPTION(x_.is_null(), logic_error,
"Gather " \
422 "Tangent: Can't find the x_ vector in GEDC \"" << globalDataKey_ <<
423 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
438 typename TRAITS::EvalData workset)
445 using Teuchos::ArrayRCP;
446 using Teuchos::ptrFromRef;
448 using Teuchos::rcp_dynamic_cast;
450 using Thyra::SpmdVectorBase;
454 vector<pair<int, GO>> GIDs;
455 string blockId(this->wda(workset).block_id);
456 const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
457 int numFields(gatherFields_.size()), numCells(localCellIds.size());
462 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
464 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
465 int indexerId(indexerIds_[fieldInd]),
466 subFieldNum(subFieldIds_[fieldInd]);
469 auto xEvRoGed = xBvRoGed_->getGEDBlock(indexerId);
470 auto subRowIndexer = indexers_[indexerId];
471 const vector<int>& elmtOffset =
472 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
473 int numBases(elmtOffset.size());
476 for (
int cell(0); cell < numCells; ++cell)
478 LO cellLocalId = localCellIds[cell];
479 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
482 for (
int basis(0); basis < numBases; ++basis)
484 int offset(elmtOffset[basis]), lid(LIDs[offset]);
485 field(cell, basis) = (*xEvRoGed)[lid];
493 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
495 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
496 int indexerId(indexerIds_[fieldInd]),
497 subFieldNum(subFieldIds_[fieldInd]);
500 ArrayRCP<const double> x;
501 rcp_dynamic_cast<SpmdVectorBase<double>>(x_->
502 getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
503 auto subRowIndexer = indexers_[indexerId];
504 const vector<int>& elmtOffset =
505 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
506 int numBases(elmtOffset.size());
509 for (
int cell(0); cell < numCells; ++cell)
511 LO cellLocalId = localCellIds[cell];
512 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
515 for (
int basis(0); basis < numBases; ++basis)
517 int offset(elmtOffset[basis]), lid(LIDs[offset]);
518 field(cell, basis) = x[lid];
525 if (hasTangentFields_)
528 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
530 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
531 int indexerId(indexerIds_[fieldInd]),
532 subFieldNum(subFieldIds_[fieldInd]);
533 auto subRowIndexer = indexers_[indexerId];
534 const vector<int>& elmtOffset =
535 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
536 int numBases(elmtOffset.size());
539 for (
int cell(0); cell < numCells; ++cell)
542 for (
int basis(0); basis < numBases; ++basis)
544 int numTangentFields(tangentFields_[fieldInd].size());
545 for (
int i(0); i < numTangentFields; ++i)
546 field(cell, basis).fastAccessDx(i) =
547 tangentFields_[fieldInd][i](cell, basis).val();
563 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
565 const Teuchos::ParameterList& p)
579 RCP<const PureBasis> basis = input.
getBasis();
592 MDField<ScalarT, Cell, NODE> f(names[fd], basis->functional);
593 gatherFields_[fd] = f;
594 this->addEvaluatedField(gatherFields_[fd]);
598 string firstName(
"<none>"), n(
"GatherSolution (BlockedEpetra");
600 firstName = names[0];
601 if (disableSensitivities_)
602 n +=
", No Sensitivities";
603 n +=
"): " + firstName +
" (" + print<EvalT>() +
")";
645GatherSolution_BlockedEpetra<panzer::Traits::Jacobian, TRAITS, LO, GO>::
647 typename TRAITS::PreEvalData d)
650 using std::logic_error;
653 using Teuchos::rcp_dynamic_cast;
654 using Teuchos::typeName;
661 applySensitivities_ =
false;
662 if ((not disableSensitivities_ ) and
663 (d.first_sensitivities_name == sensitivitiesName_))
664 applySensitivities_ =
true;
668 string post(useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X");
669 if (d.gedc->containsDataObject(globalDataKey_ + post))
671 ged = d.gedc->getDataObject(globalDataKey_ + post);
672 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
678 ged = d.gedc->getDataObject(globalDataKey_);
681 auto roGed = rcp_dynamic_cast<const BVROGED>(ged);
682 auto beLoc = rcp_dynamic_cast<const BELOC>(ged);
683 if (not roGed.is_null())
684 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
685 else if (not beLoc.is_null())
687 if (useTimeDerivativeSolutionVector_)
688 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_dxdt());
690 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_x());
691 TEUCHOS_TEST_FOR_EXCEPTION(x_.is_null(), logic_error,
"Gather " \
692 "Jacobian: Can't find x vector in GEDC \"" << globalDataKey_ <<
693 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
709 typename TRAITS::EvalData workset)
715 using Teuchos::ArrayRCP;
716 using Teuchos::ptrFromRef;
718 using Teuchos::rcp_dynamic_cast;
720 using Thyra::SpmdVectorBase;
724 string blockId(this->wda(workset).block_id);
725 const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
726 int numFields(gatherFields_.size()), numCells(localCellIds.size());
728 if (applySensitivities_)
730 if ((useTimeDerivativeSolutionVector_) and (gatherSeedIndex_ < 0))
731 seedValue = workset.alpha;
732 else if (gatherSeedIndex_ < 0)
733 seedValue = workset.beta;
734 else if (not useTimeDerivativeSolutionVector_)
735 seedValue = workset.gather_seeds[gatherSeedIndex_];
737 TEUCHOS_ASSERT(
false);
743 if (not applySensitivities_)
746 vector<int> blockOffsets;
748 int numDerivs(blockOffsets[blockOffsets.size() - 1]);
755 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
757 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
758 auto field_h = Kokkos::create_mirror_view(
field.get_view());
760 int indexerId(indexerIds_[fieldInd]), subFieldNum(subFieldIds_[fieldInd]);
763 ArrayRCP<const double> x;
764 Teuchos::RCP<const ReadOnlyVector_GlobalEvaluationData> xEvRoGed;
765 if(not x_.is_null()) {
766 rcp_dynamic_cast<SpmdVectorBase<double>>(x_->getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
768 xEvRoGed = xBvRoGed_->getGEDBlock(indexerId);
771 auto subRowIndexer = indexers_[indexerId];
772 const vector<int>& elmtOffset =
773 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
774 int startBlkOffset(blockOffsets[indexerId]), numBases(elmtOffset.size());
776 auto LIDs = subRowIndexer->getLIDs();
777 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
778 Kokkos::deep_copy(LIDs_h, LIDs);
781 for (
int cell(0); cell < numCells; ++cell)
783 LO cellLocalId = localCellIds[cell];
786 for (
int basis(0); basis < numBases; ++basis)
789 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
791 field_h(cell, basis) =
ScalarT(numDerivs, (*xEvRoGed)[lid]);
793 field_h(cell, basis) =
ScalarT(numDerivs, x[lid]);
795 field_h(cell, basis).fastAccessDx(startBlkOffset + offset) = seedValue;
798 Kokkos::deep_copy(
field.get_static_view(), field_h);