Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_MapExtractor_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Xpetra: A linear algebra interface package
4 //
5 // Copyright 2012 NTESS and the Xpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef XPETRA_MAPEXTRACTOR_DEF_HPP_
11 #define XPETRA_MAPEXTRACTOR_DEF_HPP_
12 
13 #include <Xpetra_MultiVectorFactory.hpp>
14 #include <Xpetra_VectorFactory.hpp>
15 #include <Xpetra_BlockedMultiVector.hpp>
16 
18 
19 namespace Xpetra {
20 
21 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
23  MapExtractor(const RCP<const Map>& fullmap, const std::vector<RCP<const Map>>& maps, bool bThyraMode) {
24  map_ = Teuchos::rcp(new BlockedMap(fullmap, maps, bThyraMode));
25 }
26 
27 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
29  MapExtractor(const std::vector<RCP<const Map>>& maps, const std::vector<RCP<const Map>>& thyramaps) {
30  map_ = Teuchos::rcp(new BlockedMap(maps, thyramaps));
31 }
32 
33 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
35  MapExtractor(const Teuchos::RCP<const BlockedMap>& blockedMap)
36  : map_(blockedMap) {}
37 
38 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
40  MapExtractor(const MapExtractor& input) {
41  map_ = Teuchos::rcp(new BlockedMap(*(input.getBlockedMap())));
42 }
43 
44 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
47  map_ = Teuchos::null;
48 }
49 
50 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
52  ExtractVector(const Vector& full, size_t block, Vector& partial) const {
53  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(), std::out_of_range,
54  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps() << " partial blocks.");
55  XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError,
56  "ExtractVector: map_->getMap(" << block << ",false) is null");
57 
58  partial.doImport(full, *(map_->getImporter(block)), Xpetra::INSERT);
59 }
60 
61 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
63  ExtractVector(const MultiVector& full, size_t block, MultiVector& partial) const {
64  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
65  std::out_of_range,
66  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
67  << " partial blocks.");
69  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getMap(" << block << ",false) is null");
70 
71  partial.doImport(full, *(map_->getImporter(block)), Xpetra::INSERT);
72 }
73 
74 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
76  ExtractVector(RCP<const Vector>& full, size_t block, RCP<Vector>& partial) const {
77  ExtractVector(*full, block, *partial);
78 }
79 
80 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
82  ExtractVector(RCP<Vector>& full, size_t block, RCP<Vector>& partial) const {
83  ExtractVector(*full, block, *partial);
84 }
85 
86 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
88  ExtractVector(RCP<const MultiVector>& full, size_t block, RCP<MultiVector>& partial) const {
89  ExtractVector(*full, block, *partial);
90 }
91 
92 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
94  ExtractVector(RCP<MultiVector>& full, size_t block, RCP<MultiVector>& partial) const {
95  ExtractVector(*full, block, *partial);
96 }
97 
98 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
99 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
101  ExtractVector(RCP<const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& full, size_t block, bool bThyraMode) const {
102  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
103  std::out_of_range,
104  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
105  << " partial blocks.");
107  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getMap(" << block << ",false) is null");
108  // first extract partial vector from full vector (using xpetra style GIDs)
109  const RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> vv = Xpetra::VectorFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(getMap(block, false), false);
110  ExtractVector(*full, block, *vv);
111  if (bThyraMode == false)
112  return vv;
113  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
114  Xpetra::Exceptions::RuntimeError,
115  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
116  "created using Thyra-style numbered submaps.");
117  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
118  return vv;
119 }
120 
121 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
122 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
124  ExtractVector(RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& full, size_t block, bool bThyraMode) const {
125  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
126  std::out_of_range,
127  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
128  << " partial blocks.");
130  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
131  // first extract partial vector from full vector (using xpetra style GIDs)
132  const RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>> vv = Xpetra::VectorFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(getMap(block, false), false);
133 
134  ExtractVector(*full, block, *vv);
135  if (bThyraMode == false)
136  return vv;
137  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
138  Xpetra::Exceptions::RuntimeError,
139  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
140  "created using Thyra-style numbered submaps.");
141  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
142  return vv;
143 }
144 
145 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
146 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
148  ExtractVector(RCP<const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& full, size_t block, bool bThyraMode) const {
149  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
150  std::out_of_range,
151  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
152  << " partial blocks.");
154  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
155  RCP<const BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(full);
156  if (bfull.is_null() == true) {
157  // standard case: full is not of type BlockedMultiVector
158  // first extract partial vector from full vector (using xpetra style GIDs)
159  const RCP<MultiVector> vv = MultiVectorFactory::Build(getMap(block, false), full->getNumVectors(), false);
160  // if(bThyraMode == false) {
161  // ExtractVector(*full, block, *vv);
162  // return vv;
163  //} else {
164  RCP<const Map> oldThyMapFull = full->getMap(); // temporarely store map of full
165  RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<MultiVector>(full);
166  rcpNonConstFull->replaceMap(map_->getImporter(block)->getSourceMap());
167  ExtractVector(*rcpNonConstFull, block, *vv);
168  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
169  Xpetra::Exceptions::RuntimeError,
170  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
171  "created using Thyra-style numbered submaps.");
172  if (bThyraMode == true)
173  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
174  rcpNonConstFull->replaceMap(oldThyMapFull);
175  return vv;
176  //}
177  } else {
178  // special case: full is of type BlockedMultiVector
179  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != bfull->getBlockedMap()->getNumMaps(),
180  Xpetra::Exceptions::RuntimeError,
181  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
182  << bfull->getBlockedMap()->getNumMaps()
183  << " (number of blocks in BlockedMultiVector)");
184  return bfull->getMultiVector(block, bThyraMode);
185  }
186 }
187 
188 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
189 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
191  ExtractVector(RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& full, size_t block, bool bThyraMode) const {
192  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
193  std::out_of_range,
194  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
195  << " partial blocks.");
197  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
198  RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
199  if (bfull.is_null() == true) {
200  // standard case: full is not of type BlockedMultiVector
201  // first extract partial vector from full vector (using xpetra style GIDs)
202  const RCP<MultiVector> vv = MultiVectorFactory::Build(getMap(block, false), full->getNumVectors(), false);
203  // if(bThyraMode == false) {
204  // ExtractVector(*full, block, *vv);
205  // return vv;
206  //} else {
207  RCP<const Map> oldThyMapFull = full->getMap(); // temporarely store map of full
208  full->replaceMap(map_->getImporter(block)->getSourceMap());
209  ExtractVector(*full, block, *vv);
210  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
211  Xpetra::Exceptions::RuntimeError,
212  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
213  "created using Thyra-style numbered submaps.");
214  if (bThyraMode == true)
215  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
216  full->replaceMap(oldThyMapFull);
217  return vv;
218  //}
219  } else {
220  // special case: full is of type BlockedMultiVector
221  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != bfull->getBlockedMap()->getNumMaps(),
222  Xpetra::Exceptions::RuntimeError,
223  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
224  << bfull->getBlockedMap()->getNumMaps()
225  << " (number of blocks in BlockedMultiVector)");
226  return bfull->getMultiVector(block, bThyraMode);
227  }
228 }
229 
230 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
231 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
233  ExtractVector(RCP<const Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& full, size_t block, bool bThyraMode) const {
234  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
235  std::out_of_range,
236  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
237  << " partial blocks.");
239  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
240  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != full->getBlockedMap()->getNumMaps(),
241  Xpetra::Exceptions::RuntimeError,
242  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
243  << full->getBlockedMap()->getNumMaps()
244  << " (number of blocks in BlockedMultiVector)");
245  Teuchos::RCP<MultiVector> vv = full->getMultiVector(block, bThyraMode);
246  return vv;
247 }
248 
249 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
250 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
253  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
254  std::out_of_range,
255  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
256  << " partial blocks.");
258  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
259  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != full->getBlockedMap()->getNumMaps(),
260  Xpetra::Exceptions::RuntimeError,
261  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
262  << full->getBlockedMap()->getNumMaps()
263  << " (number of blocks in BlockedMultiVector)");
264  Teuchos::RCP<MultiVector> vv = full->getMultiVector(block, bThyraMode);
265  return vv;
266 }
267 
268 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
270  InsertVector(const Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& partial, size_t block, Vector& full, bool bThyraMode) const {
271  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
272  std::out_of_range,
273  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
274  << " partial blocks.");
276  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
277  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
278  Xpetra::Exceptions::RuntimeError,
279  "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
280  "using Thyra-style numbered submaps.");
281  if (bThyraMode) {
282  // NOTE: the importer objects in the BlockedMap are always using Xpetra GIDs (or Thyra style Xpetra GIDs)
283  // The source map corresponds to the full map (in Xpetra GIDs) starting with GIDs from zero. The GIDs are consecutive in Thyra mode
284  // The target map is the partial map (in the corresponding Xpetra GIDs)
285 
286  // TODO can we skip the Export call in special cases (i.e. Src = Target map, same length, etc...)
287 
288  // store original GIDs (could be Thyra GIDs)
289  RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
290  RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<MultiVector>(rcpPartial);
291  RCP<const Map> oldThyMapPartial = rcpNonConstPartial->getMap(); // temporarely store map of partial
292  RCP<const Map> oldThyMapFull = full.getMap(); // temporarely store map of full
293 
294  // check whether getMap(block,false) is identical to target map of importer
295  XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block, false)->isSameAs(*(map_->getImporter(block)->getTargetMap())) == false,
296  Xpetra::Exceptions::RuntimeError,
297  "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of partial vector are not identical "
298  "to target Map of Importer. This should not be.");
299 
300  // XPETRA_TEST_FOR_EXCEPTION(full.getMap()->isSameAs(*(map_->getImporter(block)->getSourceMap()))==false,
301  // Xpetra::Exceptions::RuntimeError,
302  // "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of full vector are not identical to source Map of
303  // Importer. This should not be.");
304 
305  rcpNonConstPartial->replaceMap(getMap(block, false)); // temporarely switch to xpetra-style map
306  full.replaceMap(map_->getImporter(block)->getSourceMap()); // temporarely switch to Xpetra GIDs
307 
308  // do the Export
309  full.doExport(*rcpNonConstPartial, *(map_->getImporter(block)), Xpetra::INSERT);
310 
311  // switch back to original maps
312  full.replaceMap(oldThyMapFull); // reset original map (Thyra GIDs)
313  rcpNonConstPartial->replaceMap(oldThyMapPartial); // change map back to original map
314  } else {
315  // Xpetra style numbering
316  full.doExport(partial, *(map_->getImporter(block)), Xpetra::INSERT);
317  }
318 }
319 
320 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
322  InsertVector(const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& partial, size_t block, MultiVector& full, bool bThyraMode) const {
323  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
324  std::out_of_range,
325  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
326  << " partial blocks.");
328  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
329  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
330  Xpetra::Exceptions::RuntimeError,
331  "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
332  "using Thyra-style numbered submaps.");
333  if (bThyraMode) {
334  // NOTE: the importer objects in the BlockedMap are always using Xpetra GIDs (or Thyra style Xpetra GIDs)
335  // The source map corresponds to the full map (in Xpetra GIDs) starting with GIDs from zero. The GIDs are consecutive in Thyra mode
336  // The target map is the partial map (in the corresponding Xpetra GIDs)
337 
338  // TODO can we skip the Export call in special cases (i.e. Src = Target map, same length, etc...)
339 
340  // store original GIDs (could be Thyra GIDs)
341  RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
342  RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<MultiVector>(rcpPartial);
343  RCP<const Map> oldThyMapPartial = rcpNonConstPartial->getMap(); // temporarely store map of partial
344  RCP<const Map> oldThyMapFull = full.getMap(); // temporarely store map of full
345 
346  // check whether getMap(block,false) is identical to target map of importer
347  XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block, false)->isSameAs(*(map_->getImporter(block)->getTargetMap())) == false,
348  Xpetra::Exceptions::RuntimeError,
349  "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of partial vector are not identical "
350  "to target Map of Importer. This should not be.");
351 
352  // XPETRA_TEST_FOR_EXCEPTION(full.getMap()->isSameAs(*(map_->getImporter(block)->getSourceMap()))==false,
353  // Xpetra::Exceptions::RuntimeError,
354  // "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of full vector are not identical to source Map of
355  // Importer. This should not be.");
356 
357  rcpNonConstPartial->replaceMap(getMap(block, false)); // temporarely switch to xpetra-style map
358  full.replaceMap(map_->getImporter(block)->getSourceMap()); // temporarely switch to Xpetra GIDs
359 
360  // do the Export
361  full.doExport(*rcpNonConstPartial, *(map_->getImporter(block)), Xpetra::INSERT);
362 
363  // switch back to original maps
364  full.replaceMap(oldThyMapFull); // reset original map (Thyra GIDs)
365  rcpNonConstPartial->replaceMap(oldThyMapPartial); // change map back to original map
366  } else {
367  // Xpetra style numbering
368  full.doExport(partial, *(map_->getImporter(block)), Xpetra::INSERT);
369  }
370 }
371 
372 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
374  InsertVector(RCP<const Vector> partial, size_t block, RCP<Vector> full, bool bThyraMode) const {
375  InsertVector(*partial, block, *full, bThyraMode);
376 }
377 
378 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
380  InsertVector(RCP<Vector> partial, size_t block, RCP<Vector> full, bool bThyraMode) const {
381  InsertVector(*partial, block, *full, bThyraMode);
382 }
383 
384 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
387  size_t block,
389  bool bThyraMode) const {
390  RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
391  if (bfull.is_null() == true)
392  InsertVector(*partial, block, *full, bThyraMode);
393  else {
395  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
396 
397 #if 0
398  // WCMCLEN - ETI: MultiVector::setMultiVector() doesn't exist.
399  // WCMCLEN - ETI: but BlockedMultiVector::setMultiVector() does... should this be using bfull.
400  full->setMultiVector(block, partial, bThyraMode);
401 #else
402  throw std::runtime_error("Xpetra::MultiVector::setMultiVector() doesn't exist in " + std::string(__FILE__) + ":" + std::to_string(__LINE__));
403 #endif
404  }
405 }
406 
407 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
410  size_t block,
412  bool bThyraMode) const {
413  RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
414  if (bfull.is_null() == true)
415  InsertVector(*partial, block, *full, bThyraMode);
416  else {
418  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
419 
420  bfull->setMultiVector(block, partial, bThyraMode);
421  }
422 }
423 
424 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
427  size_t block,
429  bool bThyraMode) const {
431  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
432 
433  full->setMultiVector(block, partial, bThyraMode);
434 }
435 
436 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
439  size_t block,
441  bool bThyraMode) const {
443  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
444  full->setMultiVector(block, partial, bThyraMode);
445 }
446 
447 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
448 RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
450  getVector(size_t i, bool bThyraMode, bool bZero) const {
451  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
452  Xpetra::Exceptions::RuntimeError,
453  "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using "
454  "Thyra-style numbered submaps.");
455  // TODO check whether this can return a blocked multivector
457 }
458 
459 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
460 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
462  getVector(size_t i, size_t numvec, bool bThyraMode, bool bZero) const {
463  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
464  Xpetra::Exceptions::RuntimeError,
465  "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using "
466  "Thyra-style numbered submaps.");
467  // TODO check whether this can return a blocked multivector
468  return MultiVectorFactory::Build(getMap(i, bThyraMode), numvec, bZero);
469 }
470 
472 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
474  getThyraMode() const {
475  return map_->getThyraMode();
476 }
477 
478 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
479 size_t
481  NumMaps() const {
482  return map_->getNumMaps();
483 }
484 
485 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
486 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
488  getMap(size_t i, bool bThyraMode) const {
489  return map_->getMap(i, bThyraMode);
490 }
491 
492 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
493 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
495  getMap() const {
496  return map_;
497 }
498 
499 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
500 const RCP<const Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node>>
502  getBlockedMap() const {
503  return map_;
504 }
505 
506 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
507 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
509  getFullMap() const {
510  return map_->getFullMap();
511 }
512 
513 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
514 size_t
516  getMapIndexForGID(GlobalOrdinal gid) const {
517  return map_->getMapIndexForGID(gid);
518 }
519 
520 } // namespace Xpetra
521 
522 #endif /* XPETRA_MAPEXTRACTOR_DEF_HPP_ */
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map)=0
size_t getMapIndexForGID(GlobalOrdinal gid) const
returns map index in map extractor which contains GID
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 (&quot;forward mode&quot;).
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.
const RCP< const Map > getFullMap() const
the full map
const RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, Node > > getBlockedMap() const
get the underlying BlockedMap object (as BlockedMap)
virtual ~MapExtractor()
Destructor.
MapExtractor(const RCP< const Map > &fullmap, const std::vector< RCP< const Map >> &maps, bool bThyraMode=false)
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.
Exception throws to report errors in the internal logical of the program.
bool getThyraMode() const
returns true, if sub maps are stored in Thyra-style numbering
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 (&quot;forward mode&quot;).
RCP< Vector > getVector(size_t i, bool bThyraMode=false, bool bZero=true) const
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
void InsertVector(const Vector &partial, size_t block, Vector &full, bool bThyraMode=false) const
const RCP< const Map > getMap() const
get the underlying BlockedMap object (as Map)
void ExtractVector(const Vector &full, size_t block, Vector &partial) const
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
size_t NumMaps() const
number of partial maps