Thyra_DefaultBlockedLinearOpDecl.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_DEFAULT_BLOCKED_LINEAR_OP_DECL_HPP
00030 #define THYRA_DEFAULT_BLOCKED_LINEAR_OP_DECL_HPP
00031 
00032 #include "Thyra_PhysicallyBlockedLinearOpBase.hpp"
00033 #include "Thyra_SingleScalarLinearOpBase.hpp"
00034 #include "Thyra_ProductVectorSpaceBase.hpp"
00035 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00036 #include "Teuchos_Array.hpp"
00037 #include "Teuchos_Handleable.hpp"
00038 #include "Teuchos_arrayArg.hpp"
00039 
00040 namespace Thyra {
00041 
00067 template<class Scalar>
00068 class DefaultBlockedLinearOp
00069   : virtual public PhysicallyBlockedLinearOpBase<Scalar>  // Public interface
00070   , virtual protected SingleScalarLinearOpBase<Scalar>    // Implementation detail
00071   , virtual public Teuchos::Handleable<LinearOpBase<Scalar, Scalar> >
00072 {
00073 public:
00074   /* */
00075   TEUCHOS_GET_RCP(LinearOpBase<Scalar>);
00076 
00078   using SingleScalarLinearOpBase<Scalar>::apply;
00079 
00082 
00084   DefaultBlockedLinearOp();
00085 
00087 
00090 
00092   void beginBlockFill();
00094   void beginBlockFill(
00095     const int numRowBlocks, const int numColBlocks
00096     );
00098   void beginBlockFill(
00099     const Teuchos::RefCountPtr<const ProductVectorSpaceBase<Scalar> >  &productRange
00100     ,const Teuchos::RefCountPtr<const ProductVectorSpaceBase<Scalar> > &productDomain
00101     );
00103   bool blockFillIsActive() const;
00105   bool acceptsBlock(const int i, const int j) const;
00107   void setNonconstBlock(
00108     const int i, const int j
00109     ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &block
00110     );
00112   void setBlock(
00113     const int i, const int j
00114     ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &block
00115     );
00117   void endBlockFill();
00119   void uninitialize();
00120 
00122 
00125 
00127   Teuchos::RefCountPtr<const ProductVectorSpaceBase<Scalar> >
00128   productRange() const;
00130   Teuchos::RefCountPtr<const ProductVectorSpaceBase<Scalar> >
00131   productDomain() const;
00133   bool blockExists(const int i, const int j) const; 
00135   bool blockIsConst(const int i, const int j) const; 
00137   Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00138   getNonconstBlock(const int i, const int j); 
00140   Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00141   getBlock(const int i, const int j) const; 
00142 
00144 
00147 
00149   Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> > range() const;
00151   Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> > domain() const;
00153   Teuchos::RefCountPtr<const LinearOpBase<Scalar> > clone() const;
00154 
00156 
00157 
00160                                                 
00164   std::string description() const;
00165 
00173   void describe(
00174     Teuchos::FancyOStream                &out
00175     ,const Teuchos::EVerbosityLevel      verbLevel
00176     ) const;
00177 
00179 
00180 protected:
00181 
00184 
00188   bool opSupported(ETransp M_trans) const;
00189 
00191   void apply(
00192     const ETransp                     M_trans
00193     ,const MultiVectorBase<Scalar>    &X
00194     ,MultiVectorBase<Scalar>          *Y
00195     ,const Scalar                     alpha
00196     ,const Scalar                     beta
00197     ) const;
00198   
00200 
00201 private:
00202 
00203   // ///////////////////
00204   // Private types
00205 
00206   typedef Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > CNCLO;
00207   typedef Teuchos::Array<Teuchos::RefCountPtr<const VectorSpaceBase<Scalar> > > vec_array_t;
00208 
00209   template<class Scalar2>
00210   struct BlockEntry {
00211     BlockEntry() : i(-1), j(-1) {}
00212     BlockEntry( const int i_in, const int j_in, const CNCLO &block_in )
00213       :i(i_in),j(j_in),block(block_in)
00214       {}
00215     int      i;
00216     int      j;
00217     CNCLO    block;
00218   };
00219 
00220   // /////////////////////////
00221   // Private data members
00222 
00223   Teuchos::RefCountPtr<const ProductVectorSpaceBase<Scalar> >  productRange_;
00224   Teuchos::RefCountPtr<const ProductVectorSpaceBase<Scalar> >  productDomain_;
00225   int                                                          numRowBlocks_; // M
00226   int                                                          numColBlocks_; // N
00227  
00228   std::vector<CNCLO>                   Ops_;        // Final M x N storage
00229  
00230   vec_array_t                          rangeBlocks_;
00231   vec_array_t                          domainBlocks_;
00232   std::vector<BlockEntry<Scalar> >     Ops_stack_;  // Temp stack of ops begin filled (if Ops_.size()==0).
00233  bool                                  blockFillIsActive_;
00234 
00235   // ///////////////////////////
00236   // Private member functions
00237   
00238   void resetStorage( const int numRowBlocks, const int numColBlocks  );
00239   void assertBlockFillIsActive(bool) const;
00240   void assertBlockRowCol(const int i, const int j) const;
00241   void setBlockSpaces(
00242     const int i, const int j, const LinearOpBase<Scalar> &block
00243     );
00244   template<class LinearOpType>
00245   void setBlockImpl(
00246     const int i, const int j
00247     ,const Teuchos::RefCountPtr<LinearOpType> &block
00248     );
00249 
00250   // Not defined and not to be called
00251   DefaultBlockedLinearOp(const DefaultBlockedLinearOp&);
00252   DefaultBlockedLinearOp& operator=(const DefaultBlockedLinearOp&);
00253 
00254 };
00255 
00260 template<class Scalar>
00261 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00262 block2x2(
00263   const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >    &A00
00264   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &A01
00265   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &A10
00266   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &A11
00267   );
00268 
00273 template<class Scalar>
00274 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00275 block2x1(
00276   const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >    &A00
00277   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &A10
00278   );
00279 
00284 template<class Scalar>
00285 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00286 block1x2(
00287   const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >    &A00
00288   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &A01
00289   );
00290 
00295 template<class Scalar>
00296 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00297 nonconstBlock2x2(
00298   const Teuchos::RefCountPtr<LinearOpBase<Scalar> >    &A00
00299   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >   &A01
00300   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >   &A10
00301   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >   &A11
00302   );
00303 
00308 template<class Scalar>
00309 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00310 nonconstBlock2x1(
00311   const Teuchos::RefCountPtr<LinearOpBase<Scalar> >    &A00
00312   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >   &A10
00313   );
00314 
00319 template<class Scalar>
00320 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00321 nonconstBlock1x2(
00322   const Teuchos::RefCountPtr<LinearOpBase<Scalar> >    &A00
00323   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >   &A01
00324   );
00325 
00326 } // namespace Thyra
00327 
00328 #endif  // THYRA_DEFAULT_BLOCKED_LINEAR_OP_DECL_HPP

Generated on Thu Sep 18 12:33:02 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1