Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_BlockedVector_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 // Panzer
52 
53 // Thyra
54 #include "Thyra_DefaultProductVector.hpp"
55 #include "Thyra_DefaultProductVectorSpace.hpp"
56 #include "Thyra_VectorBase.hpp"
57 
58 namespace panzer
59 {
61  //
62  // Default Constructor
63  //
67  : isInitialized_(false)
68  {
69  } // end of Default Constructor
70 
72  //
73  // Copy Constructor
74  //
79  :
80  isInitialized_(false)
81  {
82  initialize(src.ghostedSpace_, Teuchos::null, src.gedBlocks_);
83  } // end of Copy Constructor
84 
86  //
87  // Initializing Constructor
88  //
92  const Teuchos::RCP<const Thyra::VectorSpaceBase<double>> ghostedSpace,
93  const Teuchos::RCP<const Thyra::VectorSpaceBase<double>> ownedSpace,
95  gedBlocks)
96  :
97  isInitialized_(false)
98  {
99  initialize(ghostedSpace, ownedSpace, gedBlocks);
100  } // end of Initializing Constructor
101 
103  //
104  // initialize()
105  //
107  void
110  const Teuchos::RCP<const Thyra::VectorSpaceBase<double>>& ghostedSpace,
111  const Teuchos::RCP<const Thyra::VectorSpaceBase<double>>& /* ownedSpace */,
113  gedBlocks)
114  {
115  using std::logic_error;
116  using std::size_t;
117  using Teuchos::rcp_dynamic_cast;
119 
120  // Assert that all the gedBlocks are initialized.
121  for (size_t i(0); i < gedBlocks.size(); ++i)
122  TEUCHOS_TEST_FOR_EXCEPTION(not gedBlocks[i]->isInitialized(),
123  logic_error, "BlockedVector_ReadOnly_GlobalEvaluationData::" \
124  "initialize: GED block " << i << " is not initialized.")
125  gedBlocks_ = gedBlocks;
126  ghostedSpace_ =
127  rcp_dynamic_cast<const DefaultProductVectorSpace<double>>(ghostedSpace);
129  "BlockedVector_ReadOnly_GlobalEvaluationData::initialize(): Ghosted " \
130  "space must be a Thyra::DefaultProductVectorSpace");
131  isInitialized_ = true;
132  } // end of initialize()
133 
135  //
136  // globalToGhost()
137  //
139  void
142  int mem)
143  {
144  using std::logic_error;
145  using std::size_t;
147  "BlockedVector_ReadOnly_GlobalEvaluationData has not been " \
148  "initialized; cannot call \"globalToGhost()\"!");
149  for (size_t i(0); i < gedBlocks_.size(); ++i)
150  gedBlocks_[i]->globalToGhost(mem);
151  } // end of globalToGhost()
152 
154  //
155  // initializeData()
156  //
158  void
161  {
162  using std::logic_error;
163  using std::size_t;
165  "BlockedVector_ReadOnly_GlobalEvaluationData has not been " \
166  "initialized; cannot call \"initializeData()\"!");
167  for (size_t i(0); i < gedBlocks_.size(); ++i)
169  } // end of initializeData()
170 
172  //
173  // setOwnedVector()
174  //
176  void
179  const Teuchos::RCP<const Thyra::VectorBase<double>>& ownedVector)
180  {
181  using std::logic_error;
182  using std::size_t;
183  using Teuchos::as;
184  using Teuchos::RCP;
185  using Thyra::castOrCreateProductVectorBase;
187  ownedVector_ = ownedVector;
189  castOrCreateProductVectorBase(ownedVector_);
190  TEUCHOS_TEST_FOR_EXCEPTION(blocks->productSpace()->numBlocks() !=
191  as<int>(gedBlocks_.size()), logic_error,
192  "BlockedVector_ReadOnly_GlobalEvaluationData owned vector has the " \
193  "wrong number of blocks!");
194  for (size_t i(0); i < gedBlocks_.size(); ++i)
195  gedBlocks_[i]->setOwnedVector(blocks->getVectorBlock(i));
196  } // end of setOwnedVector()
197 
199  //
200  // getOwnedVector()
201  //
206  {
207  return ownedVector_;
208  } // end of getOwnedVector()
209 
211  //
212  // getGhostedVector()
213  //
218  {
219  using std::logic_error;
220  using std::size_t;
221  using std::vector;
222  using Teuchos::arrayViewFromVector;
223  using Teuchos::RCP;
224  using Thyra::defaultProductVector;
225  using Thyra::VectorBase;
227  "BlockedVector_ReadOnly_GlobalEvaluationData has not been " \
228  "initialized; cannot call \"getGhostedVector()\"!");
229  vector<RCP<VectorBase<double>>> blocks;
230  for (size_t i(0); i < gedBlocks_.size(); ++i)
231  blocks.push_back(gedBlocks_[i]->getGhostedVector());
232  const vector<RCP<VectorBase<double>>>& constBlocks = blocks;
233  return defaultProductVector(ghostedSpace_,
234  arrayViewFromVector(constBlocks));
235  } // end of getGhostedVector()
236 
237 } // end of namespace panzer
238 
239 // end of Panzer_BlockedVector_ReadOnly_GlobalEvaluationData.cpp
Teuchos::RCP< const Thyra::VectorBase< double > > ownedVector_
The owned vector.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::vector< Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > > gedBlocks_
A vector of the GlobalEvaluationData blocks.
virtual void initializeData()
Initialize internal data for communication.
This class encapsulates the needs of a gather operation to do a halo exchange for blocked vectors...
virtual void globalToGhost(int mem)
Communicate the owned data to the ghosted vector.
virtual Teuchos::RCP< Thyra::VectorBase< double > > getGhostedVector() const
Get the ghosted vector.
Teuchos::RCP< const Thyra::DefaultProductVectorSpace< double > > ghostedSpace_
The vector space corresponding to the ghosted vector.
virtual Teuchos::RCP< const Thyra::VectorBase< double > > getOwnedVector() const
Get the owned vector.
virtual void setOwnedVector(const Teuchos::RCP< const Thyra::VectorBase< double >> &ownedVector)
Set the owned vector.
TypeTo as(const TypeFrom &t)
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.
bool is_null() const