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