47 #ifndef XPETRA_THYRAUTILS_HPP
48 #define XPETRA_THYRAUTILS_HPP
51 #ifdef HAVE_XPETRA_THYRA
55 #ifdef HAVE_XPETRA_TPETRA
56 #include "Tpetra_ConfigDefs.hpp"
59 #ifdef HAVE_XPETRA_EPETRA
60 #include "Epetra_config.h"
61 #include "Epetra_CombineMode.h"
64 #include "Xpetra_Map.hpp"
65 #include "Xpetra_BlockedMap.hpp"
66 #include "Xpetra_BlockedMultiVector.hpp"
68 #include "Xpetra_StridedMap.hpp"
69 #include "Xpetra_StridedMapFactory.hpp"
70 #include "Xpetra_MapExtractor.hpp"
72 #include "Xpetra_CrsMatrixWrap.hpp"
73 #include "Xpetra_MultiVectorFactory.hpp"
75 #include <Thyra_VectorSpaceBase.hpp>
76 #include <Thyra_SpmdVectorSpaceBase.hpp>
77 #include <Thyra_ProductVectorSpaceBase.hpp>
78 #include <Thyra_ProductMultiVectorBase.hpp>
79 #include <Thyra_VectorSpaceBase.hpp>
80 #include <Thyra_DefaultProductVectorSpace.hpp>
81 #include <Thyra_DefaultBlockedLinearOp.hpp>
82 #include <Thyra_LinearOpBase.hpp>
83 #include <Thyra_DetachedMultiVectorView.hpp>
84 #include <Thyra_MultiVectorStdOps.hpp>
86 #ifdef HAVE_XPETRA_TPETRA
87 #include <Thyra_TpetraThyraWrappers.hpp>
88 #include <Thyra_TpetraVector.hpp>
89 #include <Thyra_TpetraVectorSpace.hpp>
90 #include <Tpetra_Map.hpp>
91 #include <Tpetra_Vector.hpp>
92 #include <Tpetra_CrsMatrix.hpp>
93 #include <Xpetra_TpetraMap.hpp>
94 #include <Xpetra_TpetraCrsMatrix.hpp>
96 #ifdef HAVE_XPETRA_EPETRA
97 #include <Thyra_EpetraLinearOp.hpp>
98 #include <Thyra_EpetraThyraWrappers.hpp>
99 #include <Thyra_SpmdVectorBase.hpp>
100 #include <Thyra_get_Epetra_Operator.hpp>
101 #include <Epetra_Map.h>
102 #include <Epetra_Vector.h>
103 #include <Epetra_CrsMatrix.h>
110 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
class BlockedCrsMatrix;
112 template <
class Scalar,
113 class LocalOrdinal = int,
114 class GlobalOrdinal = LocalOrdinal,
119 #undef XPETRA_THYRAUTILS_SHORT
123 static Teuchos::RCP<Xpetra::StridedMap<LocalOrdinal,GlobalOrdinal,Node> >
124 toXpetra(
const Teuchos::RCP<
const Thyra::VectorSpaceBase<Scalar> >& vectorSpace,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0) {
126 Teuchos::RCP<Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > map =
toXpetra(vectorSpace);
128 if(stridedBlockId == -1) {
129 TEUCHOS_TEST_FOR_EXCEPT(map->getNodeNumElements() % stridingInfo.size() != 0);
132 TEUCHOS_TEST_FOR_EXCEPT(map->getNodeNumElements() % stridingInfo[stridedBlockId] != 0);
139 static Teuchos::RCP<Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
140 toXpetra(
const Teuchos::RCP<
const Thyra::VectorSpaceBase<Scalar> >& vectorSpace,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
142 using Teuchos::rcp_dynamic_cast;
144 using ThyVecSpaceBase = Thyra::VectorSpaceBase<Scalar>;
145 using ThyProdVecSpaceBase = Thyra::ProductVectorSpaceBase<Scalar>;
146 using ThyUtils = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>;
149 RCP<Map> resultMap = Teuchos::null;
150 RCP<const ThyProdVecSpaceBase > prodVectorSpace = rcp_dynamic_cast<
const ThyProdVecSpaceBase >(vectorSpace);
151 if(prodVectorSpace != Teuchos::null) {
154 TEUCHOS_TEST_FOR_EXCEPTION(prodVectorSpace->numBlocks()==0, std::logic_error,
"Found a product vector space with zero blocks.");
155 std::vector<RCP<const Map> > mapsThyra(prodVectorSpace->numBlocks(), Teuchos::null);
156 std::vector<RCP<const Map> > mapsXpetra(prodVectorSpace->numBlocks(), Teuchos::null);
157 for (
int b = 0; b < prodVectorSpace->numBlocks(); ++b){
158 RCP<const ThyVecSpaceBase > bv = prodVectorSpace->getBlock(b);
165 std::vector<GlobalOrdinal> gidOffsets(prodVectorSpace->numBlocks(),0);
166 for(
int i = 1; i < prodVectorSpace->numBlocks(); ++i) {
167 gidOffsets[i] = mapsThyra[i-1]->getMaxAllGlobalIndex() + gidOffsets[i-1] + 1;
170 for (
int b = 0; b < prodVectorSpace->numBlocks(); ++b){
171 RCP<const ThyVecSpaceBase > bv = prodVectorSpace->getBlock(b);
178 #ifdef HAVE_XPETRA_TPETRA
181 Teuchos::RCP<const Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetra_vsc = Teuchos::rcp_dynamic_cast<
const Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(vectorSpace);
182 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(tpetra_vsc)==
true,
Xpetra::Exceptions::RuntimeError,
"toXpetra failed to convert provided vector space to Thyra::TpetraVectorSpace. This is the general implementation for Tpetra only.");
184 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> TpMap;
185 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpVector;
186 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
187 typedef Thyra::VectorBase<Scalar> ThyVecBase;
188 RCP<ThyVecBase> rgVec = Thyra::createMember<Scalar>(vectorSpace, std::string(
"label"));
189 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgVec));
190 RCP<const TpVector> rgTpetraVec = TOE::getTpetraVector(rgVec);
191 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgTpetraVec));
192 RCP<const TpMap> rgTpetraMap = rgTpetraVec->getMap();
193 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgTpetraMap));
196 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Cannot transform Thyra::VectorSpace to Xpetra::Map. This is the general implementation for Tpetra only, but Tpetra is disabled.");
199 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(resultMap));
204 static Teuchos::RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
205 toXpetra(Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > v,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
207 using Teuchos::rcp_dynamic_cast;
210 using ThyMultVecBase = Thyra::MultiVectorBase<Scalar>;
211 using ThyProdMultVecBase = Thyra::ProductMultiVectorBase<Scalar>;
212 using ThyUtils = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>;
215 RCP<MultiVector> xpMultVec = Teuchos::null;
218 Teuchos::RCP<const ThyProdMultVecBase> thyProdVec = rcp_dynamic_cast<
const ThyProdMultVecBase >(v);
219 if(thyProdVec != Teuchos::null) {
223 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(Teuchos::rcp_dynamic_cast<BlockedMap>(fullMap)));
228 RCP<BlockedMultiVector> xpBlockedMultVec = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(xpMultVec);
229 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpBlockedMultVec));
232 for (
int b = 0; b < thyProdVec->productSpace()->numBlocks(); ++b){
233 RCP<const ThyMultVecBase> thyBlockMV = thyProdVec->getMultiVectorBlock(b);
236 xpBlockedMultVec->setMultiVector(b, xpBlockMV,
true );
240 #ifdef HAVE_XPETRA_TPETRA
241 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> ConverterT;
242 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpMultVec;
244 typedef Thyra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> ThyTpMultVec;
245 typedef Thyra::SpmdMultiVectorBase<Scalar> ThySpmdMultVecBase;
247 RCP<const ThySpmdMultVecBase> thyraSpmdMultiVector = rcp_dynamic_cast<
const ThySpmdMultVecBase>(v);
248 RCP<const ThyTpMultVec> thyraTpetraMultiVector = rcp_dynamic_cast<
const ThyTpMultVec>(thyraSpmdMultiVector);
249 TEUCHOS_TEST_FOR_EXCEPTION(thyraTpetraMultiVector == Teuchos::null,
Xpetra::Exceptions::RuntimeError,
"toXpetra failed to convert provided multi vector to Thyra::TpetraMultiVector. This is the general implementation for Tpetra only.");
250 const RCP<const TpMultVec> tpMultVec = ConverterT::getConstTpetraMultiVector(v);
251 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpMultVec));
252 RCP<TpMultVec> tpNonConstMultVec = Teuchos::rcp_const_cast<TpMultVec>(tpMultVec);
253 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpNonConstMultVec));
254 xpMultVec = rcp(
new XpTpMultVec(tpNonConstMultVec));
256 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Cannot transform Thyra::MultiVector to Xpetra::MultiVector. This is the general implementation for Tpetra only, but Teptra is disabled.");
259 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpMultVec));
264 static Teuchos::RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
265 toXpetra(Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > v,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
266 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > cv =
267 Teuchos::rcp_const_cast<
const Thyra::MultiVectorBase<Scalar> >(v);
268 Teuchos::RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > r =
274 static bool isTpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
275 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(op));
278 bool bIsTpetra =
false;
279 #ifdef HAVE_XPETRA_TPETRA
280 Teuchos::RCP<const Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetra_op = Teuchos::rcp_dynamic_cast<
const Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(op);
281 bIsTpetra = Teuchos::is_null(tpetra_op) ?
false :
true;
285 #ifdef HAVE_XPETRA_EPETRA
286 Teuchos::rcp_dynamic_cast<const Thyra::EpetraLinearOp>(op) == Teuchos::null &&
288 Teuchos::rcp_dynamic_cast<
const Thyra::DefaultBlockedLinearOp<Scalar> >(op) == Teuchos::null) {
290 typedef Thyra::TpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraLinearOp_t;
291 if(Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op) == Teuchos::null) {
292 std::cout <<
"ATTENTION: The dynamic cast to the TpetraLinearOp failed even though it should be a TpetraLinearOp." << std::endl;
293 std::cout <<
" If you are using Panzer or Stratimikos you might check that the template parameters are " << std::endl;
294 std::cout <<
" properly set!" << std::endl;
295 std::cout << Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op,
true) << std::endl;
304 if(bIsTpetra ==
false) {
305 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
306 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op);
307 if(ThyBlockedOp != Teuchos::null) {
308 TEUCHOS_TEST_FOR_EXCEPT(ThyBlockedOp->blockExists(0,0)==
false);
309 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > b00 =
310 ThyBlockedOp->getBlock(0,0);
311 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(b00));
312 bIsTpetra = isTpetra(b00);
320 static bool isEpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
324 static bool isBlockedOperator(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
326 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
327 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op);
328 if(ThyBlockedOp != Teuchos::null) {
334 static Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
335 toXpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> >& op) {
337 #ifdef HAVE_XPETRA_TPETRA
339 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
340 Teuchos::RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraOp = TOE::getConstTpetraOperator(op);
343 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraOp));
344 Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraRowMat = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraOp);
345 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraRowMat));
346 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraCrsMat = Teuchos::rcp_dynamic_cast<
const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraRowMat);
347 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraCrsMat));
348 Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraNcnstCrsMat = Teuchos::rcp_const_cast<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraCrsMat);
349 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraNcnstCrsMat));
351 Teuchos::RCP<Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > xTpetraCrsMat =
353 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpetraCrsMat));
355 Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > ret =
361 #ifdef HAVE_XPETRA_EPETRA
366 return Teuchos::null;
369 static Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
370 toXpetra(
const Teuchos::RCP<Thyra::LinearOpBase<Scalar> >& op) {
372 #ifdef HAVE_XPETRA_TPETRA
374 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
375 Teuchos::RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraOp = TOE::getTpetraOperator(op);
376 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraOp));
377 Teuchos::RCP<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraRowMat = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraOp);
378 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraRowMat));
379 Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraCrsMat = Teuchos::rcp_dynamic_cast<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraRowMat);
380 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraCrsMat));
382 Teuchos::RCP<Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > xTpetraCrsMat =
384 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpetraCrsMat));
385 return xTpetraCrsMat;
389 #ifdef HAVE_XPETRA_EPETRA
394 return Teuchos::null;
397 static Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
399 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thyraMap = Teuchos::null;
402 RCP<const BlockedMap> bmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map);
403 if(bmap.is_null() ==
false) {
405 Teuchos::Array<Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > > vecSpaces(bmap->getNumMaps());
406 for(
size_t i = 0; i < bmap->getNumMaps(); i++) {
408 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > vs =
409 Xpetra::ThyraUtils<Scalar,LO,GO,Node>::toThyra(bmap->getMap(i,
true));
413 thyraMap = Thyra::productVectorSpace<Scalar>(vecSpaces());
418 #ifdef HAVE_XPETRA_TPETRA
421 if (tpetraMap == Teuchos::null)
422 throw Exceptions::BadCast(
"Xpetra::ThyraUtils::toThyra: Cast from Xpetra::Map to Xpetra::TpetraMap failed");
423 RCP<Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > thyraTpetraMap = Thyra::tpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpetraMap->getTpetra_Map());
424 thyraMap = thyraTpetraMap;
428 #ifdef HAVE_XPETRA_EPETRA
437 static Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
441 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thMap = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(vec->getMap());
442 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getGlobalNumElements())!=thMap->dim(), std::logic_error,
"Global dimension of Xpetra map and Thyra VectorSpaceBase are different.");
443 Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<Scalar> > thSpmdMap = Teuchos::rcp_dynamic_cast<
const Thyra::SpmdVectorSpaceBase<Scalar> >(thMap);
444 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMap == Teuchos::null, std::logic_error,
"Cannot cast VectorSpaceBase to SpmdVectorSpaceBase.");
445 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getNodeNumElements())!=thSpmdMap->localSubDim(), std::logic_error,
"Local dimension of Xpetra map and Thyra VectorSpaceBase on one (or more) processor(s) are different.");
448 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> > thMVec = Thyra::createMembers(thMap, vec->getNumVectors());
449 Teuchos::RCP< Thyra::SpmdMultiVectorBase<Scalar> > thSpmdMVec = Teuchos::rcp_dynamic_cast<Thyra::SpmdMultiVectorBase<Scalar> >(thMVec);
450 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMVec == Teuchos::null, std::logic_error,
"Cannot cast MultiVectorBase to SpmdMultiVectorBase.");
453 const LocalOrdinal localOffset = ( thSpmdMap != Teuchos::null ? thSpmdMap->localOffset() : 0 );
454 const LocalOrdinal localSubDim = ( thSpmdMap != Teuchos::null ? thSpmdMap->localSubDim() : thMap->dim() );
455 Teuchos::RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
456 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thSpmdMVec,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
459 for(
size_t j = 0; j < Teuchos::as<size_t>(thSpmdMVec->domain()->dim()); ++j) {
460 Teuchos::ArrayRCP< const Scalar > vecData = vec->getData(j);
462 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
463 (*thyData)(i,j) = vecData[i];
470 static Teuchos::RCP<const Thyra::VectorBase<Scalar> >
474 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thMap = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(vec->getMap());
475 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getGlobalNumElements())!=thMap->dim(), std::logic_error,
"Global dimension of Xpetra map and Thyra VectorSpaceBase are different.");
476 Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<Scalar> > thSpmdMap = Teuchos::rcp_dynamic_cast<
const Thyra::SpmdVectorSpaceBase<Scalar> >(thMap);
477 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMap == Teuchos::null, std::logic_error,
"Cannot cast VectorSpaceBase to SpmdVectorSpaceBase.");
478 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getNodeNumElements())!=thSpmdMap->localSubDim(), std::logic_error,
"Local dimension of Xpetra map and Thyra VectorSpaceBase on one (or more) processor(s) are different.");
481 Teuchos::RCP< Thyra::VectorBase<Scalar> > thMVec = Thyra::createMember(thMap);
482 Teuchos::RCP< Thyra::SpmdVectorBase<Scalar> > thSpmdMVec = Teuchos::rcp_dynamic_cast<Thyra::SpmdVectorBase<Scalar> >(thMVec);
483 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMVec == Teuchos::null, std::logic_error,
"Cannot cast VectorBase to SpmdVectorBase.");
486 const LocalOrdinal localOffset = ( thSpmdMap != Teuchos::null ? thSpmdMap->localOffset() : 0 );
487 const LocalOrdinal localSubDim = ( thSpmdMap != Teuchos::null ? thSpmdMap->localSubDim() : thMap->dim() );
488 Teuchos::RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
489 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thSpmdMVec,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
492 for(
size_t j = 0; j < Teuchos::as<size_t>(thSpmdMVec->domain()->dim()); ++j) {
493 Teuchos::ArrayRCP< const Scalar > vecData = vec->getData(j);
495 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
496 (*thyData)(i,j) = vecData[i];
508 using Teuchos::rcp_dynamic_cast;
510 typedef Thyra::VectorSpaceBase<Scalar> ThyVecSpaceBase;
511 typedef Thyra::SpmdVectorSpaceBase<Scalar> ThySpmdVecSpaceBase;
512 typedef Thyra::MultiVectorBase<Scalar> ThyMultVecBase;
515 typedef Thyra::ProductMultiVectorBase<Scalar> ThyProdMultVecBase;
519 RCP<ThyProdMultVecBase> prodTarget = rcp_dynamic_cast<ThyProdMultVecBase>(target);
520 if(prodTarget != Teuchos::null) {
521 RCP<const BlockedMultiVector> bSourceVec = rcp_dynamic_cast<
const BlockedMultiVector>(source);
522 if(bSourceVec.is_null() ==
true) {
526 TEUCHOS_TEST_FOR_EXCEPTION(mapExtractor == Teuchos::null, std::logic_error,
"Found a Thyra product vector, but user did not provide an Xpetra::MapExtractor.");
527 TEUCHOS_TEST_FOR_EXCEPTION(prodTarget->productSpace()->numBlocks() != as<int>(mapExtractor->NumMaps()), std::logic_error,
"Inconsistent numbers of sub maps in Thyra::ProductVectorSpace and Xpetra::MapExtractor.");
529 for(
int bbb = 0; bbb < prodTarget->productSpace()->numBlocks(); ++bbb) {
531 RCP<MultiVector> xpSubBlock = mapExtractor->ExtractVector(source, bbb,
false);
534 Teuchos::RCP<ThyMultVecBase> thySubBlock = prodTarget->getNonconstMultiVectorBlock(bbb);
535 RCP<const ThyVecSpaceBase> vs = thySubBlock->range();
536 RCP<const ThySpmdVecSpaceBase> mpi_vs = rcp_dynamic_cast<
const ThySpmdVecSpaceBase>(vs);
537 const LocalOrdinal localOffset = ( mpi_vs != Teuchos::null ? mpi_vs->localOffset() : 0 );
538 const LocalOrdinal localSubDim = ( mpi_vs != Teuchos::null ? mpi_vs->localSubDim() : vs->dim() );
539 RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
540 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thySubBlock,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
543 for(
size_t j = 0; j < xpSubBlock->getNumVectors(); ++j) {
544 Teuchos::ArrayRCP< const Scalar > xpData = xpSubBlock->getData(j);
547 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
548 (*thyData)(i,j) = xpData[i];
555 TEUCHOS_TEST_FOR_EXCEPTION(prodTarget->productSpace()->numBlocks() != as<int>(bSourceVec->getBlockedMap()->getNumMaps()), std::logic_error,
"Inconsistent numbers of sub maps in Thyra::ProductVectorSpace and Xpetra::BlockedMultiVector.");
557 for(
int bbb = 0; bbb < prodTarget->productSpace()->numBlocks(); ++bbb) {
559 RCP<MultiVector> xpSubBlock = bSourceVec->getMultiVector(bbb,
true);
561 Teuchos::RCP<const ThyMultVecBase> thyXpSubBlock = toThyraMultiVector(xpSubBlock);
564 Teuchos::RCP<ThyMultVecBase> thySubBlock = prodTarget->getNonconstMultiVectorBlock(bbb);
565 Thyra::assign(thySubBlock.ptr(), *thyXpSubBlock);
574 RCP<const ThySpmdVecSpaceBase> mpi_vs = rcp_dynamic_cast<
const ThySpmdVecSpaceBase>(target->range());
575 TEUCHOS_TEST_FOR_EXCEPTION(mpi_vs == Teuchos::null, std::logic_error,
"Failed to cast Thyra::VectorSpaceBase to Thyra::SpmdVectorSpaceBase.");
576 const LocalOrdinal localOffset = ( mpi_vs != Teuchos::null ? mpi_vs->localOffset() : 0 );
577 const LocalOrdinal localSubDim = ( mpi_vs != Teuchos::null ? mpi_vs->localSubDim() : target->range()->dim() );
578 RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
579 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*target,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
582 for(
size_t j = 0; j < source->getNumVectors(); ++j) {
583 Teuchos::ArrayRCP< const Scalar > xpData = source->getData(j);
585 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
586 (*thyData)(i,j) = xpData[i];
592 static Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
595 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > thyraOp = Teuchos::null;
599 #ifdef HAVE_XPETRA_TPETRA
601 if(tpetraMat!=Teuchos::null) {
604 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpCrsMat));
605 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpCrsMat = xTpCrsMat->getTpetra_CrsMatrix();
606 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpCrsMat));
608 Teuchos::RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpRowMat = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpCrsMat);
609 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpRowMat));
610 Teuchos::RCP<const Tpetra::Operator <Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpOperator = Teuchos::rcp_dynamic_cast<
const Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpRowMat);
611 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpOperator));
613 thyraOp = Thyra::createConstLinearOp(tpOperator);
614 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraOp));
616 #ifdef HAVE_XPETRA_EPETRA
617 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Xpetra::Exceptions::RuntimeError,
"Cast to Tpetra::CrsMatrix failed. Assume matrix should be Epetra then. Epetra needs SC=double, LO=int, and GO=int or GO=long long");
619 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Xpetra::Exceptions::RuntimeError,
"Cast to Tpetra::CrsMatrix failed. Assume matrix should be Epetra then. No Epetra available");
625 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
629 static Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
632 Teuchos::RCP<Thyra::LinearOpBase<Scalar> > thyraOp = Teuchos::null;
636 #ifdef HAVE_XPETRA_TPETRA
638 if(tpetraMat!=Teuchos::null) {
641 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpCrsMat));
642 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpCrsMat = xTpCrsMat->getTpetra_CrsMatrixNonConst();
643 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpCrsMat));
645 Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpRowMat = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpCrsMat);
646 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpRowMat));
647 Teuchos::RCP<Tpetra::Operator <Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpOperator = Teuchos::rcp_dynamic_cast<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpRowMat);
648 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpOperator));
650 thyraOp = Thyra::createLinearOp(tpOperator);
651 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraOp));
654 #ifdef HAVE_XPETRA_EPETRA
655 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Xpetra::Exceptions::RuntimeError,
"Cast to TpetraCrsMatrix failed. Assuming matrix supposed to be Epetra. Epetra needs SC=double, LO=int, and GO=int or GO=long long");
657 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Xpetra::Exceptions::RuntimeError,
"Cast to TpetraCrsMatrix failed. Guess, matrix should be Epetra then, but no Epetra available.");
663 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
667 static Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
670 int nRows = mat->Rows();
671 int nCols = mat->Cols();
673 Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Ablock = mat->getInnermostCrsMatrix();
675 TEUCHOS_TEST_FOR_EXCEPT(Ablock_wrap.is_null() ==
true);
677 #ifdef HAVE_XPETRA_TPETRA
679 if(tpetraMat!=Teuchos::null) {
682 Teuchos::RCP<Thyra::PhysicallyBlockedLinearOpBase<Scalar> > blockMat =
683 Thyra::defaultBlockedLinearOp<Scalar>();
685 blockMat->beginBlockFill(nRows,nCols);
687 for (
int r=0; r<nRows; ++r) {
688 for (
int c=0; c<nCols; ++c) {
689 Teuchos::RCP<Matrix> xpmat = mat->getMatrix(r,c);
691 if(xpmat == Teuchos::null)
continue;
693 Teuchos::RCP<Thyra::LinearOpBase<Scalar> > thBlock = Teuchos::null;
696 Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xpblock =
698 if(xpblock != Teuchos::null) {
699 if(xpblock->Rows() == 1 && xpblock->Cols() == 1) {
701 Teuchos::RCP<CrsMatrixWrap> xpwrap = Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(xpblock->getCrsMatrix());
702 TEUCHOS_TEST_FOR_EXCEPT(xpwrap.is_null() ==
true);
703 thBlock = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(xpwrap->getCrsMatrix());
706 thBlock = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(xpblock);
710 Teuchos::RCP<CrsMatrixWrap> xpwrap = Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(xpmat);
711 TEUCHOS_TEST_FOR_EXCEPT(xpwrap.is_null() ==
true);
712 thBlock = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(xpwrap->getCrsMatrix());
715 blockMat->setBlock(r,c,thBlock);
719 blockMat->endBlockFill();
724 #ifdef HAVE_XPETRA_EPETRA
725 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Xpetra::Exceptions::RuntimeError,
"Cast to TpetraCrsMatrix failed. Assuming matrix supposed to be Epetra. Epetra needs SC=double, LO=int, and GO=int or GO=long long");
727 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Xpetra::Exceptions::RuntimeError,
"Cast to TpetraCrsMatrix failed. Guess, matrix should be Epetra then, but no Epetra available.");
729 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
731 #endif // endif HAVE_XPETRA_TPETRA
735 #if defined(HAVE_XPETRA_EPETRA) && !defined(HAVE_XPETRA_TPETRA)
737 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
738 #endif // endif HAVE_XPETRA_EPETRA
746 #ifdef HAVE_XPETRA_EPETRA
748 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
750 class ThyraUtils<double, int, int,
EpetraNode> {
752 typedef double Scalar;
753 typedef int LocalOrdinal;
754 typedef int GlobalOrdinal;
758 #undef XPETRA_THYRAUTILS_SHORT
763 static Teuchos::RCP<Xpetra::StridedMap<LocalOrdinal,GlobalOrdinal,Node> >
764 toXpetra(
const Teuchos::RCP<
const Thyra::VectorSpaceBase<Scalar> >& vectorSpace,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0) {
768 if(stridedBlockId == -1) {
769 TEUCHOS_TEST_FOR_EXCEPT(map->getNodeNumElements() % stridingInfo.size() != 0);
772 TEUCHOS_TEST_FOR_EXCEPT(map->getNodeNumElements() % stridingInfo[stridedBlockId] != 0);
779 static Teuchos::RCP<Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
780 toXpetra(
const Teuchos::RCP<
const Thyra::VectorSpaceBase<Scalar> >& vectorSpace,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
782 using Teuchos::rcp_dynamic_cast;
784 typedef Thyra::VectorSpaceBase<Scalar> ThyVecSpaceBase;
785 typedef Thyra::ProductVectorSpaceBase<Scalar> ThyProdVecSpaceBase;
786 typedef Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node> ThyUtils;
788 RCP<Map> resultMap = Teuchos::null;
790 RCP<const ThyProdVecSpaceBase > prodVectorSpace = rcp_dynamic_cast<
const ThyProdVecSpaceBase >(vectorSpace);
791 if(prodVectorSpace != Teuchos::null) {
794 TEUCHOS_TEST_FOR_EXCEPTION(prodVectorSpace->numBlocks()==0, std::logic_error,
"Found a product vector space with zero blocks.");
795 std::vector<RCP<const Map> > mapsThyra(prodVectorSpace->numBlocks(), Teuchos::null);
796 std::vector<RCP<const Map> > mapsXpetra(prodVectorSpace->numBlocks(), Teuchos::null);
797 for (
int b = 0; b < prodVectorSpace->numBlocks(); ++b){
798 RCP<const ThyVecSpaceBase > bv = prodVectorSpace->getBlock(b);
805 std::vector<GlobalOrdinal> gidOffsets(prodVectorSpace->numBlocks(),0);
806 for(
int i = 1; i < prodVectorSpace->numBlocks(); ++i) {
807 gidOffsets[i] = mapsThyra[i-1]->getMaxAllGlobalIndex() + gidOffsets[i-1] + 1;
810 for (
int b = 0; b < prodVectorSpace->numBlocks(); ++b){
811 RCP<const ThyVecSpaceBase > bv = prodVectorSpace->getBlock(b);
822 bool bIsTpetra =
false;
823 #ifdef HAVE_XPETRA_TPETRA
824 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
825 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
826 Teuchos::RCP<const Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetra_vsc = Teuchos::rcp_dynamic_cast<
const Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(vectorSpace);
827 bIsTpetra = Teuchos::is_null(tpetra_vsc) ?
false :
true;
832 bool bIsEpetra = !bIsTpetra;
834 #ifdef HAVE_XPETRA_TPETRA
836 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
837 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
838 typedef Thyra::VectorBase<Scalar> ThyVecBase;
839 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> TpMap;
840 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpVector;
841 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
842 RCP<ThyVecBase> rgVec = Thyra::createMember<Scalar>(vectorSpace, std::string(
"label"));
843 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgVec));
844 RCP<const TpVector> rgTpetraVec = TOE::getTpetraVector(rgVec);
845 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgTpetraVec));
846 RCP<const TpMap> rgTpetraMap = rgTpetraVec->getMap();
847 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgTpetraMap));
856 #ifdef HAVE_XPETRA_EPETRA
859 RCP<const Epetra_Map>
860 epetra_map = Teuchos::get_extra_data<RCP<const Epetra_Map> >(vectorSpace,
"epetra_map");
861 if(!Teuchos::is_null(epetra_map)) {
863 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(resultMap));
865 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"No Epetra_Map data found in Thyra::VectorSpace.");
870 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(resultMap));
875 static Teuchos::RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
876 toXpetra(Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > v,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
878 using Teuchos::rcp_dynamic_cast;
881 using ThyProdMultVecBase = Thyra::ProductMultiVectorBase<Scalar>;
882 using ThyMultVecBase = Thyra::MultiVectorBase<Scalar>;
883 using ThyUtils = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>;
886 RCP<MultiVector> xpMultVec = Teuchos::null;
889 Teuchos::RCP<const ThyProdMultVecBase> thyProdVec = rcp_dynamic_cast<
const ThyProdMultVecBase >(v);
890 if(thyProdVec != Teuchos::null) {
894 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(Teuchos::rcp_dynamic_cast<BlockedMap>(fullMap)));
899 RCP<BlockedMultiVector> xpBlockedMultVec = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(xpMultVec);
900 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpBlockedMultVec));
903 for (
int b = 0; b < thyProdVec->productSpace()->numBlocks(); ++b){
904 RCP<const ThyMultVecBase> thyBlockMV = thyProdVec->getMultiVectorBlock(b);
907 xpBlockedMultVec->setMultiVector(b, xpBlockMV,
true );
910 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpMultVec));
915 bool bIsTpetra =
false;
916 #ifdef HAVE_XPETRA_TPETRA
917 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
918 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
922 typedef Thyra::SpmdMultiVectorBase<Scalar> ThySpmdMultVecBase;
923 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> ConverterT;
924 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpMultVec;
926 typedef Thyra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> ThyTpMultVec;
928 RCP<const ThySpmdMultVecBase> thyraSpmdMultiVector = rcp_dynamic_cast<
const ThySpmdMultVecBase>(v);
929 RCP<const ThyTpMultVec> thyraTpetraMultiVector = rcp_dynamic_cast<
const ThyTpMultVec>(thyraSpmdMultiVector);
930 if(thyraTpetraMultiVector != Teuchos::null) {
932 const RCP<const TpMultVec> tpMultVec = ConverterT::getConstTpetraMultiVector(v);
933 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpMultVec));
934 RCP<TpMultVec> tpNonConstMultVec = Teuchos::rcp_const_cast<TpMultVec>(tpMultVec);
935 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpNonConstMultVec));
936 xpMultVec = rcp(
new XpTpMultVec(tpNonConstMultVec));
941 #ifdef HAVE_XPETRA_EPETRA
942 if(bIsTpetra ==
false) {
945 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(map));
947 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xeMap));
948 RCP<const Epetra_Map> eMap = Teuchos::rcpFromRef(xeMap->getEpetra_Map());
949 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(eMap));
950 Teuchos::RCP<const Epetra_MultiVector> epMultVec = Thyra::get_Epetra_MultiVector(*eMap, v);
951 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epMultVec));
952 RCP<Epetra_MultiVector> epNonConstMultVec = Teuchos::rcp_const_cast<Epetra_MultiVector>(epMultVec);
953 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epNonConstMultVec));
957 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpMultVec));
960 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
964 static Teuchos::RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
965 toXpetra(Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > v,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
966 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > cv =
967 Teuchos::rcp_const_cast<
const Thyra::MultiVectorBase<Scalar> >(v);
968 Teuchos::RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > r =
973 static bool isTpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
975 bool bIsTpetra =
false;
976 #ifdef HAVE_XPETRA_TPETRA
977 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
978 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
980 Teuchos::RCP<const Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetra_op = Teuchos::rcp_dynamic_cast<
const Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(op);
981 bIsTpetra = Teuchos::is_null(tpetra_op) ?
false :
true;
985 #ifdef HAVE_XPETRA_EPETRA
986 Teuchos::rcp_dynamic_cast<const Thyra::EpetraLinearOp>(op) == Teuchos::null &&
988 Teuchos::rcp_dynamic_cast<
const Thyra::DefaultBlockedLinearOp<Scalar> >(op) == Teuchos::null) {
990 typedef Thyra::TpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraLinearOp_t;
991 if(Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op) == Teuchos::null) {
992 std::cout <<
"ATTENTION: The dynamic cast to the TpetraLinearOp failed even though it should be a TpetraLinearOp." << std::endl;
993 std::cout <<
" If you are using Panzer or Stratimikos you might check that the template parameters are " << std::endl;
994 std::cout <<
" properly set!" << std::endl;
995 std::cout << Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op,
true) << std::endl;
1005 if(bIsTpetra ==
false) {
1006 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
1007 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op);
1008 if(ThyBlockedOp != Teuchos::null) {
1009 TEUCHOS_TEST_FOR_EXCEPT(ThyBlockedOp->blockExists(0,0)==
false);
1010 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > b00 =
1011 ThyBlockedOp->getBlock(0,0);
1012 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(b00));
1013 bIsTpetra = isTpetra(b00);
1021 static bool isEpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
1023 bool bIsEpetra =
false;
1025 #ifdef HAVE_XPETRA_EPETRA
1026 Teuchos::RCP<const Thyra::EpetraLinearOp> epetra_op = Teuchos::rcp_dynamic_cast<
const Thyra::EpetraLinearOp>(op,
false);
1027 bIsEpetra = Teuchos::is_null(epetra_op) ?
false :
true;
1034 if(bIsEpetra ==
false) {
1035 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
1036 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op,
false);
1037 if(ThyBlockedOp != Teuchos::null) {
1038 TEUCHOS_TEST_FOR_EXCEPT(ThyBlockedOp->blockExists(0,0)==
false);
1039 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > b00 =
1040 ThyBlockedOp->getBlock(0,0);
1041 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(b00));
1042 bIsEpetra = isEpetra(b00);
1050 static bool isBlockedOperator(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
1052 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
1053 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op);
1054 if(ThyBlockedOp != Teuchos::null) {
1060 static Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1061 toXpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> >& op) {
1063 #ifdef HAVE_XPETRA_TPETRA
1065 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1066 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
1068 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
1069 Teuchos::RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraOp = TOE::getConstTpetraOperator(op);
1072 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraOp));
1073 Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraRowMat = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraOp);
1074 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraRowMat));
1075 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraCrsMat = Teuchos::rcp_dynamic_cast<
const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraRowMat);
1076 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraCrsMat));
1077 Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraNcnstCrsMat = Teuchos::rcp_const_cast<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraCrsMat);
1078 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraNcnstCrsMat));
1080 Teuchos::RCP<Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > xTpetraCrsMat =
1082 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpetraCrsMat));
1083 Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > ret =
1085 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(ret));
1093 #ifdef HAVE_XPETRA_EPETRA
1095 Teuchos::RCP<const Epetra_Operator> epetra_op = Thyra::get_Epetra_Operator( *op );
1096 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_op));
1097 Teuchos::RCP<const Epetra_RowMatrix> epetra_rowmat = Teuchos::rcp_dynamic_cast<
const Epetra_RowMatrix>(epetra_op);
1098 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_rowmat));
1099 Teuchos::RCP<const Epetra_CrsMatrix> epetra_crsmat = Teuchos::rcp_dynamic_cast<
const Epetra_CrsMatrix>(epetra_rowmat);
1100 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_crsmat));
1101 Teuchos::RCP<Epetra_CrsMatrix> epetra_ncnstcrsmat = Teuchos::rcp_const_cast<Epetra_CrsMatrix>(epetra_crsmat);
1102 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_ncnstcrsmat));
1104 Teuchos::RCP<Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> > xEpetraCrsMat =
1106 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpetraCrsMat));
1108 Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > ret =
1110 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(ret));
1114 return Teuchos::null;
1117 static Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1118 toXpetra(
const Teuchos::RCP<Thyra::LinearOpBase<Scalar> >& op) {
1120 #ifdef HAVE_XPETRA_TPETRA
1122 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1123 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
1125 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
1126 Teuchos::RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraOp = TOE::getTpetraOperator(op);
1127 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraOp));
1128 Teuchos::RCP<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraRowMat = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraOp);
1129 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraRowMat));
1130 Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraCrsMat = Teuchos::rcp_dynamic_cast<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraRowMat);
1131 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraCrsMat));
1133 Teuchos::RCP<Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > xTpetraCrsMat =
1135 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpetraCrsMat));
1136 return xTpetraCrsMat;
1143 #ifdef HAVE_XPETRA_EPETRA
1145 Teuchos::RCP<Epetra_Operator> epetra_op = Thyra::get_Epetra_Operator( *op );
1146 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_op));
1147 Teuchos::RCP<Epetra_RowMatrix> epetra_rowmat = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(epetra_op);
1148 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_rowmat));
1149 Teuchos::RCP<Epetra_CrsMatrix> epetra_crsmat = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(epetra_rowmat);
1150 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_crsmat));
1152 Teuchos::RCP<Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> > xEpetraCrsMat =
1154 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpetraCrsMat));
1155 return xEpetraCrsMat;
1158 return Teuchos::null;
1161 static Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
1163 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thyraMap = Teuchos::null;
1166 RCP<const BlockedMap> bmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map);
1167 if(bmap.is_null() ==
false) {
1169 Teuchos::Array<Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > > vecSpaces(bmap->getNumMaps());
1170 for(
size_t i = 0; i < bmap->getNumMaps(); i++) {
1172 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > vs =
1173 Xpetra::ThyraUtils<Scalar,LO,GO,Node>::toThyra(bmap->getMap(i,
true));
1177 thyraMap = Thyra::productVectorSpace<Scalar>(vecSpaces());
1182 #ifdef HAVE_XPETRA_TPETRA
1184 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1185 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
1187 if (tpetraMap == Teuchos::null)
1188 throw Exceptions::BadCast(
"Xpetra::ThyraUtils::toThyra: Cast from Xpetra::Map to Xpetra::TpetraMap failed");
1189 RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > tpMap = tpetraMap->getTpetra_Map();
1190 RCP<Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > thyraTpetraMap = Thyra::tpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpMap);
1191 thyraMap = thyraTpetraMap;
1198 #ifdef HAVE_XPETRA_EPETRA
1201 if (epetraMap == Teuchos::null)
1202 throw Exceptions::BadCast(
"Xpetra::ThyraUtils::toThyra: Cast from Xpetra::Map to Xpetra::EpetraMap failed");
1203 RCP<const Thyra::VectorSpaceBase<Scalar> > thyraEpetraMap = Thyra::create_VectorSpace(Teuchos::rcpFromRef(epetraMap->getEpetra_Map()));
1204 thyraMap = thyraEpetraMap;
1211 static Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
1215 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thMap = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(vec->getMap());
1216 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getGlobalNumElements())!=thMap->dim(), std::logic_error,
"Global dimension of Xpetra map and Thyra VectorSpaceBase are different.");
1217 Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<Scalar> > thSpmdMap = Teuchos::rcp_dynamic_cast<
const Thyra::SpmdVectorSpaceBase<Scalar> >(thMap);
1218 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMap == Teuchos::null, std::logic_error,
"Cannot cast VectorSpaceBase to SpmdVectorSpaceBase.");
1219 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getNodeNumElements())!=thSpmdMap->localSubDim(), std::logic_error,
"Local dimension of Xpetra map and Thyra VectorSpaceBase on one (or more) processor(s) are different.");
1222 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> > thMVec = Thyra::createMembers(thMap, vec->getNumVectors());
1223 Teuchos::RCP< Thyra::SpmdMultiVectorBase<Scalar> > thSpmdMVec = Teuchos::rcp_dynamic_cast<Thyra::SpmdMultiVectorBase<Scalar> >(thMVec);
1224 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMVec == Teuchos::null, std::logic_error,
"Cannot cast MultiVectorBase to SpmdMultiVectorBase.");
1227 const LocalOrdinal localOffset = ( thSpmdMap != Teuchos::null ? thSpmdMap->localOffset() : 0 );
1228 const LocalOrdinal localSubDim = ( thSpmdMap != Teuchos::null ? thSpmdMap->localSubDim() : thMap->dim() );
1229 Teuchos::RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
1230 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thSpmdMVec,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
1233 for(
size_t j = 0; j < Teuchos::as<size_t>(thSpmdMVec->domain()->dim()); ++j) {
1234 Teuchos::ArrayRCP< const Scalar > vecData = vec->getData(j);
1236 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
1237 (*thyData)(i,j) = vecData[i];
1244 static Teuchos::RCP<const Thyra::VectorBase<Scalar> >
1248 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thMap = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(vec->getMap());
1249 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getGlobalNumElements())!=thMap->dim(), std::logic_error,
"Global dimension of Xpetra map and Thyra VectorSpaceBase are different.");
1250 Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<Scalar> > thSpmdMap = Teuchos::rcp_dynamic_cast<
const Thyra::SpmdVectorSpaceBase<Scalar> >(thMap);
1251 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMap == Teuchos::null, std::logic_error,
"Cannot cast VectorSpaceBase to SpmdVectorSpaceBase.");
1252 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getNodeNumElements())!=thSpmdMap->localSubDim(), std::logic_error,
"Local dimension of Xpetra map and Thyra VectorSpaceBase on one (or more) processor(s) are different.");
1255 Teuchos::RCP< Thyra::VectorBase<Scalar> > thMVec = Thyra::createMember(thMap);
1256 Teuchos::RCP< Thyra::SpmdVectorBase<Scalar> > thSpmdMVec = Teuchos::rcp_dynamic_cast<Thyra::SpmdVectorBase<Scalar> >(thMVec);
1257 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMVec == Teuchos::null, std::logic_error,
"Cannot cast VectorBase to SpmdVectorBase.");
1260 const LocalOrdinal localOffset = ( thSpmdMap != Teuchos::null ? thSpmdMap->localOffset() : 0 );
1261 const LocalOrdinal localSubDim = ( thSpmdMap != Teuchos::null ? thSpmdMap->localSubDim() : thMap->dim() );
1262 Teuchos::RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
1263 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thSpmdMVec,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
1266 for(
size_t j = 0; j < Teuchos::as<size_t>(thSpmdMVec->domain()->dim()); ++j) {
1267 Teuchos::ArrayRCP< const Scalar > vecData = vec->getData(j);
1269 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
1270 (*thyData)(i,j) = vecData[i];
1279 using Teuchos::rcp_dynamic_cast;
1281 typedef Thyra::VectorSpaceBase<Scalar> ThyVecSpaceBase;
1282 typedef Thyra::SpmdVectorSpaceBase<Scalar> ThySpmdVecSpaceBase;
1283 typedef Thyra::MultiVectorBase<Scalar> ThyMultVecBase;
1286 typedef Thyra::ProductMultiVectorBase<Scalar> ThyProdMultVecBase;
1289 RCP<ThyProdMultVecBase> prodTarget = rcp_dynamic_cast<ThyProdMultVecBase>(target);
1290 if(prodTarget != Teuchos::null) {
1292 RCP<const BlockedMultiVector> bSourceVec = rcp_dynamic_cast<
const BlockedMultiVector>(source);
1293 if(bSourceVec.is_null() ==
true) {
1297 TEUCHOS_TEST_FOR_EXCEPTION(mapExtractor == Teuchos::null, std::logic_error,
"Found a Thyra product vector, but user did not provide an Xpetra::MapExtractor.");
1298 TEUCHOS_TEST_FOR_EXCEPTION(prodTarget->productSpace()->numBlocks() != as<int>(mapExtractor->NumMaps()), std::logic_error,
"Inconsistent numbers of sub maps in Thyra::ProductVectorSpace and Xpetra::MapExtractor.");
1300 for(
int bbb = 0; bbb < prodTarget->productSpace()->numBlocks(); ++bbb) {
1302 RCP<MultiVector> xpSubBlock = mapExtractor->ExtractVector(source, bbb,
false);
1305 Teuchos::RCP<ThyMultVecBase> thySubBlock = prodTarget->getNonconstMultiVectorBlock(bbb);
1306 RCP<const ThyVecSpaceBase> vs = thySubBlock->range();
1307 RCP<const ThySpmdVecSpaceBase> mpi_vs = rcp_dynamic_cast<
const ThySpmdVecSpaceBase>(vs);
1308 const LocalOrdinal localOffset = ( mpi_vs != Teuchos::null ? mpi_vs->localOffset() : 0 );
1309 const LocalOrdinal localSubDim = ( mpi_vs != Teuchos::null ? mpi_vs->localSubDim() : vs->dim() );
1310 RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
1311 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thySubBlock,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
1314 for(
size_t j = 0; j < xpSubBlock->getNumVectors(); ++j) {
1315 Teuchos::ArrayRCP< const Scalar > xpData = xpSubBlock->getData(j);
1318 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
1319 (*thyData)(i,j) = xpData[i];
1326 TEUCHOS_TEST_FOR_EXCEPTION(prodTarget->productSpace()->numBlocks() != as<int>(bSourceVec->getBlockedMap()->getNumMaps()), std::logic_error,
"Inconsistent numbers of sub maps in Thyra::ProductVectorSpace and Xpetra::BlockedMultiVector.");
1328 for(
int bbb = 0; bbb < prodTarget->productSpace()->numBlocks(); ++bbb) {
1330 RCP<MultiVector> xpSubBlock = bSourceVec->getMultiVector(bbb,
true);
1332 Teuchos::RCP<const ThyMultVecBase> thyXpSubBlock = toThyraMultiVector(xpSubBlock);
1335 Teuchos::RCP<ThyMultVecBase> thySubBlock = prodTarget->getNonconstMultiVectorBlock(bbb);
1336 Thyra::assign(thySubBlock.ptr(), *thyXpSubBlock);
1345 RCP<const ThySpmdVecSpaceBase> mpi_vs = rcp_dynamic_cast<
const ThySpmdVecSpaceBase>(target->range());
1346 TEUCHOS_TEST_FOR_EXCEPTION(mpi_vs == Teuchos::null, std::logic_error,
"Failed to cast Thyra::VectorSpaceBase to Thyra::SpmdVectorSpaceBase.");
1347 const LocalOrdinal localOffset = ( mpi_vs != Teuchos::null ? mpi_vs->localOffset() : 0 );
1348 const LocalOrdinal localSubDim = ( mpi_vs != Teuchos::null ? mpi_vs->localSubDim() : target->range()->dim() );
1349 RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
1350 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*target,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
1353 for(
size_t j = 0; j < source->getNumVectors(); ++j) {
1354 Teuchos::ArrayRCP< const Scalar > xpData = source->getData(j);
1356 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
1357 (*thyData)(i,j) = xpData[i];
1363 static Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
1366 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > thyraOp = Teuchos::null;
1368 #ifdef HAVE_XPETRA_TPETRA
1370 if(tpetraMat!=Teuchos::null) {
1371 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1372 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
1375 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpCrsMat));
1376 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpCrsMat = xTpCrsMat->getTpetra_CrsMatrix();
1377 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpCrsMat));
1379 Teuchos::RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpRowMat = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpCrsMat);
1380 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpRowMat));
1381 Teuchos::RCP<const Tpetra::Operator <Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpOperator = Teuchos::rcp_dynamic_cast<
const Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpRowMat);
1382 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpOperator));
1384 thyraOp = Thyra::createConstLinearOp(tpOperator);
1385 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraOp));
1392 #ifdef HAVE_XPETRA_EPETRA
1394 if(epetraMat!=Teuchos::null) {
1396 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpCrsMat));
1397 Teuchos::RCP<const Epetra_CrsMatrix> epCrsMat = xEpCrsMat->getEpetra_CrsMatrix();
1398 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epCrsMat));
1400 Teuchos::RCP<const Thyra::EpetraLinearOp> thyraEpOp = Thyra::epetraLinearOp(epCrsMat,
"op");
1401 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraEpOp));
1402 thyraOp = thyraEpOp;
1408 static Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
1411 Teuchos::RCP<Thyra::LinearOpBase<Scalar> > thyraOp = Teuchos::null;
1413 #ifdef HAVE_XPETRA_TPETRA
1415 if(tpetraMat!=Teuchos::null) {
1416 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1417 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) && defined(HAVE_TPETRA_INST_DOUBLE)))
1420 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpCrsMat));
1421 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpCrsMat = xTpCrsMat->getTpetra_CrsMatrixNonConst();
1422 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpCrsMat));
1424 Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpRowMat = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpCrsMat);
1425 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpRowMat));
1426 Teuchos::RCP<Tpetra::Operator <Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpOperator = Teuchos::rcp_dynamic_cast<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpRowMat);
1427 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpOperator));
1429 thyraOp = Thyra::createLinearOp(tpOperator);
1430 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraOp));
1437 #ifdef HAVE_XPETRA_EPETRA
1439 if(epetraMat!=Teuchos::null) {
1441 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpCrsMat));
1442 Teuchos::RCP<Epetra_CrsMatrix> epCrsMat = xEpCrsMat->getEpetra_CrsMatrixNonConst();
1443 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epCrsMat));
1445 Teuchos::RCP<Thyra::EpetraLinearOp> thyraEpOp = Thyra::nonconstEpetraLinearOp(epCrsMat,
"op");
1446 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraEpOp));
1447 thyraOp = thyraEpOp;
1453 static Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
1457 #endif // #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
1459 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
1461 class ThyraUtils<double, int, long long,
EpetraNode> {
1463 typedef double Scalar;
1464 typedef int LocalOrdinal;
1465 typedef long long GlobalOrdinal;
1469 #undef XPETRA_THYRAUTILS_SHORT
1474 static Teuchos::RCP<Xpetra::StridedMap<LocalOrdinal,GlobalOrdinal,Node> >
1475 toXpetra(
const Teuchos::RCP<
const Thyra::VectorSpaceBase<Scalar> >& vectorSpace,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0) {
1479 if(stridedBlockId == -1) {
1480 TEUCHOS_TEST_FOR_EXCEPT(map->getNodeNumElements() % stridingInfo.size() != 0);
1483 TEUCHOS_TEST_FOR_EXCEPT(map->getNodeNumElements() % stridingInfo[stridedBlockId] != 0);
1490 static Teuchos::RCP<Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
1491 toXpetra(
const Teuchos::RCP<
const Thyra::VectorSpaceBase<Scalar> >& vectorSpace,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
1493 using Teuchos::rcp_dynamic_cast;
1495 typedef Thyra::VectorSpaceBase<Scalar> ThyVecSpaceBase;
1496 typedef Thyra::ProductVectorSpaceBase<Scalar> ThyProdVecSpaceBase;
1497 typedef Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node> ThyUtils;
1499 RCP<const ThyProdVecSpaceBase > prodVectorSpace = rcp_dynamic_cast<
const ThyProdVecSpaceBase >(vectorSpace);
1500 if(prodVectorSpace != Teuchos::null) {
1503 TEUCHOS_TEST_FOR_EXCEPTION(prodVectorSpace->numBlocks()==0, std::logic_error,
"Found a product vector space with zero blocks.");
1504 std::vector<RCP<const Map> > mapsThyra(prodVectorSpace->numBlocks(), Teuchos::null);
1505 std::vector<RCP<const Map> > mapsXpetra(prodVectorSpace->numBlocks(), Teuchos::null);
1506 for (
int b = 0; b < prodVectorSpace->numBlocks(); ++b){
1507 RCP<const ThyVecSpaceBase > bv = prodVectorSpace->getBlock(b);
1514 std::vector<GlobalOrdinal> gidOffsets(prodVectorSpace->numBlocks(),0);
1515 for(
int i = 1; i < prodVectorSpace->numBlocks(); ++i) {
1516 gidOffsets[i] = mapsThyra[i-1]->getMaxAllGlobalIndex() + gidOffsets[i-1] + 1;
1519 for (
int b = 0; b < prodVectorSpace->numBlocks(); ++b){
1520 RCP<const ThyVecSpaceBase > bv = prodVectorSpace->getBlock(b);
1526 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(resultMap));
1533 bool bIsTpetra =
false;
1534 #ifdef HAVE_XPETRA_TPETRA
1535 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1536 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1537 Teuchos::RCP<const Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetra_vsc = Teuchos::rcp_dynamic_cast<
const Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(vectorSpace);
1538 bIsTpetra = Teuchos::is_null(tpetra_vsc) ?
false :
true;
1543 bool bIsEpetra = !bIsTpetra;
1545 #ifdef HAVE_XPETRA_TPETRA
1547 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1548 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1549 typedef Thyra::VectorBase<Scalar> ThyVecBase;
1550 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> TpMap;
1551 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpVector;
1552 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
1553 RCP<ThyVecBase> rgVec = Thyra::createMember<Scalar>(vectorSpace, std::string(
"label"));
1554 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgVec));
1555 RCP<const TpVector> rgTpetraVec = TOE::getTpetraVector(rgVec);
1556 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgTpetraVec));
1557 RCP<const TpMap> rgTpetraMap = rgTpetraVec->getMap();
1558 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgTpetraMap));
1561 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgXpetraMap));
1569 #ifdef HAVE_XPETRA_EPETRA
1572 RCP<const Epetra_Map>
1573 epetra_map = Teuchos::get_extra_data<RCP<const Epetra_Map> >(vectorSpace,
"epetra_map");
1574 if(!Teuchos::is_null(epetra_map)) {
1576 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(rgXpetraMap));
1579 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"No Epetra_Map data found in Thyra::VectorSpace.");
1584 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Cannot transform Thyra::VectorSpace to Xpetra::Map.");
1589 static Teuchos::RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
1590 toXpetra(Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > v,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
1592 using Teuchos::rcp_dynamic_cast;
1594 typedef Thyra::ProductMultiVectorBase<Scalar> ThyProdMultVecBase;
1595 typedef Thyra::MultiVectorBase<Scalar> ThyMultVecBase;
1596 typedef Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node> ThyUtils;
1599 RCP<MultiVector> xpMultVec = Teuchos::null;
1602 Teuchos::RCP<const ThyProdMultVecBase> thyProdVec = rcp_dynamic_cast<
const ThyProdMultVecBase >(v);
1603 if(thyProdVec != Teuchos::null) {
1607 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(Teuchos::rcp_dynamic_cast<BlockedMap>(fullMap)));
1612 RCP<BlockedMultiVector> xpBlockedMultVec = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(xpMultVec);
1613 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpBlockedMultVec));
1616 for (
int b = 0; b < thyProdVec->productSpace()->numBlocks(); ++b){
1617 RCP<const ThyMultVecBase> thyBlockMV = thyProdVec->getMultiVectorBlock(b);
1620 xpBlockedMultVec->setMultiVector(b, xpBlockMV,
true );
1623 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpMultVec));
1628 bool bIsTpetra =
false;
1629 #ifdef HAVE_XPETRA_TPETRA
1630 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1631 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1635 typedef Thyra::SpmdMultiVectorBase<Scalar> ThySpmdMultVecBase;
1636 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> ConverterT;
1637 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpMultVec;
1639 typedef Thyra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> ThyTpMultVec;
1641 RCP<const ThySpmdMultVecBase> thyraSpmdMultiVector = rcp_dynamic_cast<
const ThySpmdMultVecBase>(v);
1642 RCP<const ThyTpMultVec> thyraTpetraMultiVector = rcp_dynamic_cast<
const ThyTpMultVec>(thyraSpmdMultiVector);
1643 if(thyraTpetraMultiVector != Teuchos::null) {
1645 const RCP<const TpMultVec> tpMultVec = ConverterT::getConstTpetraMultiVector(v);
1646 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpMultVec));
1647 RCP<TpMultVec> tpNonConstMultVec = Teuchos::rcp_const_cast<TpMultVec>(tpMultVec);
1648 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpNonConstMultVec));
1649 xpMultVec = rcp(
new XpTpMultVec(tpNonConstMultVec));
1650 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpMultVec));
1656 #ifdef HAVE_XPETRA_EPETRA
1657 if(bIsTpetra ==
false) {
1660 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(map));
1662 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xeMap));
1663 RCP<const Epetra_Map> eMap = Teuchos::rcpFromRef(xeMap->getEpetra_Map());
1664 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(eMap));
1665 Teuchos::RCP<const Epetra_MultiVector> epMultVec = Thyra::get_Epetra_MultiVector(*eMap, v);
1666 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epMultVec));
1667 RCP<Epetra_MultiVector> epNonConstMultVec = Teuchos::rcp_const_cast<Epetra_MultiVector>(epMultVec);
1668 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epNonConstMultVec));
1670 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xpMultVec));
1675 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Cannot transform Thyra::MultiVector to Xpetra::MultiVector.");
1680 static Teuchos::RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
1681 toXpetra(Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > v,
const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) {
1682 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > cv =
1683 Teuchos::rcp_const_cast<
const Thyra::MultiVectorBase<Scalar> >(v);
1684 Teuchos::RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > r =
1689 static bool isTpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
1691 bool bIsTpetra =
false;
1692 #ifdef HAVE_XPETRA_TPETRA
1693 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1694 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1696 Teuchos::RCP<const Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> > tpetra_op = Teuchos::rcp_dynamic_cast<
const Thyra::TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(op);
1697 bIsTpetra = Teuchos::is_null(tpetra_op) ?
false :
true;
1701 #ifdef HAVE_XPETRA_EPETRA
1702 Teuchos::rcp_dynamic_cast<const Thyra::EpetraLinearOp>(op) == Teuchos::null &&
1704 Teuchos::rcp_dynamic_cast<
const Thyra::DefaultBlockedLinearOp<Scalar> >(op) == Teuchos::null) {
1706 typedef Thyra::TpetraLinearOp<Scalar, LocalOrdinal, GlobalOrdinal, Node> TpetraLinearOp_t;
1707 if(Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op) == Teuchos::null) {
1708 std::cout <<
"ATTENTION: The dynamic cast to the TpetraLinearOp failed even though it should be a TpetraLinearOp." << std::endl;
1709 std::cout <<
" If you are using Panzer or Stratimikos you might check that the template parameters are " << std::endl;
1710 std::cout <<
" properly set!" << std::endl;
1711 std::cout << Teuchos::rcp_dynamic_cast<const TpetraLinearOp_t>(op,
true) << std::endl;
1721 if(bIsTpetra ==
false) {
1722 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
1723 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op);
1724 if(ThyBlockedOp != Teuchos::null) {
1725 TEUCHOS_TEST_FOR_EXCEPT(ThyBlockedOp->blockExists(0,0)==
false);
1726 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > b00 =
1727 ThyBlockedOp->getBlock(0,0);
1728 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(b00));
1729 bIsTpetra = isTpetra(b00);
1737 static bool isEpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
1739 bool bIsEpetra =
false;
1741 #ifdef HAVE_XPETRA_EPETRA
1742 Teuchos::RCP<const Thyra::EpetraLinearOp> epetra_op = Teuchos::rcp_dynamic_cast<
const Thyra::EpetraLinearOp>(op,
false);
1743 bIsEpetra = Teuchos::is_null(epetra_op) ?
false :
true;
1750 if(bIsEpetra ==
false) {
1751 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
1752 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op,
false);
1753 if(ThyBlockedOp != Teuchos::null) {
1754 TEUCHOS_TEST_FOR_EXCEPT(ThyBlockedOp->blockExists(0,0)==
false);
1755 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > b00 =
1756 ThyBlockedOp->getBlock(0,0);
1757 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(b00));
1758 bIsEpetra = isEpetra(b00);
1766 static bool isBlockedOperator(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> > & op){
1768 Teuchos::RCP<const Thyra::BlockedLinearOpBase<Scalar> > ThyBlockedOp =
1769 Teuchos::rcp_dynamic_cast<
const Thyra::BlockedLinearOpBase<Scalar> >(op);
1770 if(ThyBlockedOp != Teuchos::null) {
1776 static Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1777 toXpetra(
const Teuchos::RCP<
const Thyra::LinearOpBase<Scalar> >& op) {
1779 #ifdef HAVE_XPETRA_TPETRA
1781 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1782 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1784 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
1785 Teuchos::RCP<const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraOp = TOE::getConstTpetraOperator(op);
1788 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraOp));
1789 Teuchos::RCP<const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraRowMat = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraOp);
1790 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraRowMat));
1791 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraCrsMat = Teuchos::rcp_dynamic_cast<
const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraRowMat);
1792 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraCrsMat));
1793 Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraNcnstCrsMat = Teuchos::rcp_const_cast<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraCrsMat);
1794 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraNcnstCrsMat));
1796 Teuchos::RCP<Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > xTpetraCrsMat =
1798 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpetraCrsMat));
1799 Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > ret =
1801 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(ret));
1809 #ifdef HAVE_XPETRA_EPETRA
1811 Teuchos::RCP<const Epetra_Operator> epetra_op = Thyra::get_Epetra_Operator( *op );
1812 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_op));
1813 Teuchos::RCP<const Epetra_RowMatrix> epetra_rowmat = Teuchos::rcp_dynamic_cast<
const Epetra_RowMatrix>(epetra_op);
1814 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_rowmat));
1815 Teuchos::RCP<const Epetra_CrsMatrix> epetra_crsmat = Teuchos::rcp_dynamic_cast<
const Epetra_CrsMatrix>(epetra_rowmat);
1816 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_crsmat));
1817 Teuchos::RCP<Epetra_CrsMatrix> epetra_ncnstcrsmat = Teuchos::rcp_const_cast<Epetra_CrsMatrix>(epetra_crsmat);
1818 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_ncnstcrsmat));
1820 Teuchos::RCP<Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> > xEpetraCrsMat =
1822 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpetraCrsMat));
1824 Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > ret =
1826 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(ret));
1830 return Teuchos::null;
1833 static Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1834 toXpetra(
const Teuchos::RCP<Thyra::LinearOpBase<Scalar> >& op) {
1836 #ifdef HAVE_XPETRA_TPETRA
1838 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1839 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1841 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,LocalOrdinal,GlobalOrdinal,Node> TOE;
1842 Teuchos::RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraOp = TOE::getTpetraOperator(op);
1843 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraOp));
1844 Teuchos::RCP<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraRowMat = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraOp);
1845 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraRowMat));
1846 Teuchos::RCP<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > TpetraCrsMat = Teuchos::rcp_dynamic_cast<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(TpetraRowMat);
1847 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(TpetraCrsMat));
1849 Teuchos::RCP<Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > xTpetraCrsMat =
1851 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpetraCrsMat));
1852 return xTpetraCrsMat;
1859 #ifdef HAVE_XPETRA_EPETRA
1861 Teuchos::RCP<Epetra_Operator> epetra_op = Thyra::get_Epetra_Operator( *op );
1862 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_op));
1863 Teuchos::RCP<Epetra_RowMatrix> epetra_rowmat = Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(epetra_op);
1864 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_rowmat));
1865 Teuchos::RCP<Epetra_CrsMatrix> epetra_crsmat = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(epetra_rowmat);
1866 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epetra_crsmat));
1868 Teuchos::RCP<Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> > xEpetraCrsMat =
1870 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpetraCrsMat));
1871 return xEpetraCrsMat;
1874 return Teuchos::null;
1877 static Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
1879 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thyraMap = Teuchos::null;
1882 RCP<const BlockedMap> bmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map);
1883 if(bmap.is_null() ==
false) {
1885 Teuchos::Array<Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > > vecSpaces(bmap->getNumMaps());
1886 for(
size_t i = 0; i < bmap->getNumMaps(); i++) {
1888 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > vs =
1889 Xpetra::ThyraUtils<Scalar,LO,GO,Node>::toThyra(bmap->getMap(i,
true));
1893 thyraMap = Thyra::productVectorSpace<Scalar>(vecSpaces());
1898 #ifdef HAVE_XPETRA_TPETRA
1900 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
1901 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
1903 if (tpetraMap == Teuchos::null)
1904 throw Exceptions::BadCast(
"Xpetra::ThyraUtils::toThyra: Cast from Xpetra::Map to Xpetra::TpetraMap failed");
1905 RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > tpMap = tpetraMap->getTpetra_Map();
1906 RCP<Thyra::TpetraVectorSpace<Scalar,LocalOrdinal,GlobalOrdinal,Node> > thyraTpetraMap = Thyra::tpetraVectorSpace<Scalar, LocalOrdinal, GlobalOrdinal, Node>(tpMap);
1907 thyraMap = thyraTpetraMap;
1914 #ifdef HAVE_XPETRA_EPETRA
1917 if (epetraMap == Teuchos::null)
1918 throw Exceptions::BadCast(
"Xpetra::ThyraUtils::toThyra: Cast from Xpetra::Map to Xpetra::EpetraMap failed");
1919 RCP<const Thyra::VectorSpaceBase<Scalar> > thyraEpetraMap = Thyra::create_VectorSpace(Teuchos::rcpFromRef(epetraMap->getEpetra_Map()));
1920 thyraMap = thyraEpetraMap;
1927 static Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
1931 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thMap = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(vec->getMap());
1932 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getGlobalNumElements())!=thMap->dim(), std::logic_error,
"Global dimension of Xpetra map and Thyra VectorSpaceBase are different.");
1933 Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<Scalar> > thSpmdMap = Teuchos::rcp_dynamic_cast<
const Thyra::SpmdVectorSpaceBase<Scalar> >(thMap);
1934 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMap == Teuchos::null, std::logic_error,
"Cannot cast VectorSpaceBase to SpmdVectorSpaceBase.");
1935 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getNodeNumElements())!=thSpmdMap->localSubDim(), std::logic_error,
"Local dimension of Xpetra map and Thyra VectorSpaceBase on one (or more) processor(s) are different.");
1938 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> > thMVec = Thyra::createMembers(thMap, vec->getNumVectors());
1939 Teuchos::RCP< Thyra::SpmdMultiVectorBase<Scalar> > thSpmdMVec = Teuchos::rcp_dynamic_cast<Thyra::SpmdMultiVectorBase<Scalar> >(thMVec);
1940 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMVec == Teuchos::null, std::logic_error,
"Cannot cast MultiVectorBase to SpmdMultiVectorBase.");
1943 const LocalOrdinal localOffset = ( thSpmdMap != Teuchos::null ? thSpmdMap->localOffset() : 0 );
1944 const LocalOrdinal localSubDim = ( thSpmdMap != Teuchos::null ? thSpmdMap->localSubDim() : thMap->dim() );
1945 Teuchos::RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
1946 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thSpmdMVec,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
1949 for(
size_t j = 0; j < Teuchos::as<size_t>(thSpmdMVec->domain()->dim()); ++j) {
1950 Teuchos::ArrayRCP< const Scalar > vecData = vec->getData(j);
1952 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
1953 (*thyData)(i,j) = vecData[i];
1960 static Teuchos::RCP<const Thyra::VectorBase<Scalar> >
1964 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > thMap = Xpetra::ThyraUtils<Scalar,LocalOrdinal,GlobalOrdinal,Node>::toThyra(vec->getMap());
1965 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getGlobalNumElements())!=thMap->dim(), std::logic_error,
"Global dimension of Xpetra map and Thyra VectorSpaceBase are different.");
1966 Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<Scalar> > thSpmdMap = Teuchos::rcp_dynamic_cast<
const Thyra::SpmdVectorSpaceBase<Scalar> >(thMap);
1967 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMap == Teuchos::null, std::logic_error,
"Cannot cast VectorSpaceBase to SpmdVectorSpaceBase.");
1968 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<Teuchos::Ordinal>(vec->getMap()->getNodeNumElements())!=thSpmdMap->localSubDim(), std::logic_error,
"Local dimension of Xpetra map and Thyra VectorSpaceBase on one (or more) processor(s) are different.");
1971 Teuchos::RCP< Thyra::VectorBase<Scalar> > thMVec = Thyra::createMember(thMap);
1972 Teuchos::RCP< Thyra::SpmdVectorBase<Scalar> > thSpmdMVec = Teuchos::rcp_dynamic_cast<Thyra::SpmdVectorBase<Scalar> >(thMVec);
1973 TEUCHOS_TEST_FOR_EXCEPTION(thSpmdMVec == Teuchos::null, std::logic_error,
"Cannot cast VectorBase to SpmdVectorBase.");
1976 const LocalOrdinal localOffset = ( thSpmdMap != Teuchos::null ? thSpmdMap->localOffset() : 0 );
1977 const LocalOrdinal localSubDim = ( thSpmdMap != Teuchos::null ? thSpmdMap->localSubDim() : thMap->dim() );
1978 Teuchos::RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
1979 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thSpmdMVec,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
1982 for(
size_t j = 0; j < Teuchos::as<size_t>(thSpmdMVec->domain()->dim()); ++j) {
1983 Teuchos::ArrayRCP< const Scalar > vecData = vec->getData(j);
1985 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
1986 (*thyData)(i,j) = vecData[i];
1995 using Teuchos::rcp_dynamic_cast;
1997 typedef Thyra::VectorSpaceBase<Scalar> ThyVecSpaceBase;
1998 typedef Thyra::SpmdVectorSpaceBase<Scalar> ThySpmdVecSpaceBase;
1999 typedef Thyra::MultiVectorBase<Scalar> ThyMultVecBase;
2002 typedef Thyra::ProductMultiVectorBase<Scalar> ThyProdMultVecBase;
2005 RCP<ThyProdMultVecBase> prodTarget = rcp_dynamic_cast<ThyProdMultVecBase>(target);
2006 if(prodTarget != Teuchos::null) {
2007 RCP<const BlockedMultiVector> bSourceVec = rcp_dynamic_cast<
const BlockedMultiVector>(source);
2008 if(bSourceVec.is_null() ==
true) {
2012 TEUCHOS_TEST_FOR_EXCEPTION(mapExtractor == Teuchos::null, std::logic_error,
"Found a Thyra product vector, but user did not provide an Xpetra::MapExtractor.");
2013 TEUCHOS_TEST_FOR_EXCEPTION(prodTarget->productSpace()->numBlocks() != as<int>(mapExtractor->NumMaps()), std::logic_error,
"Inconsistent numbers of sub maps in Thyra::ProductVectorSpace and Xpetra::MapExtractor.");
2015 for(
int bbb = 0; bbb < prodTarget->productSpace()->numBlocks(); ++bbb) {
2017 RCP<MultiVector> xpSubBlock = mapExtractor->ExtractVector(source, bbb,
false);
2020 Teuchos::RCP<ThyMultVecBase> thySubBlock = prodTarget->getNonconstMultiVectorBlock(bbb);
2021 RCP<const ThyVecSpaceBase> vs = thySubBlock->range();
2022 RCP<const ThySpmdVecSpaceBase> mpi_vs = rcp_dynamic_cast<
const ThySpmdVecSpaceBase>(vs);
2023 const LocalOrdinal localOffset = ( mpi_vs != Teuchos::null ? mpi_vs->localOffset() : 0 );
2024 const LocalOrdinal localSubDim = ( mpi_vs != Teuchos::null ? mpi_vs->localSubDim() : vs->dim() );
2025 RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
2026 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*thySubBlock,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
2029 for(
size_t j = 0; j < xpSubBlock->getNumVectors(); ++j) {
2030 Teuchos::ArrayRCP< const Scalar > xpData = xpSubBlock->getData(j);
2033 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
2034 (*thyData)(i,j) = xpData[i];
2041 TEUCHOS_TEST_FOR_EXCEPTION(prodTarget->productSpace()->numBlocks() != as<int>(bSourceVec->getBlockedMap()->getNumMaps()), std::logic_error,
"Inconsistent numbers of sub maps in Thyra::ProductVectorSpace and Xpetra::BlockedMultiVector.");
2043 for(
int bbb = 0; bbb < prodTarget->productSpace()->numBlocks(); ++bbb) {
2045 RCP<MultiVector> xpSubBlock = bSourceVec->getMultiVector(bbb,
true);
2047 Teuchos::RCP<const ThyMultVecBase> thyXpSubBlock = toThyraMultiVector(xpSubBlock);
2050 Teuchos::RCP<ThyMultVecBase> thySubBlock = prodTarget->getNonconstMultiVectorBlock(bbb);
2051 Thyra::assign(thySubBlock.ptr(), *thyXpSubBlock);
2060 RCP<const ThySpmdVecSpaceBase> mpi_vs = rcp_dynamic_cast<
const ThySpmdVecSpaceBase>(target->range());
2061 TEUCHOS_TEST_FOR_EXCEPTION(mpi_vs == Teuchos::null, std::logic_error,
"Failed to cast Thyra::VectorSpaceBase to Thyra::SpmdVectorSpaceBase.");
2062 const LocalOrdinal localOffset = ( mpi_vs != Teuchos::null ? mpi_vs->localOffset() : 0 );
2063 const LocalOrdinal localSubDim = ( mpi_vs != Teuchos::null ? mpi_vs->localSubDim() : target->range()->dim() );
2064 RCP<Thyra::DetachedMultiVectorView<Scalar> > thyData =
2065 Teuchos::rcp(
new Thyra::DetachedMultiVectorView<Scalar>(*target,Teuchos::Range1D(localOffset,localOffset+localSubDim-1)));
2068 for(
size_t j = 0; j < source->getNumVectors(); ++j) {
2069 Teuchos::ArrayRCP< const Scalar > xpData = source->getData(j);
2071 for(LocalOrdinal i = 0; i < localSubDim; ++i) {
2072 (*thyData)(i,j) = xpData[i];
2078 static Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
2081 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> > thyraOp = Teuchos::null;
2083 #ifdef HAVE_XPETRA_TPETRA
2085 if(tpetraMat!=Teuchos::null) {
2086 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
2087 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
2090 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpCrsMat));
2091 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpCrsMat = xTpCrsMat->getTpetra_CrsMatrix();
2092 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpCrsMat));
2094 Teuchos::RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpRowMat = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpCrsMat);
2095 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpRowMat));
2096 Teuchos::RCP<const Tpetra::Operator <Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpOperator = Teuchos::rcp_dynamic_cast<
const Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpRowMat);
2097 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpOperator));
2099 thyraOp = Thyra::createConstLinearOp(tpOperator);
2100 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraOp));
2107 #ifdef HAVE_XPETRA_EPETRA
2109 if(epetraMat!=Teuchos::null) {
2111 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpCrsMat));
2112 Teuchos::RCP<const Epetra_CrsMatrix> epCrsMat = xEpCrsMat->getEpetra_CrsMatrix();
2113 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epCrsMat));
2115 Teuchos::RCP<const Thyra::EpetraLinearOp> thyraEpOp = Thyra::epetraLinearOp(epCrsMat,
"op");
2116 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraEpOp));
2117 thyraOp = thyraEpOp;
2123 static Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
2126 Teuchos::RCP<Thyra::LinearOpBase<Scalar> > thyraOp = Teuchos::null;
2128 #ifdef HAVE_XPETRA_TPETRA
2130 if(tpetraMat!=Teuchos::null) {
2131 #if ((defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)) || \
2132 (!defined(EPETRA_HAVE_OMP) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) && defined(HAVE_TPETRA_INST_DOUBLE)))
2135 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xTpCrsMat));
2136 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpCrsMat = xTpCrsMat->getTpetra_CrsMatrixNonConst();
2137 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpCrsMat));
2139 Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpRowMat = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpCrsMat);
2140 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpRowMat));
2141 Teuchos::RCP<Tpetra::Operator <Scalar, LocalOrdinal, GlobalOrdinal, Node> > tpOperator = Teuchos::rcp_dynamic_cast<Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpRowMat);
2142 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpOperator));
2144 thyraOp = Thyra::createLinearOp(tpOperator);
2145 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraOp));
2152 #ifdef HAVE_XPETRA_EPETRA
2154 if(epetraMat!=Teuchos::null) {
2156 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(xEpCrsMat));
2157 Teuchos::RCP<Epetra_CrsMatrix> epCrsMat = xEpCrsMat->getEpetra_CrsMatrixNonConst();
2158 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(epCrsMat));
2160 Teuchos::RCP<Thyra::EpetraLinearOp> thyraEpOp = Thyra::nonconstEpetraLinearOp(epCrsMat,
"op");
2161 TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraEpOp));
2162 thyraOp = thyraEpOp;
2168 static Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
2172 #endif // XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
2174 #endif // HAVE_XPETRA_EPETRA
2178 #define XPETRA_THYRAUTILS_SHORT
2179 #endif // HAVE_XPETRA_THYRA
2181 #endif // XPETRA_THYRAUTILS_HPP
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
Exception throws to report errors in the internal logical of the program.
static Teuchos::RCP< Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > transformThyra2XpetraGIDs(const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &input, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &nonOvlInput, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &nonOvlReferenceInput)
replace set of global ids by new global ids
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
Concrete implementation of Xpetra::Matrix.
static RCP< Xpetra::StridedMap< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
const RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > toXpetraNonConst(const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &map)