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 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef __Panzer_GatherTangent_BlockedEpetra_impl_hpp__
12 #define __Panzer_GatherTangent_BlockedEpetra_impl_hpp__
13 
15 //
16 // Include Files
17 //
19 
20 // Epetra
21 #include "Epetra_Map.h"
22 
23 // Panzer
27 #include "Panzer_PureBasis.hpp"
28 #include "Panzer_GlobalIndexer.hpp"
30 
31 // Phalanx
32 #include "Phalanx_DataLayout.hpp"
33 
34 // Teuchos
35 #include "Teuchos_Assert.hpp"
36 #include "Teuchos_FancyOStream.hpp"
37 
38 // Thyra
39 #include "Thyra_ProductVectorBase.hpp"
40 #include "Thyra_SpmdVectorBase.hpp"
41 
43 //
44 // Initializing Constructor
45 //
47 template<typename EvalT, typename TRAITS, typename LO, typename GO>
50  const std::vector<Teuchos::RCP<const GlobalIndexer>>&
51  indexers,
52  const Teuchos::ParameterList& p)
53  :
54  indexers_(indexers),
55  useTimeDerivativeSolutionVector_(false),
56  globalDataKey_("Tangent Gather Container")
57 {
58  using panzer::PureBasis;
59  using PHX::MDField;
60  using PHX::print;
61  using std::size_t;
62  using std::string;
63  using std::vector;
64  using Teuchos::RCP;
65 
66  // Get the necessary information from the ParameterList.
67  const vector<string>& names = *(p.get<RCP<vector<string>>>("DOF Names"));
68  indexerNames_ = p.get<RCP<vector<string>>>("Indexer Names");
69  RCP<PureBasis> basis = p.get<RCP<PureBasis>>("Basis");
70  if (p.isType<bool>("Use Time Derivative Solution Vector"))
72  p.get<bool>("Use Time Derivative Solution Vector");
73  if (p.isType<string>("Global Data Key"))
74  globalDataKey_ = p.get<string>("Global Data Key");
75 
76  // Allocate the fields.
77  int numFields(names.size());
78  gatherFields_.resize(numFields);
79  for (int fd(0); fd < numFields; ++fd)
80  {
81  gatherFields_[fd] =
82  MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
83  this->addEvaluatedField(gatherFields_[fd]);
84  } // end loop over names
85 
86  // Figure out what the first active name is.
87  string firstName("<none>");
88  if (numFields > 0)
89  firstName = names[0];
90  string n("GatherTangent (Blocked Epetra): " + firstName + " (" +
91  print<EvalT>() + ")");
92  this->setName(n);
93 } // end of Initializing Constructor
94 
96 //
97 // postRegistrationSetup()
98 //
100 template<typename EvalT, typename TRAITS, typename LO, typename GO>
101 void
104  typename TRAITS::SetupData /* d */,
105  PHX::FieldManager<TRAITS>& /* fm */)
106 {
107  using std::size_t;
108  using std::string;
109  using Teuchos::null;
110  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
111  int numFields(gatherFields_.size());
112  indexerIds_.resize(numFields);
113  subFieldIds_.resize(numFields);
114  for (int fd(0); fd < numFields; ++fd)
115  {
116  // Get the field ID from the DOF manager.
117  const string& fieldName((*indexerNames_)[fd]);
118  indexerIds_[fd] = getFieldBlock(fieldName, indexers_);
119  subFieldIds_[fd] = indexers_[indexerIds_[fd]]->getFieldNum(fieldName);
120  TEUCHOS_ASSERT(indexerIds_[fd] >= 0);
121  } // end loop over gatherFields_
122  indexerNames_ = null;
123 } // end of postRegistrationSetup()
124 
126 //
127 // preEvaluate()
128 //
130 template<typename EvalT, typename TRAITS, typename LO, typename GO>
131 void
134  typename TRAITS::PreEvalData d)
135 {
136  using std::logic_error;
137  using Teuchos::RCP;
138  using Teuchos::rcp_dynamic_cast;
139  using Teuchos::typeName;
142  using GED = GlobalEvaluationData;
143  if (d.gedc->containsDataObject(globalDataKey_))
144  {
145  RCP<GED> ged = d.gedc->getDataObject(globalDataKey_);
146  xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged, true);
147  } // end if (d.gedc.containsDataObject(globalDataKey_))
148 } // end of preEvaluate()
149 
151 //
152 // evaluateFields()
153 //
155 template<typename EvalT, typename TRAITS, typename LO, typename GO>
156 void
159  typename TRAITS::EvalData workset)
160 {
161  using PHX::MDField;
162  using std::size_t;
163  using std::string;
164  using std::vector;
165  using Teuchos::ArrayRCP;
166  using Teuchos::ptrFromRef;
167  using Teuchos::RCP;
168  using Teuchos::rcp_dynamic_cast;
169  using Thyra::VectorBase;
170  using Thyra::SpmdVectorBase;
171 
172  // If no global evaluation data container was set, then this evaluator
173  // becomes a no-op.
174  if (xBvRoGed_.is_null())
175  return;
176 
177  // For convenience, pull out some objects from the workset.
178  string blockId(this->wda(workset).block_id);
179  const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
180  int numFields(gatherFields_.size()), numCells(localCellIds.size());
181 
182  // Loop over the fields to be gathered.
183  for (int fieldIndex(0); fieldIndex < numFields; ++fieldIndex)
184  {
185  MDField<ScalarT, Cell, NODE>& field = gatherFields_[fieldIndex];
186  int indexerId(indexerIds_[fieldIndex]),
187  subFieldNum(subFieldIds_[fieldIndex]);
188 
189  // Grab the local data for inputing.
190  auto xEvRoGed = xBvRoGed_->getGEDBlock(indexerId);
191  auto subRowIndexer = indexers_[indexerId];
192  const vector<int>& elmtOffset =
193  subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
194  int numBases(elmtOffset.size());
195 
196  // Gather operation for each cell in the workset.
197  for (int cell(0); cell < numCells; ++cell)
198  {
199  LO cellLocalId = localCellIds[cell];
200  auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
201 
202  // Loop over the basis functions and fill the fields.
203  for (int basis(0); basis < numBases; ++basis)
204  {
205  int offset(elmtOffset[basis]), lid(LIDs[offset]);
206  field(cell, basis) = (*xEvRoGed)[lid];
207  } // end loop over the basis functions
208  } // end loop over localCellIds
209  } // end loop over the fields to be gathered
210 } // end of evaluateFields()
211 
212 #endif // __Panzer_GatherTangent_BlockedEpetra_impl_hpp__
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.
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< const GlobalIndexer >> &ugis)
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)