Thyra_DefaultMultiVectorProductVector.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 // 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 RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace,
00054   const 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 RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace,
00079   const 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 RCP<MultiVectorBase<Scalar> >
00103 DefaultMultiVectorProductVector<Scalar>::getNonconstMultiVector()
00104 {
00105   return multiVec_.getNonconstObj();
00106 }
00107 
00108 
00109 template <class Scalar>
00110 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::OSTab;
00150   using Teuchos::describe;
00151   RCP<FancyOStream> out = rcp(&out_arg,false);
00152   OSTab tab(out);
00153   switch(verbLevel) {
00154     case Teuchos::VERB_DEFAULT:
00155     case Teuchos::VERB_LOW:
00156       *out << this->description() << std::endl;
00157       break;
00158     case Teuchos::VERB_MEDIUM:
00159     case Teuchos::VERB_HIGH:
00160     case Teuchos::VERB_EXTREME:
00161     {
00162       *out
00163         << Teuchos::Describable::description() << "{"
00164         << "dim=" << this->space()->dim()
00165         << "}\n";
00166       OSTab tab(out);
00167       *out <<  "multiVec = " << Teuchos::describe(*multiVec_.getConstObj(),verbLevel);
00168       break;
00169     }
00170     default:
00171       TEST_FOR_EXCEPT(true); // Should never get here!
00172   }
00173 }
00174 
00175 
00176 // Overridden from ProductVectorBase
00177 
00178 
00179 template <class Scalar>
00180 RCP<VectorBase<Scalar> >
00181 DefaultMultiVectorProductVector<Scalar>::getNonconstVectorBlock(const int k)
00182 {
00183 #ifdef TEUCHOS_DEBUG
00184   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
00185 #endif
00186   return multiVec_.getNonconstObj()->col(k);
00187 }
00188 
00189 
00190 template <class Scalar>
00191 RCP<const VectorBase<Scalar> >
00192 DefaultMultiVectorProductVector<Scalar>::getVectorBlock(const int k) const
00193 {
00194 #ifdef TEUCHOS_DEBUG
00195   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
00196 #endif
00197   return multiVec_.getConstObj()->col(k);
00198 }
00199 
00200 
00201 // Overridden from ProductMultiVectorBase
00202 
00203 
00204 template <class Scalar>
00205 RCP<const ProductVectorSpaceBase<Scalar> >
00206 DefaultMultiVectorProductVector<Scalar>::productSpace() const
00207 {
00208   return productSpace_;
00209 }
00210 
00211 
00212 template <class Scalar>
00213 bool DefaultMultiVectorProductVector<Scalar>::blockIsConst(const int k) const
00214 {
00215 #ifdef TEUCHOS_DEBUG
00216   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ );
00217 #endif
00218   return multiVec_.isConst();
00219 }
00220 
00221 
00222 template <class Scalar>
00223 RCP<MultiVectorBase<Scalar> >
00224 DefaultMultiVectorProductVector<Scalar>::getNonconstMultiVectorBlock(const int k)
00225 {
00226   return getNonconstVectorBlock(k);
00227 }
00228 
00229 
00230 template <class Scalar>
00231 RCP<const MultiVectorBase<Scalar> >
00232 DefaultMultiVectorProductVector<Scalar>::getMultiVectorBlock(const int k) const
00233 {
00234   return getVectorBlock(k);
00235 }
00236 
00237 
00238 // Overridden public functions from VectorBase
00239 
00240 
00241 template <class Scalar>
00242 RCP< const VectorSpaceBase<Scalar> >
00243 DefaultMultiVectorProductVector<Scalar>::space() const
00244 {
00245   return productSpace_;
00246 }
00247 
00248 
00249 // protected
00250 
00251 
00252 // Overridden protected functions from VectorBase
00253 
00254 
00255 template <class Scalar>
00256 void DefaultMultiVectorProductVector<Scalar>::applyOpImpl(
00257   const RTOpPack::RTOpT<Scalar> &op,
00258   const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00259   const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00260   const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00261   const Index first_ele_offset,
00262   const Index sub_dim,
00263   const Index global_offset
00264   ) const
00265 {
00266   this->getDefaultProductVector()->applyOp(
00267     op, vecs, targ_vecs, reduct_obj,
00268     first_ele_offset, sub_dim, global_offset );
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()->acquireDetachedView(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()->releaseDetachedView(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>::setSubVectorImpl(
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 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   Array<RCP<const VectorBase<Scalar> > > vecArray;
00332   for ( int k = 0; k < numBlocks_; ++k) {
00333     vecArray.push_back(multiVec_.getConstObj()->col(k));
00334   }
00335 
00336   return Thyra::defaultProductVector<Scalar>(
00337     productSpace_->getDefaultProductVectorSpace(),
00338     &vecArray[0]
00339     );
00340 
00341 }
00342 
00343 
00344 } // namespace Thyra
00345 
00346 
00347 #endif // THYRA_MULTI_VECTOR_PRODUCT_VECTOR_HPP

Generated on Wed May 12 21:26:54 2010 for Thyra Operator/Vector Support by  doxygen 1.4.7