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  for (unsigned int i = 0; i < children_.size(); i++) children_[i] = bmm.children_[i]->Copy();
123  }
124 
126  virtual ~BlockReorderManager() {}
127 
129 
131  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
132  return Teuchos::rcp(new BlockReorderManager(*this));
133  }
134 
136  virtual void SetNumBlocks(int sz) {
137  children_.clear();
138  children_.resize(sz);
139  }
140 
142  virtual int GetNumBlocks() const { return children_.size(); }
143 
152  virtual void SetBlock(int blockIndex, int reorder);
153 
166  virtual void SetBlock(int blockIndex, const Teuchos::RCP<BlockReorderManager>& reorder);
167 
183  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex);
184 
199  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const;
200 
202  virtual std::string toString() const;
203 
205  virtual int LargestIndex() const;
206 
207  protected:
209  std::vector<Teuchos::RCP<BlockReorderManager> > children_;
210 };
211 
217  public:
219 
220 
222  BlockReorderLeaf(int ind) : value_(ind) {}
223 
227 
229  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
230  return Teuchos::rcp(new BlockReorderLeaf(*this));
231  }
232 
234  virtual int GetNumBlocks() const { return 0; }
235 
237  virtual void SetNumBlocks(int /* sz */) {}
238 
240  virtual void SetBlock(int /* blockIndex */, int /* reorder */) {}
241 
243  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int /* blockIndex */) {
244  return Teuchos::null;
245  }
246 
248  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int /* blockIndex */) const {
249  return Teuchos::null;
250  }
251 
253  int GetIndex() const { return value_; }
254 
256  virtual std::string toString() const {
257  std::stringstream ss;
258  ss << value_;
259  return ss.str();
260  }
261 
263  virtual int LargestIndex() const { return value_; }
264 
265  protected:
267 
269  int value_;
270 
271  private:
272  BlockReorderLeaf(); // hidden from users
273 };
274 
297 Teuchos::RCP<const Thyra::LinearOpBase<double> > buildReorderedLinearOp(
298  const BlockReorderManager& bmm,
299  const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> >& blkOp);
300 
324 Teuchos::RCP<const Thyra::LinearOpBase<double> > buildReorderedLinearOp(
325  const BlockReorderManager& rowMgr, const BlockReorderManager& colMgr,
326  const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> >& blkOp);
327 
349 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > buildReorderedVectorSpace(
350  const BlockReorderManager& mgr,
351  const Teuchos::RCP<const Thyra::ProductVectorSpaceBase<double> >& blkSpc);
352 
364 Teuchos::RCP<Thyra::MultiVectorBase<double> > buildReorderedMultiVector(
365  const BlockReorderManager& mgr,
366  const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> >& blkVec);
367 
379 Teuchos::RCP<const Thyra::MultiVectorBase<double> > buildReorderedMultiVector(
380  const BlockReorderManager& mgr,
381  const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> >& blkVec);
382 
395 Teuchos::RCP<Thyra::MultiVectorBase<double> > buildFlatMultiVector(
396  const BlockReorderManager& mgr,
397  const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> >& blkVec);
398 
411 Teuchos::RCP<const Thyra::MultiVectorBase<double> > buildFlatMultiVector(
412  const BlockReorderManager& mgr,
413  const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> >& blkVec);
414 
417 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > buildFlatVectorSpace(
418  const BlockReorderManager& mgr,
419  const Teuchos::RCP<const Thyra::VectorSpaceBase<double> >& blkSpc);
420 
434 Teuchos::RCP<const BlockReorderManager> blockedReorderFromString(std::string& reorder);
435 
436 } // end namespace Teko
437 
438 #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.