Thyra_DefaultProductVectorSpaceDecl.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_PRODUCT_VECTOR_SPACE_DECL_HPP
00030 #define THYRA_PRODUCT_VECTOR_SPACE_DECL_HPP
00031 
00032 #include "Thyra_ProductVectorSpaceBase.hpp"
00033 #include "Thyra_VectorSpaceDefaultBase.hpp"
00034 #include "Teuchos_implicit_cast.hpp"
00035 
00036 namespace Thyra {
00037 
00123 template<class Scalar>
00124 class DefaultProductVectorSpace
00125   : virtual public ProductVectorSpaceBase<Scalar>
00126   , virtual protected VectorSpaceDefaultBase<Scalar>
00127 {
00128 public:
00129 
00132 
00134   DefaultProductVectorSpace(
00135     const int                                                       numBlocks
00136     ,const Teuchos::RCP<const VectorSpaceBase<Scalar> >     vecSpaces[]
00137     );
00138   
00169   virtual void initialize(
00170     const int                                                       numBlocks
00171     ,const Teuchos::RCP<const VectorSpaceBase<Scalar> >     vecSpaces[]
00172     );
00173 
00180   bool hasBeenCloned() const;
00181 
00201   virtual void uninitialize(
00202     int                                                             *numBlocks  = NULL
00203     ,Teuchos::RCP<const VectorSpaceBase<Scalar> >           vecSpaces[] = NULL
00204     );
00205 
00214   virtual const Teuchos::RCP<const VectorSpaceBase<Scalar> >* vecSpaces() const;
00215 
00224   virtual const Index* vecSpacesOffsets() const;
00225 
00246   void getVecSpcPoss( Index i, int* kth_vector_space, Index* kth_global_offset ) const;
00247   
00249 
00252 
00254   int numBlocks() const;
00256   Teuchos::RCP<const VectorSpaceBase<Scalar> > getBlock(const int k) const; 
00257 
00259 
00262 
00263   Index dim() const;
00265   bool isCompatible( const VectorSpaceBase<Scalar>& vecSpc ) const;
00267   Teuchos::RCP< VectorBase<Scalar> > createMember() const;
00269   Scalar scalarProd( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y ) const;
00271   void scalarProds( const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y, Scalar scalar_prods[] ) const;
00273   bool hasInCoreView(const Range1D& rng, const EViewType viewType, const EStrideType strideType) const;
00275   Teuchos::RCP< const VectorSpaceFactoryBase<Scalar> > smallVecSpcFcty() const;
00277   Teuchos::RCP< MultiVectorBase<Scalar> > createMembers(int numMembers) const;
00279   Teuchos::RCP< const VectorSpaceBase<Scalar> > clone() const;
00281 
00282 
00285                                                 
00289   std::string description() const;
00290 
00298   void describe(
00299     Teuchos::FancyOStream &out,
00300     const Teuchos::EVerbosityLevel verbLevel
00301     ) const;
00302 
00304   
00305 protected:
00306 
00307   // ///////////////////////////////////
00308   // Protected member functions
00309 
00312   DefaultProductVectorSpace() : numBlocks_(0), dim_(0) {}
00313 
00314 private:
00315  
00316   // ///////////////////////////////////
00317   // Private types
00318 
00319   typedef Teuchos::Array<Teuchos::RCP<const VectorSpaceBase<Scalar> > > vecSpaces_t;
00320   typedef Teuchos::Array<Index> vecSpacesOffsets_t;
00321  
00322   // ///////////////////////////////////
00323   // Private data members
00324 
00325   int                                        numBlocks_;
00326   Teuchos::RCP<vecSpaces_t>          vecSpaces_;
00327   Teuchos::RCP<vecSpacesOffsets_t>   vecSpacesOffsets_;
00328   // cached info
00329   Index                                      dim_;
00330   bool                                       isInCore_;
00331 
00332   // ///////////////////////////////////
00333   // Private member functions
00334 
00335   void assertInitialized() const;
00336 
00337 };
00338 
00339 
00344 template<class Scalar>
00345 inline
00346 Teuchos::RCP<DefaultProductVectorSpace<Scalar> >
00347 productVectorSpace(
00348   const Teuchos::Array<Teuchos::RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00349   )
00350 {
00351   return Teuchos::rcp(
00352     new DefaultProductVectorSpace<Scalar>(vecSpaces.size(),&vecSpaces[0])
00353     );
00354 }
00355 
00356 
00362 template<class Scalar>
00363 inline
00364 Teuchos::RCP<DefaultProductVectorSpace<Scalar> >
00365 productVectorSpace(
00366   const Teuchos::RCP<const VectorSpaceBase<Scalar> > &vecSpace,
00367   const int numBlocks
00368   )
00369 {
00370   using Teuchos::Array;
00371   using Teuchos::RCP;
00372   Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaceBlocks;
00373   for ( int i = 0; i < numBlocks; ++i )
00374     vecSpaceBlocks.push_back(vecSpace);
00375   return productVectorSpace(vecSpaceBlocks);
00376 }
00377 
00378 
00379 // /////////////////////////////////
00380 // Inline members
00381 
00382 template<class Scalar>
00383 inline const Teuchos::RCP<const VectorSpaceBase<Scalar> >*
00384 DefaultProductVectorSpace<Scalar>::vecSpaces() const
00385 {
00386   return ( dim_ ? &(*vecSpaces_)[0] : NULL );
00387 }
00388 
00389 template<class Scalar>
00390 inline const Index* DefaultProductVectorSpace<Scalar>::vecSpacesOffsets() const
00391 {
00392   return ( dim_ ? &(*vecSpacesOffsets_)[0] : NULL );
00393 }
00394 
00395 template<class Scalar>
00396 inline bool DefaultProductVectorSpace<Scalar>::hasBeenCloned() const
00397 {
00398   return vecSpaces_.count() > 1;
00399 }
00400 
00401 template<class Scalar>
00402 inline
00403 void DefaultProductVectorSpace<Scalar>::assertInitialized() const
00404 {
00405   using Teuchos::implicit_cast;
00406 #ifdef TEUCHOS_DEBUG
00407   TEST_FOR_EXCEPT( is_null(vecSpaces_) );
00408 #endif
00409 }
00410 
00411 } // namespace Thyra
00412 
00413 #endif // THYRA_PRODUCT_VECTOR_SPACE_DECL_HPP

Generated on Tue Oct 20 12:47:25 2009 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.4.7