10 #ifndef XPETRA_REORDEREDBLOCKEDMULTIVECTOR_HPP
11 #define XPETRA_REORDEREDBLOCKEDMULTIVECTOR_HPP
13 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
21 #include "Xpetra_BlockedMap.hpp"
22 #include "Xpetra_BlockedMultiVector.hpp"
32 template <
class Scalar,
35 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
44 #undef XPETRA_REORDEREDBLOCKEDMULTIVECTOR_SHORT
60 Teuchos::RCP<const Xpetra::BlockReorderManager> brm,
78 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
mergeSubBlockMaps(Teuchos::RCP<const Xpetra::BlockReorderManager> brm) {
79 RCP<const BlockedMap> bmap =
fullVec_->getBlockedMap();
82 size_t numBlocks = brm->GetNumBlocks();
84 Teuchos::RCP<const Map> map = Teuchos::null;
91 map = bmap->getMap(Teuchos::as<size_t>(leaf->GetIndex()),
false);
94 std::vector<Teuchos::RCP<const Map>> subMaps(numBlocks, Teuchos::null);
96 for (
size_t i = 0; i < numBlocks; i++) {
97 Teuchos::RCP<const Xpetra::BlockReorderManager> blkMgr = brm->GetBlock(Teuchos::as<int>(i));
99 TEUCHOS_ASSERT(subMaps[i].is_null() ==
false);
104 TEUCHOS_ASSERT(map.is_null() ==
false);
113 std::string
description()
const {
return "ReorderedBlockedMultiVector"; }
116 void describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const {
117 TEUCHOS_ASSERT(
brm_ != Teuchos::null);
125 Teuchos::RCP<const Xpetra::BlockReorderManager>
brm_;
126 Teuchos::RCP<const Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
fullVec_;
129 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 RCP<const Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node>> bmap = bvec->getBlockedMap();
137 size_t numBlocks = brm->GetNumBlocks();
139 Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> map = Teuchos::null;
141 if (numBlocks == 0) {
145 map = bmap->getMap(Teuchos::as<size_t>(leaf->GetIndex()), bThyraMode);
148 std::vector<Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>> subMaps(numBlocks, Teuchos::null);
150 for (
size_t i = 0; i < numBlocks; i++) {
151 Teuchos::RCP<const Xpetra::BlockReorderManager> blkMgr = brm->GetBlock(Teuchos::as<int>(i));
153 TEUCHOS_ASSERT(subMaps[i].is_null() ==
false);
170 TEUCHOS_ASSERT(map.is_null() ==
false);
174 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
184 size_t rowSz = rowMgr->GetNumBlocks();
186 Teuchos::RCP<BlockedMultiVector> rbvec = Teuchos::null;
190 Teuchos::RCP<const Xpetra::BlockReorderLeaf> rowleaf = Teuchos::rcp_dynamic_cast<
const Xpetra::BlockReorderLeaf>(rowMgr);
193 Teuchos::RCP<MultiVector> vec = bvec->getMultiVector(rowleaf->GetIndex(),
false);
195 TEUCHOS_ASSERT(vec != Teuchos::null);
198 Teuchos::RCP<BlockedMultiVector> subBVec = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(vec);
199 if (subBVec == Teuchos::null) {
212 RCP<const BlockedMap> fullBlockedMap = bvec->getBlockedMap();
213 Teuchos::RCP<const Map> submap = fullBlockedMap->getMap(rowleaf->GetIndex(),
false);
214 std::vector<Teuchos::RCP<const Map>> rowSubMaps(1, submap);
215 Teuchos::RCP<const BlockedMap> bbmap = Teuchos::rcp(
new BlockedMap(submap, rowSubMaps,
false));
217 rbvec = Teuchos::rcp(
new ReorderedBlockedMultiVector(bbmap, rowMgr, bvec));
218 rbvec->setMultiVector(0, Teuchos::rcp_const_cast<MultiVector>(vec),
false);
223 TEUCHOS_ASSERT(rbvec != Teuchos::null);
228 Teuchos::RCP<const BlockedMap> rgBlockedMap = Teuchos::null;
229 std::vector<Teuchos::RCP<const Map>> rowSubMaps(rowSz, Teuchos::null);
230 for (
size_t i = 0; i < rowSz; i++) {
231 Teuchos::RCP<const Xpetra::BlockReorderManager> rowSubMgr = rowMgr->GetBlock(Teuchos::as<int>(i));
233 TEUCHOS_ASSERT(rowSubMaps[i].is_null() ==
false);
236 rgBlockedMap = Teuchos::rcp(
new BlockedMap(rgMergedSubMaps, rowSubMaps,
false));
237 rbvec = Teuchos::rcp(
new ReorderedBlockedMultiVector(rgBlockedMap, rowMgr, bvec));
239 for (
size_t i = 0; i < rowSz; i++) {
240 Teuchos::RCP<const Xpetra::BlockReorderManager> rowSubMgr = rowMgr->GetBlock(Teuchos::as<int>(i));
241 Teuchos::RCP<const MultiVector> subvec =
mergeSubBlocks(rowSubMgr, bvec);
242 rbvec->setMultiVector(i, Teuchos::rcp_const_cast<MultiVector>(subvec),
false);
248 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
256 TEUCHOS_ASSERT(bvec->getBlockedMap()->getThyraMode() ==
true);
259 size_t rowSz = rowMgr->GetNumBlocks();
261 Teuchos::RCP<BlockedMultiVector> rbvec = Teuchos::null;
265 Teuchos::RCP<const Xpetra::BlockReorderLeaf> rowleaf = Teuchos::rcp_dynamic_cast<
const Xpetra::BlockReorderLeaf>(rowMgr);
268 Teuchos::RCP<MultiVector> vec = bvec->getMultiVector(rowleaf->GetIndex(),
true);
270 TEUCHOS_ASSERT(vec.is_null() ==
false);
273 Teuchos::RCP<BlockedMultiVector> bbvec = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(vec);
274 if (bbvec == Teuchos::null) {
277 RCP<const BlockedMap> fullBlockedRangeMap = bvec->getBlockedMap();
279 Teuchos::RCP<const Map> xpsubmap = fullBlockedRangeMap->getMap(rowleaf->GetIndex(),
false);
280 Teuchos::RCP<const Map> thysubmap = fullBlockedRangeMap->getMap(rowleaf->GetIndex(),
true);
281 std::vector<Teuchos::RCP<const Map>> rowXpSubMaps(1, xpsubmap);
282 std::vector<Teuchos::RCP<const Map>> rowTySubMaps(1, thysubmap);
284 Teuchos::RCP<const BlockedMap> rgBlockedMap = Teuchos::rcp(
new BlockedMap(rowXpSubMaps, rowTySubMaps));
288 rbvec = Teuchos::rcp(
new ReorderedBlockedMultiVector(rgBlockedMap, rowMgr, bvec));
289 rbvec->setMultiVector(0, vec,
true);
292 rbvec = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(vec);
298 std::vector<Teuchos::RCP<const Map>> rowXpSubMaps(rowSz, Teuchos::null);
299 std::vector<Teuchos::RCP<const Map>> rowTySubMaps(rowSz, Teuchos::null);
300 for (
size_t i = 0; i < rowSz; i++) {
301 Teuchos::RCP<const Xpetra::BlockReorderManager> rowSubMgr = rowMgr->GetBlock(Teuchos::as<int>(i));
305 TEUCHOS_ASSERT(rowXpSubMaps[i].is_null() ==
false);
306 TEUCHOS_ASSERT(rowTySubMaps[i].is_null() ==
false);
309 Teuchos::RCP<const BlockedMap> rgBlockedMap = Teuchos::rcp(
new BlockedMap(rowXpSubMaps, rowTySubMaps));
311 rbvec = Teuchos::rcp(
new ReorderedBlockedMultiVector(rgBlockedMap, rowMgr, bvec));
313 for (
size_t i = 0; i < rowSz; i++) {
314 Teuchos::RCP<const Xpetra::BlockReorderManager> rowSubMgr = rowMgr->GetBlock(Teuchos::as<int>(i));
316 rbvec->setMultiVector(i, Teuchos::rcp_const_cast<MultiVector>(subvec),
true);
322 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
324 Teuchos::RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> rbvec = Teuchos::null;
325 if (bvec->getBlockedMap()->getThyraMode() ==
false) {
330 TEUCHOS_ASSERT(rbvec.is_null() ==
false);
334 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
338 Teuchos::RCP<const MultiVector> rbvec = Teuchos::null;
339 if (bvec->getBlockedMap()->getThyraMode() ==
false) {
340 rbvec =
mergeSubBlocks(brm, Teuchos::rcp_const_cast<const BlockedMultiVector>(bvec));
344 TEUCHOS_ASSERT(rbvec.is_null() ==
false);
345 return Teuchos::rcp_const_cast<MultiVector>(rbvec);
350 #define XPETRA_REORDEREDBLOCKEDMULTIVECTOR_SHORT
Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > mergeSubBlockMaps(Teuchos::RCP< const Xpetra::BlockReorderManager > brm, Teuchos::RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> bmat, bool bThyraMode)
virtual ~ReorderedBlockedMultiVector()
Destructor.
Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > mergeSubBlockMaps(Teuchos::RCP< const Xpetra::BlockReorderManager > brm)
Xpetra utility class for common map-related routines.
Teuchos::RCP< const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > buildReorderedBlockedMultiVector(Teuchos::RCP< const Xpetra::BlockReorderManager > brm, Teuchos::RCP< const Xpetra::BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> bvec)
static Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > concatenateMaps(const std::vector< Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > > &subMaps)
Helper function to concatenate several maps.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
ReorderedBlockedMultiVector(Teuchos::RCP< const BlockedMap > &rangeMap, Teuchos::RCP< const Xpetra::BlockReorderManager > brm, Teuchos::RCP< const Xpetra::BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> bvec)
Constructor.
Teuchos::RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mergeSubBlocks(Teuchos::RCP< const Xpetra::BlockReorderManager > rowMgr, Teuchos::RCP< const Xpetra::BlockReorderManager > colMgr, Teuchos::RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> bmat)
GlobalOrdinal global_ordinal_type
Teuchos::RCP< const Xpetra::BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > fullVec_
LocalOrdinal local_ordinal_type
virtual size_t getNumVectors() const
Number of columns in the multivector.
Teuchos::RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mergeSubBlocksThyra(Teuchos::RCP< const Xpetra::BlockReorderManager > rowMgr, Teuchos::RCP< const Xpetra::BlockReorderManager > colMgr, Teuchos::RCP< const Xpetra::BlockedCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> bmat)
Teuchos::RCP< const Xpetra::BlockReorderManager > brm_
std::string description() const
Return a simple one-line description of this object.