46 #ifndef XPETRA_MAPEXTRACTOR_DEF_HPP_
47 #define XPETRA_MAPEXTRACTOR_DEF_HPP_
49 #include <Xpetra_MultiVectorFactory.hpp>
50 #include <Xpetra_VectorFactory.hpp>
51 #include <Xpetra_BlockedMultiVector.hpp>
58 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 MapExtractor(
const RCP<const Map>& fullmap,
const std::vector<RCP<const Map> >& maps,
bool bThyraMode)
62 map_ = Teuchos::rcp(
new BlockedMap(fullmap, maps, bThyraMode));
65 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 MapExtractor(
const std::vector<RCP<const Map> >& maps,
const std::vector<RCP<const Map> >& thyramaps)
69 map_ = Teuchos::rcp(
new BlockedMap(maps, thyramaps));
72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
101 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps() <<
" partial blocks.");
103 "ExtractVector: map_->getMap(" << block <<
",false) is null");
109 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
116 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
117 <<
" partial blocks.");
125 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
128 ExtractVector(RCP<const Vector>& full,
size_t block, RCP<Vector>& partial)
const
130 ExtractVector(*full, block, *partial);
134 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
143 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 ExtractVector(RCP<const MultiVector>& full,
size_t block, RCP<MultiVector>& partial)
const
148 ExtractVector(*full, block, *partial);
152 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 ExtractVector(RCP<MultiVector>& full,
size_t block, RCP<MultiVector>& partial)
const
157 ExtractVector(*full, block, *partial);
161 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
162 RCP<Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
168 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
169 <<
" partial blocks.");
174 ExtractVector(*full, block, *vv);
175 if(bThyraMode ==
false)
177 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
178 Xpetra::Exceptions::RuntimeError,
179 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
180 "created using Thyra-style numbered submaps.");
181 vv->replaceMap(getMap(block,
true));
186 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
187 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
193 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
194 <<
" partial blocks.");
200 ExtractVector(*full, block, *vv);
201 if(bThyraMode ==
false)
203 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
204 Xpetra::Exceptions::RuntimeError,
205 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
206 "created using Thyra-style numbered submaps.");
207 vv->replaceMap(getMap(block,
true));
212 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
213 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
219 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
220 <<
" partial blocks.");
223 RCP<const BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(full);
224 if(bfull.is_null() ==
true)
233 RCP<const Map> oldThyMapFull = full->getMap();
234 RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<
MultiVector>(full);
235 rcpNonConstFull->
replaceMap(map_->getImporter(block)->getSourceMap());
236 ExtractVector(*rcpNonConstFull, block, *vv);
237 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
238 Xpetra::Exceptions::RuntimeError,
239 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
240 "created using Thyra-style numbered submaps.");
241 if(bThyraMode ==
true)
242 vv->replaceMap(getMap(block,
true));
243 rcpNonConstFull->replaceMap(oldThyMapFull);
251 Xpetra::Exceptions::RuntimeError,
252 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
253 << bfull->getBlockedMap()->getNumMaps()
254 <<
" (number of blocks in BlockedMultiVector)");
255 return bfull->getMultiVector(block, bThyraMode);
260 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
267 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
268 <<
" partial blocks.");
272 if(bfull.is_null() ==
true)
281 RCP<const Map> oldThyMapFull = full->getMap();
282 full->replaceMap(map_->getImporter(block)->getSourceMap());
283 ExtractVector(*full, block, *vv);
284 TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() ==
false && bThyraMode ==
true,
285 Xpetra::Exceptions::RuntimeError,
286 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
287 "created using Thyra-style numbered submaps.");
288 if(bThyraMode ==
true)
289 vv->replaceMap(getMap(block,
true));
290 full->replaceMap(oldThyMapFull);
298 Xpetra::Exceptions::RuntimeError,
299 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
300 << bfull->getBlockedMap()->getNumMaps()
301 <<
" (number of blocks in BlockedMultiVector)");
302 return bfull->getMultiVector(block, bThyraMode);
307 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
308 RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
314 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
315 <<
" partial blocks.");
319 Xpetra::Exceptions::RuntimeError,
320 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
321 << full->getBlockedMap()->getNumMaps()
322 <<
" (number of blocks in BlockedMultiVector)");
323 Teuchos::RCP<MultiVector> vv = full->getMultiVector(block, bThyraMode);
328 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
329 RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
335 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
336 <<
" partial blocks.");
340 Xpetra::Exceptions::RuntimeError,
341 "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() <<
" but should be "
342 << full->getBlockedMap()->getNumMaps()
343 <<
" (number of blocks in BlockedMultiVector)");
344 Teuchos::RCP<MultiVector> vv = full->getMultiVector(block, bThyraMode);
349 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
356 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
357 <<
" partial blocks.");
359 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: map_->getmap(" << block <<
",false) is null");
361 Xpetra::Exceptions::RuntimeError,
362 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
363 "using Thyra-style numbered submaps.");
373 RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
374 RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<
MultiVector>(rcpPartial);
375 RCP<const Map> oldThyMapPartial = rcpNonConstPartial->
getMap();
376 RCP<const Map> oldThyMapFull = full.
getMap();
380 Xpetra::Exceptions::RuntimeError,
381 "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of partial vector are not identical "
382 "to target Map of Importer. This should not be.");
389 rcpNonConstPartial->replaceMap(getMap(block,
false));
390 full.
replaceMap(map_->getImporter(block)->getSourceMap());
397 rcpNonConstPartial->replaceMap(oldThyMapPartial);
407 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
414 "ExtractVector: Error, block = " << block <<
" is too big. The MapExtractor only contains " << map_->getNumMaps()
415 <<
" partial blocks.");
417 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"ExtractVector: map_->getmap(" << block <<
",false) is null");
419 Xpetra::Exceptions::RuntimeError,
420 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
421 "using Thyra-style numbered submaps.");
431 RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
432 RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<
MultiVector>(rcpPartial);
433 RCP<const Map> oldThyMapPartial = rcpNonConstPartial->
getMap();
434 RCP<const Map> oldThyMapFull = full.
getMap();
438 Xpetra::Exceptions::RuntimeError,
439 "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of partial vector are not identical "
440 "to target Map of Importer. This should not be.");
447 rcpNonConstPartial->replaceMap(getMap(block,
false));
448 full.
replaceMap(map_->getImporter(block)->getSourceMap());
455 rcpNonConstPartial->replaceMap(oldThyMapPartial);
466 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
469 InsertVector(RCP<const Vector> partial,
size_t block, RCP<Vector> full,
bool bThyraMode)
const
471 InsertVector(*partial, block, *full, bThyraMode);
475 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
478 InsertVector(RCP<Vector> partial,
size_t block, RCP<Vector> full,
bool bThyraMode)
const
480 InsertVector(*partial, block, *full, bThyraMode);
484 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
490 bool bThyraMode)
const
492 RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
493 if(bfull.is_null() ==
true)
494 InsertVector(*partial, block, *full, bThyraMode);
498 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: map_->getmap(" << block <<
",false) is null");
503 full->setMultiVector(block, partial, bThyraMode);
505 throw std::runtime_error(
"Xpetra::MultiVector::setMultiVector() doesn't exist.");
511 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
517 bool bThyraMode)
const
519 RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
520 if(bfull.is_null() ==
true)
521 InsertVector(*partial, block, *full, bThyraMode);
525 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: map_->getmap(" << block <<
",false) is null");
527 bfull->setMultiVector(block, partial, bThyraMode);
532 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
538 bool bThyraMode)
const
541 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: map_->getmap(" << block <<
",false) is null");
543 full->setMultiVector(block, partial, bThyraMode);
547 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
553 bool bThyraMode )
const
556 map_->getMap(block,
false) == null, Xpetra::Exceptions::RuntimeError,
"InsertVector: map_->getmap(" << block <<
",false) is null");
557 full->setMultiVector(block, partial, bThyraMode);
561 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
562 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
567 Xpetra::Exceptions::RuntimeError,
568 "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using "
569 "Thyra-style numbered submaps.");
575 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
576 RCP<Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>>
578 getVector(
size_t i,
size_t numvec,
bool bThyraMode,
bool bZero)
const
581 Xpetra::Exceptions::RuntimeError,
582 "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using "
583 "Thyra-style numbered submaps.");
589 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
594 return map_->getThyraMode();
598 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
603 return map_->getNumMaps();
607 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
608 const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
612 return map_->getMap(i, bThyraMode);
616 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
617 const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
625 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
626 const RCP<const Xpetra::BlockedMap<LocalOrdinal,GlobalOrdinal,Node>>
634 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
635 const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node>>
639 return map_->getFullMap();
643 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
648 return map_->getMapIndexForGID(gid);
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map)=0
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").
static Teuchos::RCP< Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node >> &map, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
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.
Exception throws to report errors in the internal logical of the program.
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").
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)