Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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_GatherTangent_BlockedEpetra_impl_hpp__
44 #define __Panzer_GatherTangent_BlockedEpetra_impl_hpp__
45 
47 //
48 // Include Files
49 //
51 
52 // Epetra
53 #include "Epetra_Map.h"
54 
55 // Panzer
59 #include "Panzer_PureBasis.hpp"
62 
63 // Phalanx
64 #include "Phalanx_DataLayout.hpp"
65 
66 // Teuchos
67 #include "Teuchos_Assert.hpp"
68 #include "Teuchos_FancyOStream.hpp"
69 
70 // Thyra
71 #include "Thyra_ProductVectorBase.hpp"
72 #include "Thyra_SpmdVectorBase.hpp"
73 
75 //
76 // Initializing Constructor
77 //
79 template<typename EvalT, typename TRAITS, typename LO, typename GO>
82  const std::vector<Teuchos::RCP<const UniqueGlobalIndexer<LO, int>>>&
83  indexers,
84  const Teuchos::ParameterList& p)
85  :
86  indexers_(indexers),
87  useTimeDerivativeSolutionVector_(false),
88  globalDataKey_("Tangent Gather Container")
89 {
90  using panzer::PureBasis;
91  using PHX::MDField;
92  using PHX::typeAsString;
93  using std::size_t;
94  using std::string;
95  using std::vector;
96  using Teuchos::RCP;
97 
98  // Get the necessary information from the ParameterList.
99  const vector<string>& names = *(p.get<RCP<vector<string>>>("DOF Names"));
100  indexerNames_ = p.get<RCP<vector<string>>>("Indexer Names");
101  RCP<PureBasis> basis = p.get<RCP<PureBasis>>("Basis");
102  if (p.isType<bool>("Use Time Derivative Solution Vector"))
104  p.get<bool>("Use Time Derivative Solution Vector");
105  if (p.isType<string>("Global Data Key"))
106  globalDataKey_ = p.get<string>("Global Data Key");
107 
108  // Allocate the fields.
109  int numFields(names.size());
110  gatherFields_.resize(numFields);
111  for (int fd(0); fd < numFields; ++fd)
112  {
113  gatherFields_[fd] =
114  MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
115  this->addEvaluatedField(gatherFields_[fd]);
116  } // end loop over names
117 
118  // Figure out what the first active name is.
119  string firstName("<none>");
120  if (numFields > 0)
121  firstName = names[0];
122  string n("GatherTangent (Blocked Epetra): " + firstName + " (" +
123  typeAsString<EvalT>() + ")");
124  this->setName(n);
125 } // end of Initializing Constructor
126 
128 //
129 // postRegistrationSetup()
130 //
132 template<typename EvalT, typename TRAITS, typename LO, typename GO>
133 void
136  typename TRAITS::SetupData /* d */,
137  PHX::FieldManager<TRAITS>& /* fm */)
138 {
139  using std::size_t;
140  using std::string;
141  using Teuchos::null;
142  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
143  int numFields(gatherFields_.size());
144  indexerIds_.resize(numFields);
145  subFieldIds_.resize(numFields);
146  for (int fd(0); fd < numFields; ++fd)
147  {
148  // Get the field ID from the DOF manager.
149  const string& fieldName((*indexerNames_)[fd]);
150  indexerIds_[fd] = getFieldBlock(fieldName, indexers_);
151  subFieldIds_[fd] = indexers_[indexerIds_[fd]]->getFieldNum(fieldName);
152  TEUCHOS_ASSERT(indexerIds_[fd] >= 0);
153  } // end loop over gatherFields_
154  indexerNames_ = null;
155 } // end of postRegistrationSetup()
156 
158 //
159 // preEvaluate()
160 //
162 template<typename EvalT, typename TRAITS, typename LO, typename GO>
163 void
166  typename TRAITS::PreEvalData d)
167 {
168  using std::logic_error;
169  using Teuchos::RCP;
170  using Teuchos::rcp_dynamic_cast;
171  using Teuchos::typeName;
174  using GED = GlobalEvaluationData;
175  if (d.gedc->containsDataObject(globalDataKey_))
176  {
177  RCP<GED> ged = d.gedc->getDataObject(globalDataKey_);
178  xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged, true);
179  } // end if (d.gedc.containsDataObject(globalDataKey_))
180 } // end of preEvaluate()
181 
183 //
184 // evaluateFields()
185 //
187 template<typename EvalT, typename TRAITS, typename LO, typename GO>
188 void
191  typename TRAITS::EvalData workset)
192 {
193  using PHX::MDField;
194  using std::size_t;
195  using std::string;
196  using std::vector;
197  using Teuchos::ArrayRCP;
198  using Teuchos::ptrFromRef;
199  using Teuchos::RCP;
200  using Teuchos::rcp_dynamic_cast;
201  using Thyra::VectorBase;
202  using Thyra::SpmdVectorBase;
203 
204  // If no global evaluation data container was set, then this evaluator
205  // becomes a no-op.
206  if (xBvRoGed_.is_null())
207  return;
208 
209  // For convenience, pull out some objects from the workset.
210  string blockId(this->wda(workset).block_id);
211  const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
212  int numFields(gatherFields_.size()), numCells(localCellIds.size());
213 
214  // Loop over the fields to be gathered.
215  for (int fieldIndex(0); fieldIndex < numFields; ++fieldIndex)
216  {
217  MDField<ScalarT, Cell, NODE>& field = gatherFields_[fieldIndex];
218  int indexerId(indexerIds_[fieldIndex]),
219  subFieldNum(subFieldIds_[fieldIndex]);
220 
221  // Grab the local data for inputing.
222  auto xEvRoGed = xBvRoGed_->getGEDBlock(indexerId);
223  auto subRowIndexer = indexers_[indexerId];
224  const vector<int>& elmtOffset =
225  subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
226  int numBases(elmtOffset.size());
227 
228  // Gather operation for each cell in the workset.
229  for (int cell(0); cell < numCells; ++cell)
230  {
231  LO cellLocalId = localCellIds[cell];
232  auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
233 
234  // Loop over the basis functions and fill the fields.
235  for (int basis(0); basis < numBases; ++basis)
236  {
237  int offset(elmtOffset[basis]), lid(LIDs[offset]);
238  field(cell, basis) = (*xEvRoGed)[lid];
239  } // end loop over the basis functions
240  } // end loop over localCellIds
241  } // end loop over the fields to be gathered
242 } // end of evaluateFields()
243 
244 #endif // __Panzer_GatherTangent_BlockedEpetra_impl_hpp__
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > &ugis)
bool useTimeDerivativeSolutionVector_
A flag indicating whether we&#39;re to be working with or .
T & get(const std::string &name, T def_value)
Teuchos::RCP< std::vector< std::string > > indexerNames_
A list of the names of the fields to be gathered.
int numFields
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
This class encapsulates the needs of a gather operation to do a halo exchange for blocked vectors...
void preEvaluate(typename TRAITS::PreEvalData d)
Pre-Evaluate: Sets the tangent vector.
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
GatherTangent_BlockedEpetra()
Default Constructor (disabled)
void evaluateFields(typename TRAITS::EvalData d)
Evaluate Fields: Gather operation.
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we&#39;ll contribute, or in which we&#39;ll store, the result of computing this integral...
bool isType(const std::string &name) const
Description and data layouts associated with a particular basis.
#define TEUCHOS_ASSERT(assertion_test)
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)
Post-Registration Setup.
std::string typeName(const T &t)