Panzer  Version of the Day
Panzer_BlockedVector_ReadOnly_GlobalEvaluationData.cpp
Go to the documentation of this file.
1 #include "Thyra_VectorBase.hpp"
2 #include "Thyra_DefaultProductVector.hpp"
3 #include "Thyra_DefaultProductVectorSpace.hpp"
4 
7 
8 namespace panzer {
9 
10 
13  : isInitialized_(false)
14 {
15 }
16 
19  : isInitialized_(false)
20 {
21  initialize(src.ghostedSpace_,Teuchos::null,src.gedBlocks_);
22 }
23 
26  const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > ownedSpace,
27  const std::vector<Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> > & gedBlocks)
28  : isInitialized_(false)
29 {
30  initialize(ghostedSpace, ownedSpace, gedBlocks);
31 }
32 
33 void
35 initialize(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> >& ghostedSpace,
36  const Teuchos::RCP<const Thyra::VectorSpaceBase<double> >& ownedSpace,
37  const std::vector<Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> >& gedBlocks)
38 {
39  using Teuchos::rcp_dynamic_cast;
40 
41  // assert all gedBlocks are initialized
42  for(std::size_t i=0;i<gedBlocks.size();i++) {
43  TEUCHOS_TEST_FOR_EXCEPTION(!gedBlocks[i]->isInitialized(),std::logic_error,
44  "BlockedVector_ReadOnly_GlobalEvaluationData::initialize: GED block is " << i << " is not initialized.");
45  }
46 
47  gedBlocks_ = gedBlocks;
48 
49  ghostedSpace_ = rcp_dynamic_cast<const Thyra::DefaultProductVectorSpace<double> >(ghostedSpace);
50 
51  TEUCHOS_TEST_FOR_EXCEPTION(ghostedSpace_==Teuchos::null,std::logic_error,
52  "BlockedVector_ReadOnly_GED::initialize: ghosted space must be a Thyra::DefaultProductVectorSpace");
53 
54  isInitialized_ = true;
55 }
56 
57 void
59 globalToGhost(int mem)
60 {
61  TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
62  "BlockedVector_ReadOnly_GED has not been initialized, cannot call \"globalToGhost\"!");
63 
64  for(std::size_t i=0;i<gedBlocks_.size();i++)
65  gedBlocks_[i]->globalToGhost(mem);
66 }
67 
68 void
71 {
72  TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
73  "BlockedVector_ReadOnly_GED has not been initialized, cannot call \"initializeData\"!");
74 
75  for(std::size_t i=0;i<gedBlocks_.size();i++)
77 }
78 
79 void
81 setOwnedVector(const Teuchos::RCP<const Thyra::VectorBase<double> >& ownedVector)
82 {
83  ownedVector_ = ownedVector;
84 
85  Teuchos::RCP<const Thyra::ProductVectorBase<double> > blocks = Thyra::castOrCreateProductVectorBase(ownedVector_);
86 
87  TEUCHOS_TEST_FOR_EXCEPTION(blocks->productSpace()->numBlocks()!=Teuchos::as<int>(gedBlocks_.size()),std::logic_error,
88  "BlockedVector_ReadOnly_GED owned vector as the wrong number of blocks!");
89 
90  for(std::size_t i=0;i<gedBlocks_.size();i++)
91  gedBlocks_[i]->setOwnedVector(blocks->getVectorBlock(i));
92 }
93 
94 Teuchos::RCP<const Thyra::VectorBase<double> >
97 {
98  return ownedVector_;
99 }
100 
101 Teuchos::RCP<Thyra::VectorBase<double> >
104 {
105  TEUCHOS_TEST_FOR_EXCEPTION(!isInitialized_,std::logic_error,
106  "BlockedVector_ReadOnly_GED has not been initialized, cannot call \"getGhostedVector\"!");
107 
108  // unfortunately you must build the vector here!
109  std::vector<Teuchos::RCP<Thyra::VectorBase<double> > > blocks;
110  for(std::size_t i=0;i<gedBlocks_.size();i++)
111  blocks.push_back(gedBlocks_[i]->getGhostedVector());
112 
113  // why?????
114  const std::vector<Teuchos::RCP<Thyra::VectorBase<double> > > & blocks_c = blocks;
115  return Thyra::defaultProductVector(ghostedSpace_,Teuchos::arrayViewFromVector(blocks_c));
116 }
117 
118 }
virtual Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector.
virtual void setOwnedVector(const Teuchos::RCP< const Thyra::VectorBase< double > > &ownedVector)
Set the owned vector.
std::vector< Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > > gedBlocks_
PHX::MDField< ScalarT > vector
virtual void initializeData()
Initialize internal data for communication (clear the ghosted vector)
void initialize(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &ghostedSpace, const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &ownedSpace, const std::vector< Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > > &gedBlocks)
Teuchos::RCP< const Thyra::DefaultProductVectorSpace< double > > ghostedSpace_
virtual Teuchos::RCP< const Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector.