All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_MapExtractor_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_MAPEXTRACTOR_DEF_HPP_
47 #define XPETRA_MAPEXTRACTOR_DEF_HPP_
48 
49 #include <Xpetra_MultiVectorFactory.hpp>
50 #include <Xpetra_VectorFactory.hpp>
51 
53 
54 namespace Xpetra {
55 
56 
57  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
59  MapExtractor(const RCP<const Map>& fullmap, const std::vector<RCP<const Map> >& maps, bool bThyraMode)
60  {
61  map_ = Teuchos::rcp(new BlockedMap(fullmap, maps, bThyraMode));
62  }
63 
64  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
66  MapExtractor(const std::vector<RCP<const Map> >& maps, const std::vector<RCP<const Map> >& thyramaps)
67  {
68  map_ = Teuchos::rcp(new BlockedMap(maps, thyramaps));
69  }
70 
71  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74  : map_(map)
75  {}
76 
77 
78  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
81  {
82  map_ = Teuchos::rcp(new BlockedMap(*(input.getBlockedMap())));
83  }
84 
85 
86  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
89  {
90  map_ = Teuchos::null;
91  }
92 
93 
94  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
95  void
97  ExtractVector(const Vector& full, size_t block, Vector& partial) const
98  {
99  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(), std::out_of_range,
100  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps() << " partial blocks.");
101  XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block,false) == null, Xpetra::Exceptions::RuntimeError,
102  "ExtractVector: map_->getMap(" << block << ",false) is null");
103 
104  partial.doImport(full, *(map_->getImporter(block)), Xpetra::INSERT);
105  }
106 
107 
108  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
109  void
111  ExtractVector(const MultiVector& full, size_t block, MultiVector& partial) const
112  {
113  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
114  std::out_of_range,
115  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
116  << " partial blocks.");
118  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getMap(" << block << ",false) is null");
119 
120  partial.doImport(full, *(map_->getImporter(block)), Xpetra::INSERT);
121  }
122 
123 
124  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
125  void
127  ExtractVector(RCP<const Vector>& full, size_t block, RCP<Vector>& partial) const
128  {
129  ExtractVector(*full, block, *partial);
130  }
131 
132 
133  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
134  void
136  ExtractVector(RCP<Vector>& full, size_t block, RCP<Vector>& partial) const
137  {
138  ExtractVector(*full, block, *partial);
139  }
140 
141 
142  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
143  void
145  ExtractVector(RCP<const MultiVector>& full, size_t block, RCP<MultiVector>& partial) const
146  {
147  ExtractVector(*full, block, *partial);
148  }
149 
150 
151  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
152  void
154  ExtractVector(RCP<MultiVector>& full, size_t block, RCP<MultiVector>& partial) const
155  {
156  ExtractVector(*full, block, *partial);
157  }
158 
159 
160  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
163  ExtractVector(RCP<const Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& full, size_t block, bool bThyraMode) const
164  {
165  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
166  std::out_of_range,
167  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
168  << " partial blocks.");
170  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getMap(" << block << ",false) is null");
171  // first extract partial vector from full vector (using xpetra style GIDs)
173  ExtractVector(*full, block, *vv);
174  if(bThyraMode == false)
175  return vv;
176  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
177  Xpetra::Exceptions::RuntimeError,
178  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
179  "created using Thyra-style numbered submaps.");
180  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
181  return vv;
182  }
183 
184 
185  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
189  {
192 
193  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
194  std::out_of_range,
195  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
196  << " partial blocks.");
198  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
199  // first extract partial vector from full vector (using xpetra style GIDs)
200  const RCP<Vector> vv = VectorFactory::Build(getMap(block, false), false);
201  ExtractVector(*full, block, *vv);
202  if(bThyraMode == false)
203  return vv;
204  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
205  Xpetra::Exceptions::RuntimeError,
206  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
207  "created using Thyra-style numbered submaps.");
208  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
209  return vv;
210  }
211 
212 
213  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
216  ExtractVector(RCP<const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> >& full, size_t block, bool bThyraMode) const
217  {
220 
221  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
222  std::out_of_range,
223  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
224  << " partial blocks.");
226  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
227  RCP<const BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(full);
228  if(bfull.is_null() == true)
229  {
230  // standard case: full is not of type BlockedMultiVector
231  // first extract partial vector from full vector (using xpetra style GIDs)
232  const RCP<MultiVector> vv = MultiVectorFactory::Build(getMap(block, false), full->getNumVectors(), false);
233  // if(bThyraMode == false) {
234  // ExtractVector(*full, block, *vv);
235  // return vv;
236  //} else {
237  RCP<const Map> oldThyMapFull = full->getMap(); // temporarely store map of full
238  RCP<MultiVector> rcpNonConstFull = Teuchos::rcp_const_cast<MultiVector>(full);
239  rcpNonConstFull->replaceMap(map_->getImporter(block)->getSourceMap());
240  ExtractVector(*rcpNonConstFull, block, *vv);
241  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
242  Xpetra::Exceptions::RuntimeError,
243  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
244  "created using Thyra-style numbered submaps.");
245  if(bThyraMode == true)
246  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
247  rcpNonConstFull->replaceMap(oldThyMapFull);
248  return vv;
249  //}
250  }
251  else
252  {
253  // special case: full is of type BlockedMultiVector
254  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != bfull->getBlockedMap()->getNumMaps(),
255  Xpetra::Exceptions::RuntimeError,
256  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
257  << bfull->getBlockedMap()->getNumMaps()
258  << " (number of blocks in BlockedMultiVector)");
259  return bfull->getMultiVector(block, bThyraMode);
260  }
261  }
262 
263 
264  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
268  {
272 
273  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
274  std::out_of_range,
275  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
276  << " partial blocks.");
278  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
279  RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
280  if(bfull.is_null() == true)
281  {
282  // standard case: full is not of type BlockedMultiVector
283  // first extract partial vector from full vector (using xpetra style GIDs)
284  const RCP<MultiVector> vv = MultiVectorFactory::Build(getMap(block, false), full->getNumVectors(), false);
285  // if(bThyraMode == false) {
286  // ExtractVector(*full, block, *vv);
287  // return vv;
288  //} else {
289  RCP<const Map> oldThyMapFull = full->getMap(); // temporarely store map of full
290  full->replaceMap(map_->getImporter(block)->getSourceMap());
291  ExtractVector(*full, block, *vv);
292  TEUCHOS_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
293  Xpetra::Exceptions::RuntimeError,
294  "MapExtractor::ExtractVector: ExtractVector in Thyra-style numbering only possible if MapExtractor has been "
295  "created using Thyra-style numbered submaps.");
296  if(bThyraMode == true)
297  vv->replaceMap(getMap(block, true)); // switch to Thyra-style map
298  full->replaceMap(oldThyMapFull);
299  return vv;
300  //}
301  }
302  else
303  {
304  // special case: full is of type BlockedMultiVector
305  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != bfull->getBlockedMap()->getNumMaps(),
306  Xpetra::Exceptions::RuntimeError,
307  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
308  << bfull->getBlockedMap()->getNumMaps()
309  << " (number of blocks in BlockedMultiVector)");
310  return bfull->getMultiVector(block, bThyraMode);
311  }
312  }
313 
314 
315  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
319  {
321 
322  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
323  std::out_of_range,
324  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
325  << " partial blocks.");
327  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
328  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != full->getBlockedMap()->getNumMaps(),
329  Xpetra::Exceptions::RuntimeError,
330  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
331  << full->getBlockedMap()->getNumMaps()
332  << " (number of blocks in BlockedMultiVector)");
333  Teuchos::RCP<MultiVector> vv = full->getMultiVector(block, bThyraMode);
334  return vv;
335  }
336 
337 
338  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
342  {
344 
345  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
346  std::out_of_range,
347  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
348  << " partial blocks.");
350  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
351  XPETRA_TEST_FOR_EXCEPTION(map_->getNumMaps() != full->getBlockedMap()->getNumMaps(),
352  Xpetra::Exceptions::RuntimeError,
353  "ExtractVector: Number of blocks in map extractor is " << map_->getNumMaps() << " but should be "
354  << full->getBlockedMap()->getNumMaps()
355  << " (number of blocks in BlockedMultiVector)");
356  Teuchos::RCP<MultiVector> vv = full->getMultiVector(block, bThyraMode);
357  return vv;
358  }
359 
360 
361  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
362  void
364  InsertVector(const Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& partial, size_t block, Vector& full, bool bThyraMode) const
365  {
368 
369  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
370  std::out_of_range,
371  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
372  << " partial blocks.");
374  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
375  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
376  Xpetra::Exceptions::RuntimeError,
377  "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
378  "using Thyra-style numbered submaps.");
379  if(bThyraMode)
380  {
381  // NOTE: the importer objects in the BlockedMap are always using Xpetra GIDs (or Thyra style Xpetra GIDs)
382  // The source map corresponds to the full map (in Xpetra GIDs) starting with GIDs from zero. The GIDs are consecutive in Thyra mode
383  // The target map is the partial map (in the corresponding Xpetra GIDs)
384 
385  // TODO can we skip the Export call in special cases (i.e. Src = Target map, same length, etc...)
386 
387  // store original GIDs (could be Thyra GIDs)
388  RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
389  RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<MultiVector>(rcpPartial);
390  RCP<const Map> oldThyMapPartial = rcpNonConstPartial->getMap(); // temporarely store map of partial
391  RCP<const Map> oldThyMapFull = full.getMap(); // temporarely store map of full
392 
393  // check whether getMap(block,false) is identical to target map of importer
394  XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block, false)->isSameAs(*(map_->getImporter(block)->getTargetMap())) == false,
395  Xpetra::Exceptions::RuntimeError,
396  "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of partial vector are not identical "
397  "to target Map of Importer. This should not be.");
398 
399  // XPETRA_TEST_FOR_EXCEPTION(full.getMap()->isSameAs(*(map_->getImporter(block)->getSourceMap()))==false,
400  // Xpetra::Exceptions::RuntimeError,
401  // "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of full vector are not identical to source Map of
402  // Importer. This should not be.");
403 
404  rcpNonConstPartial->replaceMap(getMap(block, false)); // temporarely switch to xpetra-style map
405  full.replaceMap(map_->getImporter(block)->getSourceMap()); // temporarely switch to Xpetra GIDs
406 
407  // do the Export
408  full.doExport(*rcpNonConstPartial, *(map_->getImporter(block)), Xpetra::INSERT);
409 
410  // switch back to original maps
411  full.replaceMap(oldThyMapFull); // reset original map (Thyra GIDs)
412  rcpNonConstPartial->replaceMap(oldThyMapPartial); // change map back to original map
413  }
414  else
415  {
416  // Xpetra style numbering
417  full.doExport(partial, *(map_->getImporter(block)), Xpetra::INSERT);
418  }
419  }
420 
421 
422  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
423  void
425  InsertVector(const Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& partial, size_t block, MultiVector& full, bool bThyraMode) const
426  {
429 
430  XPETRA_TEST_FOR_EXCEPTION(block >= map_->getNumMaps(),
431  std::out_of_range,
432  "ExtractVector: Error, block = " << block << " is too big. The MapExtractor only contains " << map_->getNumMaps()
433  << " partial blocks.");
435  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "ExtractVector: map_->getmap(" << block << ",false) is null");
436  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
437  Xpetra::Exceptions::RuntimeError,
438  "MapExtractor::InsertVector: InsertVector in Thyra-style numbering only possible if MapExtractor has been created "
439  "using Thyra-style numbered submaps.");
440  if(bThyraMode)
441  {
442  // NOTE: the importer objects in the BlockedMap are always using Xpetra GIDs (or Thyra style Xpetra GIDs)
443  // The source map corresponds to the full map (in Xpetra GIDs) starting with GIDs from zero. The GIDs are consecutive in Thyra mode
444  // The target map is the partial map (in the corresponding Xpetra GIDs)
445 
446  // TODO can we skip the Export call in special cases (i.e. Src = Target map, same length, etc...)
447 
448  // store original GIDs (could be Thyra GIDs)
449  RCP<const MultiVector> rcpPartial = Teuchos::rcpFromRef(partial);
450  RCP<MultiVector> rcpNonConstPartial = Teuchos::rcp_const_cast<MultiVector>(rcpPartial);
451  RCP<const Map> oldThyMapPartial = rcpNonConstPartial->getMap(); // temporarely store map of partial
452  RCP<const Map> oldThyMapFull = full.getMap(); // temporarely store map of full
453 
454  // check whether getMap(block,false) is identical to target map of importer
455  XPETRA_TEST_FOR_EXCEPTION(map_->getMap(block, false)->isSameAs(*(map_->getImporter(block)->getTargetMap())) == false,
456  Xpetra::Exceptions::RuntimeError,
457  "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of partial vector are not identical "
458  "to target Map of Importer. This should not be.");
459 
460  // XPETRA_TEST_FOR_EXCEPTION(full.getMap()->isSameAs(*(map_->getImporter(block)->getSourceMap()))==false,
461  // Xpetra::Exceptions::RuntimeError,
462  // "MapExtractor::InsertVector: InsertVector in Thyra-style mode: Xpetra GIDs of full vector are not identical to source Map of
463  // Importer. This should not be.");
464 
465  rcpNonConstPartial->replaceMap(getMap(block, false)); // temporarely switch to xpetra-style map
466  full.replaceMap(map_->getImporter(block)->getSourceMap()); // temporarely switch to Xpetra GIDs
467 
468  // do the Export
469  full.doExport(*rcpNonConstPartial, *(map_->getImporter(block)), Xpetra::INSERT);
470 
471  // switch back to original maps
472  full.replaceMap(oldThyMapFull); // reset original map (Thyra GIDs)
473  rcpNonConstPartial->replaceMap(oldThyMapPartial); // change map back to original map
474  }
475  else
476  {
477  // Xpetra style numbering
478  full.doExport(partial, *(map_->getImporter(block)), Xpetra::INSERT);
479  }
480  }
481 
482 
483 
484  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
485  void
487  InsertVector(RCP<const Vector> partial, size_t block, RCP<Vector> full, bool bThyraMode) const
488  {
489  InsertVector(*partial, block, *full, bThyraMode);
490  }
491 
492 
493  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
494  void
496  InsertVector(RCP<Vector> partial, size_t block, RCP<Vector> full, bool bThyraMode) const
497  {
498  InsertVector(*partial, block, *full, bThyraMode);
499  }
500 
501 
502  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
503  void
506  size_t block,
508  bool bThyraMode) const
509  {
511 
512  RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
513  if(bfull.is_null() == true)
514  InsertVector(*partial, block, *full, bThyraMode);
515  else
516  {
518  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
519 
520  #if 0
521  // WCMCLEN - ETI: MultiVector::setMultiVector() doesn't exist.
522  // WCMCLEN - ETI: but BlockedMultiVector::setMultiVector() does... should this be using bfull.
523  full->setMultiVector(block, partial, bThyraMode);
524  #else
525  throw std::runtime_error("Xpetra::MultiVector::setMultiVector() doesn't exist.");
526  #endif
527  }
528  }
529 
530 
531  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
532  void
535  size_t block,
537  bool bThyraMode) const
538  {
540 
541  RCP<BlockedMultiVector> bfull = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(full);
542  if(bfull.is_null() == true)
543  InsertVector(*partial, block, *full, bThyraMode);
544  else
545  {
547  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
548 
549  bfull->setMultiVector(block, partial, bThyraMode);
550  }
551  }
552 
553 
554  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
555  void
558  size_t block,
560  bool bThyraMode) const
561  {
563  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
564 
565  full->setMultiVector(block, partial, bThyraMode);
566  }
567 
568 
569  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
570  void
573  size_t block,
575  bool bThyraMode ) const
576  {
578  map_->getMap(block, false) == null, Xpetra::Exceptions::RuntimeError, "InsertVector: map_->getmap(" << block << ",false) is null");
579  full->setMultiVector(block, partial, bThyraMode);
580  }
581 
582 
583  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
584  RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
586  getVector(size_t i, bool bThyraMode, bool bZero) const
587  {
589  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
590  Xpetra::Exceptions::RuntimeError,
591  "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using "
592  "Thyra-style numbered submaps.");
593  // TODO check whether this can return a blocked multivector
594  return VectorFactory::Build(getMap(i, bThyraMode), bZero);
595  }
596 
597 
598  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
601  getVector(size_t i, size_t numvec, bool bThyraMode, bool bZero) const
602  {
604 
605  XPETRA_TEST_FOR_EXCEPTION(map_->getThyraMode() == false && bThyraMode == true,
606  Xpetra::Exceptions::RuntimeError,
607  "MapExtractor::getVector: getVector in Thyra-style numbering only possible if MapExtractor has been created using "
608  "Thyra-style numbered submaps.");
609  // TODO check whether this can return a blocked multivector
610  return MultiVectorFactory::Build(getMap(i, bThyraMode), numvec, bZero);
611  }
612 
614  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
615  bool
618  {
619  return map_->getThyraMode();
620  }
621 
622 
623  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
624  size_t
626  NumMaps() const
627  {
628  return map_->getNumMaps();
629  }
630 
631 
632  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
635  getMap(size_t i, bool bThyraMode) const
636  {
637  return map_->getMap(i, bThyraMode);
638  }
639 
640 
641  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
644  getMap() const
645  {
646  return map_;
647  }
648 
649 
650  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
654  {
655  return map_;
656  }
657 
658 
659  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
662  getFullMap() const
663  {
664  return map_->getFullMap();
665  }
666 
667 
668  template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
669  size_t
671  getMapIndexForGID(GlobalOrdinal gid) const
672  {
673  return map_->getMapIndexForGID(gid);
674  }
675 
676 
677 } // namespace Xpetra
678 
679 #endif /* XPETRA_MAPEXTRACTOR_DEF_HPP_ */
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Exception throws to report errors in the internal logical of the program.
virtual void replaceMap(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)=0
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
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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)
MapExtractor(const RCP< const Map > &fullmap, const std::vector< RCP< const Map > > &maps, bool bThyraMode=false)
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
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
void ExtractVector(RCP< Vector > &full, size_t block, RCP< Vector > &partial) const