Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_TpetraThyraWrappers_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_TPETRA_THYRA_WRAPPERS_HPP
43 #define THYRA_TPETRA_THYRA_WRAPPERS_HPP
44 
45 
48 #include "Thyra_TpetraVector.hpp"
50 #include "Thyra_TpetraLinearOp.hpp"
51 
52 
53 namespace Thyra {
54 
55 
56 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
59  const RCP<const VectorSpaceBase<Scalar> > space,
60  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
61  )
62 {
63  using Teuchos::rcp_dynamic_cast;
66  if (nonnull(space)) {
67  tpetraSpace = rcp_dynamic_cast<const TpetraVectorSpace_t>(space, true);
68  }
69  else {
70  tpetraSpace = tpetraVectorSpace<Scalar>(tpetraMap);
71  }
72  return tpetraSpace;
73 }
74 
75 
76 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
79  const RCP<const VectorSpaceBase<Scalar> > space,
80  const RCP<const Teuchos::Comm<int> > &tpetraComm,
81  const int numCols
82  )
83 {
84  using Teuchos::rcp_dynamic_cast;
87  if (nonnull(space)) {
88  tpetraSpace = rcp_dynamic_cast<const TpetraVectorSpace_t>(space, true);
89  }
90  else {
91  tpetraSpace = tpetraVectorSpace<Scalar>(
92  Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
93  numCols, tpetraComm
94  )
95  );
96  }
97  return tpetraSpace;
98 }
99 
100 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
101 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
102 TPETRA_DEPRECATED
105  const RCP<const VectorSpaceBase<Scalar> > space,
106  const RCP<const Teuchos::Comm<int> > &tpetraComm,
107  const RCP<Node> &/* tpetraNode */,
108  const int numCols
109  )
110 {
112  <Scalar, LocalOrdinal, GlobalOrdinal, Node>
113  (space, tpetraComm, numCols);
114 }
115 #endif
116 
117 } // namespace Thyra
118 
119 
120 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
123  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
124  )
125 {
126  return tpetraVectorSpace<Scalar>(tpetraMap);
127 }
128 
129 
130 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
133  const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
134  const RCP<const VectorSpaceBase<Scalar> > space_in
135  )
136 {
137  return tpetraVector(
138  getOrCreateTpetraVectorSpace(space_in, tpetraVector_in->getMap()),
139  tpetraVector_in
140  );
141 }
142 
143 
144 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
147  const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
148  const RCP<const VectorSpaceBase<Scalar> > space
149  )
150 {
151  return constTpetraVector(
152  getOrCreateTpetraVectorSpace(space, tpetraVector_in->getMap()),
153  tpetraVector_in
154  );
155 }
156 
157 
158 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
161  const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
162  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
163  const RCP<const VectorSpaceBase<Scalar> > domainSpace
164  )
165 {
166  return tpetraMultiVector(
167  getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
168  getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
169  domainSpace, tpetraMultiVector_in->getMap()->getComm(),
170 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
171  tpetraMultiVector_in->getMap()->getNode(),
172 #endif // TPETRA_ENABLE_DEPRECATED_CODE
173  tpetraMultiVector_in->getNumVectors()
174  ),
175  tpetraMultiVector_in
176  );
177 }
178 
179 
180 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
183  const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
184  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
185  const RCP<const VectorSpaceBase<Scalar> > domainSpace
186  )
187 {
188  return constTpetraMultiVector(
189  getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
190  getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
191  domainSpace, tpetraMultiVector_in->getMap()->getComm(),
192 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
193  tpetraMultiVector_in->getMap()->getNode(),
194 #endif // TPETRA_ENABLE_DEPRECATED_CODE
195  tpetraMultiVector_in->getNumVectors()
196  ),
197  tpetraMultiVector_in
198  );
199 }
200 
201 
202 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
205  const RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
206  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
207  const RCP<const VectorSpaceBase<Scalar> > domainSpace
208  )
209 {
210  return tpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
211  getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap()),
212  getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap()),
213  tpetraOperator_in
214  );
215 }
216 
217 
218 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
221  const RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
222  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
223  const RCP<const VectorSpaceBase<Scalar> > domainSpace
224  )
225 {
226  return constTpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
227  getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap()),
228  getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap()),
229  tpetraOperator_in
230  );
231 }
232 
233 
234 namespace Thyra {
235 
236 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
237 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
239 getTpetraMap(const RCP<const VectorSpaceBase<Scalar> > &vs)
240 {
242  return Teuchos::rcp_dynamic_cast<const TpetraVectorSpace_t>(vs, true)->getTpetraMap();
243 }
244 
245 
246 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
249 getTpetraVector(const RCP<VectorBase<Scalar> > &v)
250 {
252  return Teuchos::rcp_dynamic_cast<TpetraVector_t>(v, true)->getTpetraVector();
253 }
254 
255 
256 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
259 getConstTpetraVector(const RCP<const VectorBase<Scalar> > &v)
260 {
262  return Teuchos::rcp_dynamic_cast<const TpetraVector_t>(v, true)->getConstTpetraVector();
263 }
264 
265 
266 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
269 getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> > &mv)
270 {
271 
272 #ifdef THYRA_DEBUG
273  TEUCHOS_ASSERT(nonnull(mv));
274 #endif
275 
276  using Teuchos::rcp_dynamic_cast;
277 
279  ThyraTpetraMultiVector_t;
281  rcp_dynamic_cast<ThyraTpetraMultiVector_t>(mv);
282  if (nonnull(tmv)) {
283  return tmv->getTpetraMultiVector();
284  }
285 
287  ThyraTpetraVector_t;
288  const RCP<ThyraTpetraVector_t> tv =
289  rcp_dynamic_cast<ThyraTpetraVector_t>(mv);
290  if (nonnull(tv)) {
291  return tv->getTpetraVector();
292  }
293 
294  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
295  "Error, the input mv = " << mv->description() << " does not support the"
296  " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
297 
299 
300 }
301 
302 
303 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
306 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> > &mv)
307 {
308 
309 #ifdef THYRA_DEBUG
310  TEUCHOS_ASSERT(nonnull(mv));
311 #endif
312 
313  using Teuchos::rcp_dynamic_cast;
314 
316  ThyraTpetraMultiVector_t;
318  rcp_dynamic_cast<const ThyraTpetraMultiVector_t>(mv);
319  if (nonnull(tmv)) {
320  return tmv->getConstTpetraMultiVector();
321  }
322 
324  ThyraTpetraVector_t;
326  rcp_dynamic_cast<const ThyraTpetraVector_t>(mv);
327  if (nonnull(tv)) {
328  return tv->getConstTpetraVector();
329  }
330 
331  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
332  "Error, the input mv = " << mv->description() << " does not support the"
333  " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
334 
336 
337 }
338 
339 
340 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
343 getTpetraOperator(const RCP<LinearOpBase<Scalar> > &op)
344 {
346  return Teuchos::rcp_dynamic_cast<TpetraLinearOp_t>(op, true)->getTpetraOperator();
347 }
348 
349 
350 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
353 getConstTpetraOperator(const RCP<const LinearOpBase<Scalar> > &op)
354 {
356  return Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op, true)->getConstTpetraOperator();
357 }
358 
359 
360 } // namespace Thyra
361 
362 
363 #endif // THYRA_TPETRA_THYRA_WRAPPERS_HPP
RCP< MultiVectorBase< Scalar > > createMultiVector(const RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
Concrete implementation of Thyra::MultiVector in terms of Tpetra::MultiVector.
Concrete implementation of an SPMD vector space for Tpetra.
Teuchos::RCP< const ScalarProdVectorSpaceBase< Scalar > > getOrCreateLocallyReplicatedTpetraVectorSpace(const RCP< const VectorSpaceBase< Scalar > > space, const RCP< const Teuchos::Comm< int > > &tpetraComm, const int numCols)
static RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getTpetraMap(const RCP< const VectorSpaceBase< Scalar > > &vs)
Get a const Tpetra::Map from a const Thyra::VectorSpaceBase object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > tpetraMultiVector(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Nonmember constructor for TpetraMultiVector.
RCP< const VectorBase< Scalar > > createConstVector(const RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector, const RCP< const VectorSpaceBase< Scalar > > space=Teuchos::null)
RCP< const LinearOpBase< Scalar > > createConstLinearOp(const RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
static RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraVector(const RCP< const VectorBase< Scalar > > &v)
Get a const Tpetra::Vector from a const Thyra::VectorBase object.
RCP< LinearOpBase< Scalar > > createLinearOp(const RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
static RCP< Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraMultiVector(const RCP< MultiVectorBase< Scalar > > &mv)
Get a non-const Tpetra::MultiVector from a non-const Thyra::MultiVectorBase object.
RCP< VectorBase< Scalar > > createVector(const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector, const RCP< const VectorSpaceBase< Scalar > > space=Teuchos::null)
RCP< const TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > constTpetraMultiVector(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const ScalarProdVectorSpaceBase< Scalar > > &domainSpace, const RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector)
Nonmember constructor for TpetraMultiVector.
RCP< const MultiVectorBase< Scalar > > createConstMultiVector(const RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraMultiVector, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
static RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraVector(const RCP< VectorBase< Scalar > > &v)
Get a non-const Tpetra::Vector from a non-const Thyra::VectorBase object.
Teuchos::RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOrCreateTpetraVectorSpace(const RCP< const VectorSpaceBase< Scalar > > space, const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Concrete Thyra::SpmdVectorBase using Tpetra::Vector.
RCP< TpetraVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > tpetraVector(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Nonmember constructor for TpetraVector.
RCP< const TpetraVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > constTpetraVector(const RCP< const TpetraVectorSpace< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVectorSpace, const RCP< const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector)
Nonmember constructor for TpetraVector.
bool nonnull(const boost::shared_ptr< T > &p)
static RCP< const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraMultiVector(const RCP< const MultiVectorBase< Scalar > > &mv)
Get a const Tpetra::MultiVector from a const Thyra::MultiVectorBase object.
static RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraOperator(const RCP< const LinearOpBase< Scalar > > &op)
Get a const Tpetra::Operator from a const Thyra::LinearOpBase object.
static RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraOperator(const RCP< LinearOpBase< Scalar > > &op)
Get a non-const Tpetra::Operator from a non-const Thyra::LinearOpBase object.
RCP< const VectorSpaceBase< Scalar > > createVectorSpace(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &tpetraMap)
Create a Thyra::VectorSpaceBase object given a Tpetra::Map.
#define TEUCHOS_ASSERT(assertion_test)
Concrete Thyra::LinearOpBase subclass for Tpetra::Operator.
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)