Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_EpetraVector_Write_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_Export.h"
51 
52 // Panzer
54 
55 // Thyra
56 #include "Thyra_EpetraThyraWrappers.hpp"
57 #include "Thyra_LinearOpBase.hpp"
58 #include "Thyra_SpmdVectorBase.hpp"
59 #include "Thyra_SpmdVectorSpaceBase.hpp"
60 #include "Thyra_VectorBase.hpp"
61 #include "Thyra_VectorStdOps.hpp"
62 
63 namespace panzer
64 {
66  //
67  // initialize()
68  //
70  void
73  const Teuchos::RCP<const Epetra_Export>& exporter,
74  const Teuchos::RCP<const Epetra_Map>& ghostedMap,
75  const Teuchos::RCP<const Epetra_Map>& ownedMap)
76  {
78  using Teuchos::rcp;
79  using Thyra::create_Vector;
80  using Thyra::create_VectorSpace;
81 
82  // Save the input.
83  exporter_ = exporter;
84  ghostedMap_ = ghostedMap;
85  ownedMap_ = ownedMap;
86 
87  // Build up the Thyra conversion data structures.
88  ghostedSpace_ = create_VectorSpace(ghostedMap_);
89  ownedSpace_ = create_VectorSpace(ownedMap_);
90 
91  // Allocate the vectors.
93  auto ownedVector = rcp(new Epetra_Vector(*ownedMap_));
94  ownedVector_ = create_Vector(ownedVector, ownedSpace_);
95  isInitialized_ = true;
96 
97  // Get the PHX::View corresponding to the ghosted vector.
98  ownedView_ = getView<Epetra_Vector>(*ownedVector_);
99  ghostedView_ = getView<Epetra_Vector>(*getGhostedVector());
100  } // end of initialize()
101 
103  //
104  // ghostToGlobal()
105  //
107  void
110  int /* mem */)
111  {
112  using std::invalid_argument;
113  using std::logic_error;
114  using Teuchos::RCP;
115  using Thyra::get_Epetra_Vector;
117  "EpetraVector_Write_GlobalEvaluationData::ghostToGlobal(): Owned " \
118  "vector has not been set; can't perform the halo exchange!")
119 
120  // Set different combine modes.
121  Epetra_CombineMode cm = Add;
122  switch (getCombineMode())
123  {
124  case CM_Sum:
125  cm = Add;
126  break;
127  case CM_Min:
128  cm = Epetra_Min;
129  break;
130  case CM_Max:
131  cm = Epetra_Max;
132  break;
133  case CM_Insert:
134  cm = Insert;
135  break;
136  default:
137  TEUCHOS_TEST_FOR_EXCEPTION(true, invalid_argument,
138  "EpetraVector_Write_GlobalEvaluationData::ghostToGlobal(): " \
139  "Invalid CombineMode. Valid modes are CM_Sum, CM_Max, CM_Min, " \
140  "and CM_Insert.")
141  }; // end switch (getCombineMode())
142 
143  // Do the global distribution.
144  RCP<Epetra_Vector> ownedVector_ep = get_Epetra_Vector(*ownedMap_,
145  ownedVector_);
146  ownedVector_ep->Export(*ghostedVector_, *exporter_, cm);
147  } // end of ghostToGlobal()
148 
150  //
151  // initializeData()
152  //
154  void
157  {
158  using std::logic_error;
159  using Thyra::put_scalar;
161  "EpetraVector_Write_GlobalEvaluationData has not been initialized; " \
162  "cannot call \"initializeData()\"!")
163  put_scalar(0.0, ownedVector_.ptr());
164  } // end of initializeData()
165 
167  //
168  // setOwnedVector_Epetra()
169  //
171  void
174  const Teuchos::RCP<Epetra_Vector>& ownedVector)
175  {
177  using std::logic_error;
178  using Thyra::create_Vector;
180  "EpetraVector_Write_GlobalEvaluationData::setOwnedVector_Epetra(): " \
181  "This object hasn't yet been initialized.")
182  ownedVector_ = create_Vector(ownedVector, ownedSpace_);
183  ownedView_ = getView<Epetra_Vector>(*ownedVector_);
184  } // end of setOwnedVector_Epetra()
185 
187  //
188  // getGhostedVector_Epetra()
189  //
194  {
195  using std::logic_error;
197  "EpetraVector_Write_GlobalEvaluationData::setGhostedVector_Epetra(): " \
198  "This object hasn't yet been initialized.")
200  "EpetraVector_Write_GlobalEvaluationData::setGhostedVector_Epetra(): " \
201  "The ghosted vector is just a null RCP.")
202  return ghostedVector_;
203  } // end of getGhostedVector_Epetra()
204 
206  //
207  // setOwnedVector()
208  //
210  void
213  const Teuchos::RCP<Thyra::VectorBase<double>>& ownedVector)
214  {
216  using std::logic_error;
218  "EpetraVector_Write_GlobalEvaluationData::setOwnedVector(): This " \
219  "object hasn't yet been initialized.")
220  ownedVector_ = ownedVector;
221  ownedView_ = getView<Epetra_Vector>(*ownedVector_);
222  } // end of setOwnedVector()
223 
225  //
226  // getOwnedVector()
227  //
232  {
233  using std::logic_error;
235  "EpetraVector_Write_GlobalEvaluationData::getOwnedVector(): This " \
236  "object hasn't yet been initialized.")
237  return ownedVector_;
238  } // end of getOwnedVector()
239 
241  //
242  // getGhostedVector()
243  //
248  {
249  using std::logic_error;
250  using Thyra::create_Vector;
252  "EpetraVector_Write_GlobalEvaluationData::getGhostedVector(): This " \
253  "object hasn't yet been initialized.")
255  "EpetraVector_Write_GlobalEvaluationData::getGhostedVector(): The " \
256  "ghosted vector is just a null RCP.")
257  return create_Vector(ghostedVector_, ghostedSpace_);
258  } // end of getGhostedVector()
259 
261  //
262  // print()
263  //
265  void
268  std::ostream& os) const
269  {
270  using std::string;
271  const string tab(" ");
272  os << "\n";
273  os << tab << "EpetraVector_Write_GlobalEvaluationData\n"
274  << tab << " init = " << isInitialized_ << "\n"
275  << tab << " owned = " << ownedVector_ << "\n"
276  << tab << " ghosted = " << ghostedVector_ << "\n";
277  } // end of print()
278 
279 } // end of namespace panzer
280 
281 // end of Panzer_EpetraVector_Write_GlobalEvaluationData.cpp
void setOwnedVector(const Teuchos::RCP< Thyra::VectorBase< double >> &ownedVector)
Set the owned vector (Thyra version).
VectorToViewTraits< VectorType >::View getView(typename VectorToViewTraits< VectorType >::ThyraVector &v)
void setOwnedVector_Epetra(const Teuchos::RCP< Epetra_Vector > &ownedVector)
Set the owned vector (Epetra version).
Teuchos::RCP< Thyra::VectorBase< double > > ownedVector_
The owned vector.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initialize(const Teuchos::RCP< const Epetra_Export > &exporter, const Teuchos::RCP< const Epetra_Map > &ghostedMap, const Teuchos::RCP< const Epetra_Map > &ownedMap)
Initialize this object with some Epetra communication objects.
Teuchos::RCP< Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector (Thyra version).
VectorToViewTraits< Epetra_Vector >::View getView< Epetra_Vector >(typename VectorToViewTraits< Epetra_Vector >::ThyraVector &v)
Teuchos::RCP< const Epetra_Map > ownedMap_
The map corresponding to the owned vector.
Teuchos::RCP< Epetra_Vector > getGhostedVector_Epetra() const
Get the ghosted vector (Epetra version).
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > ownedSpace_
The vector space corresponding to the owned vector.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > ghostedSpace_
The vector space corresponding to the ghosted vector.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Ptr< T > ptr() const
bool isInitialized_
A flag indicating whether or not the object has been initialized.
virtual void ghostToGlobal(int mem)
Communicate the ghosted data to the owned vector.
Teuchos::RCP< const Epetra_Map > ghostedMap_
The map corresponding to the ghosted vector.
Epetra_CombineMode
virtual void initializeData()
Clear out the ghosted vector. // JMG: Is this right?
Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector (Thyra version).
Teuchos::RCP< const Epetra_Export > exporter_
The exporter used to communicate between the owned and ghosted vectors.
CombineMode getCombineMode() const
Get the combine mode, to be used by sub classes.
bool is_null() const