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"
60template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 vv_.reserve(map->getNumMaps());
72 for(
size_t r = 0; r < map->getNumMaps(); ++r)
89template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 "BlockedMultiVector: inconsistent number of local elements of MultiVector and BlockedMap. The BlockedMap has "
97 << bmap->getMap()->getLocalNumElements() <<
" local elements. The vector has " << v->getMap()->getLocalNumElements()
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()
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()));
135template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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()));
158template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
165 vv_.resize(vin.size());
166 for(
size_t i = 0; i <
vv_.size(); i++)
171template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 for(
size_t r = 0; r <
vv_.size(); ++r)
185template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>&
195template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
204template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
212template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
221template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
231template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
237 for(
size_t r = 0; r <
map_->getNumMaps(); r++)
244template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
256 ret->setMultiVector(r, subvec, this->
getBlockedMap()->getThyraMode());
262template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
268 Teuchos::rcp_const_cast<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(
getVector(j));
273template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
278 if(
map_->getNumMaps() == 1)
280 return vv_[ 0 ]->getData(j);
287template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
294 return vv_[ 0 ]->getDataNonConst(j);
301template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
310template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
319template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
328template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
331scale(
const Scalar& alpha)
334 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
344template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
350 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
360template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
370 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector).");
371 if(bA != Teuchos::null)
377 "BlockedMultiVector::update: update with incompatible vector (different thyra mode).");
380 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors).");
381 for(
size_t r = 0; r <
map_->getNumMaps(); r++)
386 "BlockedMultiVector::update: in subvector "
387 << r <<
": Cannot add a vector of (local) length " << bA->getMultiVector(r)->getMap()->getLocalNumElements()
388 <<
" to the existing vector with " <<
getMultiVector(r)->
getMap()->getLocalNumElements() <<
" entries.");
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.");
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,
433 Xpetra::Exceptions::RuntimeError,
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());
449 Xpetra::Exceptions::RuntimeError,
450 "BlockedMultiVector::update: in subvector "
451 << r <<
": Cannot add a vector of (local) length " << part->getMap()->getLocalNumElements()
452 <<
" to the existing vector with " << getMultiVector(r)->getMap()->getLocalNumElements() <<
" entries.");
454 Xpetra::Exceptions::RuntimeError,
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);
465template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
475 if(bA != Teuchos::null && bB != Teuchos::null)
479 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector A).");
482 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector A).");
486 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector A).");
489 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector B).");
492 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector B).");
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);
511template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
521 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
527 norms[ c ] += temp_norms[ c ];
534template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
546 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
552 results[ c ] += temp_norms[ c ] * temp_norms[ c ];
560template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
570 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
576 norms[ c ] = std::max(norms[ c ], temp_norms[ c ]);
582template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
591template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
605template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
616 "BlockedMultiVector::elementWiseMultipy: B must have same blocked map than this.");
621 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getLocalNumElements() <<
" elements, B has "
622 << B.
getMap()->getLocalNumElements() <<
".");
625 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getGlobalNumElements() <<
" elements, B has "
626 << B.
getMap()->getGlobalNumElements() <<
".");
631 Teuchos::rcp_dynamic_cast<const Xpetra::BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(rcpA);
641 for(
size_t m = 0; m < bmap->getNumMaps(); m++)
647 thisPart->elementWiseMultiply(scalarAB, *partA, *partB, scalarThis);
653template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
662template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
668 return map_->getFullMap()->getLocalNumElements();
672template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
678 return map_->getFullMap()->getGlobalNumElements();
682template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
690 for(
size_t r = 0; r <
map_->getNumMaps(); ++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))
703template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
708 return std::string(
"BlockedMultiVector");
712template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
718 for(
size_t r = 0; r <
map_->getNumMaps(); r++)
723template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
736 "BlockedMultiVector::replaceMap: map is not of type BlockedMap. General implementation not available, yet.");
741 std::vector<Teuchos::RCP<const Map>> subMaps(1, map);
751 for(
size_t r = 0; r <
map_->getNumMaps(); r++)
756template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
767template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
778template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
789template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
800template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
805 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
812template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
817 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
824template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
827randomize(
const Scalar& minVal,
const Scalar& maxVal,
bool bUseXpetraImplementation)
829 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
831 getMultiVector(r)->randomize(minVal, maxVal, bUseXpetraImplementation);
836template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
845template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
854template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
864template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
874template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
882 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps()
883 <<
" partial blocks.");
888template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
893 XPETRA_MONITOR(
"BlockedMultiVector::getMultiVector(r,bThyraMode)");
896 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps()
897 <<
" partial blocks.");
905template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
919 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps() <<
" partial blocks.");
922 "The BlockedMultiVectors expects " <<
getNumVectors() <<
" vectors. The provided partial multivector has "
923 << v->getNumVectors() <<
" vectors.");
933template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
942 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
963template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
970 if(bRhs == Teuchos::null)
974 vv_ = std::vector<Teuchos::RCP<MultiVector>>(
map_->getNumMaps());
975 for(
size_t r = 0; r <
map_->getNumMaps(); ++r)
982 map_->getMap(r, bRhs->getBlockedMap()->getThyraMode()), rcpRhs->getNumVectors(),
true);
1000 if(bsrc->getBlockedMap()->getNumMaps() > 1)
1003 "1 blocks) and target is a MultiVector.");
1010 "BlockedMultiVector::assign: sub block must not be of type BlockedMultiVector.");
1018 "BlockedMultiVector::assign: source and target are BlockedMultiVectors with a different number of submaps.");
1027template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1038template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1049template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1054 bool bThyraMode)
const
1058 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps()
1059 <<
" partial blocks.");
1074 RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<MultiVector>(full);
1075 rcpNonConstFull->replaceMap(
map_->getImporter(block)->getSourceMap());
1079 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
1080 "created using Thyra-style numbered submaps.");
1081 if(bThyraMode ==
true)
1082 vv->replaceMap(
map_->getMap(block,
true));
1083 rcpNonConstFull->replaceMap(oldThyMapFull);
1092 "ExtractVector: Number of blocks in map extractor is " <<
map_->getNumMaps() <<
" but should be "
1093 << bfull->getBlockedMap()->getNumMaps()
1094 <<
" (number of blocks in BlockedMultiVector)");
1095 return bfull->getMultiVector(block, bThyraMode);
1100template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1105 bool bThyraMode)
const
1109 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps()
1110 <<
" partial blocks.");
1125 full->replaceMap(
map_->getImporter(block)->getSourceMap());
1129 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
1130 "created using Thyra-style numbered submaps.");
1131 if(bThyraMode ==
true)
1132 vv->replaceMap(
map_->getMap(block,
true));
1133 full->replaceMap(oldThyMapFull);
1142 "ExtractVector: Number of blocks in map extractor is " <<
map_->getNumMaps() <<
" but should be "
1143 << bfull->getBlockedMap()->getNumMaps()
1144 <<
" (number of blocks in BlockedMultiVector)");
1145 return bfull->getMultiVector(block, bThyraMode);
1150template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1159 "ExtractVector: Error, block = " << block <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps()
1160 <<
" partial blocks.");
1166template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1172 bool bThyraMode)
const
1176 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps()
1177 <<
" partial blocks.");
1182 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
1183 "using Thyra-style numbered submaps.");
1194 RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<MultiVector>(rcpPartial);
1209 rcpNonConstPartial->replaceMap(
map_->getMap(block,
false));
1217 rcpNonConstPartial->replaceMap(oldThyMapPartial);
1227template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1233 bool bThyraMode)
const
1236 Teuchos::rcp_dynamic_cast<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(full);
1246 full->setMultiVector(block, partial, bThyraMode);
1254template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1260 bool bThyraMode)
const
1263 Teuchos::rcp_dynamic_cast<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(full);
1269 bfull->setMultiVector(block, partial, bThyraMode);
#define XPETRA_MONITOR(funcName)
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const BlockedMap > map_
blocked map containing the sub block maps (either thyra or xpetra mode)
Teuchos::RCP< const Map > getMap() const
BlockedMultiVector(const Teuchos::RCP< const BlockedMap > &map, size_t NumVectors, bool zeroOut=true)
Constructor.
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
virtual Teuchos::RCP< const Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Tpetra::KokkosClassic::DefaultNode::DefaultNodeType > > getVector(size_t j) const
virtual size_t getNumVectors() const
Number of columns in the multivector.
void ExtractVector(RCP< const MultiVector > &full, size_t block, RCP< MultiVector > &partial) const
void InsertVector(const MultiVector &partial, size_t block, MultiVector &full, bool bThyraMode=false) const
size_t numVectors_
number of vectors (columns in multi vector)
virtual void assign(const MultiVector &rhs)
virtual std::string description() const
A simple one-line description of this object.
Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Tpetra::KokkosClassic::DefaultNode::DefaultNodeType > > getBlockedMap() const
std::vector< Teuchos::RCP< MultiVector > > vv_
array containing RCPs of the partial vectors
virtual void doExport(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)=0
Export data into this object using an Export object ("forward mode").
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
virtual void doImport(const DistObject< Packet, LocalOrdinal, GlobalOrdinal, Node > &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)=0
Import data into this object using an Import object ("forward mode").
Exception throws to report errors in the internal logical of the program.
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.
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)=0
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
basic_FancyOStream< char > FancyOStream
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
size_t global_size_t
Global size_t object.
CombineMode
Xpetra::Combine Mode enumerable type.