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