Teko  Version of the Day
 All Classes Files Functions Variables Pages
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 
262  int value_;
263 
264 private:
265  BlockReorderLeaf(); // hidden from users
266 };
267 
290 Teuchos::RCP<const Thyra::LinearOpBase<double> >
291 buildReorderedLinearOp(const BlockReorderManager & bmm,
292  const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > & blkOp);
293 
317 Teuchos::RCP<const Thyra::LinearOpBase<double> >
318 buildReorderedLinearOp(const BlockReorderManager & rowMgr,const BlockReorderManager & colMgr,
319  const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > & blkOp);
320 
342 Teuchos::RCP<const Thyra::VectorSpaceBase<double> >
343 buildReorderedVectorSpace(const BlockReorderManager & mgr,
344  const Teuchos::RCP<const Thyra::ProductVectorSpaceBase<double> > & blkSpc);
345 
357 Teuchos::RCP<Thyra::MultiVectorBase<double> >
359  const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> > & blkVec);
360 
372 Teuchos::RCP<const Thyra::MultiVectorBase<double> >
374  const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> > & blkVec);
375 
388 Teuchos::RCP<Thyra::MultiVectorBase<double> >
389 buildFlatMultiVector(const BlockReorderManager & mgr,
390  const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> > & blkVec);
391 
404 Teuchos::RCP<const Thyra::MultiVectorBase<double> >
405 buildFlatMultiVector(const BlockReorderManager & mgr,
406  const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> > & blkVec);
407 
410 Teuchos::RCP<const Thyra::VectorSpaceBase<double> >
411 buildFlatVectorSpace(const BlockReorderManager & mgr,
412  const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & blkSpc);
413 
427 Teuchos::RCP<const BlockReorderManager> blockedReorderFromString(std::string & reorder);
428 
429 } // end namespace Teko
430 
431 #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 std::string toString() const
Return a string description of this leaf class.
virtual const Teuchos::RCP< const BlockReorderManager > GetBlock(int) const
Get a particular subblock...this returns null.
virtual const Teuchos::RCP< BlockReorderManager > GetBlock(int)
Get a particular subblock...this returns null.
BlockReorderManager(const BlockReorderManager &bmm)
Copy constructor.
std::vector< Teuchos::RCP< BlockReorderManager > > children_
Definitions of the subblocks.
Class that describes how a flat blocked operator should be reordered.
virtual int GetNumBlocks() const
Gets the number of subblocks.
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.
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 int LargestIndex() const
Largest index in this manager.
BlockReorderLeaf(int ind)
Simple constructor that sets the index.
BlockReorderManager(int sz)
Set this level to have size sz.
virtual Teuchos::RCP< BlockReorderManager > Copy() const
Returns a copy of this object.
BlockReorderLeaf(const BlockReorderLeaf &brl)
Copy constructor.
virtual std::string toString() const
For sanities sake, print a readable string.
virtual void SetBlock(int, int)
Set the sub block, this does nothing b/c its a leaf.
virtual int GetNumBlocks() const
Get the number of subblocks (this one returns 0 b/c its a leaf)
virtual void SetNumBlocks(int)
Set the number of subblocks (this one does nothing b/c its a leaf)
BlockReorderManager()
Basic empty constructor.
Teuchos::RCP< const BlockReorderManager > blockedReorderFromString(std::string &reorder)
Convert a string to a block reorder manager object.
virtual void SetBlock(int blockIndex, int reorder)
Sets the sublock to a specific index value.