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  PHX::ExecSpace().fence();
125 }
126 
127 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
128 void
131 {
132  TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
133  "TpetraVector_ReadOnly_GED has not been initialized, cannot call \"initializeData\"!");
134 
135  ghostedVector_->putScalar(0.0);
136  PHX::ExecSpace().fence();
137 
138  typedef typename VectorType::dual_view_type::t_dev::memory_space DMS;
139  auto values = ghostedVector_->getLocalViewHost(Tpetra::Access::OverwriteAll);
140 
141  // initialize some ghosted values to the user specified values
142  for(std::size_t i=0;i<filteredPairs_.size();i++) {
143  const std::vector<int> & lids = filteredPairs_[i].first;
144  double value = filteredPairs_[i].second;
145  for(std::size_t j=0;j<lids.size();j++)
146  values(lids[j], 0) = value;
147  }
148 }
149 
150 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
151 void
154 {
155  TEUCHOS_ASSERT(isInitialized_);
156  ownedVector_ = ownedVector;
157 }
158 
159 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
163 {
164  TEUCHOS_ASSERT(isInitialized_);
165  return ownedVector_;
166 }
167 
168 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
172 {
173  TEUCHOS_ASSERT(isInitialized_);
174  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
175 
176  return ghostedVector_;
177 }
178 
179 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
180 void
183  ownedVector)
184 {
185  typedef Thyra::TpetraOperatorVectorExtraction<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> TOE;
186  TEUCHOS_ASSERT(isInitialized_);
187  ownedVector_ = TOE::getConstTpetraVector(ownedVector);
188 }
189 
190 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
194 {
195  TEUCHOS_ASSERT(isInitialized_);
196  return (ownedVector_ == Teuchos::null) ? Teuchos::null :
197  Thyra::createConstVector(ownedVector_, ownedSpace_);
198 }
199 
200 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
204 {
205  TEUCHOS_ASSERT(isInitialized_);
206  TEUCHOS_ASSERT(ghostedVector_!=Teuchos::null);
207 
208  return Thyra::createVector(ghostedVector_,ghostedSpace_);
209 }
210 
211 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
212 void
214 print(std::ostream & os) const
215 {
216  const std::string tab = " ";
217  os << "\n";
218  os << tab << "TpetraVector_ReadOnly_GlobalEvaluationData\n"
219  << tab << " init = " << isInitialized_ << "\n"
220  << tab << " owned = " << ownedVector_ << "\n"
221  << tab << " ghosted = " << ghostedVector_ << "\n";
222 }
223 
224 
225 }
226 
227 #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)
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)
Kokkos::View< const LO **, Kokkos::LayoutRight, PHX::Device > lids
void initialize(const Teuchos::RCP< const ImportType > &importer, const Teuchos::RCP< const MapType > &ghostedMap, const Teuchos::RCP< const MapType > &ownedMap)