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 
00355 protected:
00356 
00357   // ///////////////////////////////////
00358   // Protected member functions
00359 
00360 private:
00361  
00362   // ///////////////////////////////////
00363   // Private types
00364 
00365   typedef Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaces_t;
00366   typedef Array<Ordinal> vecSpacesOffsets_t;
00367  
00368   // ///////////////////////////////////
00369   // Private data members
00370 
00371   int numBlocks_;
00372   RCP<vecSpaces_t> vecSpaces_;
00373   RCP<vecSpacesOffsets_t> vecSpacesOffsets_;
00374   // cached info
00375   Ordinal dim_;
00376   bool isInCore_;
00377 
00378   // ///////////////////////////////////
00379   // Private member functions
00380 
00381   void assertInitialized() const;
00382 
00383 };
00384 
00385 
00390 template<class Scalar>
00391 inline
00392 RCP<DefaultProductVectorSpace<Scalar> >
00393 productVectorSpace()
00394 {
00395   return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>);
00396 }
00397 
00398 
00403 template<class Scalar>
00404 inline
00405 RCP<DefaultProductVectorSpace<Scalar> >
00406 productVectorSpace(
00407   const ArrayView<RCP<const VectorSpaceBase<Scalar> > > &vecSpaces
00408   )
00409 {
00410   return Teuchos::rcp(new DefaultProductVectorSpace<Scalar>(vecSpaces));
00411 }
00412 
00413 
00419 template<class Scalar>
00420 inline
00421 RCP<DefaultProductVectorSpace<Scalar> >
00422 productVectorSpace(
00423   const RCP<const VectorSpaceBase<Scalar> > &vecSpace,
00424   const int numBlocks
00425   )
00426 {
00427   Array<RCP<const VectorSpaceBase<Scalar> > > vecSpaceBlocks;
00428   for ( int i = 0; i < numBlocks; ++i )
00429     vecSpaceBlocks.push_back(vecSpace);
00430   return productVectorSpace<Scalar>(vecSpaceBlocks());
00431 }
00432 
00433 
00434 // /////////////////////////////////
00435 // Inline members
00436 
00437 
00438 template<class Scalar>
00439 inline const RCP<const VectorSpaceBase<Scalar> >*
00440 DefaultProductVectorSpace<Scalar>::vecSpaces() const
00441 {
00442   return ( dim_ ? &(*vecSpaces_)[0] : NULL );
00443 }
00444 
00445 
00446 template<class Scalar>
00447 inline const Ordinal*
00448 DefaultProductVectorSpace<Scalar>::vecSpacesOffsets() const
00449 {
00450   return ( dim_ ? &(*vecSpacesOffsets_)[0] : NULL );
00451 }
00452 
00453 
00454 template<class Scalar>
00455 inline bool DefaultProductVectorSpace<Scalar>::hasBeenCloned() const
00456 {
00457   return vecSpaces_.strong_count() > 1;
00458 }
00459 
00460 
00461 template<class Scalar>
00462 inline
00463 void DefaultProductVectorSpace<Scalar>::assertInitialized() const
00464 {
00465   using Teuchos::implicit_cast;
00466 #ifdef TEUCHOS_DEBUG
00467   TEUCHOS_TEST_FOR_EXCEPT( is_null(vecSpaces_) );
00468 #endif
00469 }
00470 
00471 
00472 } // namespace Thyra
00473 
00474 
00475 #endif // THYRA_DEFAULT_PRODUCT_VECTOR_SPACE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines