Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.cpp
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
44//
45// Include Files
46//
48
49// Epetra
50#include "Epetra_Import.h"
51
52// Panzer
54
55// Thyra
56#include "Thyra_EpetraThyraWrappers.hpp"
57#include "Thyra_SpmdVectorBase.hpp"
58#include "Thyra_SpmdVectorSpaceBase.hpp"
59#include "Thyra_VectorBase.hpp"
60#include "Thyra_VectorSpaceBase.hpp"
61
62namespace panzer
63{
65 //
66 // useConstantValues()
67 //
69 void
72 const std::vector<int>& indices,
73 double value)
74 {
75 using std::logic_error;
76 TEUCHOS_TEST_FOR_EXCEPTION(isInitialized_, logic_error,
77 "EpetraVector_ReadOnly_GlobalEvaluationData has been initialized; " \
78 "cannot call \"useConstantValues()\"!");
79
80 // Add this specification to the filtered pairs vector.
81 FilteredPair fp;
82 fp.first = indices;
83 fp.second = value;
84 filteredPairs_.push_back(fp);
85 } // end of useConstantValues()
86
88 //
89 // initialize()
90 //
92 void
95 const Teuchos::RCP<const Epetra_Import>& importer,
96 const Teuchos::RCP<const Epetra_Map>& ghostedMap,
97 const Teuchos::RCP<const Epetra_Map>& ownedMap)
98 {
100 using std::size_t;
101 using std::vector;
102 using Teuchos::rcp;
103 using Thyra::create_Vector;
104 using Thyra::create_VectorSpace;
105
106 // Save the input.
107 importer_ = importer;
108 ghostedMap_ = ghostedMap;
109 ownedMap_ = ownedMap;
110
111 // Build up the Thyra conversion data structures.
112 ghostedSpace_ = create_VectorSpace(ghostedMap_);
113 ownedSpace_ = create_VectorSpace(ownedMap_ );
114
115 // Allocate the vectors.
117 auto ownedVector = rcp(new Epetra_Vector(*ownedMap_));
118 ownedVector_ = create_Vector(ownedVector, ownedSpace_);
119
120 // Translate filtered pair GIDs to LIDs and initialize some ghosted values
121 // to the user-specified values.
122 for (size_t i(0); i < filteredPairs_.size(); ++i)
123 {
124 vector<int> lids;
125 const vector<int>& gids = filteredPairs_[i].first;
126 for (size_t j(0); j < gids.size(); ++j)
127 {
128 // Add legitimate LIDs to the list.
129 int lid = ghostedMap->LID(gids[j]);
130 if (lid >= 0)
131 lids.push_back(lid);
132 } // end loop over gids
133
134 // Overwrite the original GID vector with the new LID vector.
135 filteredPairs_[i].first = lids;
136 } // end loop over filteredPairs_
137 isInitialized_ = true;
138
139 // Get the PHX::Views corresponding to the owned and ghosted vectors.
140 ownedView_ = getView<const Epetra_Vector>(*ownedVector_);
141 ghostedView_ = getView<Epetra_Vector>(*getGhostedVector());
142 } // end of initialize()
143
145 //
146 // globalToGhost()
147 //
149 void
152 int /* mem */)
153 {
154 using std::logic_error;
155 using Teuchos::RCP;
156 using Thyra::get_Epetra_Vector;
157 TEUCHOS_TEST_FOR_EXCEPTION(ownedVector_.is_null(), logic_error,
158 "EpetraVector_ReadOnly_GlobalEvaluationData::globalToGhost(): Owned " \
159 "vector has not been set; can't perform the halo exchange!")
160
161 // Initialize the ghosted data, zeroing out things, and filling in
162 // specified constants.
164 RCP<const Epetra_Vector> ownedVector_ep =
165 get_Epetra_Vector(*ownedMap_, ownedVector_);
166
167 // Do the global distribution.
168 ghostedVector_->Import(*ownedVector_ep, *importer_, Insert);
169 } // end of globalToGhost()
170
172 //
173 // initializeData()
174 //
176 void
179 {
180 using std::logic_error;
181 using std::size_t;
182 using std::vector;
183 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
184 "EpetraVector_ReadOnly_GlobalEvaluationData has not been initialized, " \
185 "cannot call \"initializeData()\"!");
186 ghostedVector_->PutScalar(0);
187
188 // Initialize some ghosted values to the user-specified values.
189 for (size_t i(0); i < filteredPairs_.size(); ++i)
190 {
191 const vector<int>& lids = filteredPairs_[i].first;
192 for (size_t j(0); j < lids.size(); ++j)
193 (*ghostedVector_)[lids[j]] = filteredPairs_[i].second;
194 } // end loop over filteredPairs_
195 } // end of initializeData()
196
198 //
199 // ghostToGlobal()
200 //
202 void
205 int /* mem = 0 */)
206 {
207 } // end of ghostToGlobal()
208
210 //
211 // setOwnedVector_Epetra()
212 //
214 void
217 const Teuchos::RCP<const Epetra_Vector>& ownedVector)
218 {
220 using std::logic_error;
221 using Thyra::create_Vector;
222 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
223 "EpetraVector_ReadOnly_GlobalEvaluationData::" \
224 "setOwnedVector_Epetra(): This object hasn't yet been initialized.")
225 ownedVector_ = create_Vector(ownedVector, ownedSpace_);
226 ownedView_ = getView<const Epetra_Vector>(*ownedVector_);
227 } // end of setOwnedVector_Epetra()
228
230 //
231 // getGhostedVector_Epetra()
232 //
234 Teuchos::RCP<Epetra_Vector>
237 {
238 using std::logic_error;
239 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
240 "EpetraVector_ReadOnly_GlobalEvaluationData::" \
241 "getGhostedVector_Epetra(): This object hasn't yet been initialized.")
242 TEUCHOS_TEST_FOR_EXCEPTION(ghostedVector_.is_null(), logic_error,
243 "EpetraVector_ReadOnly_GlobalEvaluationData::" \
244 "getGhostedVector_Epetra(): The ghosted vector is just a null RCP.")
245 return ghostedVector_;
246 } // end of getGhostedVector_Epetra()
247
249 //
250 // setOwnedVector()
251 //
253 void
256 const Teuchos::RCP<const Thyra::VectorBase<double>>& ownedVector)
257 {
259 using std::logic_error;
260 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
261 "EpetraVector_ReadOnly_GlobalEvaluationData::setOwnedVector(): This " \
262 "object hasn't yet been initialized.")
263 ownedVector_ = ownedVector;
264 ownedView_ = getView<const Epetra_Vector>(*ownedVector_);
265 } // end of setOwnedVector()
266
268 //
269 // getOwnedVector()
270 //
272 Teuchos::RCP<const Thyra::VectorBase<double>>
274 getOwnedVector() const
275 {
276 using std::logic_error;
277 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
278 "EpetraVector_ReadOnly_GlobalEvaluationData::getOwnedVector(): This " \
279 "object hasn't yet been initialized.")
280 return ownedVector_;
281 } // end of getOwnedVector()
282
284 //
285 // getGhostedVector()
286 //
288 Teuchos::RCP<Thyra::VectorBase<double>>
290 getGhostedVector() const
291 {
292 using std::logic_error;
293 using Thyra::create_Vector;
294 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
295 "EpetraVector_ReadOnly_GlobalEvaluationData::getGhostedVector(): " \
296 "This object hasn't yet been initialized.")
297 TEUCHOS_TEST_FOR_EXCEPTION(ghostedVector_.is_null(), logic_error,
298 "EpetraVector_ReadOnly_GlobalEvaluationData::getGhostedVector(): The " \
299 "ghosted vector is just a null RCP.")
300 return create_Vector(ghostedVector_, ghostedSpace_);
301 } // end of getGhostedVector()
302
304 //
305 // print()
306 //
308 void
310 print(
311 std::ostream& os) const
312 {
313 using std::endl;
314 using std::string;
315 const string tab(" ");
316 os << endl
317 << tab << "EpetraVector_ReadOnly_GlobalEvaluationData" << endl
318 << tab << " init = " << isInitialized_ << endl
319 << tab << " owned = " << ownedVector_ << endl
320 << tab << " ghosted = " << ghostedVector_ << endl;
321 } // end of print()
322
323} // end of namespace panzer
324
325// end of Panzer_EpetraVector_ReadOnly_GlobalEvaluationData.cpp
Insert
Kokkos::View< const LO **, Kokkos::LayoutRight, PHX::Device > lids
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.
Teuchos::RCP< const Epetra_Import > importer_
The importer used to communicate between the owned and ghosted vectors.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > ownedSpace_
The vector space corresponding to the owned vector.
Teuchos::RCP< const Thyra::VectorBase< double > > ownedVector_
The owned vector.
void setOwnedVector(const Teuchos::RCP< const Thyra::VectorBase< double > > &ownedVector)
Set the owned vector (Thyra version).
void setOwnedVector_Epetra(const Teuchos::RCP< const Epetra_Vector > &ownedVector)
Set the owned vector (Epetra version).
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.
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...
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...
virtual void globalToGhost(int mem=0)
Communicate the owned data to the ghosted vector.
Teuchos::RCP< Epetra_Vector > getGhostedVector_Epetra() const
Get the ghosted vector (Epetra version).
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.
std::vector< FilteredPair > filteredPairs_
The list of filtered pairs, used to initialize values on the ghostedVector_.
virtual void ghostToGlobal(int mem=0)
Communicate the ghosted data to the owned vector.
bool isInitialized_
A flag indicating whether or not the object has been initialized.
VectorToViewTraits< VectorType >::View getView(typename VectorToViewTraits< VectorType >::ThyraVector &v)