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"
21template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
29 vv_.reserve(map->getNumMaps());
32 for (
size_t r = 0; r < map->getNumMaps(); ++r)
48template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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()
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()));
92template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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()));
113template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
119 vv_.resize(vin.size());
120 for (
size_t i = 0; i <
vv_.size(); i++)
124template <
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;
135template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>&
143template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
149template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
161template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
167template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
171 for (
size_t r = 0; r <
map_->getNumMaps(); r++) {
176template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186 ret->setMultiVector(r, subvec, this->
getBlockedMap()->getThyraMode());
191template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
196 Teuchos::rcp_const_cast<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(
getVector(j));
200template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
205 return vv_[0]->getData(j);
211template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
215 if (
map_->getNumMaps() == 1) {
216 return vv_[0]->getDataNonConst(j);
222template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
228template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
234template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
240template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
242 scale(
const Scalar& alpha) {
244 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
251template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
255 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
262template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
270 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector).");
271 if (bA != Teuchos::null) {
276 "BlockedMultiVector::update: update with incompatible vector (different thyra mode).");
279 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors).");
280 for (
size_t r = 0; r <
map_->getNumMaps(); r++) {
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.");
288 "BlockedMultiVector::update: in subvector "
289 << r <<
": Cannot add a vector of length " << bA->getMultiVector(r)->getMap()->getGlobalNumElements()
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,
325 Xpetra::Exceptions::RuntimeError,
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());
338 Xpetra::Exceptions::RuntimeError,
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.");
343 Xpetra::Exceptions::RuntimeError,
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);
353template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 if (bA != Teuchos::null && bB != Teuchos::null) {
364 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector A).");
367 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector A).");
371 "BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector A).");
374 "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector B).");
377 "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector B).");
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);
394template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
402 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
406 norms[c] += temp_norms[c];
411template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
421 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
425 results[c] += temp_norms[c] * temp_norms[c];
432template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
440 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
444 norms[c] = std::max(norms[c], temp_norms[c]);
449template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
455template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
466template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
475 "BlockedMultiVector::elementWiseMultipy: B must have same blocked map than this.");
480 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getLocalNumElements() <<
" elements, B has "
481 << B.
getMap()->getLocalNumElements() <<
".");
484 "BlockedMultiVector::elementWiseMultipy: A has " << A.
getMap()->getGlobalNumElements() <<
" elements, B has "
485 << B.
getMap()->getGlobalNumElements() <<
".");
490 Teuchos::rcp_dynamic_cast<const Xpetra::BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(rcpA);
500 for (
size_t m = 0; m < bmap->getNumMaps(); m++) {
505 thisPart->elementWiseMultiply(scalarAB, *partA, *partB, scalarThis);
509template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
516template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
521 return map_->getFullMap()->getLocalNumElements();
524template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
529 return map_->getFullMap()->getGlobalNumElements();
532template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
538 for (
size_t r = 0; r <
map_->getNumMaps(); ++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))
549template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
553 return std::string(
"BlockedMultiVector");
556template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
560 for (
size_t r = 0; r <
map_->getNumMaps(); r++)
564template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
573 "BlockedMultiVector::replaceMap: map is not of type BlockedMap. General implementation not available, yet.");
578 std::vector<Teuchos::RCP<const Map>> subMaps(1, map);
588 for (
size_t r = 0; r <
map_->getNumMaps(); r++)
592template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
600template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
608template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
616template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
624template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
627 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
632template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
634 randomize(
bool bUseXpetraImplementation) {
635 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
640template <
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);
648template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
654template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
660template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
668template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
676template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
683 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps()
684 <<
" partial blocks.");
688template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
692 XPETRA_MONITOR(
"BlockedMultiVector::getMultiVector(r,bThyraMode)");
695 "Error, r = " << r <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps()
696 <<
" partial blocks.");
703template <
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.");
728template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
736 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
752template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
757 if (bRhs == Teuchos::null)
761 vv_ = std::vector<Teuchos::RCP<MultiVector>>(
map_->getNumMaps());
762 for (
size_t r = 0; r <
map_->getNumMaps(); ++r) {
768 map_->getMap(r, bRhs->getBlockedMap()->getThyraMode()), rcpRhs->getNumVectors(),
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.");
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.");
805template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
813template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
821template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
826 bool bThyraMode)
const {
829 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps()
830 <<
" partial blocks.");
844 RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<MultiVector>(full);
845 rcpNonConstFull->replaceMap(
map_->getImporter(block)->getSourceMap());
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);
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);
867template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
872 bool bThyraMode)
const {
875 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " <<
map_->getNumMaps()
876 <<
" partial blocks.");
890 full->replaceMap(
map_->getImporter(block)->getSourceMap());
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);
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);
912template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
919 "ExtractVector: Error, block = " << block <<
" is too big. The BlockedMultiVector only contains " <<
map_->getNumMaps()
920 <<
" partial blocks.");
925template <
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.");
939 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
940 "using Thyra-style numbered submaps.");
950 RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<MultiVector>(rcpPartial);
965 rcpNonConstPartial->replaceMap(
map_->getMap(block,
false));
973 rcpNonConstPartial->replaceMap(oldThyMapPartial);
980template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
985 bool bThyraMode)
const {
987 Teuchos::rcp_dynamic_cast<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(full);
996 full->setMultiVector(block, partial, bThyraMode);
1003template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1008 bool bThyraMode)
const {
1010 Teuchos::rcp_dynamic_cast<Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(full);
1015 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, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
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.