Thyra_DefaultMultiVectorProductVector.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_MULTI_VECTOR_PRODUCT_VECTOR_HPP
00030 #define THYRA_MULTI_VECTOR_PRODUCT_VECTOR_HPP
00031 
00032 
00033 #include "Thyra_DefaultMultiVectorProductVectorDecl.hpp"
00034 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
00035 #include "Teuchos_Assert.hpp"
00036 
00037 
00038 namespace Thyra {
00039 
00040 
00041 // Constructors/initializers/accessors
00042 
00043 
00044 template <class Scalar>
00045 DefaultMultiVectorProductVector<Scalar>::DefaultMultiVectorProductVector()
00046 {
00047   uninitialize();
00048 }
00049 
00050 
00051 template <class Scalar>
00052 void DefaultMultiVectorProductVector<Scalar>::initialize(
00053   const Teuchos::RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace,
00054   const Teuchos::RCP<MultiVectorBase<Scalar> > &multiVec
00055   )
00056 {
00057 #ifdef TEUCHOS_DEBUG
00058   TEST_FOR_EXCEPT(is_null(productSpace));
00059   TEST_FOR_EXCEPT(is_null(multiVec));
00060   THYRA_ASSERT_VEC_SPACES(
00061     "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace,multiVec)",
00062     *multiVec->range(), *productSpace->getBlock(0)
00063     );
00064   TEUCHOS_ASSERT_EQUALITY( multiVec->domain()->dim(), productSpace->numBlocks());
00065 #endif
00066 
00067   numBlocks_ = productSpace->numBlocks();
00068 
00069   productSpace_ = productSpace;
00070 
00071   multiVec_ = multiVec;
00072 
00073 }
00074 
00075 
00076 template <class Scalar>
00077 void DefaultMultiVectorProductVector<Scalar>::initialize(
00078   const Teuchos::RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace,
00079   const Teuchos::RCP<const MultiVectorBase<Scalar> > &multiVec
00080   )
00081 {
00082 #ifdef TEUCHOS_DEBUG
00083   TEST_FOR_EXCEPT(is_null(productSpace));
00084   TEST_FOR_EXCEPT(is_null(multiVec));
00085   THYRA_ASSERT_VEC_SPACES(
00086     "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace,multiVec)",
00087     *multiVec->range(), *productSpace->getBlock(0)
00088     );
00089   TEUCHOS_ASSERT_EQUALITY( multiVec->domain()->dim(), productSpace->numBlocks() );
00090 #endif
00091 
00092   numBlocks_ = productSpace->numBlocks();
00093 
00094   productSpace_ = productSpace;
00095 
00096   multiVec_ = multiVec;
00097 
00098 }
00099 
00100 
00101 template <class Scalar>
00102 Teuchos::RCP<MultiVectorBase<Scalar> >
00103 DefaultMultiVectorProductVector<Scalar>::getNonconstMultiVector()
00104 {
00105   return multiVec_.getNonconstObj();
00106 }
00107 
00108 
00109 template <class Scalar>
00110 Teuchos::RCP<const MultiVectorBase<Scalar> >
00111 DefaultMultiVectorProductVector<Scalar>::getMultiVector() const
00112 {
00113   return multiVec_.getConstObj();
00114 }
00115 
00116 
00117 template <class Scalar>
00118 void DefaultMultiVectorProductVector<Scalar>::uninitialize()
00119 {
00120   numBlocks_ = 0;
00121   productSpace_ = Teuchos::null;
00122   multiVec_.uninitialize();
00123 }
00124 
00125 
00126 // Overridden from Teuchos::Describable
00127 
00128                                                 
00129 template<class Scalar>
00130 std::string DefaultMultiVectorProductVector<Scalar>::description() const
00131 {
00132   std::ostringstream oss;
00133   oss
00134     << Teuchos::Describable::description()
00135     << "{"
00136     << "dim="<<this->space()->dim()
00137     << ",numColumns = "<<numBlocks_
00138     << "}";
00139   return oss.str();
00140 }
00141 
00142 template<class Scalar>
00143 void DefaultMultiVectorProductVector<Scalar>::describe(
00144   Teuchos::FancyOStream &out_arg,
00145   const Teuchos::EVerbosityLevel verbLevel
00146   ) const
00147 {
00148   typedef Teuchos::ScalarTraits<Scalar>  ST;
00149   using Teuchos::RCP;
00150   using Teuchos::FancyOStream;
00151   using Teuchos::OSTab;
00152   using Teuchos::describe;
00153   RCP<FancyOStream> out = rcp(&out_arg,false);
00154   OSTab tab(out);
00155   switch(verbLevel) {
00156     case Teuchos::VERB_DEFAULT:
00157     case Teuchos::VERB_LOW:
00158       *out << this->description() << std::endl;
00159       break;
00160     case Teuchos::VERB_MEDIUM:
00161     case Teuchos::VERB_HIGH:
00162     case Teuchos::VERB_EXTREME:
00163     {
00164       *out
00165         << Teuchos::Describable::description() << "{"
00166         << "dim=" << this->space()->dim()
00167         << "}\n";
00168       OSTab tab(out);
00169       *out <<  "multiVec = " << Teuchos::describe(*multiVec_.getConstObj(),verbLevel);
00170       break;
00171     }
00172     default:
00173       TEST_FOR_EXCEPT(true); // Should never get here!
00174   }
00175 }
00176 
00177 
00178 // Overridden from ProductVectorBase
00179 
00180 
00181 template <class Scalar>
00182 Teuchos::RCP<VectorBase<Scalar> >
00183 DefaultMultiVectorProductVector<Scalar>::getNonconstVectorBlock(const int k)
00184 {
00185 #ifdef TEUCHOS_DEBUG
00186   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
00187 #endif
00188   return multiVec_.getNonconstObj()->col(k);
00189 }
00190 
00191 
00192 template <class Scalar>
00193 Teuchos::RCP<const VectorBase<Scalar> >
00194 DefaultMultiVectorProductVector<Scalar>::getVectorBlock(const int k) const
00195 {
00196 #ifdef TEUCHOS_DEBUG
00197   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
00198 #endif
00199   return multiVec_.getConstObj()->col(k);
00200 }
00201 
00202 
00203 // Overridden from ProductMultiVectorBase
00204 
00205 
00206 template <class Scalar>
00207 Teuchos::RCP<const ProductVectorSpaceBase<Scalar> >
00208 DefaultMultiVectorProductVector<Scalar>::productSpace() const
00209 {
00210   return productSpace_;
00211 }
00212 
00213 
00214 template <class Scalar>
00215 bool DefaultMultiVectorProductVector<Scalar>::blockIsConst(const int k) const
00216 {
00217 #ifdef TEUCHOS_DEBUG
00218   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
00219 #endif
00220   return multiVec_.isConst();
00221 }
00222 
00223 
00224 template <class Scalar>
00225 Teuchos::RCP<MultiVectorBase<Scalar> >
00226 DefaultMultiVectorProductVector<Scalar>::getNonconstMultiVectorBlock(const int k)
00227 {
00228   return getNonconstVectorBlock(k);
00229 }
00230 
00231 
00232 template <class Scalar>
00233 Teuchos::RCP<const MultiVectorBase<Scalar> >
00234 DefaultMultiVectorProductVector<Scalar>::getMultiVectorBlock(const int k) const
00235 {
00236   return getVectorBlock(k);
00237 }
00238 
00239 
00240 // Overridden from VectorBase
00241 
00242 
00243 template <class Scalar>
00244 Teuchos::RCP< const VectorSpaceBase<Scalar> >
00245 DefaultMultiVectorProductVector<Scalar>::space() const
00246 {
00247   return productSpace_;
00248 }
00249 
00250 
00251 template <class Scalar>
00252 void DefaultMultiVectorProductVector<Scalar>::applyOp(
00253   const RTOpPack::RTOpT<Scalar>    &op
00254   ,const int                       num_vecs
00255   ,const VectorBase<Scalar>*const  vecs[]
00256   ,const int                       num_targ_vecs
00257   ,VectorBase<Scalar>*const        targ_vecs[]
00258   ,RTOpPack::ReductTarget          *reduct_obj
00259   ,const Index                     first_ele_offset_in
00260   ,const Index                     sub_dim_in
00261   ,const Index                     global_offset_in
00262   ) const
00263 {
00264   this->getDefaultProductVector()->applyOp(
00265     op, num_vecs, vecs, num_targ_vecs, targ_vecs,
00266     reduct_obj,
00267     first_ele_offset_in, sub_dim_in, global_offset_in
00268     );
00269 }
00270 
00271 
00272 template <class Scalar>
00273 void DefaultMultiVectorProductVector<Scalar>::acquireDetachedVectorViewImpl(
00274   const Range1D& rng_in, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00275   ) const
00276 {
00277   this->getDefaultProductVector()->acquireDetachedVectorViewImpl(rng_in,sub_vec);
00278 }
00279 
00280 
00281 template <class Scalar>
00282 void DefaultMultiVectorProductVector<Scalar>::releaseDetachedVectorViewImpl(
00283   RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00284   ) const
00285 {
00286   this->getDefaultProductVector()->releaseDetachedVectorViewImpl(sub_vec);
00287 }
00288 
00289 
00290 template <class Scalar>
00291 void DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(
00292   const Range1D& rng_in, RTOpPack::SubVectorView<Scalar>* sub_vec
00293   )
00294 {
00295   TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(...)!");
00296 }
00297 
00298 
00299 template <class Scalar>
00300 void DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(
00301   RTOpPack::SubVectorView<Scalar>* sub_vec
00302   )
00303 {
00304   TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(...)!");
00305 }
00306 
00307 
00308 template <class Scalar>
00309 void DefaultMultiVectorProductVector<Scalar>::setSubVector(
00310   const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00311   )
00312 {
00313   TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::setSubVector(...)!");
00314 }
00315 
00316 
00317 // private
00318 
00319 
00320 template <class Scalar>
00321 Teuchos::RCP<const DefaultProductVector<Scalar> >
00322 DefaultMultiVectorProductVector<Scalar>::getDefaultProductVector() const
00323 {
00324 
00325   // This function exists since in general we can not create views of a column
00326   // vectors and expect the changes to be mirrored in the mulit-vector
00327   // automatically.  Later, we might be able to change this once we have a
00328   // Thyra::MultiVectorBase::hasDirectColumnVectorView() function and it
00329   // returns true.  Until then, this is the safe way to do this ...
00330 
00331   using Teuchos::Array; using Teuchos::RCP;
00332 
00333   Array<RCP<const VectorBase<Scalar> > > vecArray;
00334   for ( int k = 0; k < numBlocks_; ++k) {
00335     vecArray.push_back(multiVec_.getConstObj()->col(k));
00336   }
00337 
00338   return Thyra::defaultProductVector<Scalar>(
00339     productSpace_->getDefaultProductVectorSpace(),
00340     &vecArray[0]
00341     );
00342 
00343 }
00344 
00345 
00346 } // namespace Thyra
00347 
00348 
00349 #endif // THYRA_MULTI_VECTOR_PRODUCT_VECTOR_HPP

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