Thyra Version of the Day
Thyra_TpetraMultiVector_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_TPETRA_MULTIVECTOR_HPP
00043 #define THYRA_TPETRA_MULTIVECTOR_HPP
00044 
00045 #include "Thyra_TpetraMultiVector_decl.hpp"
00046 #include "Thyra_TpetraVectorSpace.hpp"
00047 #include "Thyra_TpetraVector.hpp"
00048 #include "Teuchos_Assert.hpp"
00049 
00050 
00051 namespace Thyra {
00052 
00053 
00054 // Constructors/initializers/accessors
00055 
00056 
00057 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00058 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::TpetraMultiVector()
00059 {}
00060 
00061 
00062 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00063 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::initialize(
00064   const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
00065   const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
00066   const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector
00067   )
00068 {
00069   initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
00070 }
00071 
00072 
00073 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00074 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::constInitialize(
00075   const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
00076   const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
00077   const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector
00078   )
00079 {
00080   initializeImpl(tpetraVectorSpace, domainSpace, tpetraMultiVector);
00081 }
00082 
00083 
00084 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00085 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00086 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getTpetraMultiVector()
00087 {
00088   return tpetraMultiVector_.getNonconstObj();
00089 }
00090 
00091 
00092 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00093 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00094 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getConstTpetraMultiVector() const
00095 {
00096   return tpetraMultiVector_;
00097 }
00098 
00099 
00100 // Overridden public functions form MultiVectorAdapterBase
00101 
00102 
00103 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00104 RCP< const ScalarProdVectorSpaceBase<Scalar> >
00105 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::domainScalarProdVecSpc() const
00106 {
00107   return domainSpace_;
00108 }
00109 
00110 
00111 // Overridden protected functions from MultiVectorBase
00112 
00113 
00114 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00115 RCP<const VectorBase<Scalar> >
00116 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::colImpl(Ordinal j) const
00117 {
00118 #ifdef TEUCHOS_DEBUG
00119   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->domain()->dim());
00120 #endif
00121   return constTpetraVector<Scalar>(
00122     tpetraVectorSpace_,
00123     tpetraMultiVector_->getVector(j)
00124     );
00125 }
00126 
00127 
00128 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00129 RCP<VectorBase<Scalar> >
00130 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstColImpl(Ordinal j)
00131 {
00132 #ifdef TEUCHOS_DEBUG
00133   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->domain()->dim());
00134 #endif
00135   return tpetraVector<Scalar>(
00136     tpetraVectorSpace_,
00137     tpetraMultiVector_.getNonconstObj()->getVectorNonConst(j)
00138     );
00139 }
00140 
00141 
00142 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00143 RCP<const MultiVectorBase<Scalar> >
00144 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::contigSubViewImpl(
00145   const Range1D& col_rng_in
00146   ) const
00147 {
00148 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00149   std::cerr << "\nTpetraMultiVector::subView(Range1D) const called!\n";
00150 #endif
00151   const Range1D colRng = this->validateColRange(col_rng_in);
00152 
00153   const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetraView =
00154     this->getConstTpetraMultiVector()->subView(colRng);
00155 
00156   const RCP<const ScalarProdVectorSpaceBase<Scalar> > viewDomainSpace =
00157     tpetraVectorSpace<Scalar>(
00158         Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal>(
00159           tpetraView->getNumVectors(),
00160           tpetraView->getMap()->getComm(),
00161           tpetraView->getMap()->getNode()
00162           )
00163         );
00164 
00165   return constTpetraMultiVector(
00166       tpetraVectorSpace_,
00167       viewDomainSpace,
00168       tpetraView
00169       );
00170 }
00171 
00172 
00173 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00174 RCP<MultiVectorBase<Scalar> >
00175 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstContigSubViewImpl(
00176   const Range1D& col_rng_in
00177   )
00178 {
00179 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00180   std::cerr << "\nTpetraMultiVector::subView(Range1D) called!\n";
00181 #endif
00182   const Range1D colRng = this->validateColRange(col_rng_in);
00183 
00184   const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetraView =
00185     this->getTpetraMultiVector()->subViewNonConst(colRng);
00186 
00187   const RCP<const ScalarProdVectorSpaceBase<Scalar> > viewDomainSpace =
00188     tpetraVectorSpace<Scalar>(
00189         Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal>(
00190           tpetraView->getNumVectors(),
00191           tpetraView->getMap()->getComm(),
00192           tpetraView->getMap()->getNode()
00193           )
00194         );
00195 
00196   return tpetraMultiVector(
00197       tpetraVectorSpace_,
00198       viewDomainSpace,
00199       tpetraView
00200       );
00201 }
00202 
00203 
00204 /* ToDo: Implement these?
00205 
00206 
00207 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00208 RCP<const MultiVectorBase<Scalar> >
00209 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonContigSubViewImpl(
00210   const ArrayView<const int> &cols
00211   ) const
00212 {
00213   THYRA_DEBUG_ASSERT_MV_COLS("nonContigSubViewImpl(cols)", cols);
00214   const int numCols = cols.size();
00215   const ArrayRCP<Scalar> localValuesView = createContiguousCopy(cols);
00216   return defaultSpmdMultiVector<Scalar>(
00217     spmdRangeSpace_,
00218     createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
00219     localValuesView
00220     );
00221 }
00222 
00223 
00224 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00225 RCP<MultiVectorBase<Scalar> >
00226 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstNonContigSubViewImpl(
00227   const ArrayView<const int> &cols )
00228 {
00229   THYRA_DEBUG_ASSERT_MV_COLS("nonContigSubViewImpl(cols)", cols);
00230   const int numCols = cols.size();
00231   const ArrayRCP<Scalar> localValuesView = createContiguousCopy(cols);
00232   const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
00233   RCP<CopyBackSpmdMultiVectorEntries<Scalar> > copyBackView =
00234     copyBackSpmdMultiVectorEntries<Scalar>(cols, localValuesView.getConst(),
00235       localSubDim, localValues_.create_weak(), leadingDim_);
00236   return Teuchos::rcpWithEmbeddedObjPreDestroy(
00237     new TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00238       spmdRangeSpace_,
00239       createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
00240       localValuesView),
00241     copyBackView
00242     );
00243 }
00244 
00245 */
00246 
00247 
00248 // Overridden protected members from SpmdMultiVectorBase
00249 
00250 
00251 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00252 RCP<const SpmdVectorSpaceBase<Scalar> >
00253 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::spmdSpaceImpl() const
00254 {
00255   return tpetraVectorSpace_;
00256 }
00257 
00258 
00259 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00260 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getNonconstLocalMultiVectorDataImpl(
00261   const Ptr<ArrayRCP<Scalar> > &localValues, const Ptr<Ordinal> &leadingDim
00262   )
00263 {
00264   *localValues = tpetraMultiVector_.getNonconstObj()->get1dViewNonConst();
00265   *leadingDim = tpetraMultiVector_->getStride();
00266 }
00267 
00268 
00269 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00270 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getLocalMultiVectorDataImpl(
00271   const Ptr<ArrayRCP<const Scalar> > &localValues, const Ptr<Ordinal> &leadingDim
00272   ) const
00273 {
00274   *localValues = tpetraMultiVector_->get1dView();
00275   *leadingDim = tpetraMultiVector_->getStride();
00276 }
00277 
00278 
00279 // private
00280 
00281 
00282 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00283 template<class TpetraMultiVector_t>
00284 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::initializeImpl(
00285   const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
00286   const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
00287   const RCP<TpetraMultiVector_t> &tpetraMultiVector
00288   )
00289 {
00290 #ifdef THYRA_DEBUG
00291   TEUCHOS_ASSERT(nonnull(tpetraVectorSpace));
00292   TEUCHOS_ASSERT(nonnull(domainSpace));
00293   TEUCHOS_ASSERT(nonnull(tpetraMultiVector));
00294   // ToDo: Check to make sure that tpetraMultiVector is compatible with
00295   // tpetraVectorSpace.
00296 #endif
00297   tpetraVectorSpace_ = tpetraVectorSpace;
00298   domainSpace_ = domainSpace;
00299   tpetraMultiVector_.initialize(tpetraMultiVector);
00300   this->updateSpmdSpace();
00301 }
00302 
00303 
00304 
00305 } // end namespace Thyra
00306 
00307 
00308 #endif // THYRA_TPETRA_MULTIVECTOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines