Teko  Version of the Day
Teko_BlockedReordering.hpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #ifndef __Teko_BlockedReordering_hpp__
48 #define __Teko_BlockedReordering_hpp__
49 
50 #include <string>
51 #include <vector>
52 
53 #include "Teuchos_RCP.hpp"
54 
55 #include "Thyra_LinearOpBase.hpp"
56 #include "Thyra_LinearOpDefaultBase.hpp"
57 #include "Thyra_BlockedLinearOpBase.hpp"
58 #include "Thyra_ProductMultiVectorBase.hpp"
59 
60 namespace Teko {
61 
110 public:
112 
113 
116 
118  BlockReorderManager(int sz) : children_(sz,Teuchos::null) {}
119 
122  : children_(bmm.children_.size())
123  { for(unsigned int i=0;i<children_.size();i++) children_[i] = bmm.children_[i]->Copy(); }
124 
126  virtual ~BlockReorderManager() {}
127 
129 
131  virtual Teuchos::RCP<BlockReorderManager> Copy() const
132  { return Teuchos::rcp(new BlockReorderManager(*this)); }
133 
135  virtual void SetNumBlocks(int sz)
136  { children_.clear(); children_.resize(sz); }
137 
139  virtual int GetNumBlocks() const
140  { return children_.size(); }
141 
150  virtual void SetBlock(int blockIndex,int reorder);
151 
164  virtual void SetBlock(int blockIndex,const Teuchos::RCP<BlockReorderManager> & reorder);
165 
181  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex);
182 
197  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const;
198 
200  virtual std::string toString() const;
201 
203  virtual int LargestIndex() const;
204 
205 protected:
207  std::vector<Teuchos::RCP<BlockReorderManager> > children_;
208 };
209 
215 public:
217 
218 
220  BlockReorderLeaf(int ind) : value_(ind) { }
221 
224  : value_(brl.value_) {}
226 
228  virtual Teuchos::RCP<BlockReorderManager> Copy() const
229  { return Teuchos::rcp(new BlockReorderLeaf(*this)); }
230 
232  virtual int GetNumBlocks() const { return 0; }
233 
235  virtual void SetNumBlocks(int sz) {}
236 
238  virtual void SetBlock(int blockIndex,int reorder) { }
239 
241  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex)
242  { return Teuchos::null; }
243 
245  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const
246  { return Teuchos::null; }
247 
249  int GetIndex() const { return value_; }
250 
252  virtual std::string toString() const
253  { std::stringstream ss; ss << value_; return ss.str(); }
254 
256  virtual int LargestIndex() const { return value_; }
257 
258 protected:
260  int value_;
261 
262 private:
263  BlockReorderLeaf(); // hidden from users
264 };
265 
288 Teuchos::RCP<const Thyra::LinearOpBase<double> >
290  const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > & blkOp);
291 
315 Teuchos::RCP<const Thyra::LinearOpBase<double> >
317  const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > & blkOp);
318 
340 Teuchos::RCP<const Thyra::VectorSpaceBase<double> >
342  const Teuchos::RCP<const Thyra::ProductVectorSpaceBase<double> > & blkSpc);
343 
355 Teuchos::RCP<Thyra::MultiVectorBase<double> >
357  const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> > & blkVec);
358 
370 Teuchos::RCP<const Thyra::MultiVectorBase<double> >
372  const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> > & blkVec);
373 
386 Teuchos::RCP<Thyra::MultiVectorBase<double> >
388  const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> > & blkVec);
389 
402 Teuchos::RCP<const Thyra::MultiVectorBase<double> >
404  const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> > & blkVec);
405 
408 Teuchos::RCP<const Thyra::VectorSpaceBase<double> >
409 buildFlatVectorSpace(const BlockReorderManager & mgr,
410  const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & blkSpc);
411 
425 Teuchos::RCP<const BlockReorderManager> blockedReorderFromString(std::string & reorder);
426 
427 } // end namespace Teko
428 
429 #endif
int GetIndex() const
Get the the index that is stored in this block.
int value_
The value of the index for this leaf.
virtual void SetNumBlocks(int sz)
Set the number of subblocks (this one does nothing b/c its a leaf)
virtual std::string toString() const
Return a string description of this leaf class.
BlockReorderManager(const BlockReorderManager &bmm)
Copy constructor.
std::vector< Teuchos::RCP< BlockReorderManager > > children_
Definitions of the subblocks.
Teuchos::RCP< Thyra::MultiVectorBase< double > > buildFlatMultiVector(const BlockReorderManager &mgr, const Teuchos::RCP< Thyra::ProductMultiVectorBase< double > > &blkVec)
Convert a reordered multivector into a flat multivector.
Class that describes how a flat blocked operator should be reordered.
virtual const Teuchos::RCP< const BlockReorderManager > GetBlock(int blockIndex) const
Get a particular subblock...this returns null.
virtual int GetNumBlocks() const
Gets the number of subblocks.
virtual const Teuchos::RCP< BlockReorderManager > GetBlock(int blockIndex)
Get a particular subblock...this returns null.
virtual int LargestIndex() const
Largest index in this manager.
virtual const Teuchos::RCP< BlockReorderManager > GetBlock(int blockIndex)
Get a particular block. If there is no block at this index location return a new one.
virtual ~BlockReorderManager()
Do nothing destructor.
virtual Teuchos::RCP< BlockReorderManager > Copy() const
Make a copy of this object.
virtual void SetNumBlocks(int sz)
Sets the number of subblocks.
virtual int LargestIndex() const
Largest index in this manager.
BlockReorderLeaf(int ind)
Simple constructor that sets the index.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > buildReorderedVectorSpace(const BlockReorderManager &mgr, const Teuchos::RCP< const Thyra::ProductVectorSpaceBase< double > > &blkSpc)
Use the BlockReorderManager to change a flat vector space into a composite vector space...
BlockReorderManager(int sz)
Set this level to have size sz.
virtual void SetBlock(int blockIndex, int reorder)
Set the sub block, this does nothing b/c its a leaf.
virtual Teuchos::RCP< BlockReorderManager > Copy() const
Returns a copy of this object.
Teuchos::RCP< const BlockReorderManager > blockedReorderFromString(std::string &reorder)
Convert a string to a block reorder manager object.
BlockReorderLeaf(const BlockReorderLeaf &brl)
Copy constructor.
Teuchos::RCP< const Thyra::LinearOpBase< double > > buildReorderedLinearOp(const BlockReorderManager &bmm, const Teuchos::RCP< const Thyra::BlockedLinearOpBase< double > > &blkOp)
Use the BlockReorderManager to change a flat square blocked operator into a composite operator...
virtual std::string toString() const
For sanities sake, print a readable string.
virtual int GetNumBlocks() const
Get the number of subblocks (this one returns 0 b/c its a leaf)
BlockReorderManager()
Basic empty constructor.
Teuchos::RCP< Thyra::MultiVectorBase< double > > buildReorderedMultiVector(const BlockReorderManager &mgr, const Teuchos::RCP< Thyra::ProductMultiVectorBase< double > > &blkVec)
Convert a flat multi vector into a reordered multivector.
virtual void SetBlock(int blockIndex, int reorder)
Sets the sublock to a specific index value.