43#ifndef __Panzer_GatherSolution_Epetra_impl_hpp__
44#define __Panzer_GatherSolution_Epetra_impl_hpp__
53#include "Epetra_Vector.h"
65#include "Teuchos_Assert.hpp"
68#include "Thyra_SpmdVectorBase.hpp"
75template<
typename TRAITS,
typename LO,
typename GO>
78 const Teuchos::RCP<const panzer::GlobalIndexer>& indexer,
79 const Teuchos::ParameterList& p)
91 using vvstring = std::vector<std::vector<std::string>>;
95 RCP<const PureBasis> basis = input.
getBasis();
102 int numFields(names.size());
104 for (
int fd(0); fd < numFields; ++fd)
107 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
112 if (tangentFieldNames.size() > 0)
114 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size())
117 for (
int fd(0); fd < numFields; ++fd)
119 int numTangentFields(tangentFieldNames[fd].size());
121 for (
int i(0); i < numTangentFields; ++i)
124 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
132 string firstName(
"<none>");
134 firstName = names[0];
135 string n(
"GatherSolution (Epetra): " + firstName +
" (Residual)");
144template<
typename TRAITS,
typename LO,
typename GO>
148 typename TRAITS::SetupData ,
151 using std::logic_error;
157 for (
int fd(0); fd < numFields; ++fd)
164 TEUCHOS_TEST_FOR_EXCEPTION(
fieldIds_[fd] == -1, logic_error,
165 "GatherSolution_Epetra<Residual>: Could not find field \"" +
166 fieldName +
"\" in the global indexer. ")
176template<
typename TRAITS,
typename LO,
typename GO>
180 typename TRAITS::PreEvalData d)
184 using Teuchos::rcp_dynamic_cast;
197 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
205 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
206 auto locPair = rcp_dynamic_cast<LPGED>(ged);
207 if (not locPair.is_null())
209 RCP<LOC> loc = locPair->getGhostedLOC();
210 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
212 if (not epetraContainer.is_null())
215 x_ = epetraContainer->get_dxdt();
217 x_ = epetraContainer->get_x();
224 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
232template<
typename TRAITS,
typename LO,
typename GO>
236 typename TRAITS::EvalData workset)
242 using Teuchos::ArrayRCP;
243 using Teuchos::ptrFromRef;
245 using Teuchos::rcp_dynamic_cast;
246 using Thyra::SpmdVectorBase;
249 string blockId(this->
wda(workset).block_id);
250 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
251 int numCells(localCellIds.size()), numFields(
gatherFields_.size());
258 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
259 Kokkos::deep_copy(LIDs_h, LIDs);
261 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
263 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
264 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
266 const vector<int>& elmtOffset =
268 int numBases(elmtOffset.size());
270 for (
int cell(0); cell < numCells; ++cell)
272 size_t cellLocalId(localCellIds[cell]);
274 for (
int basis(0); basis < numBases; ++basis)
276 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
278 field_h(cell, basis) = (*xEvRoGed_)[lid];
280 field_h(cell, basis) = (*x_)[lid];
283 Kokkos::deep_copy(field.get_static_view(), field_h);
293template<
typename TRAITS,
typename LO,
typename GO>
296 const Teuchos::RCP<const panzer::GlobalIndexer>& indexer,
297 const Teuchos::ParameterList& p)
309 using vvstring = std::vector<std::vector<std::string>>;
313 RCP<const PureBasis> basis = input.
getBasis();
320 int numFields(names.size());
322 for (
int fd(0); fd < numFields; ++fd)
325 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
330 if (tangentFieldNames.size() > 0)
332 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size())
335 for (
int fd(0); fd < numFields; ++fd)
337 int numTangentFields(tangentFieldNames[fd].size());
339 for (
int i(0); i < numTangentFields; ++i)
342 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
350 string firstName(
"<none>");
352 firstName = names[0];
353 string n(
"GatherSolution (Epetra): " + firstName +
" (" +
354 print<EvalT>() +
")");
363template<
typename TRAITS,
typename LO,
typename GO>
367 typename TRAITS::SetupData ,
370 using std::logic_error;
376 for (
int fd(0); fd < numFields; ++fd)
383 TEUCHOS_TEST_FOR_EXCEPTION(
fieldIds_[fd] == -1, logic_error,
384 "GatherSolution_Epetra<Tangent>: Could not find field \"" + fieldName
385 +
"\" in the global indexer. ")
395template<
typename TRAITS,
typename LO,
typename GO>
399 typename TRAITS::PreEvalData d)
403 using Teuchos::rcp_dynamic_cast;
416 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
424 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
425 auto locPair = rcp_dynamic_cast<LPGED>(ged);
426 if (not locPair.is_null())
428 RCP<LOC> loc = locPair->getGhostedLOC();
429 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
431 if (not epetraContainer.is_null())
434 x_ = epetraContainer->get_dxdt();
436 x_ = epetraContainer->get_x();
443 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
451template<
typename TRAITS,
typename LO,
typename GO>
455 typename TRAITS::EvalData workset)
461 using Teuchos::ArrayRCP;
462 using Teuchos::ptrFromRef;
464 using Teuchos::rcp_dynamic_cast;
465 using Thyra::SpmdVectorBase;
468 string blockId(this->
wda(workset).block_id);
469 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
470 int numCells(localCellIds.size()), numFields(
gatherFields_.size());
476 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
477 Kokkos::deep_copy(LIDs_h, LIDs);
479 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
481 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
482 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
484 const vector<int>& elmtOffset =
486 int numBases(elmtOffset.size());
488 for (
int cell(0); cell < numCells; ++cell)
490 size_t cellLocalId(localCellIds[cell]);
492 for (
int basis(0); basis < numBases; ++basis)
494 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
496 field_h(cell, basis) = (*xEvRoGed_)[lid];
498 field_h(cell, basis) = (*x_)[lid];
506 for (
int i(0); i < numTangentFields; ++i){
507 auto tf = Kokkos::create_mirror_view(
tangentFields_[fieldInd][i].get_static_view());
508 Kokkos::deep_copy(tf,
tangentFields_[fieldInd][i].get_static_view());
510 for (
int cell(0); cell < numCells; ++cell) {
513 const vector<int>& elmtOffset =
515 int numBases(elmtOffset.size());
518 for (
int basis(0); basis < numBases; ++basis){
519 field_h(cell, basis).fastAccessDx(i) =
520 tf(cell, basis).val();
525 Kokkos::deep_copy(field.get_static_view(), field_h);
534template<
typename TRAITS,
typename LO,
typename GO>
537 const Teuchos::RCP<const panzer::GlobalIndexer>& indexer,
538 const Teuchos::ParameterList& p)
552 RCP<const PureBasis> basis = input.
getBasis();
561 int numFields(names.size());
563 for (
int fd(0); fd < numFields; ++fd)
565 MDField<ScalarT, Cell, NODE> f(names[fd], basis->functional);
571 string firstName(
"<none>"), n(
"GatherSolution (Epetra");
573 firstName = names[0];
575 n +=
", No Sensitivities";
576 n +=
"): " + firstName +
" (Jacobian)";
585template<
typename TRAITS,
typename LO,
typename GO>
589 typename TRAITS::SetupData ,
592 using std::logic_error;
598 for (
int fd(0); fd < numFields; ++fd)
605 TEUCHOS_TEST_FOR_EXCEPTION(
fieldIds_[fd] == -1, logic_error,
606 "GatherSolution_Epetra<Jacobian>: Could not find field \"" +
607 fieldName +
"\" in the global indexer. ")
617template<
typename TRAITS,
typename LO,
typename GO>
621 typename TRAITS::PreEvalData d)
625 using Teuchos::rcp_dynamic_cast;
644 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
652 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
653 auto locPair = rcp_dynamic_cast<LPGED>(ged);
654 if (not locPair.is_null())
656 RCP<LOC> loc = locPair->getGhostedLOC();
657 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
659 if (not epetraContainer.is_null())
662 x_ = epetraContainer->get_dxdt();
664 x_ = epetraContainer->get_x();
671 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
679template<
typename TRAITS,
typename LO,
typename GO>
683 typename TRAITS::EvalData workset)
689 using Teuchos::ArrayRCP;
690 using Teuchos::ptrFromRef;
692 using Teuchos::rcp_dynamic_cast;
693 using Thyra::SpmdVectorBase;
696 string blockId(this->
wda(workset).block_id);
697 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
698 int numFields(
gatherFields_.size()), numCells(localCellIds.size());
705 seedValue = workset.alpha;
707 seedValue = workset.beta;
711 TEUCHOS_ASSERT(
false)
724 if (this->
wda.getDetailsIndex() == 1)
727 dos =
globalIndexer_->getElementBlockGIDCount(workset.details(0).block_id);
734 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
735 Kokkos::deep_copy(LIDs_h, LIDs);
737 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
739 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
740 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
742 const vector<int>& elmtOffset =
744 int numBases(elmtOffset.size());
746 for (
int cell(0); cell < numCells; ++cell)
748 size_t cellLocalId(localCellIds[cell]);
750 for (
int basis(0); basis < numBases; ++basis)
752 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
754 field_h(cell, basis) = (*xEvRoGed_)[lid];
756 field_h(cell, basis) = (*x_)[lid];
763 const vector<int>& elmtOffset =
765 int numBases(elmtOffset.size());
768 for (
int cell(0); cell < numCells; ++cell)
771 for (
int basis(0); basis < numBases; ++basis)
774 int offset(elmtOffset[basis]);
776 field_h(cell, basis).fastAccessDx(dos + offset) = seedValue;
780 Kokkos::deep_copy(field.get_static_view(), field_h);
This class provides a boundary exchange communication mechanism for vectors.
WorksetDetailsAccessor wda
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
bool disableSensitivities_
Flag to disable sensitivities absolutely.
std::vector< int > fieldIds_
Field IDs, which need to be mapped.
std::vector< std::string > indexerNames_
A list of the names of the fields to be gathered.
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
std::string sensitivitiesName_
Sets which gather operations have sensitivities.
Teuchos::RCP< panzer::EpetraVector_ReadOnly_GlobalEvaluationData > xEvRoGed_
The GlobalEvaluationData containing both the owned and ghosted vectors.
bool applySensitivities_
Used by evaluateFields() to turn on/off a certain set of sensitivities.
Teuchos::RCP< Epetra_Vector > x_
The solution vector.
int gatherSeedIndex_
Which gather seed in the workset to use.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we're to be working with or .
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
Maps the local (field, element, basis) triplet to a global ID for scattering.
Teuchos::RCP< panzer::EpetraVector_ReadOnly_GlobalEvaluationData > xEvRoGed_
The GlobalEvaluationData containing both the owned and ghosted vectors.
bool hasTangentFields_
A flag indicating whether or not we have tangent fields.
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
std::vector< std::string > indexerNames_
A list of the names of the fields to be gathered.
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
Maps the local (field, element, basis) triplet to a global ID for scattering.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we're to be working with or .
std::vector< int > fieldIds_
Field IDs, which need to be mapped.
std::vector< std::vector< PHX::MDField< const ScalarT, Cell, NODE > > > tangentFields_
Fields for storing the tangent components of the solution vector .
Teuchos::RCP< Epetra_Vector > x_
The solution vector.
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we should be working with or .
std::vector< int > fieldIds_
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< std::string > indexerNames_
A list of the names of the fields to be gathered.
std::vector< std::vector< PHX::MDField< const ScalarT, Cell, NODE > > > tangentFields_
Fields for storing the tangent components of the solution vector .
bool hasTangentFields_
A flag indicating whether or not we have tangent fields.
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
Maps the local (field, element, basis) triplet to a global ID for scattering.
Teuchos::RCP< panzer::EpetraVector_ReadOnly_GlobalEvaluationData > xEvRoGed_
The GlobalEvaluationData containing both the owned and ghosted vectors.
Teuchos::RCP< Epetra_Vector > x_
The solution vector.
Gathers solution values from the Newton solution vector into the nodal fields of the field manager.
Description and data layouts associated with a particular basis.