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 // 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 
12 //
13 // Include Files
14 //
16 
17 // Epetra
18 #include "Epetra_Export.h"
19 
20 // Panzer
22 
23 // Thyra
24 #include "Thyra_EpetraThyraWrappers.hpp"
25 #include "Thyra_LinearOpBase.hpp"
26 #include "Thyra_SpmdVectorBase.hpp"
27 #include "Thyra_SpmdVectorSpaceBase.hpp"
28 #include "Thyra_VectorBase.hpp"
29 #include "Thyra_VectorStdOps.hpp"
30 
31 namespace panzer
32 {
34  //
35  // initialize()
36  //
38  void
41  const Teuchos::RCP<const Epetra_Export>& exporter,
42  const Teuchos::RCP<const Epetra_Map>& ghostedMap,
43  const Teuchos::RCP<const Epetra_Map>& ownedMap)
44  {
46  using Teuchos::rcp;
47  using Thyra::create_Vector;
48  using Thyra::create_VectorSpace;
49 
50  // Save the input.
51  exporter_ = exporter;
52  ghostedMap_ = ghostedMap;
53  ownedMap_ = ownedMap;
54 
55  // Build up the Thyra conversion data structures.
56  ghostedSpace_ = create_VectorSpace(ghostedMap_);
57  ownedSpace_ = create_VectorSpace(ownedMap_);
58 
59  // Allocate the vectors.
61  auto ownedVector = rcp(new Epetra_Vector(*ownedMap_));
62  ownedVector_ = create_Vector(ownedVector, ownedSpace_);
63  isInitialized_ = true;
64 
65  // Get the PHX::View corresponding to the ghosted vector.
66  ownedView_ = getView<Epetra_Vector>(*ownedVector_);
67  ghostedView_ = getView<Epetra_Vector>(*getGhostedVector());
68  } // end of initialize()
69 
71  //
72  // ghostToGlobal()
73  //
75  void
78  int /* mem */)
79  {
80  using std::invalid_argument;
81  using std::logic_error;
82  using Teuchos::RCP;
83  using Thyra::get_Epetra_Vector;
85  "EpetraVector_Write_GlobalEvaluationData::ghostToGlobal(): Owned " \
86  "vector has not been set; can't perform the halo exchange!")
87 
88  // Set different combine modes.
90  switch (getCombineMode())
91  {
92  case CM_Sum:
93  cm = Add;
94  break;
95  case CM_Min:
96  cm = Epetra_Min;
97  break;
98  case CM_Max:
99  cm = Epetra_Max;
100  break;
101  case CM_Insert:
102  cm = Insert;
103  break;
104  default:
105  TEUCHOS_TEST_FOR_EXCEPTION(true, invalid_argument,
106  "EpetraVector_Write_GlobalEvaluationData::ghostToGlobal(): " \
107  "Invalid CombineMode. Valid modes are CM_Sum, CM_Max, CM_Min, " \
108  "and CM_Insert.")
109  }; // end switch (getCombineMode())
110 
111  // Do the global distribution.
112  RCP<Epetra_Vector> ownedVector_ep = get_Epetra_Vector(*ownedMap_,
113  ownedVector_);
114  ownedVector_ep->Export(*ghostedVector_, *exporter_, cm);
115  } // end of ghostToGlobal()
116 
118  //
119  // initializeData()
120  //
122  void
125  {
126  using std::logic_error;
127  using Thyra::put_scalar;
129  "EpetraVector_Write_GlobalEvaluationData has not been initialized; " \
130  "cannot call \"initializeData()\"!")
131  put_scalar(0.0, ownedVector_.ptr());
132  } // end of initializeData()
133 
135  //
136  // setOwnedVector_Epetra()
137  //
139  void
142  const Teuchos::RCP<Epetra_Vector>& ownedVector)
143  {
145  using std::logic_error;
146  using Thyra::create_Vector;
148  "EpetraVector_Write_GlobalEvaluationData::setOwnedVector_Epetra(): " \
149  "This object hasn't yet been initialized.")
150  ownedVector_ = create_Vector(ownedVector, ownedSpace_);
151  ownedView_ = getView<Epetra_Vector>(*ownedVector_);
152  } // end of setOwnedVector_Epetra()
153 
155  //
156  // getGhostedVector_Epetra()
157  //
162  {
163  using std::logic_error;
165  "EpetraVector_Write_GlobalEvaluationData::setGhostedVector_Epetra(): " \
166  "This object hasn't yet been initialized.")
168  "EpetraVector_Write_GlobalEvaluationData::setGhostedVector_Epetra(): " \
169  "The ghosted vector is just a null RCP.")
170  return ghostedVector_;
171  } // end of getGhostedVector_Epetra()
172 
174  //
175  // setOwnedVector()
176  //
178  void
181  const Teuchos::RCP<Thyra::VectorBase<double>>& ownedVector)
182  {
184  using std::logic_error;
186  "EpetraVector_Write_GlobalEvaluationData::setOwnedVector(): This " \
187  "object hasn't yet been initialized.")
188  ownedVector_ = ownedVector;
189  ownedView_ = getView<Epetra_Vector>(*ownedVector_);
190  } // end of setOwnedVector()
191 
193  //
194  // getOwnedVector()
195  //
200  {
201  using std::logic_error;
203  "EpetraVector_Write_GlobalEvaluationData::getOwnedVector(): This " \
204  "object hasn't yet been initialized.")
205  return ownedVector_;
206  } // end of getOwnedVector()
207 
209  //
210  // getGhostedVector()
211  //
216  {
217  using std::logic_error;
218  using Thyra::create_Vector;
220  "EpetraVector_Write_GlobalEvaluationData::getGhostedVector(): This " \
221  "object hasn't yet been initialized.")
223  "EpetraVector_Write_GlobalEvaluationData::getGhostedVector(): The " \
224  "ghosted vector is just a null RCP.")
225  return create_Vector(ghostedVector_, ghostedSpace_);
226  } // end of getGhostedVector()
227 
229  //
230  // print()
231  //
233  void
236  std::ostream& os) const
237  {
238  using std::string;
239  const string tab(" ");
240  os << "\n";
241  os << tab << "EpetraVector_Write_GlobalEvaluationData\n"
242  << tab << " init = " << isInitialized_ << "\n"
243  << tab << " owned = " << ownedVector_ << "\n"
244  << tab << " ghosted = " << ghostedVector_ << "\n";
245  } // end of print()
246 
247 } // end of namespace panzer
248 
249 // 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