Teko Version of the Day
Teko_BlockedReordering.hpp
00001 /*
00002 // @HEADER
00003 // 
00004 // ***********************************************************************
00005 // 
00006 //      Teko: A package for block and physics based preconditioning
00007 //                  Copyright 2010 Sandia Corporation 
00008 //  
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 //  
00012 // Redistribution and use in source and binary forms, with or without
00013 // modification, are permitted provided that the following conditions are
00014 // met:
00015 //  
00016 // 1. Redistributions of source code must retain the above copyright
00017 // notice, this list of conditions and the following disclaimer.
00018 //  
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 // notice, this list of conditions and the following disclaimer in the
00021 // documentation and/or other materials provided with the distribution.
00022 //  
00023 // 3. Neither the name of the Corporation nor the names of the
00024 // contributors may be used to endorse or promote products derived from
00025 // this software without specific prior written permission. 
00026 //  
00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 //  
00039 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
00040 // 
00041 // ***********************************************************************
00042 // 
00043 // @HEADER
00044 
00045 */
00046 
00047 #ifndef __Teko_BlockedReordering_hpp__
00048 #define __Teko_BlockedReordering_hpp__
00049 
00050 #include <string>
00051 #include <vector>
00052 
00053 #include "Teuchos_RCP.hpp"
00054 
00055 #include "Thyra_LinearOpBase.hpp"
00056 #include "Thyra_LinearOpDefaultBase.hpp"
00057 #include "Thyra_BlockedLinearOpBase.hpp"
00058 #include "Thyra_ProductMultiVectorBase.hpp"
00059 
00060 namespace Teko {
00061 
00109 class BlockReorderManager {
00110 public:
00112 
00113    
00115    BlockReorderManager() : children_(0) {}
00116 
00118    BlockReorderManager(int sz) : children_(sz,Teuchos::null) {}
00119 
00121    BlockReorderManager(const BlockReorderManager & bmm)
00122       : children_(bmm.children_.size()) 
00123    { for(unsigned int i=0;i<children_.size();i++) children_[i] = bmm.children_[i]->Copy(); }
00124 
00126    virtual ~BlockReorderManager() {}
00127 
00129 
00131    virtual Teuchos::RCP<BlockReorderManager> Copy() const
00132    { return Teuchos::rcp(new BlockReorderManager(*this)); }
00133 
00135    virtual void SetNumBlocks(int sz)
00136    { children_.clear(); children_.resize(sz); }
00137 
00139    virtual int GetNumBlocks() const
00140    { return children_.size(); }
00141 
00150    virtual void SetBlock(int blockIndex,int reorder);
00151 
00164    virtual void SetBlock(int blockIndex,const Teuchos::RCP<BlockReorderManager> & reorder);
00165 
00181    virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex);
00182 
00197    virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const;
00198 
00200    virtual std::string toString() const;
00201 
00203    virtual int LargestIndex() const;
00204 
00205 protected:
00207    std::vector<Teuchos::RCP<BlockReorderManager> > children_;
00208 };
00209 
00214 class BlockReorderLeaf : public BlockReorderManager {
00215 public:
00217 
00218    
00220    BlockReorderLeaf(int ind) : value_(ind) { }
00221 
00223    BlockReorderLeaf(const BlockReorderLeaf & brl)
00224       : value_(brl.value_) {}
00226 
00228    virtual Teuchos::RCP<BlockReorderManager> Copy() const
00229    { return Teuchos::rcp(new BlockReorderLeaf(*this)); }
00230 
00232    virtual int GetNumBlocks() const { return 0; }
00233 
00235    virtual void SetNumBlocks(int sz) {}
00236 
00238    virtual void SetBlock(int blockIndex,int reorder) { }
00239 
00241    virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex)
00242    { return Teuchos::null; }
00243 
00245    virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const
00246    { return Teuchos::null; }
00247 
00249    int GetIndex() const { return value_; }
00250 
00252    virtual std::string toString() const
00253    { std::stringstream ss; ss << value_; return ss.str(); }
00254 
00256    virtual int LargestIndex() const { return value_; }
00257 
00258 protected:
00260    int value_;
00261 
00262 private:
00263    BlockReorderLeaf(); // hidden from users
00264 };
00265 
00288 Teuchos::RCP<const Thyra::LinearOpBase<double> >
00289 buildReorderedLinearOp(const BlockReorderManager & bmm,
00290                        const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > & blkOp);
00291 
00315 Teuchos::RCP<const Thyra::LinearOpBase<double> >
00316 buildReorderedLinearOp(const BlockReorderManager & rowMgr,const BlockReorderManager & colMgr,
00317                        const Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > & blkOp);
00318 
00340 Teuchos::RCP<const Thyra::VectorSpaceBase<double> >
00341 buildReorderedVectorSpace(const BlockReorderManager & mgr,
00342                           const Teuchos::RCP<const Thyra::ProductVectorSpaceBase<double> > & blkSpc);
00343 
00355 Teuchos::RCP<Thyra::MultiVectorBase<double> >
00356 buildReorderedMultiVector(const BlockReorderManager & mgr,
00357                           const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> > & blkVec);
00358 
00370 Teuchos::RCP<const Thyra::MultiVectorBase<double> >
00371 buildReorderedMultiVector(const BlockReorderManager & mgr,
00372                           const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> > & blkVec);
00373 
00386 Teuchos::RCP<Thyra::MultiVectorBase<double> >
00387 buildFlatMultiVector(const BlockReorderManager & mgr,
00388                      const Teuchos::RCP<Thyra::ProductMultiVectorBase<double> > & blkVec);
00389 
00402 Teuchos::RCP<const Thyra::MultiVectorBase<double> >
00403 buildFlatMultiVector(const BlockReorderManager & mgr,
00404                      const Teuchos::RCP<const Thyra::ProductMultiVectorBase<double> > & blkVec);
00405 
00419 Teuchos::RCP<const BlockReorderManager> blockedReorderFromString(std::string & reorder);
00420 
00421 } // end namespace Teko
00422 
00423 #endif
 All Classes Files Functions Variables