Panzer  Version of the Day
Panzer_GatherTangent_BlockedEpetra_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_EPETRA_IMPL_HPP
44 #define PANZER_GATHER_TANGENT_BLOCKED_EPETRA_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
51 #include "Panzer_PureBasis.hpp"
52 #include "Panzer_EpetraLinearObjFactory.hpp"
54 
55 #include "Teuchos_FancyOStream.hpp"
56 
57 #include "Thyra_SpmdVectorBase.hpp"
58 #include "Thyra_ProductVectorBase.hpp"
59 
60 #include "Epetra_Map.h"
61 
62 template<typename EvalT,typename TRAITS,typename LO,typename GO>
65  const Teuchos::ParameterList& p)
66  : indexers_(indexers)
67  , useTimeDerivativeSolutionVector_(false)
68  , globalDataKey_("Tangent Gather Container")
69 {
70  const std::vector<std::string>& names =
71  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
72 
73  indexerNames_ = p.get< Teuchos::RCP< std::vector<std::string> > >("Indexer Names");
74 
75  Teuchos::RCP<panzer::PureBasis> basis =
76  p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
77 
78  gatherFields_.resize(names.size());
79  for (std::size_t fd = 0; fd < names.size(); ++fd) {
80  gatherFields_[fd] =
81  PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
82  this->addEvaluatedField(gatherFields_[fd]);
83  }
84 
85  if (p.isType<bool>("Use Time Derivative Solution Vector"))
86  useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
87 
88  if (p.isType<std::string>("Global Data Key"))
89  globalDataKey_ = p.get<std::string>("Global Data Key");
90 
91  this->setName("Gather Tangent");
92 }
93 
94 // **********************************************************************
95 template<typename EvalT,typename TRAITS,typename LO,typename GO>
97 postRegistrationSetup(typename TRAITS::SetupData d,
99 {
100  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
101 
102  indexerIds_.resize(gatherFields_.size());
103  subFieldIds_.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 
109  indexerIds_[fd] = getFieldBlock(fieldName,indexers_);
110  subFieldIds_[fd] = indexers_[indexerIds_[fd]]->getFieldNum(fieldName);
111 
112  TEUCHOS_ASSERT(indexerIds_[fd]>=0);
113 
114  // setup the field data object
115  this->utils.setFieldData(gatherFields_[fd],fm);
116  }
117 
118  indexerNames_ = Teuchos::null; // Don't need this anymore
119 }
120 
121 // **********************************************************************
122 template<typename EvalT,typename TRAITS,typename LO,typename GO>
124 preEvaluate(typename TRAITS::PreEvalData d)
125 {
127 
128  typedef BlockedEpetraLinearObjContainer BLOC;
129 
130  // try to extract linear object container
131  if (d.gedc.containsDataObject(globalDataKey_)) {
132  Teuchos::RCP<const BLOC> blockedContainer = Teuchos::rcp_dynamic_cast<const BLOC>(d.gedc.getDataObject(globalDataKey_),true);
133 
134  if (useTimeDerivativeSolutionVector_)
135  x_ = Teuchos::rcp_dynamic_cast<ProductVectorBase<double> >(blockedContainer->get_dxdt());
136  else
137  x_ = Teuchos::rcp_dynamic_cast<ProductVectorBase<double> >(blockedContainer->get_x());
138  }
139 }
140 
141 // **********************************************************************
142 template<typename EvalT,typename TRAITS,typename LO,typename GO>
144 evaluateFields(typename TRAITS::EvalData workset)
145 {
146  using Teuchos::RCP;
147  using Teuchos::ArrayRCP;
148  using Teuchos::ptrFromRef;
149  using Teuchos::rcp_dynamic_cast;
150 
151  using Thyra::VectorBase;
152  using Thyra::SpmdVectorBase;
153 
154  // If x_ was not initialized, then no global evaluation data
155  // container was set, in which case this evaluator becomes a no-op
156  if (x_ == Teuchos::null)
157  return;
158 
159  // for convenience pull out some objects from workset
160  std::string blockId = this->wda(workset).block_id;
161  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
162 
163  // loop over the fields to be gathered
164  Teuchos::ArrayRCP<const double> local_x;
165  for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
166 
167  int indexerId = indexerIds_[fieldIndex];
168  int subFieldNum = subFieldIds_[fieldIndex];
169 
170  // grab local data for inputing
171  rcp_dynamic_cast<SpmdVectorBase<double> >(x_->getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(local_x));
172 
173  auto subRowIndexer = indexers_[indexerId];
174  const std::vector<int> & elmtOffset = subRowIndexer->getGIDFieldOffsets(blockId,subFieldNum);
175 
176  // gather operation for each cell in workset
177  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
178  LO cellLocalId = localCellIds[worksetCellIndex];
179 
180  const std::vector<int> & LIDs = subRowIndexer->getElementLIDs(cellLocalId);
181 
182  // loop over basis functions and fill the fields
183  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
184  int offset = elmtOffset[basis];
185  int lid = LIDs[offset];
186 
187  // TEUCHOS_ASSERT(indexerId==GIDs[offset].first);
188  // TEUCHOS_ASSERT(lid<local_x.size() && lid>=0);
189 
190  (gatherFields_[fieldIndex])(worksetCellIndex,basis) = local_x[lid];
191  }
192  }
193  }
194 }
195 
196 // **********************************************************************
197 
198 #endif
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > &ugis)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
Teuchos::RCP< std::vector< std::string > > indexerNames_
PHX::MDField< ScalarT > vector
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)