Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_TpetraThyraWrappers_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 // 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_THYRA_WRAPPERS_HPP
00043 #define THYRA_TPETRA_THYRA_WRAPPERS_HPP
00044 
00045 
00046 #include "Thyra_TpetraThyraWrappers.hpp"
00047 #include "Thyra_TpetraVectorSpace.hpp"
00048 #include "Thyra_TpetraVector.hpp"
00049 #include "Thyra_TpetraMultiVector.hpp"
00050 #include "Thyra_TpetraLinearOp.hpp"
00051 
00052 
00053 namespace Thyra {
00054 
00055 
00056 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00057 Teuchos::RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00058 getOrCreateTpetraVectorSpace(
00059   const RCP<const VectorSpaceBase<Scalar> > space,
00060   const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
00061   )
00062 {
00063   using Teuchos::rcp_dynamic_cast;
00064   typedef TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpetraVectorSpace_t;
00065   RCP<const TpetraVectorSpace_t> tpetraSpace;
00066   if (nonnull(space)) {
00067     tpetraSpace = rcp_dynamic_cast<const TpetraVectorSpace_t>(space, true);
00068   }
00069   else {
00070     tpetraSpace = tpetraVectorSpace<Scalar>(tpetraMap);
00071   }
00072   return tpetraSpace;
00073 }
00074 
00075 
00076 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00077 Teuchos::RCP<const ScalarProdVectorSpaceBase<Scalar> >
00078 getOrCreateLocallyReplicatedTpetraVectorSpace(
00079   const RCP<const VectorSpaceBase<Scalar> > space,
00080   const RCP<const Teuchos::Comm<int> > &tpetraComm,
00081   const RCP<Node> &tpetraNode,
00082   const int numCols
00083   )
00084 {
00085   using Teuchos::rcp_dynamic_cast;
00086   typedef TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpetraVectorSpace_t;
00087   RCP<const TpetraVectorSpace_t> tpetraSpace;
00088   if (nonnull(space)) {
00089     tpetraSpace = rcp_dynamic_cast<const TpetraVectorSpace_t>(space, true);
00090   }
00091   else {
00092     tpetraSpace = tpetraVectorSpace<Scalar>(
00093       Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal>(
00094         numCols, tpetraComm, tpetraNode 
00095         )
00096       );
00097   }
00098   return tpetraSpace;
00099 }
00100 
00101 
00102 } // namespace Thyra
00103 
00104 
00105 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00106 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00107 Thyra::createVectorSpace(
00108   const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
00109   )
00110 {
00111   return tpetraVectorSpace<Scalar>(tpetraMap);
00112 }
00113 
00114 
00115 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00116 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00117 Thyra::createVector(
00118   const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
00119   const RCP<const VectorSpaceBase<Scalar> > space_in
00120   )
00121 {
00122   return tpetraVector(
00123     getOrCreateTpetraVectorSpace(space_in, tpetraVector_in->getMap()),
00124     tpetraVector_in
00125     );
00126 }
00127 
00128 
00129 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00130 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00131 Thyra::createConstVector(
00132   const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
00133   const RCP<const VectorSpaceBase<Scalar> > space
00134   )
00135 {
00136   return constTpetraVector(
00137     getOrCreateTpetraVectorSpace(space, tpetraVector_in->getMap()),
00138     tpetraVector_in
00139     );
00140 }
00141 
00142 
00143 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00144 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00145 Thyra::createMultiVector(
00146   const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
00147   const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
00148   const RCP<const VectorSpaceBase<Scalar> > domainSpace
00149   )
00150 {
00151   return tpetraMultiVector(
00152     getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
00153     getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
00154       domainSpace, tpetraMultiVector_in->getMap()->getComm(),
00155       tpetraMultiVector_in->getMap()->getNode(),
00156       tpetraMultiVector_in->getNumVectors()
00157       ),
00158     tpetraMultiVector_in
00159     );
00160 }
00161 
00162 
00163 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00164 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00165 Thyra::createConstMultiVector(
00166   const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
00167   const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
00168   const RCP<const VectorSpaceBase<Scalar> > domainSpace
00169   )
00170 {
00171   return constTpetraMultiVector(
00172     getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
00173     getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
00174       domainSpace, tpetraMultiVector_in->getMap()->getComm(),
00175       tpetraMultiVector_in->getMap()->getNode(),
00176       tpetraMultiVector_in->getNumVectors()
00177       ),
00178     tpetraMultiVector_in
00179     );
00180 }
00181 
00182 
00183 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00184 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00185 Thyra::createLinearOp(
00186   const RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
00187   const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
00188   const RCP<const VectorSpaceBase<Scalar> > domainSpace
00189   )
00190 {
00191   return tpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00192     getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap()),
00193     getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap()),
00194     tpetraOperator_in
00195     );
00196 }
00197 
00198 
00199 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00200 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00201 Thyra::createConstLinearOp(
00202   const RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
00203   const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
00204   const RCP<const VectorSpaceBase<Scalar> > domainSpace
00205   )
00206 {
00207   return constTpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
00208     getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap()),
00209     getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap()),
00210     tpetraOperator_in
00211     );
00212 }
00213 
00214 
00215 namespace Thyra {
00216 
00217 
00218 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00219 RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00220 TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
00221 getTpetraVector(const RCP<VectorBase<Scalar> > &v)
00222 {
00223   typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraVector_t;
00224   return Teuchos::rcp_dynamic_cast<TpetraVector_t>(v, true)->getTpetraVector();
00225 }
00226 
00227 
00228 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00229 RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00230 TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
00231 getConstTpetraVector(const RCP<const VectorBase<Scalar> > &v)
00232 {
00233   typedef TpetraVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraVector_t;
00234   return Teuchos::rcp_dynamic_cast<const TpetraVector_t>(v, true)->getConstTpetraVector();
00235 }
00236 
00237 
00238 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00239 RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00240 TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
00241 getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> > &mv)
00242 {
00243 
00244 #ifdef THYRA_DEBUG
00245   TEUCHOS_ASSERT(nonnull(mv));
00246 #endif
00247 
00248   using Teuchos::rcp_dynamic_cast;
00249   
00250   typedef Thyra::TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
00251     ThyraTpetraMultiVector_t;
00252   const RCP<ThyraTpetraMultiVector_t> tmv =
00253     rcp_dynamic_cast<ThyraTpetraMultiVector_t>(mv);
00254   if (nonnull(tmv)) {
00255     return tmv->getTpetraMultiVector();
00256   }
00257   
00258   typedef Thyra::TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
00259     ThyraTpetraVector_t;
00260   const RCP<ThyraTpetraVector_t> tv =
00261     rcp_dynamic_cast<ThyraTpetraVector_t>(mv);
00262   if (nonnull(tv)) {
00263     return tv->getTpetraVector();
00264   }
00265 
00266   TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
00267     "Error, the input mv = " << mv->description() << " does not support the"
00268     " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
00269 
00270   return Teuchos::null;
00271 
00272 }
00273 
00274 
00275 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00276 RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00277 TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
00278 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> > &mv)
00279 {
00280 
00281 #ifdef THYRA_DEBUG
00282   TEUCHOS_ASSERT(nonnull(mv));
00283 #endif
00284 
00285   using Teuchos::rcp_dynamic_cast;
00286   
00287   typedef Thyra::TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
00288     ThyraTpetraMultiVector_t;
00289   const RCP<const ThyraTpetraMultiVector_t> tmv =
00290     rcp_dynamic_cast<const ThyraTpetraMultiVector_t>(mv);
00291   if (nonnull(tmv)) {
00292     return tmv->getConstTpetraMultiVector();
00293   }
00294   
00295   typedef Thyra::TpetraVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
00296     ThyraTpetraVector_t;
00297   const RCP<const ThyraTpetraVector_t> tv =
00298     rcp_dynamic_cast<const ThyraTpetraVector_t>(mv);
00299   if (nonnull(tv)) {
00300     return tv->getConstTpetraVector();
00301   }
00302 
00303   TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
00304     "Error, the input mv = " << mv->description() << " does not support the"
00305     " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
00306 
00307   return Teuchos::null;
00308 
00309 }
00310 
00311 
00312 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00313 RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00314 TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
00315 getTpetraOperator(const RCP<LinearOpBase<Scalar> > &op)
00316 {
00317   typedef TpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraLinearOp_t;
00318   return Teuchos::rcp_dynamic_cast<TpetraLinearOp_t>(op, true)->getTpetraOperator();
00319 }
00320 
00321 
00322 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
00323 RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
00324 TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
00325 getConstTpetraOperator(const RCP<const LinearOpBase<Scalar> > &op)
00326 {
00327   typedef TpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraLinearOp_t;
00328   return Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op, true)->getConstTpetraOperator();
00329 }
00330 
00331 
00332 } // namespace Thyra
00333 
00334 
00335 #endif // THYRA_TPETRA_THYRA_WRAPPERS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines