Panzer  Version of the Day
Panzer_GatherTangent_BlockedTpetra_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_BLOCKED_TPETRA_IMPL_HPP
44 #define PANZER_GATHER_TANGENT_BLOCKED_TPETRA_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
51 #include "Panzer_PureBasis.hpp"
52 #include "Panzer_TpetraLinearObjFactory.hpp"
54 
55 #include "Teuchos_FancyOStream.hpp"
56 
57 #include "Thyra_SpmdVectorBase.hpp"
58 #include "Thyra_ProductVectorBase.hpp"
59 
60 #include "Tpetra_Map.hpp"
61 
62 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
65  const Teuchos::RCP<const BlockedDOFManager<LO,GO> > & indexer,
66  const Teuchos::ParameterList& p)
67  : gidIndexer_(indexer)
68  , useTimeDerivativeSolutionVector_(false)
69  , globalDataKey_("Tangent Gather Container")
70 {
71  const std::vector<std::string>& names =
72  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
73 
75 
78 
79  gatherFields_.resize(names.size());
80  for (std::size_t fd = 0; fd < names.size(); ++fd) {
81  gatherFields_[fd] =
82  PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
83  this->addEvaluatedField(gatherFields_[fd]);
84  }
85 
86  if (p.isType<bool>("Use Time Derivative Solution Vector"))
87  useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
88 
89  if (p.isType<std::string>("Global Data Key"))
90  globalDataKey_ = p.get<std::string>("Global Data Key");
91 
92  this->setName("Gather Tangent");
93 }
94 
95 // **********************************************************************
96 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
98 postRegistrationSetup(typename TRAITS::SetupData d,
100 {
101  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
102 
103  fieldIds_.resize(gatherFields_.size());
104 
105  for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
106  // get field ID from DOF manager
107  const std::string& fieldName = (*indexerNames_)[fd];
108  fieldIds_[fd] = gidIndexer_->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 S,typename LO,typename GO,typename NodeT>
120 preEvaluate(typename TRAITS::PreEvalData d)
121 {
122  // try to extract linear object container
123  if (d.gedc.containsDataObject(globalDataKey_)) {
124  blockedContainer_ = Teuchos::rcp_dynamic_cast<const ContainerType>(d.gedc.getDataObject(globalDataKey_),true);
125  }
126 }
127 
128 // **********************************************************************
129 template <typename EvalT,typename TRAITS,typename S,typename LO,typename GO,typename NodeT>
131 evaluateFields(typename TRAITS::EvalData workset)
132 {
133  using Teuchos::RCP;
134  using Teuchos::ArrayRCP;
135  using Teuchos::ptrFromRef;
136  using Teuchos::rcp_dynamic_cast;
137 
138  using Thyra::VectorBase;
139  using Thyra::SpmdVectorBase;
141 
142  // If blockedContainer_ was not initialized, then no global evaluation data
143  // container was set, in which case this evaluator becomes a no-op
144  if (blockedContainer_ == Teuchos::null)
145  return;
146 
147  Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
148  out.setShowProcRank(true);
149  out.setOutputToRootOnly(-1);
150 
151  std::vector<std::pair<int,GO> > GIDs;
152  std::vector<LO> LIDs;
153 
154  // for convenience pull out some objects from workset
155  std::string blockId = this->wda(workset).block_id;
156  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
157 
159  if (useTimeDerivativeSolutionVector_)
160  x = rcp_dynamic_cast<ProductVectorBase<double> >(blockedContainer_->get_dxdt());
161  else
162  x = rcp_dynamic_cast<ProductVectorBase<double> >(blockedContainer_->get_x());
163 
164  // gather operation for each cell in workset
165  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
166  LO cellLocalId = localCellIds[worksetCellIndex];
167 
168  gidIndexer_->getElementGIDs(cellLocalId,GIDs,blockId);
169 
170  // caculate the local IDs for this element
171  LIDs.resize(GIDs.size());
172  for(std::size_t i=0;i<GIDs.size();i++) {
173  // used for doing local ID lookups
174  RCP<const MapType> x_map = blockedContainer_->getMapForBlock(GIDs[i].first);
175 
176  LIDs[i] = x_map->getLocalElement(GIDs[i].second);
177  }
178 
179  // loop over the fields to be gathered
181  for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
182  int fieldNum = fieldIds_[fieldIndex];
183  int indexerId = gidIndexer_->getFieldBlock(fieldNum);
184 
185  // grab local data for inputing
186  RCP<SpmdVectorBase<double> > block_x = rcp_dynamic_cast<SpmdVectorBase<double> >(x->getNonconstVectorBlock(indexerId));
187  block_x->getLocalData(ptrFromRef(local_x));
188 
189  const std::vector<int> & elmtOffset = gidIndexer_->getGIDFieldOffsets(blockId,fieldNum);
190 
191  // loop over basis functions and fill the fields
192  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
193  int offset = elmtOffset[basis];
194  int lid = LIDs[offset];
195 
196  (gatherFields_[fieldIndex])(worksetCellIndex,basis) = local_x[lid];
197  }
198  }
199  }
200 }
201 
202 // **********************************************************************
203 
204 #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)
bool isType(const std::string &name) const
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis> or <Cell,Basis>