Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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_GatherTangent_Epetra_impl_hpp__
44 #define __Panzer_GatherTangent_Epetra_impl_hpp__
45 
47 //
48 // Include Files
49 //
51 
52 // Epetra
53 #include "Epetra_Vector.h"
54 
55 // Panzer
58 #include "Panzer_PureBasis.hpp"
59 #include "Panzer_GlobalIndexer.hpp"
61 
62 // Teuchos
63 #include "Teuchos_Assert.hpp"
64 
65 // Thyra
66 #include "Thyra_SpmdVectorBase.hpp"
67 
69 //
70 // Initializing Constructor
71 //
73 template<typename EvalT, typename TRAITS, typename LO, typename GO>
77  const Teuchos::ParameterList& p)
78  :
79  globalIndexer_(indexer),
80  useTimeDerivativeSolutionVector_(false),
81  globalDataKey_("Tangent Gather Container")
82 {
83  using panzer::PureBasis;
84  using PHX::MDField;
85  using PHX::print;
86  using std::size_t;
87  using std::string;
88  using std::vector;
89  using Teuchos::RCP;
90 
91  // Get the necessary information from the ParameterList.
92  const vector<string>& names = *(p.get<RCP<vector<string>>>("DOF Names"));
93  indexerNames_ = p.get<RCP<vector<string>>>("Indexer Names");
95  if (p.isType<RCP<PureBasis>>("Basis"))
96  basis = p.get<RCP<PureBasis>>("Basis");
97  else // if (not p.isType<RCP<PureBasis>>("Basis"))
98  basis = p.get<RCP<const PureBasis>>("Basis");
99  if (p.isType<bool>("Use Time Derivative Solution Vector"))
101  p.get<bool>("Use Time Derivative Solution Vector");
102  if (p.isType<string>("Global Data Key"))
103  globalDataKey_ = p.get<string>("Global Data Key");
104 
105  // Allocate fields.
106  int numFields(names.size());
107  gatherFields_.resize(numFields);
108  for (int fd(0); fd < numFields; ++fd)
109  {
110  gatherFields_[fd] =
111  MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
112  this->addEvaluatedField(gatherFields_[fd]);
113  } // end loop over names
114 
115  // Figure out what the first active name is.
116  string firstName("<none>");
117  if (numFields > 0)
118  firstName = names[0];
119  string n("GatherTangent (Epetra): " + firstName + " (" +
120  print<EvalT>() + ")");
121  this->setName(n);
122 } // end of Initializing Constructor
123 
125 //
126 // postRegistrationSetup()
127 //
129 template<typename EvalT, typename TRAITS, typename LO, typename GO>
130 void
133  typename TRAITS::SetupData /* d */,
134  PHX::FieldManager<TRAITS>& /* fm */)
135 {
136  using std::logic_error;
137  using std::size_t;
138  using std::string;
139  using Teuchos::null;
140  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
141  int numFields(gatherFields_.size());
142  fieldIds_.resize(numFields);
143  for (int fd(0); fd < numFields; ++fd)
144  {
145  // Get the field ID from the DOF manager.
146  const string& fieldName((*indexerNames_)[fd]);
147  fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
148 
149  // This is the error return code; raise the alarm.
150  TEUCHOS_TEST_FOR_EXCEPTION(fieldIds_[fd] == -1, logic_error,
151  "GatherTangent_Epetra<Residual>: Could not find field \"" + fieldName +
152  "\" in the global indexer. ");
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 Teuchos::RCP;
169  using Teuchos::rcp_dynamic_cast;
171  using GED = GlobalEvaluationData;
172  if (d.gedc->containsDataObject(globalDataKey_))
173  {
174  RCP<GED> ged = d.gedc->getDataObject(globalDataKey_);
175  dxdpEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged, true);
176  }
177 } // end of preEvaluate()
178 
180 //
181 // evaluateFields()
182 //
184 template<typename EvalT, typename TRAITS, typename LO, typename GO>
185 void
188  typename TRAITS::EvalData workset)
189 {
190  using PHX::MDField;
191  using std::size_t;
192  using std::string;
193  using std::vector;
194  using Teuchos::ArrayRCP;
195  using Teuchos::ptrFromRef;
196  using Teuchos::RCP;
197  using Teuchos::rcp_dynamic_cast;
198  using Thyra::SpmdVectorBase;
199 
200  // If no global evaluation data container was set, then this evaluator
201  // becomes a no-op.
202  if (dxdpEvRoGed_.is_null())
203  return;
204 
205  // For convenience, pull out some objects from the workset.
206  string blockId(this->wda(workset).block_id);
207  const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
208  int numCells(localCellIds.size()), numFields(gatherFields_.size());
209 
210  // NOTE: A reordering of these loops will likely improve performance. The
211  // "getGIDFieldOffsets may be expensive. However the "getElementGIDs"
212  // can be cheaper. However the lookup for LIDs may be more expensive!
213 
214  // Gather operation for each cell in the workset.
215  for (int cell(0); cell < numCells; ++cell)
216  {
217  size_t cellLocalId(localCellIds[cell]);
218  auto LIDs = globalIndexer_->getElementLIDs(cellLocalId);
219 
220  // Loop over the fields to be gathered.
221  for (int fieldIndex(0); fieldIndex < numFields; ++fieldIndex)
222  {
223  MDField<ScalarT, Cell, NODE>& field = gatherFields_[fieldIndex];
224  int fieldNum(fieldIds_[fieldIndex]);
225  const vector<int>& elmtOffset =
226  globalIndexer_->getGIDFieldOffsets(blockId, fieldNum);
227  int numBases(elmtOffset.size());
228 
229  // Loop over the basis functions and fill the fields.
230  for (int basis(0); basis < numBases; ++basis)
231  {
232  int offset(elmtOffset[basis]), lid(LIDs[offset]);
233  field(cell, basis) = (*dxdpEvRoGed_)[lid];
234  } // end loop over the basis functions
235  } // end loop over the fields to be gathered
236  } // end loop over the cells in the workset
237 } // end of evaluateFields()
238 
239 #endif // __Panzer_GatherTangent_Epetra_impl_hpp__
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
T & get(const std::string &name, T def_value)
std::string globalDataKey_
The key identifying the GlobalEvaluationData.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< std::vector< std::string > > indexerNames_
A list of the names of the fields to be gathered.
GatherTangent_Epetra()
Default Constructor (disabled).
int numFields
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &fm)
Post-Registration Setup.
This class provides a boundary exchange communication mechanism for vectors.
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 preEvaluate(typename TRAITS::PreEvalData d)
Pre-Evaluate: Sets the tangent vector.
void evaluateFields(typename TRAITS::EvalData d)
Evaluate Fields: Gather operation.
bool useTimeDerivativeSolutionVector_
A flag indicating whether we should be working with or .