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"
22#include "Panzer_DOFManager.hpp"
23
24#include "Teuchos_FancyOStream.hpp"
25
26#include "Tpetra_Vector.hpp"
27#include "Tpetra_Map.hpp"
28
29template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
32 const Teuchos::RCP<const panzer::GlobalIndexer> & indexer,
33 const Teuchos::ParameterList& p)
34 : globalIndexer_(indexer)
35 , useTimeDerivativeSolutionVector_(false)
36 , globalDataKey_("Tangent Gather Container")
37{
38 const std::vector<std::string>& names =
39 *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
40
41 indexerNames_ = p.get< Teuchos::RCP< std::vector<std::string> > >("Indexer Names");
42
43 // this is beging to fix the issues with incorrect use of const
44 Teuchos::RCP<const panzer::PureBasis> basis;
45 if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
46 basis = p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
47 else
48 basis = p.get< Teuchos::RCP<const panzer::PureBasis> >("Basis");
49
50 gatherFields_.resize(names.size());
51 for (std::size_t fd = 0; fd < names.size(); ++fd) {
52 gatherFields_[fd] =
53 PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
54 this->addEvaluatedField(gatherFields_[fd]);
55 // If tpetraContainer_ is null, the evalaution is a no-op. In this
56 // case we need to preserve zero initial value. Do this by not
57 // sharing.
58 this->addUnsharedField(gatherFields_[fd].fieldTag().clone());
59 }
60
61 if (p.isType<bool>("Use Time Derivative Solution Vector"))
62 useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
63
64 if (p.isType<std::string>("Global Data Key"))
65 globalDataKey_ = p.get<std::string>("Global Data Key");
66
67 this->setName("Gather Tangent");
68}
69
70// **********************************************************************
71template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
73postRegistrationSetup(typename TRAITS::SetupData /* d */,
75{
76 TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
77
78 fieldIds_.resize(gatherFields_.size());
79
80 gatherFieldsVoV_.initialize("GatherSolution_Teptra<Tangent>",gatherFields_.size());
81
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);
86 }
87
88 gatherFieldsVoV_.syncHostToDevice();
89
90 indexerNames_ = Teuchos::null; // Don't need this anymore
91}
92
93// **********************************************************************
94template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
96preEvaluate(typename TRAITS::PreEvalData d)
97{
98 using Teuchos::RCP;
99 using Teuchos::rcp_dynamic_cast;
100
102
103 // try to extract linear object container
104 if (d.gedc->containsDataObject(globalDataKey_)) {
105 RCP<GlobalEvaluationData> ged = d.gedc->getDataObject(globalDataKey_);
106 RCP<LOCPair_GlobalEvaluationData> loc_pair =
107 rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
108
109 if(loc_pair!=Teuchos::null) {
110 Teuchos::RCP<LinearObjContainer> loc = loc_pair->getGhostedLOC();
111 tpetraContainer_ = rcp_dynamic_cast<LOC>(loc,true);
112 }
113
114 if(tpetraContainer_==Teuchos::null) {
115 tpetraContainer_ = rcp_dynamic_cast<LOC>(ged,true);
116 }
117 }
118}
119
120// **********************************************************************
121template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
123evaluateFields(typename TRAITS::EvalData workset)
124{
125 // If tpetraContainer_ was not initialized, then no global evaluation data
126 // container was set, in which case this evaluator becomes a no-op
127 if (tpetraContainer_ == Teuchos::null)
128 return;
129
131 // for convenience pull out some objects from workset
132 std::string blockId = this->wda(workset).block_id;
133
134 Teuchos::RCP<typename LOC::VectorType> x;
135 if (useTimeDerivativeSolutionVector_)
136 x = tpetraContainer_->get_dxdt();
137 else
138 x = tpetraContainer_->get_x();
139
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);
153 }
154 });
155}
156
157// **********************************************************************
158
159#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)
const Teuchos::RCP< VectorType > get_dxdt() const