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