Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_GatherTangent_Tpetra_impl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP
12#define PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP
13
14#include "Teuchos_Assert.hpp"
15#include "Phalanx_DataLayout.hpp"
16
18#include "Panzer_PureBasis.hpp"
23#include "Panzer_DOFManager.hpp"
24
25#include "Teuchos_FancyOStream.hpp"
26
27#include "Tpetra_Vector.hpp"
28#include "Tpetra_Map.hpp"
29
30template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
33 const Teuchos::RCP<const panzer::GlobalIndexer> & indexer,
34 const Teuchos::ParameterList& p)
35 : globalIndexer_(indexer)
36 , useTimeDerivativeSolutionVector_(false)
37 , globalDataKey_("Tangent Gather Container")
38{
39 const std::vector<std::string>& names =
40 *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
41
42 indexerNames_ = p.get< Teuchos::RCP< std::vector<std::string> > >("Indexer Names");
43
44 // this is beging to fix the issues with incorrect use of const
45 Teuchos::RCP<const panzer::PureBasis> basis;
46 if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
47 basis = p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
48 else
49 basis = p.get< Teuchos::RCP<const panzer::PureBasis> >("Basis");
50
51 gatherFields_.resize(names.size());
52 for (std::size_t fd = 0; fd < names.size(); ++fd) {
53 gatherFields_[fd] =
54 PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
55 this->addEvaluatedField(gatherFields_[fd]);
56 // If tpetraContainer_ is null, the evalaution is a no-op. In this
57 // case we need to preserve zero initial value. Do this by not
58 // sharing.
59 this->addUnsharedField(gatherFields_[fd].fieldTag().clone());
60 }
61
62 if (p.isType<bool>("Use Time Derivative Solution Vector"))
63 useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
64
65 if (p.isType<std::string>("Global Data Key"))
66 globalDataKey_ = p.get<std::string>("Global Data Key");
67
68 this->setName("Gather Tangent");
69}
70
71// **********************************************************************
72template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
74postRegistrationSetup(typename TRAITS::SetupData /* d */,
76{
77 TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
78
79 fieldIds_.resize(gatherFields_.size());
80
81 gatherFieldsVoV_.initialize("GatherSolution_Teptra<Tangent>",gatherFields_.size());
82
83 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
84 const std::string& fieldName = (*indexerNames_)[fd];
85 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
86 gatherFieldsVoV_.addView(gatherFields_[fd].get_static_view(),fd);
87 }
88
89 gatherFieldsVoV_.syncHostToDevice();
90
91 indexerNames_ = Teuchos::null; // Don't need this anymore
92}
93
94// **********************************************************************
95template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
97preEvaluate(typename TRAITS::PreEvalData d)
98{
99 using Teuchos::RCP;
100 using Teuchos::rcp_dynamic_cast;
101
104
105 if (!d.gedc->containsDataObject(globalDataKey_))
106 return;
107
108 RCP<GlobalEvaluationData> ged = d.gedc->getDataObject(globalDataKey_);
109
110 // try to extract a linear object container, possibly wrapped in a LOCPair
111 {
112 RCP<LOC> tpetraContainer = rcp_dynamic_cast<LOC>(ged);
113 RCP<LOCPair_GlobalEvaluationData> loc_pair =
114 rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
115
116 if(loc_pair!=Teuchos::null)
117 tpetraContainer = rcp_dynamic_cast<LOC>(loc_pair->getGhostedLOC(),true);
118
119 if(tpetraContainer!=Teuchos::null) {
120 if (useTimeDerivativeSolutionVector_)
121 x_vector_ = tpetraContainer->get_dxdt_mv();
122 else
123 x_vector_ = tpetraContainer->get_x_mv();
124
125 return;
126 }
127 }
128
129 // otherwise it must be a read-only ghosted vector, which is what the model
130 // evaluator hands out for the tangent gather containers (throws if not)
131 {
132 RCP<RO_GED> ro_ged = rcp_dynamic_cast<RO_GED>(ged,true);
133 x_vector_ = ro_ged->getGhostedVector_Tpetra();
134 }
135}
136
137// **********************************************************************
138template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
140evaluateFields(typename TRAITS::EvalData workset)
141{
142 // If x_vector_ was not initialized, then no global evaluation data
143 // container was set, in which case this evaluator becomes a no-op
144 if (x_vector_ == Teuchos::null)
145 return;
146
147 // for convenience pull out some objects from workset
148 std::string blockId = this->wda(workset).block_id;
149
150 auto x = x_vector_;
151
152 auto cellLocalIdsKokkos = this->wda(workset).getLocalCellIDs();
153 auto lids = globalIndexer_->getLIDs();
154 auto vov = Teuchos::rcp_dynamic_cast<const panzer::DOFManager>(globalIndexer_,true)->getGIDFieldOffsetsKokkos(blockId,fieldIds_);
155 auto gidFieldOffsets = vov.getViewDevice();
156 auto gatherFieldsDevice = gatherFieldsVoV_.getViewDevice();
157 auto x_view = x->getLocalViewDevice(Tpetra::Access::ReadWrite);
158 Kokkos::MDRangePolicy<PHX::Device::execution_space,Kokkos::Rank<2>> policy({0,0},{cellLocalIdsKokkos.extent(0),gidFieldOffsets.extent(0)});
159 Kokkos::parallel_for("GatherSolutionTpetra<Tangent>",policy,KOKKOS_LAMBDA(const int worksetCellIndex, const int fieldIndex) {
160 for(std::size_t basis=0;basis<gidFieldOffsets(fieldIndex).extent(0);basis++) {
161 int offset = gidFieldOffsets(fieldIndex)(basis);
162 LO lid = lids(cellLocalIdsKokkos(worksetCellIndex),offset);
163 auto& gf_ref = (gatherFieldsDevice[fieldIndex])(worksetCellIndex,basis);
164 gf_ref = x_view(lid,0);
165 }
166 });
167}
168
169// **********************************************************************
170
171#endif
PHX::View< const LO ** > lids
void preEvaluate(typename TRAITS::PreEvalData d)
Teuchos::RCP< std::vector< std::string > > indexerNames_
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
void evaluateFields(typename TRAITS::EvalData d)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
Tpetra-backed implementation of LinearObjContainer.