Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DefaultMultiVectorProductVectorSpace_def.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_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
00030 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
00031 
00032 
00033 #include "Thyra_DefaultMultiVectorProductVectorSpace_decl.hpp"
00034 #include "Thyra_DefaultMultiVectorProductVector.hpp"
00035 
00036 
00037 namespace Thyra {
00038 
00039 
00040 // Constructors/initializers/accessors
00041 
00042 
00043 template<class Scalar>
00044 DefaultMultiVectorProductVectorSpace<Scalar>::DefaultMultiVectorProductVectorSpace()
00045   : numColumns_(-1)
00046 {}
00047 
00048 
00049 template<class Scalar>
00050 void DefaultMultiVectorProductVectorSpace<Scalar>::initialize(
00051   const Teuchos::RCP<const VectorSpaceBase<Scalar> > &space,
00052   const int numColumns
00053   )
00054 {
00055 #ifdef TEUCHOS_DEBUG
00056   TEST_FOR_EXCEPT(is_null(space));
00057   TEST_FOR_EXCEPT(numColumns <= 0);
00058 #endif
00059   space_ = space;
00060   numColumns_ = numColumns;
00061   defaultProdVecSpc_ = productVectorSpace(space,numColumns);
00062 }
00063 
00064 
00065 template<class Scalar>
00066 void DefaultMultiVectorProductVectorSpace<Scalar>::uninitialize(
00067   Teuchos::RCP<const VectorSpaceBase<Scalar> > *space,
00068   int *numColumns
00069   )
00070 {
00071   TEST_FOR_EXCEPT("ToDo: Implement when needed!");
00072 }
00073   
00074   
00075 // Overridden from DefaultMultiVectorProductVectorSpace
00076 
00077 
00078 template<class Scalar>
00079 int DefaultMultiVectorProductVectorSpace<Scalar>::numBlocks() const
00080 {
00081   return numColumns_;
00082 }
00083 
00084 
00085 template<class Scalar>
00086 Teuchos::RCP<const VectorSpaceBase<Scalar> >
00087 DefaultMultiVectorProductVectorSpace<Scalar>::getBlock(const int k) const
00088 {
00089   TEST_FOR_EXCEPT( k < 0 || numColumns_ < k );
00090   return space_;
00091 }
00092 
00093 
00094 // Overridden from VectorSpaceBase
00095 
00096 
00097 template<class Scalar>
00098 Ordinal DefaultMultiVectorProductVectorSpace<Scalar>::dim() const
00099 {
00100   if (nonnull(space_))
00101     return numColumns_ * space_->dim();
00102   return -1;
00103 }
00104 
00105 
00106 template<class Scalar>
00107 bool DefaultMultiVectorProductVectorSpace<Scalar>::isCompatible(
00108   const VectorSpaceBase<Scalar>& vecSpc
00109   ) const
00110 {
00111   const DefaultMultiVectorProductVectorSpace<Scalar> *multiVecProdVecSpc
00112     = dynamic_cast<const DefaultMultiVectorProductVectorSpace<Scalar>*>(&vecSpc);
00113   if ( multiVecProdVecSpc != 0 ) {
00114     return (
00115       ( numColumns_ == multiVecProdVecSpc->numColumns_ )
00116       && 
00117       ( space_->isCompatible(*multiVecProdVecSpc->space_) )
00118       );
00119   }
00120   return false;
00121 }
00122 
00123 
00124 template<class Scalar>
00125 Teuchos::RCP< VectorBase<Scalar> >
00126 DefaultMultiVectorProductVectorSpace<Scalar>::createMember() const
00127 {
00128   return multiVectorProductVector<Scalar>(
00129     Teuchos::rcp(new DefaultMultiVectorProductVectorSpace<Scalar>(*this))
00130     );
00131 }
00132 
00133 
00134 template<class Scalar>
00135 Scalar DefaultMultiVectorProductVectorSpace<Scalar>::scalarProd(
00136   const VectorBase<Scalar> &x_in,
00137   const VectorBase<Scalar> &y_in
00138   ) const
00139 {
00140   return defaultProdVecSpc_->scalarProd(x_in,y_in);
00141   // 2007/05/23: rabartl: ToDo: Implement this in a more efficient way using
00142   // the block scalar product using a single global reduction!
00143 }
00144 
00145 template<class Scalar>
00146 void DefaultMultiVectorProductVectorSpace<Scalar>::scalarProdsImpl(
00147   const MultiVectorBase<Scalar> &X_in,
00148   const MultiVectorBase<Scalar> &Y_in,
00149   const ArrayView<Scalar> &scalarProds_out
00150   ) const
00151 {
00152   defaultProdVecSpc_->scalarProds(X_in, Y_in, scalarProds_out);
00153   // 2007/05/23: rabartl: ToDo: Implement this in a more efficient way once
00154   // you have a specialized multi-vector implementation.
00155 }
00156 
00157 template<class Scalar>
00158 bool DefaultMultiVectorProductVectorSpace<Scalar>::hasInCoreView(
00159   const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
00160   ) const
00161 {
00162   return defaultProdVecSpc_->hasInCoreView(rng_in,viewType,strideType);
00163 }
00164 
00165 template<class Scalar>
00166 Teuchos::RCP< const VectorSpaceFactoryBase<Scalar> >
00167 DefaultMultiVectorProductVectorSpace<Scalar>::smallVecSpcFcty() const
00168 {
00169   if (!is_null(space_))
00170     return space_->smallVecSpcFcty();
00171   return Teuchos::null;
00172 }
00173 
00174 template<class Scalar>
00175 Teuchos::RCP< MultiVectorBase<Scalar> >
00176 DefaultMultiVectorProductVectorSpace<Scalar>::createMembers(int numMembers) const
00177 {
00178   return VectorSpaceDefaultBase<Scalar>::createMembers(numMembers);
00179   // 2007/05/23: rabartl: ToDo: Return MultiVectorProductMultiVector object
00180   // once MultiVectorProductMultiVector is created when needed!
00181 }
00182 
00183 
00184 template<class Scalar>
00185 Teuchos::RCP< const VectorSpaceBase<Scalar> >
00186 DefaultMultiVectorProductVectorSpace<Scalar>::clone() const
00187 {
00188   // Warning! If the client uninitialized this object then changes the
00189   // constituent vector spaces then we are in trouble!  The client is warned
00190   // in documentation!
00191   Teuchos::RCP<DefaultMultiVectorProductVectorSpace<Scalar> >
00192     mvpvs = Teuchos::rcp(new DefaultMultiVectorProductVectorSpace<Scalar>());
00193   mvpvs->numColumns_ = numColumns_;
00194   mvpvs->space_ = space_;
00195   mvpvs->defaultProdVecSpc_ = defaultProdVecSpc_;
00196   return mvpvs;
00197 }
00198 
00199 
00200 // Overridden from Teuchos::Describable
00201 
00202                                                 
00203 template<class Scalar>
00204 std::string DefaultMultiVectorProductVectorSpace<Scalar>::description() const
00205 {
00206   std::ostringstream oss;
00207   oss
00208     << Teuchos::Describable::description() << "{"
00209     << "dim="<<this->dim()
00210     << ", numBlocks="<<numColumns_
00211     << "}";
00212   return oss.str();
00213 }
00214 
00215 
00216 template<class Scalar>
00217 void DefaultMultiVectorProductVectorSpace<Scalar>::describe(
00218   Teuchos::FancyOStream &out_arg,
00219   const Teuchos::EVerbosityLevel verbLevel
00220   ) const
00221 {
00222   typedef Teuchos::ScalarTraits<Scalar>  ST;
00223   using Teuchos::RCP;
00224   using Teuchos::FancyOStream;
00225   using Teuchos::OSTab;
00226   RCP<FancyOStream> out = rcp(&out_arg,false);
00227   OSTab tab(out);
00228   switch(verbLevel) {
00229     case Teuchos::VERB_DEFAULT:
00230     case Teuchos::VERB_LOW:
00231       *out << this->description() << std::endl;
00232       break;
00233     case Teuchos::VERB_MEDIUM:
00234     case Teuchos::VERB_HIGH:
00235     case Teuchos::VERB_EXTREME:
00236     {
00237       *out
00238         << this->description() << std::endl;
00239       if (nonnull(space_)) {
00240         OSTab tab2(out);
00241         *out
00242           <<  "Constituent vector space 'space' is the same for all spaces V[0],V[1],,,V[numBlocks-1]:\n";
00243         tab.incrTab();
00244         *out << "space = " << Teuchos::describe(*space_,verbLevel);
00245       }
00246       break;
00247     }
00248     default:
00249       TEST_FOR_EXCEPT(true); // Should never get here!
00250   }
00251 }
00252 
00253 
00254 } // namespace Thyra
00255 
00256 
00257 #endif // THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_SPACE_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines