46 #ifndef XPETRA_MAPEXTRACTOR_HPP_ 47 #define XPETRA_MAPEXTRACTOR_HPP_ 54 #include <Teuchos_Describable.hpp> 69 template <
class Scalar ,
81 #undef XPETRA_MAPEXTRACTOR_SHORT 90 if(bThyraMode ==
false) {
95 size_t numAllElements = 0;
96 for(
size_t v = 0; v < maps.size(); ++v) {
97 numAllElements += maps[v]->getGlobalNumElements();
100 "logic error. full map and sub maps have not same number of elements. We cannot build MapExtractor with Xpetra-style numbering. Please make sure that you want Xpetra-style numbering instead of Thyra-style numbering.");
105 std::cout <<
"Create Map Extractor in Thyra Mode!!! " << std::endl;
110 for(
size_t v = 0; v < maps.size(); ++v) {
112 "logic error. When using Thyra-style numbering all sub-block maps must start with zero as GID.");
119 std::vector<GlobalOrdinal> gidOffsets(maps.size(),0);
120 for(
size_t v = 1; v < maps.size(); ++v) {
121 gidOffsets[v] = maps[v-1]->getMaxAllGlobalIndex() + gidOffsets[v-1] + 1;
125 maps_.resize(maps.size());
126 std::vector<GlobalOrdinal> fullMapGids;
128 for(
size_t v = 0; v < maps.size(); ++v) {
129 std::vector<GlobalOrdinal> subMapGids(maps[v]->getNodeNumElements(),0);
130 for (LocalOrdinal l = 0; l < Teuchos::as<LocalOrdinal>(maps[v]->getNodeNumElements()); ++l) {
131 GlobalOrdinal myGid = maps[v]->getGlobalElement(l);
132 subMapGids[l] = myGid + gidOffsets[v];
133 fullMapGids.push_back(myGid + gidOffsets[v]);
154 size_t numAllElements = 0;
155 for(
size_t v = 0; v <
maps_.size(); ++v) {
156 numAllElements +=
maps_[v]->getGlobalNumElements();
159 "logic error. full map and sub maps have not same number of elements. This cannot be. Please report the bug to the Xpetra developers!");
164 for (
unsigned i = 0; i <
maps_.size(); ++i)
168 "logic error. full map and sub maps are inconsistently distributed over the processors.");
176 "ExtractVector: maps_[" << block <<
"] is null");
182 "ExtractVector: maps_[" << block <<
"] is null");
192 "ExtractVector: maps_[" << block <<
"] is null");
196 if(bThyraMode ==
false)
return xpetraVec;
198 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
204 for(
size_t i=0; i < xpetraVec->getLocalLength(); i++) {
205 thyraVecData[i] = xpetraVecData[i];
211 "ExtractVector: maps_[" << block <<
"] is null");
214 if(bThyraMode ==
false)
return xpetraVec;
216 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
222 for(
size_t i=0; i < xpetraVec->getLocalLength(); i++) {
223 thyraVecData[i] = xpetraVecData[i];
229 "ExtractVector: maps_[" << block <<
"] is null");
232 if(bThyraMode ==
false)
return xpetraVec;
234 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
237 for(
size_t k=0; k < xpetraVec->getNumVectors(); k++) {
240 for(
size_t i=0; i < xpetraVec->getLocalLength(); i++) {
241 thyraVecData[i] = xpetraVecData[i];
248 "ExtractVector: maps_[" << block <<
"] is null");
251 if(bThyraMode ==
false)
return xpetraVec;
253 "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
256 for(
size_t k=0; k < xpetraVec->getNumVectors(); k++) {
259 for(
size_t i=0; i < xpetraVec->getLocalLength(); i++) {
260 thyraVecData[i] = xpetraVecData[i];
271 "InsertVector: maps_[" << block <<
"] is null");
273 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
279 for(
size_t i=0; i < xpetraVec->getLocalLength(); i++) {
280 xpetraVecData[i] = thyraVecData[i];
290 "InsertVector: maps_[" << block <<
"] is null");
292 "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
299 for(
size_t i=0; i < xpetraVec->getLocalLength(); i++) {
300 xpetraVecData[i] = thyraVecData[i];
320 "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
325 "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using Thyra-style numbered submaps.");
346 "MapExtractor::getMap: cannot return sub map in Thyra-style numbering if MapExtractor object is not created using Thyra-style numbered submaps.");
355 for (
size_t i = 0; i <
NumMaps(); i++)
356 if (
getMap(i)->isNodeGlobalElement(gid) ==
true)
360 "getMapIndexForGID: GID " << gid <<
" is not contained by a map in mapextractor." );
370 for (
size_t i = 0; i <
NumMaps(); i++) {
375 if (fullMap->isNodeGlobalElement(*it) ==
false)
390 #define XPETRA_MAPEXTRACTOR_SHORT
static RCP< Import< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &source, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &target)
Constructor specifying the number of non-zeros for all rows.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &node=defaultArgNode())
Map constructor with Xpetra-defined contiguous uniform distribution.
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").
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const_pointer const_iterator
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").
static RCP< Vector > Build(const Teuchos::RCP< const Map > &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.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const =0
Const view of the local values in a particular vector of this multivector.