11 #ifndef PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP
12 #define PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP
14 #include "Teuchos_Assert.hpp"
15 #include "Phalanx_DataLayout.hpp"
24 #include "Teuchos_FancyOStream.hpp"
26 #include "Tpetra_Vector.hpp"
27 #include "Tpetra_Map.hpp"
29 template<
typename EvalT,
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
34 : globalIndexer_(indexer)
35 , useTimeDerivativeSolutionVector_(false)
36 , globalDataKey_(
"Tangent Gather Container")
38 const std::vector<std::string>& names =
51 for (std::size_t fd = 0; fd < names.size(); ++fd) {
61 if (p.
isType<
bool>(
"Use Time Derivative Solution Vector"))
64 if (p.
isType<std::string>(
"Global Data Key"))
67 this->setName(
"Gather Tangent");
71 template<
typename EvalT,
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
78 fieldIds_.resize(gatherFields_.size());
80 gatherFieldsVoV_.initialize(
"GatherSolution_Teptra<Tangent>",gatherFields_.size());
82 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
83 const std::string& fieldName = (*indexerNames_)[fd];
84 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
85 gatherFieldsVoV_.addView(gatherFields_[fd].get_static_view(),fd);
88 gatherFieldsVoV_.syncHostToDevice();
90 indexerNames_ = Teuchos::null;
94 template<
typename EvalT,
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
99 using Teuchos::rcp_dynamic_cast;
104 if (d.gedc->containsDataObject(globalDataKey_)) {
109 if(loc_pair!=Teuchos::null) {
111 tpetraContainer_ = rcp_dynamic_cast<LOC>(loc,
true);
114 if(tpetraContainer_==Teuchos::null) {
115 tpetraContainer_ = rcp_dynamic_cast<LOC>(ged,
true);
121 template<
typename EvalT,
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
127 if (tpetraContainer_ == Teuchos::null)
132 std::string blockId = this->wda(workset).block_id;
135 if (useTimeDerivativeSolutionVector_)
136 x = tpetraContainer_->get_dxdt();
138 x = tpetraContainer_->get_x();
140 auto cellLocalIdsKokkos = this->wda(workset).getLocalCellIDs();
141 auto lids = globalIndexer_->getLIDs();
142 auto vov = Teuchos::rcp_dynamic_cast<
const panzer::DOFManager>(globalIndexer_,
true)->getGIDFieldOffsetsKokkos(blockId,fieldIds_);
143 auto gidFieldOffsets = vov.getViewDevice();
144 auto gatherFieldsDevice = gatherFieldsVoV_.getViewDevice();
145 auto x_view = x->getLocalViewDevice(Tpetra::Access::ReadWrite);
146 Kokkos::MDRangePolicy<PHX::Device::execution_space,Kokkos::Rank<2>> policy({0,0},{cellLocalIdsKokkos.extent(0),gidFieldOffsets.extent(0)});
147 Kokkos::parallel_for(
"GatherSolutionTpetra<Tangent>",policy,KOKKOS_LAMBDA(
const int worksetCellIndex,
const int fieldIndex) {
148 for(std::size_t basis=0;basis<gidFieldOffsets(fieldIndex).extent(0);basis++) {
149 int offset = gidFieldOffsets(fieldIndex)(basis);
150 LO lid =
lids(cellLocalIdsKokkos(worksetCellIndex),offset);
151 auto& gf_ref = (gatherFieldsDevice[fieldIndex])(worksetCellIndex,basis);
152 gf_ref = x_view(lid,0);
Teuchos::RCP< std::vector< std::string > > indexerNames_
void preEvaluate(typename TRAITS::PreEvalData d)
void evaluateFields(typename TRAITS::EvalData d)
T & get(const std::string &name, T def_value)
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
Teuchos::RCP< LinearObjContainer > getGhostedLOC() const
bool useTimeDerivativeSolutionVector_
std::string globalDataKey_
bool isType(const std::string &name) const
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
#define TEUCHOS_ASSERT(assertion_test)
Kokkos::View< const LO **, Kokkos::LayoutRight, PHX::Device > lids