Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_GatherTangent_BlockedTpetra_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_BLOCKED_TPETRA_IMPL_HPP
12 #define PANZER_GATHER_TANGENT_BLOCKED_TPETRA_IMPL_HPP
13 
14 #include "Teuchos_Assert.hpp"
15 #include "Phalanx_DataLayout.hpp"
16 
17 #include "Panzer_GlobalIndexer.hpp"
19 #include "Panzer_PureBasis.hpp"
20 #include "Panzer_TpetraLinearObjFactory.hpp"
23 
24 #include "Teuchos_FancyOStream.hpp"
25 
26 #include "Thyra_SpmdVectorBase.hpp"
27 #include "Thyra_ProductVectorBase.hpp"
28 
29 #include "Tpetra_Map.hpp"
30 
31 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
35  const Teuchos::ParameterList& p)
36  : gidIndexer_(indexer)
37  , useTimeDerivativeSolutionVector_(false)
38  , globalDataKey_("Tangent Gather Container")
39 {
40  const std::vector<std::string>& names =
41  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
42 
44 
47 
48  gatherFields_.resize(names.size());
49  for (std::size_t fd = 0; fd < names.size(); ++fd) {
50  gatherFields_[fd] =
51  PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
52  this->addEvaluatedField(gatherFields_[fd]);
53  }
54 
55  if (p.isType<bool>("Use Time Derivative Solution Vector"))
56  useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
57 
58  if (p.isType<std::string>("Global Data Key"))
59  globalDataKey_ = p.get<std::string>("Global Data Key");
60 
61  this->setName("Gather Tangent");
62 }
63 
64 // **********************************************************************
65 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
67 postRegistrationSetup(typename TRAITS::SetupData /* d */,
68  PHX::FieldManager<TRAITS>& /* fm */)
69 {
70  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
71 
72  fieldIds_.resize(gatherFields_.size());
73 
74  for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
75  // get field ID from DOF manager
76  const std::string& fieldName = (*indexerNames_)[fd];
77  fieldIds_[fd] = gidIndexer_->getFieldNum(fieldName);
78  }
79 
80  indexerNames_ = Teuchos::null; // Don't need this anymore
81 }
82 
83 // **********************************************************************
84 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
86 preEvaluate(typename TRAITS::PreEvalData d)
87 {
88  // try to extract linear object container
89  if (d.gedc->containsDataObject(globalDataKey_)) {
90  blockedContainer_ = Teuchos::rcp_dynamic_cast<const ContainerType>(d.gedc->getDataObject(globalDataKey_),true);
91  }
92 }
93 
94 // **********************************************************************
95 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
97 evaluateFields(typename TRAITS::EvalData workset)
98 {
99  using Teuchos::RCP;
100  using Teuchos::ArrayRCP;
101  using Teuchos::ptrFromRef;
102  using Teuchos::rcp_dynamic_cast;
103 
104  using Thyra::VectorBase;
105  using Thyra::SpmdVectorBase;
107 
108  // If blockedContainer_ was not initialized, then no global evaluation data
109  // container was set, in which case this evaluator becomes a no-op
110  if (blockedContainer_ == Teuchos::null)
111  return;
112 
113  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
114  out.setShowProcRank(true);
115  out.setOutputToRootOnly(-1);
116 
117  std::vector<std::pair<int,GO> > GIDs;
118  std::vector<LO> LIDs;
119 
120  // for convenience pull out some objects from workset
121  std::string blockId = this->wda(workset).block_id;
122  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
123 
125  if (useTimeDerivativeSolutionVector_)
126  x = rcp_dynamic_cast<ProductVectorBase<double> >(blockedContainer_->get_dxdt());
127  else
128  x = rcp_dynamic_cast<ProductVectorBase<double> >(blockedContainer_->get_x());
129 
130  // gather operation for each cell in workset
131  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
132  LO cellLocalId = localCellIds[worksetCellIndex];
133 
134  gidIndexer_->getElementGIDsPair(cellLocalId,GIDs,blockId);
135 
136  // caculate the local IDs for this element
137  LIDs.resize(GIDs.size());
138  for(std::size_t i=0;i<GIDs.size();i++) {
139  // used for doing local ID lookups
140  RCP<const MapType> x_map = blockedContainer_->getMapForBlock(GIDs[i].first);
141 
142  LIDs[i] = x_map->getLocalElement(GIDs[i].second);
143  }
144 
145  // loop over the fields to be gathered
147  for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
148  int fieldNum = fieldIds_[fieldIndex];
149  int indexerId = gidIndexer_->getFieldBlock(fieldNum);
150 
151  // grab local data for inputing
152  RCP<SpmdVectorBase<double> > block_x = rcp_dynamic_cast<SpmdVectorBase<double> >(x->getNonconstVectorBlock(indexerId));
153  block_x->getLocalData(ptrFromRef(local_x));
154 
155  const std::vector<int> & elmtOffset = gidIndexer_->getGIDFieldOffsets(blockId,fieldNum);
156 
157  // loop over basis functions and fill the fields
158  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
159  int offset = elmtOffset[basis];
160  int lid = LIDs[offset];
161 
162  (gatherFields_[fieldIndex])(worksetCellIndex,basis) = local_x[lid];
163  }
164  }
165  }
166 }
167 
168 // **********************************************************************
169 
170 #endif
Teuchos::RCP< std::vector< std::string > > indexerNames_
basic_FancyOStream & setShowProcRank(const bool showProcRank)
T & get(const std::string &name, T def_value)
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
bool isType(const std::string &name) const
#define TEUCHOS_ASSERT(assertion_test)