Panzer  Version of the Day
Panzer_GatherTangent_Epetra_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_EPETRA_IMPL_HPP
44 #define PANZER_GATHER_TANGENT_EPETRA_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
50 #include "Panzer_PureBasis.hpp"
55 
56 #include "Teuchos_FancyOStream.hpp"
57 
58 #include "Epetra_Vector.h"
59 #include "Epetra_Map.h"
60 
61 template<typename EvalT,typename TRAITS,typename LO,typename GO>
64  const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer,
65  const Teuchos::ParameterList& p)
66  : globalIndexer_(indexer)
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 
74 
75  // this is beging to fix the issues with incorrect use of const
77  if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
79  else
81 
82  gatherFields_.resize(names.size());
83  for (std::size_t fd = 0; fd < names.size(); ++fd) {
84  gatherFields_[fd] =
85  PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
86  this->addEvaluatedField(gatherFields_[fd]);
87  }
88 
89  if (p.isType<bool>("Use Time Derivative Solution Vector"))
90  useTimeDerivativeSolutionVector_ = p.get<bool>("Use Time Derivative Solution Vector");
91 
92  if (p.isType<std::string>("Global Data Key"))
93  globalDataKey_ = p.get<std::string>("Global Data Key");
94 
95  // figure out what the first active name is
96  std::string firstName = "<none>";
97  if(names.size()>0)
98  firstName = names[0];
99 
100  std::string n = "GatherTangent (Epetra): "+firstName+" ()";
101  this->setName(n);
102 }
103 
104 // **********************************************************************
105 template<typename EvalT,typename TRAITS,typename LO,typename GO>
107 postRegistrationSetup(typename TRAITS::SetupData d,
109 {
110  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
111 
112  fieldIds_.resize(gatherFields_.size());
113 
114  for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
115  // get field ID from DOF manager
116  const std::string& fieldName = (*indexerNames_)[fd];
117  fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
118 
119  // this is the error return code, raise the alarm
120  if(fieldIds_[fd]==-1) {
121  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
122  "GatherTangent_Epetra<Residual>: Could not find field \"" + fieldName + "\" in the global indexer. ");
123  // wouldn't it be nice to print more information???
124  }
125 
126  // setup the field data object
127  this->utils.setFieldData(gatherFields_[fd],fm);
128  }
129 
130  indexerNames_ = Teuchos::null; // Don't need this anymore
131 }
132 
133 // **********************************************************************
134 template<typename EvalT,typename TRAITS,typename LO,typename GO>
136 preEvaluate(typename TRAITS::PreEvalData d)
137 {
138  using Teuchos::RCP;
139  using Teuchos::rcp_dynamic_cast;
140 
141  // try to extract linear object container
142  if (d.gedc.containsDataObject(globalDataKey_)) {
143  RCP<GlobalEvaluationData> ged = d.gedc.getDataObject(globalDataKey_);
144  RCP<EpetraLinearObjContainer> epetraContainer = rcp_dynamic_cast<EpetraLinearObjContainer>(ged);
145  RCP<LOCPair_GlobalEvaluationData> loc_pair = rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
146 
147  if(loc_pair!=Teuchos::null) {
148  Teuchos::RCP<LinearObjContainer> loc = loc_pair->getGhostedLOC();
149  // extract linear object container
150  epetraContainer = rcp_dynamic_cast<EpetraLinearObjContainer>(loc);
151  }
152 
153  if(epetraContainer!=Teuchos::null) {
154  if (useTimeDerivativeSolutionVector_)
155  dxdp_ = epetraContainer->get_dxdt();
156  else
157  dxdp_ = epetraContainer->get_x();
158  }
159  }
160 }
161 
162 // **********************************************************************
163 template<typename EvalT,typename TRAITS,typename LO,typename GO>
165 evaluateFields(typename TRAITS::EvalData workset)
166 {
167  // If dxdp_ was not initialized, then no global evaluation data
168  // container was set, in which case this evaluator becomes a no-op
169  if (dxdp_ == Teuchos::null)
170  return;
171 
172  std::vector<int> LIDs;
173 
174  // for convenience pull out some objects from workset
175  std::string blockId = this->wda(workset).block_id;
176  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
177 
178  // NOTE: A reordering of these loops will likely improve performance
179  // The "getGIDFieldOffsets may be expensive. However the
180  // "getElementGIDs" can be cheaper. However the lookup for LIDs
181  // may be more expensive!
182 
183  Epetra_Vector & dxdp = *dxdp_;
184 
185  // gather operation for each cell in workset
186  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
187  std::size_t cellLocalId = localCellIds[worksetCellIndex];
188 
189  LIDs = globalIndexer_->getElementLIDs(cellLocalId);
190 
191  // loop over the fields to be gathered
192  for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
193  int fieldNum = fieldIds_[fieldIndex];
194  const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
195 
196  // loop over basis functions and fill the fields
197  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
198  int offset = elmtOffset[basis];
199  int lid = LIDs[offset];
200  (gatherFields_[fieldIndex])(worksetCellIndex,basis) = dxdp[lid];
201  }
202  }
203  }
204 }
205 
206 // **********************************************************************
207 
208 #endif
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< std::vector< std::string > > indexerNames_
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
const Teuchos::RCP< Epetra_Vector > get_x() const
bool isType(const std::string &name) const
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>
void preEvaluate(typename TRAITS::PreEvalData d)
void evaluateFields(typename TRAITS::EvalData d)
const Teuchos::RCP< Epetra_Vector > get_dxdt() const