Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DefaultProductVectorSpace_decl.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_PRODUCT_VECTOR_SPACE_DECL_HPP
00030 #define THYRA_DEFAULT_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 
00038 
00122 template<class Scalar>
00123 class DefaultProductVectorSpace
00124   : virtual public ProductVectorSpaceBase<Scalar>,
00125     virtual protected VectorSpaceDefaultBase<Scalar>
00126 {
00127 public:
00128 
00131 
00133   DefaultProductVectorSpace();
00134 
00136   DefaultProductVectorSpace(
00137     const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00138     );
00139   
00178   virtual void initialize(
00179     const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00180     );
00181 
00188   bool hasBeenCloned() const;
00189 
00210   virtual void uninitialize(
00211     const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces = Teuchos::null
00212     );
00213 
00222   virtual const RCP<const VectorSpaceBase<Scalar> >* vecSpaces() const;
00223 
00232   virtual const Ordinal* vecSpacesOffsets() const;
00233 
00262   void getVecSpcPoss( Ordinal i, int* kth_vector_space, Ordinal* kth_global_offset ) const;
00263   
00265 
00268 
00270   int numBlocks() const;
00272   RCP<const VectorSpaceBase<Scalar> > getBlock(const int k) const; 
00273 
00275 
00278 
00280   Ordinal dim() const;
00281 
00285   bool isCompatible( const VectorSpaceBase<Scalar>& vecSpc ) const;
00286 
00288   RCP< VectorBase<Scalar> > createMember() const;
00289 
00293   Scalar scalarProd(
00294     const VectorBase<Scalar>& x, const VectorBase<Scalar>& y ) const;
00295 
00299   void scalarProdsImpl(
00300     const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y,
00301     const ArrayView<Scalar> &scalarProds ) const;
00302 
00306   bool hasInCoreView(const Range1D& rng, const EViewType viewType,
00307     const EStrideType strideType) const;
00308 
00310   RCP< const VectorSpaceFactoryBase<Scalar> > smallVecSpcFcty() const;
00311 
00313   RCP< MultiVectorBase<Scalar> > createMembers(int numMembers) const;
00314 
00316   RCP< const VectorSpaceBase<Scalar> > clone() const;
00317 
00319 
00322                                                 
00326   std::string description() const;
00327 
00335   void describe(
00336     Teuchos::FancyOStream &out,
00337     const Teuchos::EVerbosityLevel verbLevel
00338     ) const;
00339 
00341 
00344 
00346   DefaultProductVectorSpace(
00347     const int numBlocks_in,
00348     const RCP<const VectorSpaceBase<Scalar> > vecSpaces_in[]
00349     )
00350     : numBlocks_(-1), dim_(-1)
00351     {
00352       initialize(numBlocks_in, vecSpaces_in);
00353     }
00354 
00356   void initialize(
00357     const int numBlocks_in,
00358     const RCP<const VectorSpaceBase<Scalar> > vecSpaces_in[]
00359     )
00360     {
00361       initialize(Teuchos::arrayView(vecSpaces_in, numBlocks_in));
00362     }
00363 
00365   
00366 protected:
00367 
00368   // ///////////////////////////////////
00369   // Protected member functions
00370 
00371 private:
00372  
00373   // ///////////////////////////////////
00374   // Private types
00375 
00376   typedef Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaces_t;
00377   typedef Array<Ordinal> vecSpacesOffsets_t;
00378  
00379   // ///////////////////////////////////
00380   // Private data members
00381 
00382   int numBlocks_;
00383   RCP<vecSpaces_t> vecSpaces_;
00384   RCP<vecSpacesOffsets_t> vecSpacesOffsets_;
00385   // cached info
00386   Ordinal dim_;
00387   bool isInCore_;
00388 
00389   // ///////////////////////////////////
00390   // Private member functions
00391 
00392   void assertInitialized() const;
00393 
00394 };
00395 
00396 
00401 template<class Scalar>
00402 inline
00403 RCP<DefaultProductVectorSpace<Scalar> >
00404 productVectorSpace()
00405 {
00406   return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>);
00407 }
00408 
00409 
00414 template<class Scalar>
00415 inline
00416 RCP<DefaultProductVectorSpace<Scalar> >
00417 productVectorSpace(
00418   const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00419   )
00420 {
00421   return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>(vecSpaces));
00422 }
00423 
00424 
00430 template<class Scalar>
00431 inline
00432 RCP<DefaultProductVectorSpace<Scalar> >
00433 productVectorSpace(
00434   const RCP<const VectorSpaceBase<Scalar> > &vecSpace,
00435   const int numBlocks
00436   )
00437 {
00438   Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaceBlocks;
00439   for ( int i = 0; i < numBlocks; ++i )
00440     vecSpaceBlocks.push_back(vecSpace);
00441   return productVectorSpace<Scalar>(vecSpaceBlocks());
00442 }
00443 
00444 
00445 // /////////////////////////////////
00446 // Inline members
00447 
00448 
00449 template<class Scalar>
00450 inline const RCP<const VectorSpaceBase<Scalar> >*
00451 DefaultProductVectorSpace<Scalar>::vecSpaces() const
00452 {
00453   return ( dim_ ? &(*vecSpaces_)[0] : NULL );
00454 }
00455 
00456 
00457 template<class Scalar>
00458 inline const Ordinal*
00459 DefaultProductVectorSpace<Scalar>::vecSpacesOffsets() const
00460 {
00461   return ( dim_ ? &(*vecSpacesOffsets_)[0] : NULL );
00462 }
00463 
00464 
00465 template<class Scalar>
00466 inline bool DefaultProductVectorSpace<Scalar>::hasBeenCloned() const
00467 {
00468   return vecSpaces_.count() > 1;
00469 }
00470 
00471 
00472 template<class Scalar>
00473 inline
00474 void DefaultProductVectorSpace<Scalar>::assertInitialized() const
00475 {
00476   using Teuchos::implicit_cast;
00477 #ifdef TEUCHOS_DEBUG
00478   TEST_FOR_EXCEPT( is_null(vecSpaces_) );
00479 #endif
00480 }
00481 
00482 
00483 } // namespace Thyra
00484 
00485 
00486 #endif // THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines