Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_TpetraVector_ReadOnly_GlobalEvaluationData_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_TpetraVector_ReadOnly_GlobalEvaluationData_impl_hpp__
12 #define __Panzer_TpetraVector_ReadOnly_GlobalEvaluationData_impl_hpp__
13 
14 #include "Thyra_TpetraThyraWrappers.hpp"
15 
16 namespace panzer {
17 
18 using Teuchos::RCP;
19 
20 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
21 void
23 useConstantValues(const std::vector<GlobalOrdinalT> & indices,double value)
24 {
25  TEUCHOS_TEST_FOR_EXCEPTION(isInitialized_,std::logic_error,
26  "TpetraVector_ReadOnly_GED has been initialized, cannot call \"useConstantValues\"!");
27 
28  // add this specification to the filtered pairs vector
29  FilteredGlobalPair pair;
30  pair.first = indices;
31  pair.second = value;
32  globalFilteredPairs_.push_back(pair);
33 }
34 
35 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
36 void
39  const RCP<const MapType>& ghostedMap,
40  const RCP<const MapType>& ownedMap)
41 {
42  importer_ = importer;
43  ghostedMap_ = ghostedMap;
44  ownedMap_ = ownedMap;
45 
46  // allocate the ghosted vector
47  ghostedVector_ = Teuchos::rcp(new VectorType(ghostedMap_));
48 
49  // build up the thyra conversion data structures
50  ghostedSpace_ = Thyra::tpetraVectorSpace<ScalarT, LocalOrdinalT,
51  GlobalOrdinalT, NodeT>(ghostedMap_);
52  ownedSpace_ = Thyra::tpetraVectorSpace<ScalarT, LocalOrdinalT,
53  GlobalOrdinalT, NodeT>(ownedMap_);
54 
55 
56  // translate filtered pair GIDs to LIDs
57  // initialize some ghosted values to the user specified values
58  filteredPairs_.resize(globalFilteredPairs_.size());
59  for(std::size_t i=0;i<globalFilteredPairs_.size();i++) {
60  std::vector<LocalOrdinalT> lids;
61  const std::vector<GlobalOrdinalT> & gids = globalFilteredPairs_[i].first;
62  for(std::size_t j=0;j<gids.size();j++) {
63  LocalOrdinalT lid = ghostedMap->getLocalElement(gids[j]);
64 
65  // add legit LIDs to list
66  if(lid>=0)
67  lids.push_back(lid);
68  }
69 
70  // convert original GID vector to LID vector, store value as well
71  filteredPairs_[i].first = lids;
72  filteredPairs_[i].second = globalFilteredPairs_[i].second;
73  }
74 
75  isInitialized_ = true;
76 }
77 
78 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
79 void
81 globalToGhost(int /* mem */)
82 {
83  TEUCHOS_TEST_FOR_EXCEPTION(ownedVector_ == Teuchos::null, std::logic_error,
84  "Owned vector has not been set, can't perform the halo exchange!");
85 
86  // Initialize the ghosted data, zeroing out things, and filling in specified
87  // constants.
88  initializeData();
89 
90  // Do the global distribution.
91  ghostedVector_->doImport(*ownedVector_, *importer_, Tpetra::INSERT);
92  PHX::ExecSpace().fence();
93 }
94 
95 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
96 void
99 {
100  TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
101  "TpetraVector_ReadOnly_GED has not been initialized, cannot call \"initializeData\"!");
102 
103  ghostedVector_->putScalar(0.0);
104  PHX::ExecSpace().fence();
105 
106  auto values = ghostedVector_->getLocalViewHost(Tpetra::Access::OverwriteAll);
107 
108  // initialize some ghosted values to the user specified values
109  for(std::size_t i=0;i<filteredPairs_.size();i++) {
110  const std::vector<int> & lids = filteredPairs_[i].first;
111  double value = filteredPairs_[i].second;
112  for(std::size_t j=0;j<lids.size();j++)
113  values(lids[j], 0) = value;
114  }
115 }
116 
117 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
118 void
121 {
122  TEUCHOS_ASSERT(isInitialized_);
123  ownedVector_ = ownedVector;
124 }
125 
126 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
130 {
131  TEUCHOS_ASSERT(isInitialized_);
132  return ownedVector_;
133 }
134 
135 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
139 {
140  TEUCHOS_ASSERT(isInitialized_);
141  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
142 
143  return ghostedVector_;
144 }
145 
146 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
147 void
150  ownedVector)
151 {
152  typedef Thyra::TpetraOperatorVectorExtraction<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> TOE;
153  TEUCHOS_ASSERT(isInitialized_);
154  ownedVector_ = TOE::getConstTpetraVector(ownedVector);
155 }
156 
157 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
161 {
162  TEUCHOS_ASSERT(isInitialized_);
163  return (ownedVector_ == Teuchos::null) ? Teuchos::null :
164  Thyra::createConstVector(ownedVector_, ownedSpace_);
165 }
166 
167 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
171 {
172  TEUCHOS_ASSERT(isInitialized_);
173  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
174 
175  return Thyra::createVector(ghostedVector_,ghostedSpace_);
176 }
177 
178 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
179 void
181 print(std::ostream & os) const
182 {
183  const std::string tab = " ";
184  os << "\n";
185  os << tab << "TpetraVector_ReadOnly_GlobalEvaluationData\n"
186  << tab << " init = " << isInitialized_ << "\n"
187  << tab << " owned = " << ownedVector_ << "\n"
188  << tab << " ghosted = " << ghostedVector_ << "\n";
189 }
190 
191 
192 }
193 
194 #endif
Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > VectorType
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 useConstantValues(const std::vector< GlobalOrdinalT > &indices, double value)
Teuchos::RCP< const Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector (Thyra version)
Kokkos::View< const LO **, Kokkos::LayoutRight, PHX::Device > lids
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOwnedVector_Tpetra(const Teuchos::RCP< const VectorType > &ownedVector)
Set the owned vector (Tpetra version)
Teuchos::RCP< const VectorType > getOwnedVector_Tpetra() const
Get the owned vector (Tpetra version)
Teuchos::RCP< VectorType > getGhostedVector_Tpetra() const
Get the ghosted vector (Tpetra version)
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector (Thyra version)
void initialize(const Teuchos::RCP< const ImportType > &importer, const Teuchos::RCP< const MapType > &ghostedMap, const Teuchos::RCP< const MapType > &ownedMap)