Panzer  Version of the Day
Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.cpp
Go to the documentation of this file.
2 
3 #include "Epetra_Import.h"
4 
5 #include "Thyra_VectorBase.hpp"
6 #include "Thyra_LinearOpBase.hpp"
7 #include "Thyra_EpetraThyraWrappers.hpp"
8 #include "Thyra_get_Epetra_Operator.hpp"
9 
10 namespace panzer {
11 
12 using Teuchos::RCP;
13 
14 void
16 useConstantValues(const std::vector<int> & indices,double value)
17 {
19  "EpetraVector_ReadOnly_GED has been initialized, cannot call \"useConstantValues\"!");
20 
21  // add this specification to the filetered pairs vector
22  FilteredPair pair;
23  pair.first = indices;
24  pair.second = value;
25  filteredPairs_.push_back(pair);
26 }
27 
28 void
31  const RCP<const Epetra_Map>& ghostedMap,
32  const RCP<const Epetra_Map>& ownedMap)
33 {
34  importer_ = importer;
35  ghostedMap_ = ghostedMap;
36  ownedMap_ = ownedMap;
37 
38  // allocate the ghosted vector
39  ghostedVector_ = Teuchos::rcp(new Epetra_Vector(*ghostedMap_));
40 
41  // build up the thyra conversion data structures
42  ghostedSpace_ = Thyra::create_VectorSpace(ghostedMap_);
43  ownedSpace_ = Thyra::create_VectorSpace(ownedMap_);
44 
45  // translate filtered pair GIDs to LIDs
46  // initialize some ghosted values to the user specified values
47  for(std::size_t i=0;i<filteredPairs_.size();i++) {
48  std::vector<int> lids;
49  const std::vector<int> & gids = filteredPairs_[i].first;
50  for(std::size_t j=0;j<gids.size();j++) {
51  int lid = ghostedMap->LID(gids[j]);
52 
53  // add legit LIDs to list
54  if(lid>=0)
55  lids.push_back(lid);
56  }
57 
58  // overwrite original GID vector with new LID vector
59  filteredPairs_[i].first = lids;
60  }
61 
62  isInitialized_ = true;
63 }
64 
65 void
67 globalToGhost(int mem)
68 {
69  TEUCHOS_TEST_FOR_EXCEPTION(ownedVector_ == Teuchos::null,std::logic_error,
70  "Owned vector has not been set, can't perform the halo exchange!");
71 
72  // Initialize the ghosted data, zeroing out things, and filling in specified
73  // constants.
75  Teuchos::RCP<const Epetra_Vector> ownedVector_ep = Thyra::get_Epetra_Vector(
77 
78  // Do the global distribution.
79  ghostedVector_->Import(*ownedVector_ep, *importer_, Insert);
80 }
81 
82 void
85 {
87  "EpetraVector_ReadOnly_GED has not been initialized, cannot call \"initializeData\"!");
88 
89  ghostedVector_->PutScalar(0.0);
90 
91  // initialize some ghosted values to the user specified values
92  for(std::size_t i=0;i<filteredPairs_.size();i++) {
93  const std::vector<int> & lids = filteredPairs_[i].first;
94  double value = filteredPairs_[i].second;
95  for(std::size_t j=0;j<lids.size();j++)
96  (*ghostedVector_)[lids[j]] = value;
97  }
98 }
99 
100 void
103 {
105  ownedVector_ = Thyra::create_Vector(ownedVector, ownedSpace_);
106 }
107 
111 {
113  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
114 
115  return ghostedVector_;
116 }
117 
118 void
121  ownedVector)
122 {
124  // ownedVector_ep_ = Thyra::get_Epetra_Vector(*ownedMap_, ownedVector);
125  ownedVector_ = ownedVector;
126 /*
127  std::cout << "SETTING OWNED" << std::endl;
128  std::cout << Teuchos::describe(*ownedVector, Teuchos::VERB_EXTREME) << std::endl;
129  ownedVector_->Print(std::cout);
130  std::cout << std::endl;
131 */
132 }
133 
137 {
139  // return (ownedVector_==Teuchos::null) ? Teuchos::null :
140  // Thyra::create_Vector(ownedVector_, ownedSpace_);
141  return ownedVector_;
142 }
143 
147 {
149  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
150 
151  return Thyra::create_Vector(ghostedVector_,ghostedSpace_);
152 }
153 
154 void
156 print(std::ostream & os) const
157 {
158  const std::string tab = " ";
159  os << "\n";
160  os << tab << "EpetraVector_ReadOnly_GlobalEvaluationData\n"
161  << tab << " init = " << isInitialized_ << "\n"
162  << tab << " owned = " << ownedVector_ << "\n"
163  << tab << " ghosted = " << ghostedVector_ << "\n";
164 
165  /*
166  os << "GHOSTED MAP\n";
167  ghostedMap_->Print(os);
168  os << "\n\n";
169 
170  os << "GHOSTED Vector\n";
171  ghostedVector_->Print(os);
172  os << "\n\n";
173 
174  os << "OWNED MAP\n";
175  ownedMap_->Print(os);
176  os << "\n\n";
177 
178  os << "OWNED Vector\n";
179  ownedVector_->Print(os);
180  os << "\n\n";
181  */
182 }
183 
184 
185 }
void setOwnedVector(const Teuchos::RCP< const Thyra::VectorBase< double > > &ownedVector)
Set the owned vector (Thyra version)
#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)
Kokkos::View< const LO **, PHX::Device > lids
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector (Thyra version)
Teuchos::RCP< Epetra_Vector > getGhostedVector_Epetra() const
Get the ghosted vector (Epetra version)
Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector (Thyra version)
#define TEUCHOS_ASSERT(assertion_test)
void initialize(const Teuchos::RCP< const Epetra_Import > &importer, const Teuchos::RCP< const Epetra_Map > &ghostedMap, const Teuchos::RCP< const Epetra_Map > &ownedMap)