11#ifndef __Panzer_GatherSolution_Epetra_impl_hpp__
12#define __Panzer_GatherSolution_Epetra_impl_hpp__
21#include "Epetra_Vector.h"
33#include "Teuchos_Assert.hpp"
36#include "Thyra_SpmdVectorBase.hpp"
43template<
typename TRAITS,
typename LO,
typename GO>
46 const Teuchos::RCP<const panzer::GlobalIndexer>& indexer,
47 const Teuchos::ParameterList& p)
59 using vvstring = std::vector<std::vector<std::string>>;
63 RCP<const PureBasis> basis = input.
getBasis();
70 int numFields(names.size());
72 for (
int fd(0); fd < numFields; ++fd)
75 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
80 if (tangentFieldNames.size() > 0)
82 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size())
85 for (
int fd(0); fd < numFields; ++fd)
87 int numTangentFields(tangentFieldNames[fd].size());
89 for (
int i(0); i < numTangentFields; ++i)
92 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
100 string firstName(
"<none>");
102 firstName = names[0];
103 string n(
"GatherSolution (Epetra): " + firstName +
" (Residual)");
112template<
typename TRAITS,
typename LO,
typename GO>
116 typename TRAITS::SetupData ,
119 using std::logic_error;
125 for (
int fd(0); fd < numFields; ++fd)
132 TEUCHOS_TEST_FOR_EXCEPTION(
fieldIds_[fd] == -1, logic_error,
133 "GatherSolution_Epetra<Residual>: Could not find field \"" +
134 fieldName +
"\" in the global indexer. ")
144template<
typename TRAITS,
typename LO,
typename GO>
148 typename TRAITS::PreEvalData d)
152 using Teuchos::rcp_dynamic_cast;
165 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
173 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
174 auto locPair = rcp_dynamic_cast<LPGED>(ged);
175 if (not locPair.is_null())
177 RCP<LOC> loc = locPair->getGhostedLOC();
178 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
180 if (not epetraContainer.is_null())
183 x_ = epetraContainer->get_dxdt();
185 x_ = epetraContainer->get_x();
192 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
200template<
typename TRAITS,
typename LO,
typename GO>
204 typename TRAITS::EvalData workset)
210 using Teuchos::ArrayRCP;
211 using Teuchos::ptrFromRef;
213 using Teuchos::rcp_dynamic_cast;
214 using Thyra::SpmdVectorBase;
217 string blockId(this->
wda(workset).block_id);
218 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
219 int numCells(localCellIds.size()), numFields(
gatherFields_.size());
226 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
227 Kokkos::deep_copy(LIDs_h, LIDs);
229 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
231 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
232 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
234 const vector<int>& elmtOffset =
236 int numBases(elmtOffset.size());
238 for (
int cell(0); cell < numCells; ++cell)
240 size_t cellLocalId(localCellIds[cell]);
242 for (
int basis(0); basis < numBases; ++basis)
244 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
246 field_h(cell, basis) = (*xEvRoGed_)[lid];
248 field_h(cell, basis) = (*x_)[lid];
251 Kokkos::deep_copy(field.get_static_view(), field_h);
261template<
typename TRAITS,
typename LO,
typename GO>
264 const Teuchos::RCP<const panzer::GlobalIndexer>& indexer,
265 const Teuchos::ParameterList& p)
277 using vvstring = std::vector<std::vector<std::string>>;
281 RCP<const PureBasis> basis = input.
getBasis();
288 int numFields(names.size());
290 for (
int fd(0); fd < numFields; ++fd)
293 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
298 if (tangentFieldNames.size() > 0)
300 TEUCHOS_ASSERT(
gatherFields_.size() == tangentFieldNames.size())
303 for (
int fd(0); fd < numFields; ++fd)
305 int numTangentFields(tangentFieldNames[fd].size());
307 for (
int i(0); i < numTangentFields; ++i)
310 MDField<const ScalarT, Cell, NODE>(tangentFieldNames[fd][i],
318 string firstName(
"<none>");
320 firstName = names[0];
321 string n(
"GatherSolution (Epetra): " + firstName +
" (" +
322 print<EvalT>() +
")");
331template<
typename TRAITS,
typename LO,
typename GO>
335 typename TRAITS::SetupData ,
338 using std::logic_error;
344 for (
int fd(0); fd < numFields; ++fd)
351 TEUCHOS_TEST_FOR_EXCEPTION(
fieldIds_[fd] == -1, logic_error,
352 "GatherSolution_Epetra<Tangent>: Could not find field \"" + fieldName
353 +
"\" in the global indexer. ")
363template<
typename TRAITS,
typename LO,
typename GO>
367 typename TRAITS::PreEvalData d)
371 using Teuchos::rcp_dynamic_cast;
384 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
392 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
393 auto locPair = rcp_dynamic_cast<LPGED>(ged);
394 if (not locPair.is_null())
396 RCP<LOC> loc = locPair->getGhostedLOC();
397 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
399 if (not epetraContainer.is_null())
402 x_ = epetraContainer->get_dxdt();
404 x_ = epetraContainer->get_x();
411 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
419template<
typename TRAITS,
typename LO,
typename GO>
423 typename TRAITS::EvalData workset)
429 using Teuchos::ArrayRCP;
430 using Teuchos::ptrFromRef;
432 using Teuchos::rcp_dynamic_cast;
433 using Thyra::SpmdVectorBase;
436 string blockId(this->
wda(workset).block_id);
437 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
438 int numCells(localCellIds.size()), numFields(
gatherFields_.size());
444 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
445 Kokkos::deep_copy(LIDs_h, LIDs);
447 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
449 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
450 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
452 const vector<int>& elmtOffset =
454 int numBases(elmtOffset.size());
456 for (
int cell(0); cell < numCells; ++cell)
458 size_t cellLocalId(localCellIds[cell]);
460 for (
int basis(0); basis < numBases; ++basis)
462 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
464 field_h(cell, basis) = (*xEvRoGed_)[lid];
466 field_h(cell, basis) = (*x_)[lid];
474 for (
int i(0); i < numTangentFields; ++i){
475 auto tf = Kokkos::create_mirror_view(
tangentFields_[fieldInd][i].get_static_view());
476 Kokkos::deep_copy(tf,
tangentFields_[fieldInd][i].get_static_view());
478 for (
int cell(0); cell < numCells; ++cell) {
481 const vector<int>& elmtOffset2 =
483 int numBases2(elmtOffset2.size());
486 for (
int basis(0); basis < numBases2; ++basis){
487 field_h(cell, basis).fastAccessDx(i) =
488 tf(cell, basis).val();
493 Kokkos::deep_copy(field.get_static_view(), field_h);
502template<
typename TRAITS,
typename LO,
typename GO>
505 const Teuchos::RCP<const panzer::GlobalIndexer>& indexer,
506 const Teuchos::ParameterList& p)
520 RCP<const PureBasis> basis = input.
getBasis();
529 int numFields(names.size());
531 for (
int fd(0); fd < numFields; ++fd)
533 MDField<ScalarT, Cell, NODE> f(names[fd], basis->functional);
539 string firstName(
"<none>"), n(
"GatherSolution (Epetra");
541 firstName = names[0];
543 n +=
", No Sensitivities";
544 n +=
"): " + firstName +
" (Jacobian)";
553template<
typename TRAITS,
typename LO,
typename GO>
557 typename TRAITS::SetupData ,
560 using std::logic_error;
566 for (
int fd(0); fd < numFields; ++fd)
573 TEUCHOS_TEST_FOR_EXCEPTION(
fieldIds_[fd] == -1, logic_error,
574 "GatherSolution_Epetra<Jacobian>: Could not find field \"" +
575 fieldName +
"\" in the global indexer. ")
585template<
typename TRAITS,
typename LO,
typename GO>
589 typename TRAITS::PreEvalData d)
593 using Teuchos::rcp_dynamic_cast;
612 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
620 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
621 auto locPair = rcp_dynamic_cast<LPGED>(ged);
622 if (not locPair.is_null())
624 RCP<LOC> loc = locPair->getGhostedLOC();
625 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
627 if (not epetraContainer.is_null())
630 x_ = epetraContainer->get_dxdt();
632 x_ = epetraContainer->get_x();
639 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
647template<
typename TRAITS,
typename LO,
typename GO>
651 typename TRAITS::EvalData workset)
657 using Teuchos::ArrayRCP;
658 using Teuchos::ptrFromRef;
660 using Teuchos::rcp_dynamic_cast;
661 using Thyra::SpmdVectorBase;
664 string blockId(this->
wda(workset).block_id);
665 const vector<size_t>& localCellIds = this->
wda(workset).cell_local_ids;
666 int numFields(
gatherFields_.size()), numCells(localCellIds.size());
673 seedValue = workset.alpha;
675 seedValue = workset.beta;
679 TEUCHOS_ASSERT(
false)
692 if (this->
wda.getDetailsIndex() == 1)
695 dos =
globalIndexer_->getElementBlockGIDCount(workset.details(0).block_id);
702 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
703 Kokkos::deep_copy(LIDs_h, LIDs);
705 for (
int fieldInd(0); fieldInd < numFields; ++fieldInd)
707 MDField<ScalarT, Cell, NODE>& field =
gatherFields_[fieldInd];
708 auto field_h = Kokkos::create_mirror_view(field.get_static_view());
710 const vector<int>& elmtOffset =
712 int numBases(elmtOffset.size());
714 for (
int cell(0); cell < numCells; ++cell)
716 size_t cellLocalId(localCellIds[cell]);
718 for (
int basis(0); basis < numBases; ++basis)
720 int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
722 field_h(cell, basis) = (*xEvRoGed_)[lid];
724 field_h(cell, basis) = (*x_)[lid];
731 const vector<int>& elmtOffset2 =
733 int numBases2(elmtOffset2.size());
736 for (
int cell(0); cell < numCells; ++cell)
739 for (
int basis(0); basis < numBases2; ++basis)
742 int offset(elmtOffset2[basis]);
744 field_h(cell, basis).fastAccessDx(dos + offset) = seedValue;
748 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.
Abstract, linear-algebra-library-agnostic container for the vectors and matrix used in a nonlinear/tr...
Description and data layouts associated with a particular basis.