Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.cpp
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 
12 //
13 // Include Files
14 //
16 
17 // Epetra
18 #include "Epetra_Import.h"
19 
20 // Panzer
22 
23 // Thyra
24 #include "Thyra_EpetraThyraWrappers.hpp"
25 #include "Thyra_SpmdVectorBase.hpp"
26 #include "Thyra_SpmdVectorSpaceBase.hpp"
27 #include "Thyra_VectorBase.hpp"
28 #include "Thyra_VectorSpaceBase.hpp"
29 
30 namespace panzer
31 {
33  //
34  // useConstantValues()
35  //
37  void
40  const std::vector<int>& indices,
41  double value)
42  {
43  using std::logic_error;
45  "EpetraVector_ReadOnly_GlobalEvaluationData has been initialized; " \
46  "cannot call \"useConstantValues()\"!");
47 
48  // Add this specification to the filtered pairs vector.
49  FilteredPair fp;
50  fp.first = indices;
51  fp.second = value;
52  filteredPairs_.push_back(fp);
53  } // end of useConstantValues()
54 
56  //
57  // initialize()
58  //
60  void
63  const Teuchos::RCP<const Epetra_Import>& importer,
64  const Teuchos::RCP<const Epetra_Map>& ghostedMap,
65  const Teuchos::RCP<const Epetra_Map>& ownedMap)
66  {
68  using std::size_t;
69  using std::vector;
70  using Teuchos::rcp;
71  using Thyra::create_Vector;
72  using Thyra::create_VectorSpace;
73 
74  // Save the input.
75  importer_ = importer;
76  ghostedMap_ = ghostedMap;
77  ownedMap_ = ownedMap;
78 
79  // Build up the Thyra conversion data structures.
80  ghostedSpace_ = create_VectorSpace(ghostedMap_);
81  ownedSpace_ = create_VectorSpace(ownedMap_ );
82 
83  // Allocate the vectors.
85  auto ownedVector = rcp(new Epetra_Vector(*ownedMap_));
86  ownedVector_ = create_Vector(ownedVector, ownedSpace_);
87 
88  // Translate filtered pair GIDs to LIDs and initialize some ghosted values
89  // to the user-specified values.
90  for (size_t i(0); i < filteredPairs_.size(); ++i)
91  {
92  vector<int> lids;
93  const vector<int>& gids = filteredPairs_[i].first;
94  for (size_t j(0); j < gids.size(); ++j)
95  {
96  // Add legitimate LIDs to the list.
97  int lid = ghostedMap->LID(gids[j]);
98  if (lid >= 0)
99  lids.push_back(lid);
100  } // end loop over gids
101 
102  // Overwrite the original GID vector with the new LID vector.
103  filteredPairs_[i].first = lids;
104  } // end loop over filteredPairs_
105  isInitialized_ = true;
106 
107  // Get the PHX::Views corresponding to the owned and ghosted vectors.
108  ownedView_ = getView<const Epetra_Vector>(*ownedVector_);
109  ghostedView_ = getView<Epetra_Vector>(*getGhostedVector());
110  } // end of initialize()
111 
113  //
114  // globalToGhost()
115  //
117  void
120  int /* mem */)
121  {
122  using std::logic_error;
123  using Teuchos::RCP;
124  using Thyra::get_Epetra_Vector;
126  "EpetraVector_ReadOnly_GlobalEvaluationData::globalToGhost(): Owned " \
127  "vector has not been set; can't perform the halo exchange!")
128 
129  // Initialize the ghosted data, zeroing out things, and filling in
130  // specified constants.
131  initializeData();
132  RCP<const Epetra_Vector> ownedVector_ep =
133  get_Epetra_Vector(*ownedMap_, ownedVector_);
134 
135  // Do the global distribution.
136  ghostedVector_->Import(*ownedVector_ep, *importer_, Insert);
137  } // end of globalToGhost()
138 
140  //
141  // initializeData()
142  //
144  void
147  {
148  using std::logic_error;
149  using std::size_t;
150  using std::vector;
152  "EpetraVector_ReadOnly_GlobalEvaluationData has not been initialized, " \
153  "cannot call \"initializeData()\"!");
154  ghostedVector_->PutScalar(0);
155 
156  // Initialize some ghosted values to the user-specified values.
157  for (size_t i(0); i < filteredPairs_.size(); ++i)
158  {
159  const vector<int>& lids = filteredPairs_[i].first;
160  for (size_t j(0); j < lids.size(); ++j)
161  (*ghostedVector_)[lids[j]] = filteredPairs_[i].second;
162  } // end loop over filteredPairs_
163  } // end of initializeData()
164 
166  //
167  // ghostToGlobal()
168  //
170  void
173  int /* mem = 0 */)
174  {
175  } // end of ghostToGlobal()
176 
178  //
179  // setOwnedVector_Epetra()
180  //
182  void
185  const Teuchos::RCP<const Epetra_Vector>& ownedVector)
186  {
188  using std::logic_error;
189  using Thyra::create_Vector;
191  "EpetraVector_ReadOnly_GlobalEvaluationData::" \
192  "setOwnedVector_Epetra(): This object hasn't yet been initialized.")
193  ownedVector_ = create_Vector(ownedVector, ownedSpace_);
194  ownedView_ = getView<const Epetra_Vector>(*ownedVector_);
195  } // end of setOwnedVector_Epetra()
196 
198  //
199  // getGhostedVector_Epetra()
200  //
205  {
206  using std::logic_error;
208  "EpetraVector_ReadOnly_GlobalEvaluationData::" \
209  "getGhostedVector_Epetra(): This object hasn't yet been initialized.")
211  "EpetraVector_ReadOnly_GlobalEvaluationData::" \
212  "getGhostedVector_Epetra(): The ghosted vector is just a null RCP.")
213  return ghostedVector_;
214  } // end of getGhostedVector_Epetra()
215 
217  //
218  // setOwnedVector()
219  //
221  void
224  const Teuchos::RCP<const Thyra::VectorBase<double>>& ownedVector)
225  {
227  using std::logic_error;
229  "EpetraVector_ReadOnly_GlobalEvaluationData::setOwnedVector(): This " \
230  "object hasn't yet been initialized.")
231  ownedVector_ = ownedVector;
232  ownedView_ = getView<const Epetra_Vector>(*ownedVector_);
233  } // end of setOwnedVector()
234 
236  //
237  // getOwnedVector()
238  //
243  {
244  using std::logic_error;
246  "EpetraVector_ReadOnly_GlobalEvaluationData::getOwnedVector(): This " \
247  "object hasn't yet been initialized.")
248  return ownedVector_;
249  } // end of getOwnedVector()
250 
252  //
253  // getGhostedVector()
254  //
259  {
260  using std::logic_error;
261  using Thyra::create_Vector;
263  "EpetraVector_ReadOnly_GlobalEvaluationData::getGhostedVector(): " \
264  "This object hasn't yet been initialized.")
266  "EpetraVector_ReadOnly_GlobalEvaluationData::getGhostedVector(): The " \
267  "ghosted vector is just a null RCP.")
268  return create_Vector(ghostedVector_, ghostedSpace_);
269  } // end of getGhostedVector()
270 
272  //
273  // print()
274  //
276  void
279  std::ostream& os) const
280  {
281  using std::endl;
282  using std::string;
283  const string tab(" ");
284  os << endl
285  << tab << "EpetraVector_ReadOnly_GlobalEvaluationData" << endl
286  << tab << " init = " << isInitialized_ << endl
287  << tab << " owned = " << ownedVector_ << endl
288  << tab << " ghosted = " << ghostedVector_ << endl;
289  } // end of print()
290 
291 } // end of namespace panzer
292 
293 // end of Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.cpp
virtual void globalToGhost(int mem=0)
Communicate the owned data to the ghosted vector.
VectorToViewTraits< VectorType >::View getView(typename VectorToViewTraits< VectorType >::ThyraVector &v)
Teuchos::RCP< const Epetra_Import > importer_
The importer used to communicate between the owned and ghosted vectors.
VectorToViewTraits< const Epetra_Vector >::View getView< const Epetra_Vector >(typename VectorToViewTraits< const Epetra_Vector >::ThyraVector &v)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setOwnedVector_Epetra(const Teuchos::RCP< const Epetra_Vector > &ownedVector)
Set the owned vector (Epetra version).
VectorToViewTraits< Epetra_Vector >::View getView< Epetra_Vector >(typename VectorToViewTraits< Epetra_Vector >::ThyraVector &v)
void useConstantValues(const std::vector< int > &indices, double value)
Choose a few GIDs and, instead of zeroing them out in the ghosted vector, set them to a specified val...
Kokkos::View< const LO **, Kokkos::LayoutRight, PHX::Device > lids
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Epetra_Vector > getGhostedVector_Epetra() const
Get the ghosted vector (Epetra version).
virtual void ghostToGlobal(int mem=0)
Communicate the ghosted data to the owned vector.
Teuchos::RCP< const Thyra::VectorBase< double > > ownedVector_
The owned vector.
int LID(int GID) const
void setOwnedVector(const Teuchos::RCP< const Thyra::VectorBase< double >> &ownedVector)
Set the owned vector (Thyra version).
std::vector< FilteredPair > filteredPairs_
The list of filtered pairs, used to initialize values on the ghostedVector_.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > ownedSpace_
The vector space corresponding to the owned vector.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > ghostedSpace_
The vector space corresponding to the ghosted vector.
std::pair< std::vector< int >, double > FilteredPair
A list of global IDs (which will be translated to local IDs), paired with a value to be assigned in t...
Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector (Thyra version).
Teuchos::RCP< const Epetra_Map > ownedMap_
The map corresponding to the owned vector.
bool isInitialized_
A flag indicating whether or not the object has been initialized.
Teuchos::RCP< const Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector (Thyra version).
Teuchos::RCP< const Epetra_Map > ghostedMap_
The map corresponding to the ghosted vector.
void initialize(const Teuchos::RCP< const Epetra_Import > &importer, const Teuchos::RCP< const Epetra_Map > &ghostedMap, const Teuchos::RCP< const Epetra_Map > &ownedMap)
Initialize this object with some Epetra communication objects.
bool is_null() const