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 
114  // This fixes the case of dxdpEvRoGed_ being null and no
115  // operations performed during evalaute. Keeps the field with
116  // initial zero state.
117  this->addUnsharedField(gatherFields_[fd].fieldTag().clone());
118  } // end loop over names
119 
120  // Figure out what the first active name is.
121  string firstName("<none>");
122  if (numFields > 0)
123  firstName = names[0];
124  string n("GatherTangent (Epetra): " + firstName + " (" +
125  print<EvalT>() + ")");
126  this->setName(n);
127 } // end of Initializing Constructor
128 
130 //
131 // postRegistrationSetup()
132 //
134 template<typename EvalT, typename TRAITS, typename LO, typename GO>
135 void
138  typename TRAITS::SetupData /* d */,
139  PHX::FieldManager<TRAITS>& /* fm */)
140 {
141  using std::logic_error;
142  using std::size_t;
143  using std::string;
144  using Teuchos::null;
145  TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size());
146  int numFields(gatherFields_.size());
147  fieldIds_.resize(numFields);
148  for (int fd(0); fd < numFields; ++fd)
149  {
150  // Get the field ID from the DOF manager.
151  const string& fieldName((*indexerNames_)[fd]);
152  fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
153 
154  // This is the error return code; raise the alarm.
155  TEUCHOS_TEST_FOR_EXCEPTION(fieldIds_[fd] == -1, logic_error,
156  "GatherTangent_Epetra<Residual>: Could not find field \"" + fieldName +
157  "\" in the global indexer. ");
158  } // end loop over gatherFields_
159  indexerNames_ = null;
160 } // end of postRegistrationSetup()
161 
163 //
164 // preEvaluate()
165 //
167 template<typename EvalT, typename TRAITS, typename LO, typename GO>
168 void
171  typename TRAITS::PreEvalData d)
172 {
173  using Teuchos::RCP;
174  using Teuchos::rcp_dynamic_cast;
176  using GED = GlobalEvaluationData;
177  if (d.gedc->containsDataObject(globalDataKey_))
178  {
179  RCP<GED> ged = d.gedc->getDataObject(globalDataKey_);
180  dxdpEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged, true);
181  }
182 } // end of preEvaluate()
183 
185 //
186 // evaluateFields()
187 //
189 template<typename EvalT, typename TRAITS, typename LO, typename GO>
190 void
193  typename TRAITS::EvalData workset)
194 {
195  using PHX::MDField;
196  using std::size_t;
197  using std::string;
198  using std::vector;
199  using Teuchos::ArrayRCP;
200  using Teuchos::ptrFromRef;
201  using Teuchos::RCP;
202  using Teuchos::rcp_dynamic_cast;
203  using Thyra::SpmdVectorBase;
204 
205  // If no global evaluation data container was set, then this evaluator
206  // becomes a no-op.
207  if (dxdpEvRoGed_.is_null())
208  return;
209 
210  // For convenience, pull out some objects from the workset.
211  string blockId(this->wda(workset).block_id);
212  const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
213  int numCells(localCellIds.size()), numFields(gatherFields_.size());
214 
215  // NOTE: A reordering of these loops will likely improve performance. The
216  // "getGIDFieldOffsets may be expensive. However the "getElementGIDs"
217  // can be cheaper. However the lookup for LIDs may be more expensive!
218 
219  // Gather operation for each cell in the workset.
220  auto LIDs = globalIndexer_->getLIDs();
221  auto LIDs_h = Kokkos::create_mirror_view(LIDs);
222  Kokkos::deep_copy(LIDs_h, LIDs);
223  // Loop over the fields to be gathered.
224  for (int fieldIndex(0); fieldIndex < numFields; ++fieldIndex)
225  {
226  MDField<ScalarT, Cell, NODE>& field = gatherFields_[fieldIndex];
227  auto field_h = Kokkos::create_mirror_view(field.get_static_view());
228  for (int cell(0); cell < numCells; ++cell)
229  {
230  size_t cellLocalId(localCellIds[cell]);
231  int fieldNum(fieldIds_[fieldIndex]);
232  const vector<int>& elmtOffset =
233  globalIndexer_->getGIDFieldOffsets(blockId, fieldNum);
234  int numBases(elmtOffset.size());
235 
236  // Loop over the basis functions and fill the fields.
237  for (int basis(0); basis < numBases; ++basis)
238  {
239  int offset(elmtOffset[basis]), lid(LIDs_h(cellLocalId, offset));
240  field_h(cell, basis) = (*dxdpEvRoGed_)[lid];
241  } // end loop over the basis functions
242  } // end loop over the cells in the workset
243  Kokkos::deep_copy(field.get_static_view(), field_h);
244  } // end loop over the fields to be gathered
245 } // end of evaluateFields()
246 
247 #endif // __Panzer_GatherTangent_Epetra_impl_hpp__
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
The fields to be gathered.
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
Create a copy.
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 .