Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_BlockedVector_ReadOnly_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// Panzer
20
21// Thyra
22#include "Thyra_DefaultProductVector.hpp"
23#include "Thyra_DefaultProductVectorSpace.hpp"
24#include "Thyra_VectorBase.hpp"
25
26namespace panzer
27{
29 //
30 // Default Constructor
31 //
35 : isInitialized_(false)
36 {
37 } // end of Default Constructor
38
40 //
41 // Copy Constructor
42 //
47 :
48 isInitialized_(false)
49 {
50 initialize(src.ghostedSpace_, Teuchos::null, src.gedBlocks_);
51 } // end of Copy Constructor
52
54 //
55 // Initializing Constructor
56 //
60 const Teuchos::RCP<const Thyra::VectorSpaceBase<double>> ghostedSpace,
61 const Teuchos::RCP<const Thyra::VectorSpaceBase<double>> ownedSpace,
62 const std::vector<Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData>>&
63 gedBlocks)
64 :
65 isInitialized_(false)
66 {
67 initialize(ghostedSpace, ownedSpace, gedBlocks);
68 } // end of Initializing Constructor
69
71 //
72 // initialize()
73 //
75 void
78 const Teuchos::RCP<const Thyra::VectorSpaceBase<double>>& ghostedSpace,
79 const Teuchos::RCP<const Thyra::VectorSpaceBase<double>>& /* ownedSpace */,
80 const std::vector<Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData>>&
81 gedBlocks)
82 {
83 using std::logic_error;
84 using std::size_t;
85 using Teuchos::rcp_dynamic_cast;
87
88 // Assert that all the gedBlocks are initialized.
89 for (size_t i(0); i < gedBlocks.size(); ++i)
90 TEUCHOS_TEST_FOR_EXCEPTION(not gedBlocks[i]->isInitialized(),
91 logic_error, "BlockedVector_ReadOnly_GlobalEvaluationData::" \
92 "initialize: GED block " << i << " is not initialized.")
93 gedBlocks_ = gedBlocks;
95 rcp_dynamic_cast<const DefaultProductVectorSpace<double>>(ghostedSpace);
96 TEUCHOS_TEST_FOR_EXCEPTION(ghostedSpace_.is_null(), logic_error,
97 "BlockedVector_ReadOnly_GlobalEvaluationData::initialize(): Ghosted " \
98 "space must be a Thyra::DefaultProductVectorSpace");
99 isInitialized_ = true;
100 } // end of initialize()
101
103 //
104 // globalToGhost()
105 //
107 void
110 int mem)
111 {
112 using std::logic_error;
113 using std::size_t;
114 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
115 "BlockedVector_ReadOnly_GlobalEvaluationData has not been " \
116 "initialized; cannot call \"globalToGhost()\"!");
117 for (size_t i(0); i < gedBlocks_.size(); ++i)
118 gedBlocks_[i]->globalToGhost(mem);
119 } // end of globalToGhost()
120
122 //
123 // initializeData()
124 //
126 void
129 {
130 using std::logic_error;
131 using std::size_t;
132 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
133 "BlockedVector_ReadOnly_GlobalEvaluationData has not been " \
134 "initialized; cannot call \"initializeData()\"!");
135 for (size_t i(0); i < gedBlocks_.size(); ++i)
137 } // end of initializeData()
138
140 //
141 // setOwnedVector()
142 //
144 void
147 const Teuchos::RCP<const Thyra::VectorBase<double>>& ownedVector)
148 {
149 using std::logic_error;
150 using std::size_t;
151 using Teuchos::as;
152 using Teuchos::RCP;
153 using Thyra::castOrCreateProductVectorBase;
155 ownedVector_ = ownedVector;
156 RCP<const ProductVectorBase<double>> blocks =
157 castOrCreateProductVectorBase(ownedVector_);
158 TEUCHOS_TEST_FOR_EXCEPTION(blocks->productSpace()->numBlocks() !=
159 as<int>(gedBlocks_.size()), logic_error,
160 "BlockedVector_ReadOnly_GlobalEvaluationData owned vector has the " \
161 "wrong number of blocks!");
162 for (size_t i(0); i < gedBlocks_.size(); ++i)
163 gedBlocks_[i]->setOwnedVector(blocks->getVectorBlock(i));
164 } // end of setOwnedVector()
165
167 //
168 // getOwnedVector()
169 //
171 Teuchos::RCP<const Thyra::VectorBase<double>>
173 getOwnedVector() const
174 {
175 return ownedVector_;
176 } // end of getOwnedVector()
177
179 //
180 // getGhostedVector()
181 //
183 Teuchos::RCP<Thyra::VectorBase<double>>
185 getGhostedVector() const
186 {
187 using std::logic_error;
188 using std::size_t;
189 using std::vector;
190 using Teuchos::arrayViewFromVector;
191 using Teuchos::RCP;
192 using Thyra::defaultProductVector;
193 using Thyra::VectorBase;
194 TEUCHOS_TEST_FOR_EXCEPTION(not isInitialized_, logic_error,
195 "BlockedVector_ReadOnly_GlobalEvaluationData has not been " \
196 "initialized; cannot call \"getGhostedVector()\"!");
197 vector<RCP<VectorBase<double>>> blocks;
198 for (size_t i(0); i < gedBlocks_.size(); ++i)
199 blocks.push_back(gedBlocks_[i]->getGhostedVector());
200 const vector<RCP<VectorBase<double>>>& constBlocks = blocks;
201 return defaultProductVector(ghostedSpace_,
202 arrayViewFromVector(constBlocks));
203 } // end of getGhostedVector()
204
205} // end of namespace panzer
206
207// end of Panzer_BlockedVector_ReadOnly_GlobalEvaluationData.cpp
This class encapsulates the needs of a gather operation to do a halo exchange for blocked vectors.
virtual Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector.
bool isInitialized_
A flag indicating whether or not the object has been initialized.
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)
Initialize this object using the sub-GlobalEvaluationData objects.
Teuchos::RCP< const Thyra::VectorBase< double > > ownedVector_
The owned vector.
Teuchos::RCP< const Thyra::DefaultProductVectorSpace< double > > ghostedSpace_
The vector space corresponding to the ghosted vector.
std::vector< Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > > gedBlocks_
A vector of the GlobalEvaluationData blocks.
virtual void globalToGhost(int mem)
Communicate the owned data to the ghosted vector.
virtual void setOwnedVector(const Teuchos::RCP< const Thyra::VectorBase< double > > &ownedVector)
Set the owned vector.
virtual Teuchos::RCP< const Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector.