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 } // namespace Thyra
101 
102 
103 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
106  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > &tpetraMap
107  )
108 {
109  return tpetraVectorSpace<Scalar>(tpetraMap);
110 }
111 
112 
113 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
116  const RCP<Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
117  const RCP<const VectorSpaceBase<Scalar> > space_in
118  )
119 {
120  return tpetraVector(
121  getOrCreateTpetraVectorSpace(space_in, tpetraVector_in->getMap()),
122  tpetraVector_in
123  );
124 }
125 
126 
127 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
130  const RCP<const Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraVector_in,
131  const RCP<const VectorSpaceBase<Scalar> > space
132  )
133 {
134  return constTpetraVector(
135  getOrCreateTpetraVectorSpace(space, tpetraVector_in->getMap()),
136  tpetraVector_in
137  );
138 }
139 
140 
141 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
144  const RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
145  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
146  const RCP<const VectorSpaceBase<Scalar> > domainSpace
147  )
148 {
149  return tpetraMultiVector(
150  getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
151  getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
152  domainSpace, tpetraMultiVector_in->getMap()->getComm(),
153  tpetraMultiVector_in->getNumVectors()
154  ),
155  tpetraMultiVector_in
156  );
157 }
158 
159 
160 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
163  const RCP<const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraMultiVector_in,
164  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
165  const RCP<const VectorSpaceBase<Scalar> > domainSpace
166  )
167 {
168  return constTpetraMultiVector(
169  getOrCreateTpetraVectorSpace(rangeSpace, tpetraMultiVector_in->getMap()),
170  getOrCreateLocallyReplicatedTpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
171  domainSpace, tpetraMultiVector_in->getMap()->getComm(),
172  tpetraMultiVector_in->getNumVectors()
173  ),
174  tpetraMultiVector_in
175  );
176 }
177 
178 
179 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
182  const RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
183  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
184  const RCP<const VectorSpaceBase<Scalar> > domainSpace
185  )
186 {
187  return tpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
188  getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap()),
189  getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap()),
190  tpetraOperator_in
191  );
192 }
193 
194 
195 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
198  const RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator_in,
199  const RCP<const VectorSpaceBase<Scalar> > rangeSpace,
200  const RCP<const VectorSpaceBase<Scalar> > domainSpace
201  )
202 {
203  return constTpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
204  getOrCreateTpetraVectorSpace(rangeSpace, tpetraOperator_in->getRangeMap()),
205  getOrCreateTpetraVectorSpace(domainSpace, tpetraOperator_in->getDomainMap()),
206  tpetraOperator_in
207  );
208 }
209 
210 
211 namespace Thyra {
212 
213 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
214 RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
216 getTpetraMap(const RCP<const VectorSpaceBase<Scalar> > &vs)
217 {
219  return Teuchos::rcp_dynamic_cast<const TpetraVectorSpace_t>(vs, true)->getTpetraMap();
220 }
221 
222 
223 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
226 getTpetraVector(const RCP<VectorBase<Scalar> > &v)
227 {
229  return Teuchos::rcp_dynamic_cast<TpetraVector_t>(v, true)->getTpetraVector();
230 }
231 
232 
233 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
236 getConstTpetraVector(const RCP<const VectorBase<Scalar> > &v)
237 {
239  return Teuchos::rcp_dynamic_cast<const TpetraVector_t>(v, true)->getConstTpetraVector();
240 }
241 
242 
243 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
246 getTpetraMultiVector(const RCP<MultiVectorBase<Scalar> > &mv)
247 {
248 
249 #ifdef THYRA_DEBUG
250  TEUCHOS_ASSERT(nonnull(mv));
251 #endif
252 
253  using Teuchos::rcp_dynamic_cast;
254 
256  ThyraTpetraMultiVector_t;
258  rcp_dynamic_cast<ThyraTpetraMultiVector_t>(mv);
259  if (nonnull(tmv)) {
260  return tmv->getTpetraMultiVector();
261  }
262 
264  ThyraTpetraVector_t;
265  const RCP<ThyraTpetraVector_t> tv =
266  rcp_dynamic_cast<ThyraTpetraVector_t>(mv);
267  if (nonnull(tv)) {
268  return tv->getTpetraVector();
269  }
270 
271  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
272  "Error, the input mv = " << mv->description() << " does not support the"
273  " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
274 
276 
277 }
278 
279 
280 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
283 getConstTpetraMultiVector(const RCP<const MultiVectorBase<Scalar> > &mv)
284 {
285 
286 #ifdef THYRA_DEBUG
287  TEUCHOS_ASSERT(nonnull(mv));
288 #endif
289 
290  using Teuchos::rcp_dynamic_cast;
291 
293  ThyraTpetraMultiVector_t;
295  rcp_dynamic_cast<const ThyraTpetraMultiVector_t>(mv);
296  if (nonnull(tmv)) {
297  return tmv->getConstTpetraMultiVector();
298  }
299 
301  ThyraTpetraVector_t;
303  rcp_dynamic_cast<const ThyraTpetraVector_t>(mv);
304  if (nonnull(tv)) {
305  return tv->getConstTpetraVector();
306  }
307 
308  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
309  "Error, the input mv = " << mv->description() << " does not support the"
310  " Thyra::TpetraMultiVector or the Thyra::TpetraVector interfaces!");
311 
313 
314 }
315 
316 
317 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
320 getTpetraOperator(const RCP<LinearOpBase<Scalar> > &op)
321 {
323  return Teuchos::rcp_dynamic_cast<TpetraLinearOp_t>(op, true)->getTpetraOperator();
324 }
325 
326 
327 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
330 getConstTpetraOperator(const RCP<const LinearOpBase<Scalar> > &op)
331 {
333  return Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op, true)->getConstTpetraOperator();
334 }
335 
336 
337 } // namespace Thyra
338 
339 
340 #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)