Panzer  Version of the Day
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"
53 
54 #include "Teuchos_FancyOStream.hpp"
55 
56 #include "Tpetra_Vector.hpp"
57 #include "Tpetra_Map.hpp"
58 
59 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
62  const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer,
63  const Teuchos::ParameterList& p)
64  : globalIndexer_(indexer)
65  , useTimeDerivativeSolutionVector_(false)
66  , globalDataKey_("Tangent Gather Container")
67 {
68  const std::vector<std::string>& names =
69  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
70 
71  indexerNames_ = p.get< Teuchos::RCP< std::vector<std::string> > >("Indexer Names");
72 
73  // this is beging to fix the issues with incorrect use of const
74  Teuchos::RCP<const panzer::PureBasis> basis;
75  if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
76  basis = p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
77  else
78  basis = p.get< Teuchos::RCP<const panzer::PureBasis> >("Basis");
79 
80  gatherFields_.resize(names.size());
81  for (std::size_t fd = 0; fd < names.size(); ++fd) {
82  gatherFields_[fd] =
83  PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
84  this->addEvaluatedField(gatherFields_[fd]);
85  }
86 
87  if (p.isType<bool>("Use Time Derivative Solution Vector"))
88  useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
89 
90  if (p.isType<std::string>("Global Data Key"))
91  globalDataKey_ = p.get<std::string>("Global Data Key");
92 
93  this->setName("Gather Tangent");
94 }
95 
96 // **********************************************************************
97 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
99 postRegistrationSetup(typename TRAITS::SetupData d,
101 {
102  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
103 
104  fieldIds_.resize(gatherFields_.size());
105 
106  for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
107  const std::string& fieldName = (*indexerNames_)[fd];
108  fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
109 
110  // setup the field data object
111  this->utils.setFieldData(gatherFields_[fd],fm);
112  }
113 
114  indexerNames_ = Teuchos::null; // Don't need this anymore
115 }
116 
117 // **********************************************************************
118 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
120 preEvaluate(typename TRAITS::PreEvalData d)
121 {
122  using Teuchos::RCP;
123  using Teuchos::rcp_dynamic_cast;
124 
126 
127  // try to extract linear object container
128  if (d.gedc.containsDataObject(globalDataKey_)) {
129  RCP<GlobalEvaluationData> ged = d.gedc.getDataObject(globalDataKey_);
130  RCP<LOCPair_GlobalEvaluationData> loc_pair =
131  rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
132 
133  if(loc_pair!=Teuchos::null) {
134  Teuchos::RCP<LinearObjContainer> loc = loc_pair->getGhostedLOC();
135  tpetraContainer_ = rcp_dynamic_cast<LOC>(loc,true);
136  }
137 
138  if(tpetraContainer_==Teuchos::null) {
139  tpetraContainer_ = rcp_dynamic_cast<LOC>(ged,true);
140  }
141  }
142 }
143 
144 // **********************************************************************
145 template<typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT>
147 evaluateFields(typename TRAITS::EvalData workset)
148 {
149  // If tpetraContainer_ was not initialized, then no global evaluation data
150  // container was set, in which case this evaluator becomes a no-op
151  if (tpetraContainer_ == Teuchos::null)
152  return;
153 
155 
156  std::vector<LO> LIDs;
157 
158  // for convenience pull out some objects from workset
159  std::string blockId = this->wda(workset).block_id;
160  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
161 
162  Teuchos::RCP<typename LOC::VectorType> x;
163  if (useTimeDerivativeSolutionVector_)
164  x = tpetraContainer_->get_dxdt();
165  else
166  x = tpetraContainer_->get_x();
167 
168  Teuchos::ArrayRCP<const double> x_array = x->get1dView();
169 
170  // NOTE: A reordering of these loops will likely improve performance
171  // The "getGIDFieldOffsets may be expensive. However the
172  // "getElementGIDs" can be cheaper. However the lookup for LIDs
173  // may be more expensive!
174 
175  // gather operation for each cell in workset
176  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
177  std::size_t cellLocalId = localCellIds[worksetCellIndex];
178 
179  LIDs = globalIndexer_->getElementLIDs(cellLocalId);
180 
181  // loop over the fields to be gathered
182  for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
183  int fieldNum = fieldIds_[fieldIndex];
184  const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
185 
186  // loop over basis functions and fill the fields
187  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
188  int offset = elmtOffset[basis];
189  LO lid = LIDs[offset];
190  (gatherFields_[fieldIndex])(worksetCellIndex,basis) = x_array[lid];
191  }
192  }
193  }
194 }
195 
196 // **********************************************************************
197 
198 #endif
Teuchos::RCP< std::vector< std::string > > indexerNames_
void preEvaluate(typename TRAITS::PreEvalData d)
void evaluateFields(typename TRAITS::EvalData d)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
Teuchos::RCP< LinearObjContainer > getGhostedLOC() const
const Teuchos::RCP< VectorType > get_dxdt() const
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)