10 #ifndef XPETRA_BLOCKEDMULTIVECTOR_DEF_HPP
11 #define XPETRA_BLOCKEDMULTIVECTOR_DEF_HPP
15 #include "Xpetra_MultiVectorFactory.hpp"
16 #include "Xpetra_BlockedVector.hpp"
17 #include "Xpetra_MapExtractor.hpp"
21 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
27 numVectors_ = NumVectors;
29 vv_.reserve(map->getNumMaps());
32 for (
size_t r = 0; r < map->getNumMaps(); ++r)
48 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
49 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
51 Teuchos::RCP<const MultiVector> v) {
54 "BlockedMultiVector: inconsistent number of local elements of MultiVector and BlockedMap. The BlockedMap has "
55 << bmap->getMap()->getLocalNumElements() <<
" local elements. The vector has " << v->getMap()->getLocalNumElements()
59 "BlockedMultiVector: inconsistent number of global elements of MultiVector and BlockedMap. The BlockedMap has "
60 << bmap->getMap()->getGlobalNumElements() <<
" local elements. The vector has " << v->getMap()->getGlobalNumElements()
69 numVectors_ = v->getNumVectors();
74 vv_.reserve(bmap->getNumMaps());
77 for (
size_t r = 0; r < bmap->getNumMaps(); ++r)
78 vv_.push_back(this->ExtractVector(v, r, bmap->getThyraMode()));
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
95 Teuchos::RCP<const MultiVector> v) {
99 std::vector<RCP<const Map>> maps;
100 maps.reserve(mapExtractor->NumMaps());
101 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
102 maps.push_back(mapExtractor->getMap(r, mapExtractor->getThyraMode()));
106 vv_.reserve(mapExtractor->NumMaps());
109 for (
size_t r = 0; r < mapExtractor->NumMaps(); ++r)
110 vv_.push_back(this->ExtractVector(v, r, mapExtractor->getThyraMode()));
113 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
116 std::vector<Teuchos::RCP<MultiVector>>& vin) {
119 vv_.resize(vin.size());
120 for (
size_t i = 0; i < vv_.size(); i++)
124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
127 for (
size_t r = 0; r < vv_.size(); ++r) {
128 vv_[r] = Teuchos::null;
131 map_ = Teuchos::null;
135 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
143 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
149 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
161 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
167 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
171 for (
size_t r = 0; r < map_->getNumMaps(); r++) {
172 getMultiVector(r)->putScalar(value);
176 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
177 Teuchos::RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
180 RCP<Xpetra::BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> ret =
183 for (
size_t r = 0; r < getBlockedMap()->getNumMaps(); r++) {
184 RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> subvec =
185 this->getMultiVector(r, this->getBlockedMap()->getThyraMode())->getVector(j);
186 ret->setMultiVector(r, subvec, this->getBlockedMap()->getThyraMode());
191 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 Teuchos::RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
195 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> ret =
200 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
201 Teuchos::ArrayRCP<const Scalar>
204 if (map_->getNumMaps() == 1) {
208 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
211 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212 Teuchos::ArrayRCP<Scalar>
215 if (map_->getNumMaps() == 1) {
219 TEUCHOS_UNREACHABLE_RETURN(Teuchos::null);
222 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
228 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
234 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
240 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
244 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
245 if (getMultiVector(r) != Teuchos::null) {
246 getMultiVector(r)->scale(alpha);
251 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
253 scale(Teuchos::ArrayView<const Scalar> alpha) {
255 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
256 if (getMultiVector(r) != Teuchos::null) {
257 getMultiVector(r)->scale(alpha);
262 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
266 Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
267 Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpA);
268 TEUCHOS_TEST_FOR_EXCEPTION(numVectors_ != rcpA->getNumVectors(),
270 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector).");
271 if (bA != Teuchos::null) {
274 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() != bA->getBlockedMap()->getThyraMode(),
276 "BlockedMultiVector::update: update with incompatible vector (different thyra mode).");
277 TEUCHOS_TEST_FOR_EXCEPTION(map_->getNumMaps() != bA->getBlockedMap()->getNumMaps(),
279 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors).");
280 for (
size_t r = 0; r < map_->getNumMaps(); r++) {
281 XPETRA_TEST_FOR_EXCEPTION(getMultiVector(r)->getMap()->getLocalNumElements() != bA->getMultiVector(r)->getMap()->getLocalNumElements(),
283 "BlockedMultiVector::update: in subvector "
284 << r <<
": Cannot add a vector of (local) length " << bA->getMultiVector(r)->getMap()->getLocalNumElements()
285 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getLocalNumElements() <<
" entries.");
286 XPETRA_TEST_FOR_EXCEPTION(getMultiVector(r)->getMap()->getGlobalNumElements() != bA->getMultiVector(r)->getMap()->getGlobalNumElements(),
288 "BlockedMultiVector::update: in subvector "
289 << r <<
": Cannot add a vector of length " << bA->getMultiVector(r)->getMap()->getGlobalNumElements()
290 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getGlobalNumElements() <<
" entries.");
298 Teuchos::RCP<MultiVector> lmv = getMultiVector(r);
299 Teuchos::RCP<MultiVector> rmv = bA->getMultiVector(r);
302 Teuchos::RCP<BlockedMultiVector> blmv = Teuchos::rcp_dynamic_cast<
BlockedMultiVector>(lmv);
303 Teuchos::RCP<BlockedMultiVector> brmv = Teuchos::rcp_dynamic_cast<
BlockedMultiVector>(rmv);
305 if (blmv.is_null() ==
true && brmv.is_null() ==
false) {
307 TEUCHOS_TEST_FOR_EXCEPTION(brmv->getBlockedMap()->getNumMaps() > 1,
309 "BlockedMultiVector::update: Standard MultiVector object does not accept BlockedMultVector object as "
310 "parameter in update call.");
311 lmv->
update(alpha, *(brmv->getMultiVector(0)), beta);
313 lmv->update(alpha, *rmv, beta);
320 if (getBlockedMap()->getNumMaps() == 1) {
324 getMultiVector(0)->getMap()->isSameAs(*(rcpA->getMap())) ==
false,
326 "BlockedMultiVector::update: update with incompatible vector (maps of full vector do not match with map in MapExtractor).");
327 getMultiVector(0)->update(alpha, *rcpA, beta);
333 for (
size_t r = 0; r < map_->getNumMaps(); r++) {
336 Teuchos::RCP<const MultiVector> part = this->ExtractVector(rcpA, r, map_->getThyraMode());
339 "BlockedMultiVector::update: in subvector "
340 << r <<
": Cannot add a vector of (local) length " << part->getMap()->getLocalNumElements()
341 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getLocalNumElements() <<
" entries.");
344 "BlockedMultiVector::update: in subvector "
345 << r <<
": Cannot add a vector of length " << part->getMap()->getGlobalNumElements()
346 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getGlobalNumElements() <<
" entries.");
347 getMultiVector(r)->update(alpha, *part, beta);
353 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
357 Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
358 Teuchos::RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
359 Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpA);
360 Teuchos::RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
361 if (bA != Teuchos::null && bB != Teuchos::null) {
362 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() != bA->getBlockedMap()->getThyraMode(),
364 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector A).");
365 TEUCHOS_TEST_FOR_EXCEPTION(map_->getNumMaps() != bA->getBlockedMap()->getNumMaps(),
367 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector A).");
368 TEUCHOS_TEST_FOR_EXCEPTION(
369 numVectors_ != bA->getNumVectors(),
371 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector A).");
372 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() != bB->getBlockedMap()->getThyraMode(),
374 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector B).");
375 TEUCHOS_TEST_FOR_EXCEPTION(map_->getNumMaps() != bB->getBlockedMap()->getNumMaps(),
377 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector B).");
378 TEUCHOS_TEST_FOR_EXCEPTION(
379 numVectors_ != bB->getNumVectors(),
381 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector B).");
383 for (
size_t r = 0; r < map_->getNumMaps(); r++) {
386 "BlockedMultiVector::update: update with incompatible vector (different maps in partial vector " << r <<
").");
387 getMultiVector(r)->update(alpha, *(bA->getMultiVector(r)), beta, *(bB->getMultiVector(r)), gamma);
394 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
396 norm1(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms)
const {
398 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
399 Array<Magnitude> temp_norms(getNumVectors());
400 std::fill(norms.begin(), norms.end(), ScalarTraits<Magnitude>::zero());
401 std::fill(temp_norms.begin(), temp_norms.end(), ScalarTraits<Magnitude>::zero());
402 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
403 if (getMultiVector(r) != Teuchos::null) {
404 getMultiVector(r)->norm1(temp_norms);
405 for (
size_t c = 0; c < getNumVectors(); ++c)
406 norms[c] += temp_norms[c];
411 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
413 norm2(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms)
const {
415 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
416 Array<Magnitude> results(getNumVectors());
417 Array<Magnitude> temp_norms(getNumVectors());
418 std::fill(norms.begin(), norms.end(), ScalarTraits<Magnitude>::zero());
419 std::fill(results.begin(), results.end(), ScalarTraits<Magnitude>::zero());
420 std::fill(temp_norms.begin(), temp_norms.end(), ScalarTraits<Magnitude>::zero());
421 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
422 if (getMultiVector(r) != Teuchos::null) {
423 getMultiVector(r)->norm2(temp_norms);
424 for (
size_t c = 0; c < getNumVectors(); ++c)
425 results[c] += temp_norms[c] * temp_norms[c];
428 for (
size_t c = 0; c < getNumVectors(); ++c)
429 norms[c] = Teuchos::ScalarTraits<Magnitude>::squareroot(results[c]);
432 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
434 normInf(
const Teuchos::ArrayView<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType>& norms)
const {
436 typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
437 Array<Magnitude> temp_norms(getNumVectors());
438 std::fill(norms.begin(), norms.end(), ScalarTraits<Magnitude>::zero());
439 std::fill(temp_norms.begin(), temp_norms.end(), ScalarTraits<Magnitude>::zero());
440 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
441 if (getMultiVector(r) != Teuchos::null) {
442 getMultiVector(r)->normInf(temp_norms);
443 for (
size_t c = 0; c < getNumVectors(); ++c)
444 norms[c] = std::max(norms[c], temp_norms[c]);
449 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
455 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
466 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
475 "BlockedMultiVector::elementWiseMultipy: B must have same blocked map than this.");
478 TEUCHOS_TEST_FOR_EXCEPTION(A.
getMap()->getLocalNumElements() != B.
getMap()->getLocalNumElements(),
480 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getLocalNumElements() <<
" elements, B has "
481 << B.
getMap()->getLocalNumElements() <<
".");
482 TEUCHOS_TEST_FOR_EXCEPTION(A.
getMap()->getGlobalNumElements() != B.
getMap()->getGlobalNumElements(),
484 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getGlobalNumElements() <<
" elements, B has "
485 << B.
getMap()->getGlobalNumElements() <<
".");
487 RCP<const BlockedMap> bmap = getBlockedMap();
488 RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rcpA = Teuchos::rcpFromRef(A);
489 RCP<const Xpetra::BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> bA =
492 RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
493 RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
494 TEUCHOS_TEST_FOR_EXCEPTION(
500 for (
size_t m = 0; m < bmap->getNumMaps(); m++) {
501 RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> partA = bA->
getMultiVector(m, bmap->getThyraMode())->getVector(0);
502 RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> partB = bB->getMultiVector(m, bmap->getThyraMode());
503 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> thisPart = this->getMultiVector(m, bmap->getThyraMode());
505 thisPart->elementWiseMultiply(scalarAB, *partA, *partB, scalarThis);
509 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
516 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
521 return map_->getFullMap()->getLocalNumElements();
524 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
529 return map_->getFullMap()->getGlobalNumElements();
532 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
538 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
539 RCP<const MultiVector> a = getMultiVector(r);
541 if ((a == Teuchos::null && b != Teuchos::null) || (a != Teuchos::null && b == Teuchos::null))
543 if (a != Teuchos::null && b != Teuchos::null && !a->isSameSize(*b))
549 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
553 return std::string(
"BlockedMultiVector");
556 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
558 describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const {
559 out << description() << std::endl;
560 for (
size_t r = 0; r < map_->getNumMaps(); r++)
561 getMultiVector(r)->
describe(out, verbLevel);
564 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
568 RCP<const BlockedMap> bmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map);
569 if (bmap.is_null() ==
true) {
571 if (this->getBlockedMap()->getNumMaps() > 1) {
573 "BlockedMultiVector::replaceMap: map is not of type BlockedMap. General implementation not available, yet.");
574 TEUCHOS_UNREACHABLE_RETURN();
578 std::vector<Teuchos::RCP<const Map>> subMaps(1, map);
579 map_ = Teuchos::rcp(
new BlockedMap(map, subMaps, this->getBlockedMap()->getThyraMode()));
580 this->getMultiVector(0)->replaceMap(map);
583 RCP<const BlockedMap> mybmap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(map_);
588 for (
size_t r = 0; r < map_->getNumMaps(); r++)
589 getMultiVector(r)->replaceMap(bmap->getMap(r, map_->getThyraMode()));
592 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
600 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
608 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
616 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
624 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
627 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
628 getMultiVector(r)->
setSeed(seed);
632 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
635 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
636 getMultiVector(r)->
randomize(bUseXpetraImplementation);
640 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
642 randomize(
const Scalar& minVal,
const Scalar& maxVal,
bool bUseXpetraImplementation) {
643 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
644 getMultiVector(r)->
randomize(minVal, maxVal, bUseXpetraImplementation);
648 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
654 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
660 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
661 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
668 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
669 Teuchos::RCP<const Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>
676 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
677 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
681 TEUCHOS_TEST_FOR_EXCEPTION(r > map_->getNumMaps(),
683 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps()
684 <<
" partial blocks.");
688 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
689 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
692 XPETRA_MONITOR(
"BlockedMultiVector::getMultiVector(r,bThyraMode)");
693 TEUCHOS_TEST_FOR_EXCEPTION(r > map_->getNumMaps(),
695 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps()
696 <<
" partial blocks.");
703 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
715 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps() <<
" partial blocks.");
718 "The BlockedMultiVectors expects " << getNumVectors() <<
" vectors. The provided partial multivector has "
719 << v->getNumVectors() <<
" vectors.");
723 Teuchos::RCP<MultiVector> vv = Teuchos::rcp_const_cast<
MultiVector>(v);
724 TEUCHOS_TEST_FOR_EXCEPTION(vv == Teuchos::null, Xpetra::Exceptions::RuntimeError,
"Partial vector must not be Teuchos::null");
728 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
729 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
736 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
737 RCP<MultiVector> vi = getMultiVector(r);
739 if (bvi.is_null() ==
true) {
740 this->InsertVector(vi, r, v, map_->getThyraMode());
742 RCP<MultiVector> mvi = bvi->
Merge();
743 this->InsertVector(mvi, r, v, map_->getThyraMode());
752 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
755 Teuchos::RCP<const MultiVector> rcpRhs = Teuchos::rcpFromRef(rhs);
756 Teuchos::RCP<const BlockedMultiVector> bRhs = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpRhs);
757 if (bRhs == Teuchos::null)
760 map_ = Teuchos::rcp(
new BlockedMap(*(bRhs->getBlockedMap())));
761 vv_ = std::vector<Teuchos::RCP<MultiVector>>(map_->getNumMaps());
762 for (
size_t r = 0; r < map_->getNumMaps(); ++r) {
764 RCP<MultiVector> src = bRhs->getMultiVector(r, map_->getThyraMode());
768 map_->getMap(r, bRhs->getBlockedMap()->getThyraMode()), rcpRhs->getNumVectors(),
true);
773 if (bsrc.is_null() ==
true && bvv.is_null() ==
true) {
775 }
else if (bsrc.is_null() ==
true && bvv.is_null() ==
false) {
778 }
else if (bsrc.is_null() ==
false && bvv.is_null() ==
true) {
781 if (bsrc->getBlockedMap()->getNumMaps() > 1) {
783 "BlockedMultiVector::assign: source vector is of type BlockedMultiVector (with more than "
784 "1 blocks) and target is a MultiVector.");
785 TEUCHOS_UNREACHABLE_RETURN();
787 RCP<MultiVector> ssrc = bsrc->getMultiVector(0, map_->getThyraMode());
791 "BlockedMultiVector::assign: sub block must not be of type BlockedMultiVector.");
797 "BlockedMultiVector::assign: source and target are BlockedMultiVectors with a different number of submaps.");
802 numVectors_ = rcpRhs->getNumVectors();
805 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
810 ExtractVector(*full, block, *partial);
813 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
814 void BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
818 ExtractVector(*full, block, *partial);
821 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
822 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
823 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
826 bool bThyraMode)
const {
829 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
830 <<
" partial blocks.");
833 RCP<const BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(full);
834 if (bfull.is_null() ==
true) {
837 const RCP<MultiVector> vv =
843 RCP<const Map> oldThyMapFull = full->getMap();
844 RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<MultiVector>(full);
845 rcpNonConstFull->replaceMap(map_->getImporter(block)->getSourceMap());
846 ExtractVector(*rcpNonConstFull, block, *vv);
847 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
848 Xpetra::Exceptions::RuntimeError,
849 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
850 "created using Thyra-style numbered submaps.");
851 if (bThyraMode ==
true)
852 vv->replaceMap(map_->getMap(block,
true));
853 rcpNonConstFull->replaceMap(oldThyMapFull);
859 Xpetra::Exceptions::RuntimeError,
860 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
861 << bfull->getBlockedMap()->getNumMaps()
862 <<
" (number of blocks in BlockedMultiVector)");
863 return bfull->getMultiVector(block, bThyraMode);
867 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
868 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
869 BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
872 bool bThyraMode)
const {
875 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
876 <<
" partial blocks.");
878 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: map_->getmap(" << block <<
",false) is null");
879 RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
880 if (bfull.is_null() ==
true) {
883 const RCP<MultiVector> vv =
889 RCP<const Map> oldThyMapFull = full->getMap();
890 full->replaceMap(map_->getImporter(block)->getSourceMap());
891 ExtractVector(*full, block, *vv);
892 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
893 Xpetra::Exceptions::RuntimeError,
894 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
895 "created using Thyra-style numbered submaps.");
896 if (bThyraMode ==
true)
897 vv->replaceMap(map_->getMap(block,
true));
898 full->replaceMap(oldThyMapFull);
904 Xpetra::Exceptions::RuntimeError,
905 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
906 << bfull->getBlockedMap()->getNumMaps()
907 <<
" (number of blocks in BlockedMultiVector)");
908 return bfull->getMultiVector(block, bThyraMode);
912 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
913 void BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
919 "ExtractVector: Error, block = " << block <<
" is too big. The BlockedMultiVector only contains " << map_->getNumMaps()
920 <<
" partial blocks.");
921 XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: maps_[" << block <<
"] is null");
925 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
930 bool bThyraMode)
const {
933 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
934 <<
" partial blocks.");
936 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: map_->getmap(" << block <<
",false) is null");
938 Xpetra::Exceptions::RuntimeError,
939 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
940 "using Thyra-style numbered submaps.");
949 RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
950 RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<
MultiVector>(rcpPartial);
951 RCP<const Map> oldThyMapPartial = rcpNonConstPartial->
getMap();
952 RCP<const Map> oldThyMapFull = full.
getMap();
965 rcpNonConstPartial->replaceMap(map_->getMap(block,
false));
966 full.
replaceMap(map_->getImporter(block)->getSourceMap());
973 rcpNonConstPartial->replaceMap(oldThyMapPartial);
980 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
985 bool bThyraMode)
const {
986 RCP<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> bfull =
988 if (bfull.is_null() ==
true)
989 InsertVector(*partial, block, *full, bThyraMode);
991 XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: maps_[" << block <<
"] is null");
996 full->setMultiVector(block, partial, bThyraMode);
998 throw Xpetra::Exceptions::RuntimeError(
"MultiVector::setMultiVector() is not implemented.");
1003 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1004 void BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1008 bool bThyraMode)
const {
1009 RCP<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> bfull =
1011 if (bfull.is_null() ==
true)
1012 InsertVector(*partial, block, *full, bThyraMode);
1014 XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: maps_[" << block <<
"] is null");
1015 bfull->setMultiVector(block, partial, bThyraMode);
1021 #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.
Factory for any type of Xpetra::MultiVector and its derived classes.
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 Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
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 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.