Thyra Version of the Day
Thyra_DefaultProductVectorSpace_decl.hpp
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
00043 #define THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
00044 
00045 #include "Thyra_ProductVectorSpaceBase.hpp"
00046 #include "Thyra_VectorSpaceDefaultBase.hpp"
00047 #include "Teuchos_implicit_cast.hpp"
00048 
00049 namespace Thyra {
00050 
00051 
00135 template<class Scalar>
00136 class DefaultProductVectorSpace
00137   : virtual public ProductVectorSpaceBase<Scalar>,
00138     virtual protected VectorSpaceDefaultBase<Scalar>
00139 {
00140 public:
00141 
00144 
00146   DefaultProductVectorSpace();
00147 
00149   DefaultProductVectorSpace(
00150     const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00151     );
00152   
00191   virtual void initialize(
00192     const ArrayView<const RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00193     );
00194 
00201   bool hasBeenCloned() const;
00202 
00223   virtual void uninitialize(
00224     const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces = Teuchos::null
00225     );
00226 
00235   virtual const RCP<const VectorSpaceBase<Scalar> >* vecSpaces() const;
00236 
00245   virtual const Ordinal* vecSpacesOffsets() const;
00246 
00275   void getVecSpcPoss( Ordinal i, int* kth_vector_space, Ordinal* kth_global_offset ) const;
00276   
00278 
00281 
00283   int numBlocks() const;
00285   RCP<const VectorSpaceBase<Scalar> > getBlock(const int k) const; 
00286 
00288 
00291 
00293   Ordinal dim() const;
00294 
00298   bool isCompatible( const VectorSpaceBase<Scalar>& vecSpc ) const;
00299 
00301   RCP< VectorBase<Scalar> > createMember() const;
00302 
00306   Scalar scalarProd(
00307     const VectorBase<Scalar>& x, const VectorBase<Scalar>& y ) const;
00308 
00312   void scalarProdsImpl(
00313     const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y,
00314     const ArrayView<Scalar> &scalarProds ) const;
00315 
00319   bool hasInCoreView(const Range1D& rng, const EViewType viewType,
00320     const EStrideType strideType) const;
00321 
00323   RCP< const VectorSpaceFactoryBase<Scalar> > smallVecSpcFcty() const;
00324 
00326   RCP< MultiVectorBase<Scalar> > createMembers(int numMembers) const;
00327 
00329   RCP< const VectorSpaceBase<Scalar> > clone() const;
00330 
00332 
00335                                                 
00339   std::string description() const;
00340 
00348   void describe(
00349     Teuchos::FancyOStream &out,
00350     const Teuchos::EVerbosityLevel verbLevel
00351     ) const;
00352 
00354 
00357 
00359   THYRA_DEPRECATED
00360   DefaultProductVectorSpace(
00361     const int numBlocks_in,
00362     const RCP<const VectorSpaceBase<Scalar> > vecSpaces_in[]
00363     )
00364     : numBlocks_(-1), dim_(-1)
00365     {
00366       using Teuchos::as;
00367       initialize(Teuchos::arrayView(vecSpaces_in, as<Ordinal>(numBlocks_in)));
00368     }
00369 
00371   THYRA_DEPRECATED
00372   void initialize(
00373     const int numBlocks_in,
00374     const RCP<const VectorSpaceBase<Scalar> > vecSpaces_in[]
00375     )
00376     {
00377       using Teuchos::as;
00378       initialize(Teuchos::arrayView(vecSpaces_in, as<Ordinal>(numBlocks_in)));
00379     }
00380 
00382   
00383 protected:
00384 
00385   // ///////////////////////////////////
00386   // Protected member functions
00387 
00388 private:
00389  
00390   // ///////////////////////////////////
00391   // Private types
00392 
00393   typedef Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaces_t;
00394   typedef Array<Ordinal> vecSpacesOffsets_t;
00395  
00396   // ///////////////////////////////////
00397   // Private data members
00398 
00399   int numBlocks_;
00400   RCP<vecSpaces_t> vecSpaces_;
00401   RCP<vecSpacesOffsets_t> vecSpacesOffsets_;
00402   // cached info
00403   Ordinal dim_;
00404   bool isInCore_;
00405 
00406   // ///////////////////////////////////
00407   // Private member functions
00408 
00409   void assertInitialized() const;
00410 
00411 };
00412 
00413 
00418 template<class Scalar>
00419 inline
00420 RCP<DefaultProductVectorSpace<Scalar> >
00421 productVectorSpace()
00422 {
00423   return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>);
00424 }
00425 
00426 
00431 template<class Scalar>
00432 inline
00433 RCP<DefaultProductVectorSpace<Scalar> >
00434 productVectorSpace(
00435   const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00436   )
00437 {
00438   return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>(vecSpaces));
00439 }
00440 
00441 
00447 template<class Scalar>
00448 inline
00449 RCP<DefaultProductVectorSpace<Scalar> >
00450 productVectorSpace(
00451   const RCP<const VectorSpaceBase<Scalar> > &vecSpace,
00452   const int numBlocks
00453   )
00454 {
00455   Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaceBlocks;
00456   for ( int i = 0; i < numBlocks; ++i )
00457     vecSpaceBlocks.push_back(vecSpace);
00458   return productVectorSpace<Scalar>(vecSpaceBlocks());
00459 }
00460 
00461 
00462 // /////////////////////////////////
00463 // Inline members
00464 
00465 
00466 template<class Scalar>
00467 inline const RCP<const VectorSpaceBase<Scalar> >*
00468 DefaultProductVectorSpace<Scalar>::vecSpaces() const
00469 {
00470   return ( dim_ ? &(*vecSpaces_)[0] : NULL );
00471 }
00472 
00473 
00474 template<class Scalar>
00475 inline const Ordinal*
00476 DefaultProductVectorSpace<Scalar>::vecSpacesOffsets() const
00477 {
00478   return ( dim_ ? &(*vecSpacesOffsets_)[0] : NULL );
00479 }
00480 
00481 
00482 template<class Scalar>
00483 inline bool DefaultProductVectorSpace<Scalar>::hasBeenCloned() const
00484 {
00485   return vecSpaces_.count() > 1;
00486 }
00487 
00488 
00489 template<class Scalar>
00490 inline
00491 void DefaultProductVectorSpace<Scalar>::assertInitialized() const
00492 {
00493   using Teuchos::implicit_cast;
00494 #ifdef TEUCHOS_DEBUG
00495   TEUCHOS_TEST_FOR_EXCEPT( is_null(vecSpaces_) );
00496 #endif
00497 }
00498 
00499 
00500 } // namespace Thyra
00501 
00502 
00503 #endif // THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines