11#ifndef __Panzer_GatherSolution_BlockedEpetra_impl_hpp__
12#define __Panzer_GatherSolution_BlockedEpetra_impl_hpp__
30#include "Phalanx_DataLayout.hpp"
33#include "Teuchos_Assert.hpp"
34#include "Teuchos_FancyOStream.hpp"
37#include "Thyra_ProductVectorBase.hpp"
38#include "Thyra_SpmdVectorBase.hpp"
45template<
typename TRAITS,
typename LO,
typename GO>
49 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
51 const Teuchos::ParameterList& p)
63 using vvstring = std::vector<std::vector<std::string>>;
67 RCP<const PureBasis> basis = input.
getBasis();
74 int numFields(names.size());
76 for (
int fd(0); fd < numFields; ++fd)
79 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
84 if (tangentFieldNames.size() > 0)
86 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size());
89 for (
int fd(0); fd < numFields; ++fd)
91 int numTangentFields(tangentFieldNames[fd].size());
93 for (
int i(0); i < numTangentFields; ++i)
96 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
104 string firstName(
"<none>");
106 firstName = names[0];
107 string n(
"GatherSolution (BlockedEpetra): " + firstName +
" (" +
108 print<EvalT>() +
")");
117template<
typename TRAITS,
typename LO,
typename GO>
122 typename TRAITS::SetupData ,
131 for (
int fd(0); fd < numFields; ++fd)
147template<
typename TRAITS,
typename LO,
typename GO>
152 typename TRAITS::PreEvalData d)
154 using std::logic_error;
157 using Teuchos::rcp_dynamic_cast;
158 using Teuchos::typeName;
170 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
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())
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 " <<
202template<
typename TRAITS,
typename LO,
typename GO>
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());
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);
280template<
typename TRAITS,
typename LO,
typename GO>
283 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
285 const Teuchos::ParameterList& p)
297 using vvstring = std::vector<std::vector<std::string>>;
301 RCP<const PureBasis> basis = input.
getBasis();
308 int numFields(names.size());
310 for (
int fd(0); fd < numFields; ++fd)
313 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
318 if (tangentFieldNames.size() > 0)
320 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size());
323 for (
int fd(0); fd < numFields; ++fd)
325 int numTangentFields(tangentFieldNames[fd].size());
327 for (
int i(0); i < numTangentFields; ++i)
330 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
338 string firstName(
"<none>");
340 firstName = names[0];
341 string n(
"GatherSolution Tangent (BlockedEpetra): " + firstName +
" (" +
342 print<EvalT>() +
")");
351template<
typename TRAITS,
typename LO,
typename GO>
355 typename TRAITS::SetupData ,
364 for (
int fd(0); fd < numFields; ++fd)
380template<
typename TRAITS,
typename LO,
typename GO>
384 typename TRAITS::PreEvalData d)
386 using std::logic_error;
389 using Teuchos::rcp_dynamic_cast;
390 using Teuchos::typeName;
402 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
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())
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 " <<
434template<
typename TRAITS,
typename LO,
typename GO>
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];
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];
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];
528 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
530 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[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)
545 for (
int i(0); i < numTangentFields; ++i)
546 field(cell, basis).fastAccessDx(i) =
559template<
typename TRAITS,
typename LO,
typename GO>
563 const std::vector<Teuchos::RCP<const GlobalIndexer>>&
565 const Teuchos::ParameterList& p)
579 RCP<const PureBasis> basis = input.
getBasis();
588 int numFields(names.size());
590 for (
int fd(0); fd < numFields; ++fd)
592 MDField<ScalarT, Cell, NODE> f(names[fd], basis->functional);
598 string firstName(
"<none>"), n(
"GatherSolution (BlockedEpetra");
600 firstName = names[0];
602 n +=
", No Sensitivities";
603 n +=
"): " + firstName +
" (" + print<EvalT>() +
")";
612template<
typename TRAITS,
typename LO,
typename GO>
617 typename TRAITS::SetupData ,
626 for (
int fd(0); fd < numFields; ++fd)
642template<
typename TRAITS,
typename LO,
typename GO>
647 typename TRAITS::PreEvalData d)
650 using std::logic_error;
653 using Teuchos::rcp_dynamic_cast;
654 using Teuchos::typeName;
672 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
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())
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 " \
693 "\" (" << post <<
"). A cast failed for " << ged <<
". Type is " <<
704template<
typename TRAITS,
typename LO,
typename GO>
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());
731 seedValue = workset.alpha;
733 seedValue = workset.beta;
737 TEUCHOS_ASSERT(
false);
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());
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);
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)