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 public functions from SpmdMultiVectorBase
00112 
00113 
00114 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00115 RCP<const SpmdVectorSpaceBase<Scalar> >
00116 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::spmdSpace() const
00117 {
00118   return tpetraVectorSpace_;
00119 }
00120 
00121 
00122 // Overridden protected functions from MultiVectorBase
00123 
00124 
00125 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00126 RCP<const VectorBase<Scalar> >
00127 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::colImpl(Ordinal j) const
00128 {
00129 #ifdef TEUCHOS_DEBUG
00130   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->domain()->dim());
00131 #endif
00132   return constTpetraVector<Scalar>(
00133     tpetraVectorSpace_,
00134     tpetraMultiVector_->getVector(j)
00135     );
00136 }
00137 
00138 
00139 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00140 RCP<VectorBase<Scalar> >
00141 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstColImpl(Ordinal j)
00142 {
00143 #ifdef TEUCHOS_DEBUG
00144   TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->domain()->dim());
00145 #endif
00146   return tpetraVector<Scalar>(
00147     tpetraVectorSpace_,
00148     tpetraMultiVector_.getNonconstObj()->getVectorNonConst(j)
00149     );
00150 }
00151 
00152 
00153 /* ToDo: Implement these?
00154 
00155 
00156 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00157 RCP<MultiVectorBase<Scalar> >
00158 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstContigSubViewImpl(
00159   const Range1D& col_rng_in
00160   )
00161 {
00162 #ifdef THYRA_DEFAULT_SPMD_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00163   std::cerr << "\nSpmdMultiVectorStd<Scalar>::subView() called!\n";
00164 #endif
00165   const Range1D colRng = this->validateColRange(col_rng_in);
00166   return Teuchos::rcp(
00167     new TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00168       spmdRangeSpace_,
00169       Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
00170         spmdRangeSpace_->smallVecSpcFcty()->createVecSpc(colRng.size())
00171         ,true
00172         ),
00173       localValues_.persistingView(colRng.lbound()*leadingDim_,colRng.size()*spmdRangeSpace_->localSubDim()),
00174       leadingDim_
00175       )
00176     );
00177 }
00178 
00179 
00180 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00181 RCP<const MultiVectorBase<Scalar> >
00182 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonContigSubViewImpl(
00183   const ArrayView<const int> &cols
00184   ) const
00185 {
00186   THYRA_DEBUG_ASSERT_MV_COLS("nonContigSubViewImpl(cols)", cols);
00187   const int numCols = cols.size();
00188   const ArrayRCP<Scalar> localValuesView = createContiguousCopy(cols);
00189   return defaultSpmdMultiVector<Scalar>(
00190     spmdRangeSpace_,
00191     createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
00192     localValuesView
00193     );
00194 }
00195 
00196 
00197 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00198 RCP<MultiVectorBase<Scalar> >
00199 TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::nonconstNonContigSubViewImpl(
00200   const ArrayView<const int> &cols )
00201 {
00202   THYRA_DEBUG_ASSERT_MV_COLS("nonContigSubViewImpl(cols)", cols);
00203   const int numCols = cols.size();
00204   const ArrayRCP<Scalar> localValuesView = createContiguousCopy(cols);
00205   const Ordinal localSubDim = spmdRangeSpace_->localSubDim();
00206   RCP<CopyBackSpmdMultiVectorEntries<Scalar> > copyBackView =
00207     copyBackSpmdMultiVectorEntries<Scalar>(cols, localValuesView.getConst(),
00208       localSubDim, localValues_.create_weak(), leadingDim_);
00209   return Teuchos::rcpWithEmbeddedObjPreDestroy(
00210     new TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00211       spmdRangeSpace_,
00212       createSmallScalarProdVectorSpaceBase<Scalar>(spmdRangeSpace_, numCols),
00213       localValuesView),
00214     copyBackView
00215     );
00216 }
00217 
00218 */
00219 
00220 
00221 // Overridden protected members from SpmdMultiVectorBase
00222 
00223 
00224 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00225 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getNonconstLocalDataImpl(
00226   const Ptr<ArrayRCP<Scalar> > &localValues, const Ptr<Ordinal> &leadingDim
00227   )
00228 {
00229   *localValues = tpetraMultiVector_.getNonconstObj()->get1dViewNonConst();
00230   *leadingDim = tpetraMultiVector_->getStride();
00231 }
00232 
00233 
00234 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00235 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getLocalDataImpl(
00236   const Ptr<ArrayRCP<const Scalar> > &localValues, const Ptr<Ordinal> &leadingDim
00237   ) const
00238 {
00239   *localValues = tpetraMultiVector_->get1dView();
00240   *leadingDim = tpetraMultiVector_->getStride();
00241 }
00242 
00243 
00244 // private
00245 
00246 
00247 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00248 template<class TpetraMultiVector_t>
00249 void TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::initializeImpl(
00250   const RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVectorSpace,
00251   const RCP<const ScalarProdVectorSpaceBase<Scalar> > &domainSpace,
00252   const RCP<TpetraMultiVector_t> &tpetraMultiVector
00253   )
00254 {
00255 #ifdef THYRA_DEBUG
00256   TEUCHOS_ASSERT(nonnull(tpetraVectorSpace));
00257   TEUCHOS_ASSERT(nonnull(domainSpace));
00258   TEUCHOS_ASSERT(nonnull(tpetraMultiVector));
00259   // ToDo: Check to make sure that tpetraMultiVector is compatible with
00260   // tpetraVectorSpace.
00261 #endif
00262   tpetraVectorSpace_ = tpetraVectorSpace;
00263   domainSpace_ = domainSpace;
00264   tpetraMultiVector_.initialize(tpetraMultiVector);
00265   this->updateSpmdSpace();
00266 }
00267 
00268 
00269 
00270 } // end namespace Thyra
00271 
00272 
00273 #endif // THYRA_TPETRA_MULTIVECTOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines