Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_GatherTangent_Tpetra_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP
44 #define PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
50 #include "Panzer_PureBasis.hpp"
54 
55 #include "Teuchos_FancyOStream.hpp"
56 
57 #include "Tpetra_Vector.hpp"
58 #include "Tpetra_Map.hpp"
59 
60 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
63  const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer,
64  const Teuchos::ParameterList& p)
65  : globalIndexer_(indexer)
66  , useTimeDerivativeSolutionVector_(false)
67  , globalDataKey_("Tangent Gather Container")
68 {
69  const std::vector<std::string>& names =
70  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
71 
73 
74  // this is beging to fix the issues with incorrect use of const
76  if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
77  basis = p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
78  else
79  basis = p.get< Teuchos::RCP<const panzer::PureBasis> >("Basis");
80 
81  gatherFields_.resize(names.size());
82  for (std::size_t fd = 0; fd < names.size(); ++fd) {
83  gatherFields_[fd] =
84  PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
85  this->addEvaluatedField(gatherFields_[fd]);
86  }
87 
88  if (p.isType<bool>("Use Time Derivative Solution Vector"))
89  useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
90 
91  if (p.isType<std::string>("Global Data Key"))
92  globalDataKey_ = p.get<std::string>("Global Data Key");
93 
94  this->setName("Gather Tangent");
95 }
96 
97 // **********************************************************************
98 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
100 postRegistrationSetup(typename TRAITS::SetupData /* d */,
101  PHX::FieldManager<TRAITS>& /* fm */)
102 {
103  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
104 
105  fieldIds_.resize(gatherFields_.size());
106 
107  for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
108  const std::string& fieldName = (*indexerNames_)[fd];
109  fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
110  }
111 
112  indexerNames_ = Teuchos::null; // Don't need this anymore
113 }
114 
115 // **********************************************************************
116 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
118 preEvaluate(typename TRAITS::PreEvalData d)
119 {
120  using Teuchos::RCP;
121  using Teuchos::rcp_dynamic_cast;
122 
124 
125  // try to extract linear object container
126  if (d.gedc->containsDataObject(globalDataKey_)) {
127  RCP<GlobalEvaluationData> ged = d.gedc->getDataObject(globalDataKey_);
129  rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
130 
131  if(loc_pair!=Teuchos::null) {
133  tpetraContainer_ = rcp_dynamic_cast<LOC>(loc,true);
134  }
135 
136  if(tpetraContainer_==Teuchos::null) {
137  tpetraContainer_ = rcp_dynamic_cast<LOC>(ged,true);
138  }
139  }
140 }
141 
142 // **********************************************************************
143 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
145 evaluateFields(typename TRAITS::EvalData workset)
146 {
147  // If tpetraContainer_ was not initialized, then no global evaluation data
148  // container was set, in which case this evaluator becomes a no-op
149  if (tpetraContainer_ == Teuchos::null)
150  return;
151 
153  // for convenience pull out some objects from workset
154  std::string blockId = this->wda(workset).block_id;
155  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
156 
158  if (useTimeDerivativeSolutionVector_)
159  x = tpetraContainer_->get_dxdt();
160  else
161  x = tpetraContainer_->get_x();
162 
163  Teuchos::ArrayRCP<const double> x_array = x->get1dView();
164 
165  // NOTE: A reordering of these loops will likely improve performance
166  // The "getGIDFieldOffsets may be expensive. However the
167  // "getElementGIDs" can be cheaper. However the lookup for LIDs
168  // may be more expensive!
169 
170  // gather operation for each cell in workset
171  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
172  std::size_t cellLocalId = localCellIds[worksetCellIndex];
173 
174  auto LIDs = globalIndexer_->getElementLIDs(cellLocalId);
175 
176  // loop over the fields to be gathered
177  for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
178  int fieldNum = fieldIds_[fieldIndex];
179  const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
180 
181  // loop over basis functions and fill the fields
182  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
183  int offset = elmtOffset[basis];
184  LO lid = LIDs[offset];
185  (gatherFields_[fieldIndex])(worksetCellIndex,basis) = x_array[lid];
186  }
187  }
188  }
189 }
190 
191 // **********************************************************************
192 
193 #endif
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)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
Teuchos::RCP< LinearObjContainer > getGhostedLOC() const
bool isType(const std::string &name) const
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
#define TEUCHOS_ASSERT(assertion_test)