43#ifndef __Panzer_GatherSolution_BlockedEpetra_impl_hpp__
44#define __Panzer_GatherSolution_BlockedEpetra_impl_hpp__
62#include "Phalanx_DataLayout.hpp"
65#include "Teuchos_Assert.hpp"
66#include "Teuchos_FancyOStream.hpp"
69#include "Thyra_ProductVectorBase.hpp"
70#include "Thyra_SpmdVectorBase.hpp"
77template<
typename TRAITS,
typename LO,
typename GO>
81 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
83 const Teuchos::ParameterList& p)
95 using vvstring = std::vector<std::vector<std::string>>;
99 RCP<const PureBasis> basis = input.
getBasis();
106 int numFields(names.size());
108 for (
int fd(0); fd < numFields; ++fd)
111 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
116 if (tangentFieldNames.size() > 0)
118 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size());
121 for (
int fd(0); fd < numFields; ++fd)
123 int numTangentFields(tangentFieldNames[fd].size());
125 for (
int i(0); i < numTangentFields; ++i)
128 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
136 string firstName(
"<none>");
138 firstName = names[0];
139 string n(
"GatherSolution (BlockedEpetra): " + firstName +
" (" +
140 print<EvalT>() +
")");
149template<
typename TRAITS,
typename LO,
typename GO>
154 typename TRAITS::SetupData ,
163 for (
int fd(0); fd < numFields; ++fd)
179template<
typename TRAITS,
typename LO,
typename GO>
184 typename TRAITS::PreEvalData d)
186 using std::logic_error;
189 using Teuchos::rcp_dynamic_cast;
190 using Teuchos::typeName;
202 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
211 auto roGed = rcp_dynamic_cast<const BVROGED>(ged);
212 auto beLoc = rcp_dynamic_cast<const BELOC>(ged);
213 if (not roGed.is_null())
214 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
215 else if (not beLoc.is_null())
218 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_dxdt());
220 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_x());
221 TEUCHOS_TEST_FOR_EXCEPTION(
x_.is_null(), logic_error,
"Gather " \
222 "Residual: Can't find the x_ vector in GEDC \"" <<
globalDataKey_ <<
223 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
234template<
typename TRAITS,
typename LO,
typename GO>
239 typename TRAITS::EvalData workset)
245 using Teuchos::ArrayRCP;
246 using Teuchos::ptrFromRef;
248 using Teuchos::rcp_dynamic_cast;
250 using Thyra::SpmdVectorBase;
254 string blockId(this->
wda(workset).block_id);
255 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
256 int numFields(
gatherFields_.size()), numCells(localCellIds.size());
259 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
261 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
262 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
268 ArrayRCP<const double> x;
269 Teuchos::RCP<const ReadOnlyVector_GlobalEvaluationData> xEvRoGed;
271 if(not
x_.is_null()) {
272 rcp_dynamic_cast<SpmdVectorBase<double>>(
x_->
273 getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
276 xEvRoGed =
xBvRoGed_->getGEDBlock(indexerId);
279 auto subRowIndexer =
indexers_[indexerId];
280 const vector<int>& elmtOffset =
281 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
282 int numBases(elmtOffset.size());
284 auto LIDs = subRowIndexer->getLIDs();
285 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
286 Kokkos::deep_copy(LIDs_h, LIDs);
289 for (
int cell(0); cell < numCells; ++cell)
291 LO cellLocalId = localCellIds[cell];
294 for (
int basis(0); basis < numBases; ++basis)
296 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
298 field_h(cell, basis) = (*xEvRoGed)[lid];
300 field_h(cell, basis) = x[lid];
303 Kokkos::deep_copy(field.get_static_view(), field_h);
312template<
typename TRAITS,
typename LO,
typename GO>
315 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
317 const Teuchos::ParameterList& p)
329 using vvstring = std::vector<std::vector<std::string>>;
333 RCP<const PureBasis> basis = input.
getBasis();
340 int numFields(names.size());
342 for (
int fd(0); fd < numFields; ++fd)
345 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
350 if (tangentFieldNames.size() > 0)
352 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size());
355 for (
int fd(0); fd < numFields; ++fd)
357 int numTangentFields(tangentFieldNames[fd].size());
359 for (
int i(0); i < numTangentFields; ++i)
362 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
370 string firstName(
"<none>");
372 firstName = names[0];
373 string n(
"GatherSolution Tangent (BlockedEpetra): " + firstName +
" (" +
374 print<EvalT>() +
")");
383template<
typename TRAITS,
typename LO,
typename GO>
387 typename TRAITS::SetupData ,
396 for (
int fd(0); fd < numFields; ++fd)
412template<
typename TRAITS,
typename LO,
typename GO>
416 typename TRAITS::PreEvalData d)
418 using std::logic_error;
421 using Teuchos::rcp_dynamic_cast;
422 using Teuchos::typeName;
434 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
443 auto roGed = rcp_dynamic_cast<const BVROGED>(ged);
444 auto beLoc = rcp_dynamic_cast<const BELOC>(ged);
445 if (not roGed.is_null())
446 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
447 else if (not beLoc.is_null())
450 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_dxdt());
452 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_x());
453 TEUCHOS_TEST_FOR_EXCEPTION(
x_.is_null(), logic_error,
"Gather " \
454 "Tangent: Can't find the x_ vector in GEDC \"" <<
globalDataKey_ <<
455 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
466template<
typename TRAITS,
typename LO,
typename GO>
470 typename TRAITS::EvalData workset)
477 using Teuchos::ArrayRCP;
478 using Teuchos::ptrFromRef;
480 using Teuchos::rcp_dynamic_cast;
482 using Thyra::SpmdVectorBase;
486 vector<pair<int, GO>> GIDs;
487 string blockId(this->
wda(workset).block_id);
488 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
489 int numFields(
gatherFields_.size()), numCells(localCellIds.size());
494 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
496 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
501 auto xEvRoGed =
xBvRoGed_->getGEDBlock(indexerId);
502 auto subRowIndexer =
indexers_[indexerId];
503 const vector<int>& elmtOffset =
504 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
505 int numBases(elmtOffset.size());
508 for (
int cell(0); cell < numCells; ++cell)
510 LO cellLocalId = localCellIds[cell];
511 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
514 for (
int basis(0); basis < numBases; ++basis)
516 int offset(elmtOffset[basis]), lid(LIDs[offset]);
517 field(cell, basis) = (*xEvRoGed)[lid];
525 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
527 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
532 ArrayRCP<const double> x;
533 rcp_dynamic_cast<SpmdVectorBase<double>>(
x_->
534 getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
535 auto subRowIndexer =
indexers_[indexerId];
536 const vector<int>& elmtOffset =
537 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
538 int numBases(elmtOffset.size());
541 for (
int cell(0); cell < numCells; ++cell)
543 LO cellLocalId = localCellIds[cell];
544 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
547 for (
int basis(0); basis < numBases; ++basis)
549 int offset(elmtOffset[basis]), lid(LIDs[offset]);
550 field(cell, basis) = x[lid];
560 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
562 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
565 auto subRowIndexer =
indexers_[indexerId];
566 const vector<int>& elmtOffset =
567 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
568 int numBases(elmtOffset.size());
571 for (
int cell(0); cell < numCells; ++cell)
574 for (
int basis(0); basis < numBases; ++basis)
577 for (
int i(0); i < numTangentFields; ++i)
578 field(cell, basis).fastAccessDx(i) =
591template<
typename TRAITS,
typename LO,
typename GO>
595 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
597 const Teuchos::ParameterList& p)
611 RCP<const PureBasis> basis = input.
getBasis();
620 int numFields(names.size());
622 for (
int fd(0); fd < numFields; ++fd)
624 MDField<ScalarT, Cell, NODE> f(names[fd], basis->functional);
630 string firstName(
"<none>"), n(
"GatherSolution (BlockedEpetra");
632 firstName = names[0];
634 n +=
", No Sensitivities";
635 n +=
"): " + firstName +
" (" + print<EvalT>() +
")";
644template<
typename TRAITS,
typename LO,
typename GO>
649 typename TRAITS::SetupData ,
658 for (
int fd(0); fd < numFields; ++fd)
674template<
typename TRAITS,
typename LO,
typename GO>
679 typename TRAITS::PreEvalData d)
682 using std::logic_error;
685 using Teuchos::rcp_dynamic_cast;
686 using Teuchos::typeName;
704 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
713 auto roGed = rcp_dynamic_cast<const BVROGED>(ged);
714 auto beLoc = rcp_dynamic_cast<const BELOC>(ged);
715 if (not roGed.is_null())
716 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
717 else if (not beLoc.is_null())
720 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_dxdt());
722 x_ = rcp_dynamic_cast<ProductVectorBase<double>>(beLoc->get_x());
723 TEUCHOS_TEST_FOR_EXCEPTION(
x_.is_null(), logic_error,
"Gather " \
725 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
736template<
typename TRAITS,
typename LO,
typename GO>
741 typename TRAITS::EvalData workset)
747 using Teuchos::ArrayRCP;
748 using Teuchos::ptrFromRef;
750 using Teuchos::rcp_dynamic_cast;
752 using Thyra::SpmdVectorBase;
756 string blockId(this->
wda(workset).block_id);
757 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
758 int numFields(
gatherFields_.size()), numCells(localCellIds.size());
763 seedValue = workset.alpha;
765 seedValue = workset.beta;
769 TEUCHOS_ASSERT(
false);
778 vector<int> blockOffsets;
780 int numDerivs(blockOffsets[blockOffsets.size() - 1]);
787 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
789 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
790 auto field_h = Kokkos::create_mirror_view(field.get_view());
795 ArrayRCP<const double> x;
796 Teuchos::RCP<const ReadOnlyVector_GlobalEvaluationData> xEvRoGed;
797 if(not
x_.is_null()) {
798 rcp_dynamic_cast<SpmdVectorBase<double>>(
x_->getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
800 xEvRoGed =
xBvRoGed_->getGEDBlock(indexerId);
803 auto subRowIndexer =
indexers_[indexerId];
804 const vector<int>& elmtOffset =
805 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
806 int startBlkOffset(blockOffsets[indexerId]), numBases(elmtOffset.size());
808 auto LIDs = subRowIndexer->getLIDs();
809 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
810 Kokkos::deep_copy(LIDs_h, LIDs);
813 for (
int cell(0); cell < numCells; ++cell)
815 LO cellLocalId = localCellIds[cell];
818 for (
int basis(0); basis < numBases; ++basis)
821 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
823 field_h(cell, basis) =
ScalarT(numDerivs, (*xEvRoGed)[lid]);
825 field_h(cell, basis) =
ScalarT(numDerivs, x[lid]);
827 field_h(cell, basis).fastAccessDx(startBlkOffset + offset) = seedValue;
830 Kokkos::deep_copy(field.get_static_view(), field_h);
This class encapsulates the needs of a gather operation to do a halo exchange for blocked vectors.
WorksetDetailsAccessor wda
std::string sensitivitiesName_
Sets which gather operations have sensitivities.
bool applySensitivities_
Used by evaluateFields() to turn on/off a certain set of sensitivities.
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we should be working with or .
std::vector< int > subFieldIds_
Sub-field IDs, which need to be mapped.
std::vector< int > indexerIds_
The block index into indexers_.
std::vector< std::string > indexerNames_
A list of the names of the fields to be gathered.
std::vector< Teuchos::RCP< const GlobalIndexer > > indexers_
These map the local (field, element, basis) triplet to a global ID for scattering.
Teuchos::RCP< panzer::BlockedVector_ReadOnly_GlobalEvaluationData > xBvRoGed_
The GlobalEvaluationData containing both the owned and ghosted solution vectors.
int gatherSeedIndex_
Which gather seed in the workset to use.
bool disableSensitivities_
Flag to disable sensitivities absolutely.
panzer::Traits::Jacobian::ScalarT ScalarT
The scalar type.
void preEvaluate(typename TRAITS::PreEvalData d)
Pre-Evaluate: Sets the solution vector.
Teuchos::RCP< Thyra::ProductVectorBase< double > > x_
The solution vector.
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
void preEvaluate(typename TRAITS::PreEvalData d)
Pre-Evaluate: Sets the solution vector.
std::vector< std::string > indexerNames_
A list of the names of the fields to be gathered.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we should be working with or .
bool hasTangentFields_
A flag indicating whether or not we have tangent fields.
std::vector< std::vector< PHX::MDField< const ScalarT, Cell, NODE > > > tangentFields_
Fields for storing the tangent components of the solution vector .
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
Teuchos::RCP< panzer::BlockedVector_ReadOnly_GlobalEvaluationData > xBvRoGed_
The GlobalEvaluationData containing both the owned and ghosted solution vectors.
std::vector< int > subFieldIds_
Sub-field IDs, which need to be mapped.
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
std::vector< Teuchos::RCP< const GlobalIndexer > > indexers_
These map the local (field, element, basis) triplet to a global ID for scattering.
std::vector< int > indexerIds_
The block index into indexers_.
Teuchos::RCP< Thyra::ProductVectorBase< double > > x_
The solution vector.
bool hasTangentFields_
A flag indicating whether or not we have tangent fields.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we should be working with or .
Teuchos::RCP< Thyra::ProductVectorBase< double > > x_
The solution vector.
std::vector< int > subFieldIds_
Sub-field IDs, which need to be mapped.
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
std::vector< int > indexerIds_
The block index into indexers_.
std::vector< std::string > indexerNames_
A list of the names of the fields to be gathered.
Teuchos::RCP< panzer::BlockedVector_ReadOnly_GlobalEvaluationData > xBvRoGed_
The GlobalEvaluationData containing both the owned and ghosted solution vectors.
std::vector< std::vector< PHX::MDField< const ScalarT, Cell, NODE > > > tangentFields_
Fields for storing the tangent components of the solution vector .
std::vector< Teuchos::RCP< const GlobalIndexer > > indexers_
These map the local (field, element, basis) triplet to a global ID for scattering.
Gathers solution values from the Newton solution vector into the nodal fields of the field manager.
void evaluateFields(typename TRAITS::EvalData d)
Evaluate Fields.
GatherSolution_BlockedEpetra(const Teuchos::ParameterList &p)
Constructor.
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &fm)
Post-Registration Setup.
Description and data layouts associated with a particular basis.
void computeBlockOffsets(const std::string &blockId, const std::vector< Teuchos::RCP< GlobalIndexer > > &ugis, std::vector< int > &blockOffsets)
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< const GlobalIndexer > > &ugis)