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