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 //
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_TpetraVector_ReadOnly_GlobalEvaluationData_impl_hpp__
44 #define __Panzer_TpetraVector_ReadOnly_GlobalEvaluationData_impl_hpp__
45 
46 #include "Thyra_TpetraThyraWrappers.hpp"
47 
48 namespace panzer {
49 
50 using Teuchos::RCP;
51 
52 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
53 void
55 useConstantValues(const std::vector<GlobalOrdinalT> & indices,double value)
56 {
57  TEUCHOS_TEST_FOR_EXCEPTION(isInitialized_,std::logic_error,
58  "TpetraVector_ReadOnly_GED has been initialized, cannot call \"useConstantValues\"!");
59 
60  // add this specification to the filtered pairs vector
61  FilteredGlobalPair pair;
62  pair.first = indices;
63  pair.second = value;
64  globalFilteredPairs_.push_back(pair);
65 }
66 
67 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
68 void
71  const RCP<const MapType>& ghostedMap,
72  const RCP<const MapType>& ownedMap)
73 {
74  importer_ = importer;
75  ghostedMap_ = ghostedMap;
76  ownedMap_ = ownedMap;
77 
78  // allocate the ghosted vector
79  ghostedVector_ = Teuchos::rcp(new VectorType(ghostedMap_));
80 
81  // build up the thyra conversion data structures
82  ghostedSpace_ = Thyra::tpetraVectorSpace<ScalarT, LocalOrdinalT,
83  GlobalOrdinalT, NodeT>(ghostedMap_);
84  ownedSpace_ = Thyra::tpetraVectorSpace<ScalarT, LocalOrdinalT,
85  GlobalOrdinalT, NodeT>(ownedMap_);
86 
87 
88  // translate filtered pair GIDs to LIDs
89  // initialize some ghosted values to the user specified values
90  filteredPairs_.resize(globalFilteredPairs_.size());
91  for(std::size_t i=0;i<globalFilteredPairs_.size();i++) {
92  std::vector<LocalOrdinalT> lids;
93  const std::vector<GlobalOrdinalT> & gids = globalFilteredPairs_[i].first;
94  for(std::size_t j=0;j<gids.size();j++) {
95  LocalOrdinalT lid = ghostedMap->getLocalElement(gids[j]);
96 
97  // add legit LIDs to list
98  if(lid>=0)
99  lids.push_back(lid);
100  }
101 
102  // convert original GID vector to LID vector, store value as well
103  filteredPairs_[i].first = lids;
104  filteredPairs_[i].second = globalFilteredPairs_[i].second;
105  }
106 
107  isInitialized_ = true;
108 }
109 
110 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
111 void
113 globalToGhost(int /* mem */)
114 {
115  TEUCHOS_TEST_FOR_EXCEPTION(ownedVector_ == Teuchos::null, std::logic_error,
116  "Owned vector has not been set, can't perform the halo exchange!");
117 
118  // Initialize the ghosted data, zeroing out things, and filling in specified
119  // constants.
120  initializeData();
121 
122  // Do the global distribution.
123  ghostedVector_->doImport(*ownedVector_, *importer_, Tpetra::INSERT);
124 }
125 
126 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
127 void
130 {
131  TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
132  "TpetraVector_ReadOnly_GED has not been initialized, cannot call \"initializeData\"!");
133 
134  ghostedVector_->putScalar(0.0);
135 
136  typedef typename VectorType::dual_view_type::t_dev::memory_space DMS;
137  auto values_2d = ghostedVector_->template getLocalView<DMS>();
138  auto values = Kokkos::subview(values_2d, Kokkos::ALL (), 0);
139 
140  // initialize some ghosted values to the user specified values
141  for(std::size_t i=0;i<filteredPairs_.size();i++) {
142  const std::vector<int> & lids = filteredPairs_[i].first;
143  double value = filteredPairs_[i].second;
144  for(std::size_t j=0;j<lids.size();j++)
145  values(lids[j]) = value;
146  }
147 }
148 
149 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
150 void
153 {
154  TEUCHOS_ASSERT(isInitialized_);
155  ownedVector_ = ownedVector;
156 }
157 
158 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
162 {
163  TEUCHOS_ASSERT(isInitialized_);
164  return ownedVector_;
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 ghostedVector_;
176 }
177 
178 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
179 void
182  ownedVector)
183 {
184  typedef Thyra::TpetraOperatorVectorExtraction<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> TOE;
185  TEUCHOS_ASSERT(isInitialized_);
186  ownedVector_ = TOE::getConstTpetraVector(ownedVector);
187 }
188 
189 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
193 {
194  TEUCHOS_ASSERT(isInitialized_);
195  return (ownedVector_ == Teuchos::null) ? Teuchos::null :
196  Thyra::createConstVector(ownedVector_, ownedSpace_);
197 }
198 
199 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
203 {
204  TEUCHOS_ASSERT(isInitialized_);
205  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
206 
207  return Thyra::createVector(ghostedVector_,ghostedSpace_);
208 }
209 
210 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
211 void
213 print(std::ostream & os) const
214 {
215  const std::string tab = " ";
216  os << "\n";
217  os << tab << "TpetraVector_ReadOnly_GlobalEvaluationData\n"
218  << tab << " init = " << isInitialized_ << "\n"
219  << tab << " owned = " << ownedVector_ << "\n"
220  << tab << " ghosted = " << ghostedVector_ << "\n";
221 }
222 
223 
224 }
225 
226 #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 **, 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)