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 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_TPETRA_THYRA_WRAPPERS_HPP
11 #define THYRA_TPETRA_THYRA_WRAPPERS_HPP
12 
13 
16 #include "Thyra_TpetraVector.hpp"
18 #include "Thyra_TpetraLinearOp.hpp"
19 
20 
21 namespace Thyra {
22 
23 
24 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
27  const RCP<const VectorSpaceBase<Scalar> > space,
28  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
29  )
30 {
31  using Teuchos::rcp_dynamic_cast;
34  if (nonnull(space)) {
35  tpetraSpace = rcp_dynamic_cast<const TpetraVectorSpace_t>(space, true);
36  }
37  else {
38  tpetraSpace = tpetraVectorSpace<Scalar>(tpetraMap);
39  }
40  return tpetraSpace;
41 }
42 
43 
44 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
47  const RCP<const VectorSpaceBase<Scalar> > space,
48  const RCP<const Teuchos::Comm<int> > &tpetraComm,
49  const int numCols
50  )
51 {
52  using Teuchos::rcp_dynamic_cast;
55  if (nonnull(space)) {
56  tpetraSpace = rcp_dynamic_cast<const TpetraVectorSpace_t>(space, true);
57  }
58  else {
59  tpetraSpace = tpetraVectorSpace<Scalar>(
60  Tpetra::createLocalMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(
61  numCols, tpetraComm
62  )
63  );
64  }
65  return tpetraSpace;
66 }
67 
68 } // namespace Thyra
69 
70 
71 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
75  )
76 {
77  return tpetraVectorSpace<Scalar>(tpetraMap);
78 }
79 
80 
81 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
84  const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
85  const RCP<const VectorSpaceBase<Scalar> > space_in
86  )
87 {
88  return tpetraVector(
89  getOrCreateTpetraVectorSpace(space_in, tpetraVector_in->getMap()),
90  tpetraVector_in
91  );
92 }
93 
94 
95 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
98  const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
99  const RCP<const VectorSpaceBase<Scalar> > space
100  )
101 {
102  return constTpetraVector(
103  getOrCreateTpetraVectorSpace(space, tpetraVector_in->getMap()),
104  tpetraVector_in
105  );
106 }
107 
108 
109 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
112  const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
113  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
114  const RCP<const VectorSpaceBase<Scalar> > domainSpace
115  )
116 {
117  return tpetraMultiVector(
118  getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
119  getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
120  domainSpace, tpetraMultiVector_in->getMap()->getComm(),
121  tpetraMultiVector_in->getNumVectors()
122  ),
123  tpetraMultiVector_in
124  );
125 }
126 
127 
128 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
131  const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
132  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
133  const RCP<const VectorSpaceBase<Scalar> > domainSpace
134  )
135 {
136  return constTpetraMultiVector(
137  getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
138  getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
139  domainSpace, tpetraMultiVector_in->getMap()->getComm(),
140  tpetraMultiVector_in->getNumVectors()
141  ),
142  tpetraMultiVector_in
143  );
144 }
145 
146 
147 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
150  const RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
151  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
152  const RCP<const VectorSpaceBase<Scalar> > domainSpace
153  )
154 {
155  Teuchos::RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetraRangeSpace = getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap());
156  Teuchos::RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetraDomainSpace = getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap());
157 
158  return tpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
159  tpetraRangeSpace,
160  tpetraDomainSpace,
161  tpetraOperator_in
162  );
163 }
164 
165 
166 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
169  const RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
170  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
171  const RCP<const VectorSpaceBase<Scalar> > domainSpace
172  )
173 {
174  Teuchos::RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetraRangeSpace = getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap());
175  Teuchos::RCP<const TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetraDomainSpace = getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap());
176  return constTpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
177  tpetraRangeSpace,
178  tpetraDomainSpace,
179  tpetraOperator_in
180  );
181 }
182 
183 
184 namespace Thyra {
185 
186 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
187 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
189 getTpetraMap(const RCP<const VectorSpaceBase<Scalar> > &vs)
190 {
192  return Teuchos::rcp_dynamic_cast<const TpetraVectorSpace_t>(vs, true)->getTpetraMap();
193 }
194 
195 
196 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
199 getTpetraVector(const RCP<VectorBase<Scalar> > &v)
200 {
202  return Teuchos::rcp_dynamic_cast<TpetraVector_t>(v, true)->getTpetraVector();
203 }
204 
205 
206 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
209 getConstTpetraVector(const RCP<const VectorBase<Scalar> > &v)
210 {
212  return Teuchos::rcp_dynamic_cast<const TpetraVector_t>(v, true)->getConstTpetraVector();
213 }
214 
215 
216 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
219 getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> > &mv)
220 {
221 
222 #ifdef THYRA_DEBUG
223  TEUCHOS_ASSERT(nonnull(mv));
224 #endif
225 
226  using Teuchos::rcp_dynamic_cast;
227 
229  ThyraTpetraMultiVector_t;
231  rcp_dynamic_cast<ThyraTpetraMultiVector_t>(mv);
232  if (nonnull(tmv)) {
233  return tmv->getTpetraMultiVector();
234  }
235 
237  ThyraTpetraVector_t;
238  const RCP<ThyraTpetraVector_t> tv =
239  rcp_dynamic_cast<ThyraTpetraVector_t>(mv);
240  if (nonnull(tv)) {
241  return tv->getTpetraVector();
242  }
243 
244  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
245  "Error, the input mv = " << mv->description() << " does not support the"
246  " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
247 
249 
250 }
251 
252 
253 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
256 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> > &mv)
257 {
258 
259 #ifdef THYRA_DEBUG
260  TEUCHOS_ASSERT(nonnull(mv));
261 #endif
262 
263  using Teuchos::rcp_dynamic_cast;
264 
266  ThyraTpetraMultiVector_t;
268  rcp_dynamic_cast<const ThyraTpetraMultiVector_t>(mv);
269  if (nonnull(tmv)) {
270  return tmv->getConstTpetraMultiVector();
271  }
272 
274  ThyraTpetraVector_t;
276  rcp_dynamic_cast<const ThyraTpetraVector_t>(mv);
277  if (nonnull(tv)) {
278  return tv->getConstTpetraVector();
279  }
280 
281  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
282  "Error, the input mv = " << mv->description() << " does not support the"
283  " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
284 
286 
287 }
288 
289 
290 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
293 getTpetraOperator(const RCP<LinearOpBase<Scalar> > &op)
294 {
296  return Teuchos::rcp_dynamic_cast<TpetraLinearOp_t>(op, true)->getTpetraOperator();
297 }
298 
299 
300 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
303 getConstTpetraOperator(const RCP<const LinearOpBase<Scalar> > &op)
304 {
306  return Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op, true)->getConstTpetraOperator();
307 }
308 
309 
310 } // namespace Thyra
311 
312 
313 #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 non-const 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 const 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)