47 #ifndef XPETRA_BLOCKEDMULTIVECTOR_DEF_HPP
48 #define XPETRA_BLOCKEDMULTIVECTOR_DEF_HPP
52 #include "Xpetra_MultiVectorFactory.hpp"
53 #include "Xpetra_BlockedVector.hpp"
54 #include "Xpetra_MapExtractor.hpp"
60 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 numVectors_ = NumVectors;
69 vv_.reserve(map->getNumMaps());
72 for(
size_t r = 0; r < map->getNumMaps(); ++r)
89 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
92 Teuchos::RCP<const MultiVector> v)
96 "BlockedMultiVector: inconsistent number of local elements of MultiVector and BlockedMap. The BlockedMap has "
97 << bmap->getMap()->getNodeNumElements() <<
" local elements. The vector has " << v->getMap()->getNodeNumElements()
101 "BlockedMultiVector: inconsistent number of global elements of MultiVector and BlockedMap. The BlockedMap has "
102 << bmap->getMap()->getGlobalNumElements() <<
" local elements. The vector has " << v->getMap()->getGlobalNumElements()
111 numVectors_ = v->getNumVectors();
116 vv_.reserve(bmap->getNumMaps());
119 for(
size_t r = 0; r < bmap->getNumMaps(); ++r)
120 vv_.push_back(this->ExtractVector(v, r, bmap->getThyraMode()));
135 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
138 Teuchos::RCP<const MultiVector> v)
140 numVectors_ = v->getNumVectors();
143 std::vector<RCP<const Map>> maps;
144 maps.reserve(mapExtractor->NumMaps());
145 for(
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
146 maps.push_back(mapExtractor->getMap(r, mapExtractor->getThyraMode()));
150 vv_.reserve(mapExtractor->NumMaps());
153 for(
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
154 vv_.push_back(this->ExtractVector(v, r, mapExtractor->getThyraMode()));
158 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
161 std::vector<Teuchos::RCP<MultiVector>>& vin)
165 vv_.resize(vin.size());
166 for(
size_t i = 0; i < vv_.size(); i++)
171 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
172 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
173 ~BlockedMultiVector()
175 for(
size_t r = 0; r < vv_.size(); ++r)
177 vv_[ r ] = Teuchos::null;
180 map_ = Teuchos::null;
185 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
195 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
204 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
221 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
231 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
237 for(
size_t r = 0; r < map_->getNumMaps(); r++)
239 getMultiVector(r)->putScalar(value);
244 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
245 Teuchos::RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
249 RCP<Xpetra::BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> ret =
252 for(
size_t r = 0; r < getBlockedMap()->getNumMaps(); r++)
254 RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> subvec =
255 this->getMultiVector(r, this->getBlockedMap()->getThyraMode())->getVector(j);
256 ret->setMultiVector(r, subvec, this->getBlockedMap()->getThyraMode());
262 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
263 Teuchos::RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
267 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> ret =
273 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
274 Teuchos::ArrayRCP<const Scalar>
278 if(map_->getNumMaps() == 1)
283 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
287 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
288 Teuchos::ArrayRCP<Scalar>
292 if(map_->getNumMaps() == 1)
297 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
301 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
310 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
319 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
328 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
334 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
336 if(getMultiVector(r) != Teuchos::null)
338 getMultiVector(r)->scale(alpha);
344 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
347 scale(Teuchos::ArrayView<const Scalar> alpha)
350 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
352 if(getMultiVector(r) != Teuchos::null)
354 getMultiVector(r)->scale(alpha);
360 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
366 Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
367 Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpA);
368 TEUCHOS_TEST_FOR_EXCEPTION(numVectors_ != rcpA->getNumVectors(),
370 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector).");
371 if(bA != Teuchos::null)
375 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() != bA->getBlockedMap()->getThyraMode(),
377 "BlockedMultiVector::update: update with incompatible vector (different thyra mode).");
378 TEUCHOS_TEST_FOR_EXCEPTION(map_->getNumMaps() != bA->getBlockedMap()->getNumMaps(),
380 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors).");
381 for(
size_t r = 0; r < map_->getNumMaps(); r++)
384 XPETRA_TEST_FOR_EXCEPTION(getMultiVector(r)->getMap()->getNodeNumElements() != bA->getMultiVector(r)->getMap()->getNodeNumElements(),
386 "BlockedMultiVector::update: in subvector "
387 << r <<
": Cannot add a vector of (local) length " << bA->getMultiVector(r)->getMap()->getNodeNumElements()
388 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getNodeNumElements() <<
" entries.");
389 XPETRA_TEST_FOR_EXCEPTION(getMultiVector(r)->getMap()->getGlobalNumElements() != bA->getMultiVector(r)->getMap()->getGlobalNumElements(),
391 "BlockedMultiVector::update: in subvector "
392 << r <<
": Cannot add a vector of length " << bA->getMultiVector(r)->getMap()->getGlobalNumElements()
393 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getGlobalNumElements() <<
" entries.");
401 Teuchos::RCP<MultiVector> lmv = getMultiVector(r);
402 Teuchos::RCP<MultiVector> rmv = bA->getMultiVector(r);
405 Teuchos::RCP<BlockedMultiVector> blmv = Teuchos::rcp_dynamic_cast<
BlockedMultiVector>(lmv);
406 Teuchos::RCP<BlockedMultiVector> brmv = Teuchos::rcp_dynamic_cast<
BlockedMultiVector>(rmv);
408 if(blmv.is_null() ==
true && brmv.is_null() ==
false)
411 TEUCHOS_TEST_FOR_EXCEPTION(brmv->getBlockedMap()->getNumMaps() > 1,
413 "BlockedMultiVector::update: Standard MultiVector object does not accept BlockedMultVector object as "
414 "parameter in update call.");
415 lmv->
update(alpha, *(brmv->getMultiVector(0)), beta);
418 lmv->update(alpha, *rmv, beta);
427 if(getBlockedMap()->getNumMaps() == 1)
432 getMultiVector(0)->getMap()->isSameAs(*(rcpA->getMap())) ==
false,
434 "BlockedMultiVector::update: update with incompatible vector (maps of full vector do not match with map in MapExtractor).");
435 getMultiVector(0)->update(alpha, *rcpA, beta);
443 for(
size_t r = 0; r < map_->getNumMaps(); r++)
447 Teuchos::RCP<const MultiVector> part = this->ExtractVector(rcpA, r, map_->getThyraMode());
450 "BlockedMultiVector::update: in subvector "
451 << r <<
": Cannot add a vector of (local) length " << part->getMap()->getNodeNumElements()
452 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getNodeNumElements() <<
" entries.");
455 "BlockedMultiVector::update: in subvector "
456 << r <<
": Cannot add a vector of length " << part->getMap()->getGlobalNumElements()
457 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getGlobalNumElements() <<
" entries.");
458 getMultiVector(r)->update(alpha, *part, beta);
465 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
471 Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
472 Teuchos::RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
473 Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpA);
474 Teuchos::RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
475 if(bA != Teuchos::null && bB != Teuchos::null)
477 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() != bA->getBlockedMap()->getThyraMode(),
479 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector A).");
480 TEUCHOS_TEST_FOR_EXCEPTION(map_->getNumMaps() != bA->getBlockedMap()->getNumMaps(),
482 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector A).");
483 TEUCHOS_TEST_FOR_EXCEPTION(
484 numVectors_ != bA->getNumVectors(),
486 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector A).");
487 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() != bB->getBlockedMap()->getThyraMode(),
489 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector B).");
490 TEUCHOS_TEST_FOR_EXCEPTION(map_->getNumMaps() != bB->getBlockedMap()->getNumMaps(),
492 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector B).");
493 TEUCHOS_TEST_FOR_EXCEPTION(
494 numVectors_ != bB->getNumVectors(),
496 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector B).");
498 for(
size_t r = 0; r < map_->getNumMaps(); r++)
502 "BlockedMultiVector::update: update with incompatible vector (different maps in partial vector " << r <<
").");
503 getMultiVector(r)->update(alpha, *(bA->getMultiVector(r)), beta, *(bB->getMultiVector(r)), gamma);
511 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
514 norm1(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms)
const
517 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
518 Array<Magnitude> temp_norms(getNumVectors());
519 std::fill(norms.begin(), norms.end(), ScalarTraits<Magnitude>::zero());
520 std::fill(temp_norms.begin(), temp_norms.end(), ScalarTraits<Magnitude>::zero());
521 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
523 if(getMultiVector(r) != Teuchos::null)
525 getMultiVector(r)->norm1(temp_norms);
526 for(
size_t c = 0; c < getNumVectors(); ++c)
527 norms[ c ] += temp_norms[ c ];
534 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
537 norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms)
const
540 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
541 Array<Magnitude> results(getNumVectors());
542 Array<Magnitude> temp_norms(getNumVectors());
543 std::fill(norms.begin(), norms.end(), ScalarTraits<Magnitude>::zero());
544 std::fill(results.begin(), results.end(), ScalarTraits<Magnitude>::zero());
545 std::fill(temp_norms.begin(), temp_norms.end(), ScalarTraits<Magnitude>::zero());
546 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
548 if(getMultiVector(r) != Teuchos::null)
550 getMultiVector(r)->norm2(temp_norms);
551 for(
size_t c = 0; c < getNumVectors(); ++c)
552 results[ c ] += temp_norms[ c ] * temp_norms[ c ];
555 for(
size_t c = 0; c < getNumVectors(); ++c)
556 norms[ c ] = Teuchos::ScalarTraits<Magnitude>::squareroot(results[ c ]);
560 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
563 normInf(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms)
const
566 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
567 Array<Magnitude> temp_norms(getNumVectors());
568 std::fill(norms.begin(), norms.end(), ScalarTraits<Magnitude>::zero());
569 std::fill(temp_norms.begin(), temp_norms.end(), ScalarTraits<Magnitude>::zero());
570 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
572 if(getMultiVector(r) != Teuchos::null)
574 getMultiVector(r)->normInf(temp_norms);
575 for(
size_t c = 0; c < getNumVectors(); ++c)
576 norms[ c ] = std::max(norms[ c ], temp_norms[ c ]);
582 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
591 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
605 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
616 "BlockedMultiVector::elementWiseMultipy: B must have same blocked map than this.");
619 TEUCHOS_TEST_FOR_EXCEPTION(A.
getMap()->getNodeNumElements() != B.
getMap()->getNodeNumElements(),
621 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getNodeNumElements() <<
" elements, B has "
622 << B.
getMap()->getNodeNumElements() <<
".");
623 TEUCHOS_TEST_FOR_EXCEPTION(A.
getMap()->getGlobalNumElements() != B.
getMap()->getGlobalNumElements(),
625 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getGlobalNumElements() <<
" elements, B has "
626 << B.
getMap()->getGlobalNumElements() <<
".");
628 RCP<const BlockedMap> bmap = getBlockedMap();
629 RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rcpA = Teuchos::rcpFromRef(A);
630 RCP<const Xpetra::BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> bA =
633 RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
634 RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
635 TEUCHOS_TEST_FOR_EXCEPTION(
641 for(
size_t m = 0; m < bmap->getNumMaps(); m++)
643 RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> partA = bA->
getMultiVector(m, bmap->getThyraMode())->getVector(0);
644 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> partB = bB->getMultiVector(m, bmap->getThyraMode());
645 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> thisPart = this->getMultiVector(m, bmap->getThyraMode());
647 thisPart->elementWiseMultiply(scalarAB, *partA, *partB, scalarThis);
653 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
662 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
668 return map_->getFullMap()->getNodeNumElements();
672 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
678 return map_->getFullMap()->getGlobalNumElements();
682 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
690 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
692 RCP<const MultiVector> a = getMultiVector(r);
694 if((a == Teuchos::null && b != Teuchos::null) || (a != Teuchos::null && b == Teuchos::null))
696 if(a != Teuchos::null && b != Teuchos::null && !a->isSameSize(*b))
703 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
708 return std::string(
"BlockedMultiVector");
712 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
715 describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
717 out << description() << std::endl;
718 for(
size_t r = 0; r < map_->getNumMaps(); r++)
719 getMultiVector(r)->
describe(out, verbLevel);
723 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
729 RCP<const BlockedMap> bmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map);
730 if(bmap.is_null() ==
true)
733 if(this->getBlockedMap()->getNumMaps() > 1)
736 "BlockedMultiVector::replaceMap: map is not of type BlockedMap. General implementation not available, yet.");
737 TEUCHOS_UNREACHABLE_RETURN();
741 std::vector<Teuchos::RCP<const Map>> subMaps(1, map);
742 map_ = Teuchos::rcp(
new BlockedMap(map, subMaps, this->getBlockedMap()->getThyraMode()));
743 this->getMultiVector(0)->replaceMap(map);
746 RCP<const BlockedMap> mybmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map_);
751 for(
size_t r = 0; r < map_->getNumMaps(); r++)
752 getMultiVector(r)->replaceMap(bmap->getMap(r, map_->getThyraMode()));
756 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
767 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
778 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
789 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
800 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
805 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
807 getMultiVector(r)->
setSeed(seed);
812 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
817 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
819 getMultiVector(r)->
randomize(bUseXpetraImplementation);
824 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
833 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
834 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
843 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
844 Teuchos::RCP<const Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>
853 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
854 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
859 TEUCHOS_TEST_FOR_EXCEPTION(r > map_->getNumMaps(),
861 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps()
862 <<
" partial blocks.");
867 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
868 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
872 XPETRA_MONITOR(
"BlockedMultiVector::getMultiVector(r,bThyraMode)");
873 TEUCHOS_TEST_FOR_EXCEPTION(r > map_->getNumMaps(),
875 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps()
876 <<
" partial blocks.");
884 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
898 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps() <<
" partial blocks.");
901 "The BlockedMultiVectors expects " << getNumVectors() <<
" vectors. The provided partial multivector has "
902 << v->getNumVectors() <<
" vectors.");
906 Teuchos::RCP<MultiVector> vv = Teuchos::rcp_const_cast<
MultiVector>(v);
907 TEUCHOS_TEST_FOR_EXCEPTION(vv == Teuchos::null, Xpetra::Exceptions::RuntimeError,
"Partial vector must not be Teuchos::null");
912 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
913 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
921 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
923 RCP<MultiVector> vi = getMultiVector(r);
925 if(bvi.is_null() ==
true)
927 this->InsertVector(vi, r, v, map_->getThyraMode());
931 RCP<MultiVector> mvi = bvi->
Merge();
932 this->InsertVector(mvi, r, v, map_->getThyraMode());
942 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
947 Teuchos::RCP<const MultiVector> rcpRhs = Teuchos::rcpFromRef(rhs);
948 Teuchos::RCP<const BlockedMultiVector> bRhs = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpRhs);
949 if(bRhs == Teuchos::null)
952 map_ = Teuchos::rcp(
new BlockedMap(*(bRhs->getBlockedMap())));
953 vv_ = std::vector<Teuchos::RCP<MultiVector>>(map_->getNumMaps());
954 for(
size_t r = 0; r < map_->getNumMaps(); ++r)
957 RCP<MultiVector> src = bRhs->getMultiVector(r, map_->getThyraMode());
961 map_->getMap(r, bRhs->getBlockedMap()->getThyraMode()), rcpRhs->getNumVectors(),
true);
966 if(bsrc.is_null() ==
true && bvv.is_null() ==
true)
970 else if(bsrc.is_null() ==
true && bvv.is_null() ==
false)
975 else if(bsrc.is_null() ==
false && bvv.is_null() ==
true)
979 if(bsrc->getBlockedMap()->getNumMaps() > 1)
982 "1 blocks) and target is a MultiVector.");
983 TEUCHOS_UNREACHABLE_RETURN();
985 RCP<MultiVector> ssrc = bsrc->getMultiVector(0, map_->getThyraMode());
989 "BlockedMultiVector::assign: sub block must not be of type BlockedMultiVector.");
997 "BlockedMultiVector::assign: source and target are BlockedMultiVectors with a different number of submaps.");
1002 numVectors_ = rcpRhs->getNumVectors();
1006 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1013 ExtractVector(*full, block, *partial);
1017 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1019 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1024 ExtractVector(*full, block, *partial);
1028 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1029 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1030 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1033 bool bThyraMode)
const
1037 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
1038 <<
" partial blocks.");
1041 RCP<const BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(full);
1042 if(bfull.is_null() ==
true)
1046 const RCP<MultiVector> vv =
1052 RCP<const Map> oldThyMapFull = full->getMap();
1053 RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<MultiVector>(full);
1054 rcpNonConstFull->replaceMap(map_->getImporter(block)->getSourceMap());
1055 ExtractVector(*rcpNonConstFull, block, *vv);
1056 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
1057 Xpetra::Exceptions::RuntimeError,
1058 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
1059 "created using Thyra-style numbered submaps.");
1060 if(bThyraMode ==
true)
1061 vv->replaceMap(map_->getMap(block,
true));
1062 rcpNonConstFull->replaceMap(oldThyMapFull);
1070 Xpetra::Exceptions::RuntimeError,
1071 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
1072 << bfull->getBlockedMap()->getNumMaps()
1073 <<
" (number of blocks in BlockedMultiVector)");
1074 return bfull->getMultiVector(block, bThyraMode);
1079 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1080 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
1081 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1084 bool bThyraMode)
const
1088 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
1089 <<
" partial blocks.");
1091 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: map_->getmap(" << block <<
",false) is null");
1092 RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
1093 if(bfull.is_null() ==
true)
1097 const RCP<MultiVector> vv =
1103 RCP<const Map> oldThyMapFull = full->getMap();
1104 full->replaceMap(map_->getImporter(block)->getSourceMap());
1105 ExtractVector(*full, block, *vv);
1106 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
1107 Xpetra::Exceptions::RuntimeError,
1108 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
1109 "created using Thyra-style numbered submaps.");
1110 if(bThyraMode ==
true)
1111 vv->replaceMap(map_->getMap(block,
true));
1112 full->replaceMap(oldThyMapFull);
1120 Xpetra::Exceptions::RuntimeError,
1121 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
1122 << bfull->getBlockedMap()->getNumMaps()
1123 <<
" (number of blocks in BlockedMultiVector)");
1124 return bfull->getMultiVector(block, bThyraMode);
1129 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1131 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1138 "ExtractVector: Error, block = " << block <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps()
1139 <<
" partial blocks.");
1140 XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: maps_[" << block <<
"] is null");
1145 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1151 bool bThyraMode)
const
1155 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
1156 <<
" partial blocks.");
1158 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: map_->getmap(" << block <<
",false) is null");
1160 Xpetra::Exceptions::RuntimeError,
1161 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
1162 "using Thyra-style numbered submaps.");
1172 RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
1173 RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<
MultiVector>(rcpPartial);
1174 RCP<const Map> oldThyMapPartial = rcpNonConstPartial->
getMap();
1175 RCP<const Map> oldThyMapFull = full.
getMap();
1188 rcpNonConstPartial->replaceMap(map_->getMap(block,
false));
1189 full.
replaceMap(map_->getImporter(block)->getSourceMap());
1196 rcpNonConstPartial->replaceMap(oldThyMapPartial);
1206 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1212 bool bThyraMode)
const
1214 RCP<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> bfull =
1216 if(bfull.is_null() ==
true)
1217 InsertVector(*partial, block, *full, bThyraMode);
1220 XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: maps_[" << block <<
"] is null");
1225 full->setMultiVector(block, partial, bThyraMode);
1227 throw Xpetra::Exceptions::RuntimeError(
"MultiVector::setMultiVector() is not implemented.");
1233 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1235 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1239 bool bThyraMode)
const
1241 RCP<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> bfull =
1243 if(bfull.is_null() ==
true)
1244 InsertVector(*partial, block, *full, bThyraMode);
1247 XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: maps_[" << block <<
"] is null");
1248 bfull->setMultiVector(block, partial, bThyraMode);
1256 #endif // XPETRA_BLOCKEDMULTIVECTOR_DEF_HPP
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map)=0
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)=0
Export data into this object using an Export object ("forward mode").
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.
BlockedMultiVector(const Teuchos::RCP< const BlockedMap > &map, size_t NumVectors, bool zeroOut=true)
Constructor.
Exception throws to report errors in the internal logical of the program.
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
virtual void update(const Scalar &alpha, const MultiVector &A, const Scalar &beta)
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)=0
Import data into this object using an Import object ("forward mode").
Teuchos::RCP< MultiVector > Merge() const
merge BlockedMultiVector blocks to a single MultiVector
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
virtual void setSeed(unsigned int seed)
Set seed for Random function.
size_t global_size_t
Global size_t object.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
return partial multivector associated with block row r
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual size_t getNumVectors() const
Number of columns in the multivector.
CombineMode
Xpetra::Combine Mode enumerable type.
#define XPETRA_MONITOR(funcName)
virtual void randomize(bool bUseXpetraImplementation=false)
Set multi-vector values to random numbers.