Xpetra_BlockedMultiVector.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 // Tobias Wiesner (tawiesn@sandia.gov)
42 // Ray Tuminaro (rstumin@sandia.gov)
43 //
44 // ***********************************************************************
45 //
46 // @HEADER
47 #ifndef XPETRA_BLOCKEDMULTIVECTOR_HPP
48 #define XPETRA_BLOCKEDMULTIVECTOR_HPP
49 
50 /* this file is automatically generated - do not edit (see script/interfaces.py) */
51 
52 #include "Xpetra_ConfigDefs.hpp"
53 #include "Xpetra_Map.hpp"
54 #include "Xpetra_MultiVector.hpp"
55 #include "Xpetra_MapExtractor.hpp"
56 
57 
58 namespace Xpetra {
59 
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61  // forward declaration of Vector, needed to prevent circular inclusions
62  template<class S, class LO, class GO, class N> class Vector;
63 #endif
64 
65  template <class Scalar = double,
66  class LocalOrdinal = Map<>::local_ordinal_type,
67  class GlobalOrdinal = typename Map<LocalOrdinal>::global_ordinal_type,
68  class Node = typename Map<LocalOrdinal, GlobalOrdinal>::node_type>
70  : public MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >
71  {
72  public:
73  typedef Scalar scalar_type;
74  typedef LocalOrdinal local_ordinal_type;
75  typedef GlobalOrdinal global_ordinal_type;
76  typedef Node node_type;
77 
78  private:
79 #undef XPETRA_BLOCKEDMULTIVECTOR_SHORT
80 #include "Xpetra_UseShortNames.hpp"
81 
82  public:
84 
85 
87 
98  BlockedMultiVector(Teuchos::RCP<const MapExtractor> mapExtractor,
99  Teuchos::RCP<const MultiVector> v)
100  : mapextractor_(mapExtractor)
101  {
102  bThyraMode_ = mapExtractor->getThyraMode();
103 
104  vv_.reserve(mapExtractor->NumMaps());
105 
106  // add CrsMatrix objects in row,column order
107  for (size_t r = 0; r < mapExtractor->NumMaps(); ++r)
108  vv_.push_back(mapExtractor->ExtractVector(v, r, bThyraMode_));
109 
110  numVectors_ = v->getNumVectors();
111  }
112 
124  BlockedMultiVector(Teuchos::RCP<const MapExtractor> mapExtractor,
125  Teuchos::RCP<MultiVector> v)
126  : mapextractor_(mapExtractor)
127  {
128  bThyraMode_ = mapExtractor->getThyraMode();
129 
130  vv_.reserve(mapExtractor->NumMaps());
131 
132  // add CrsMatrix objects in row,column order
133  for (size_t r = 0; r < mapExtractor->NumMaps(); ++r)
134  vv_.push_back(mapExtractor->ExtractVector(v, r, bThyraMode_));
135 
136  numVectors_ = v->getNumVectors();
137  }
138 
140  virtual ~BlockedMultiVector() { }
141 
150  operator= (const MultiVector& rhs) {
151  assign (rhs); // dispatch to protected virtual method
152  return *this;
153  }
154 
156 
158 
160  virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {
161  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::replaceGlobalValue: Not (yet) supported by BlockedMultiVector.");
162  }
163 
165  virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value) {
166  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::sumIntoGlobalValue: Not (yet) supported by BlockedMultiVector.");
167  }
168 
170  virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {
171  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::replaceLocalValue: Not supported by BlockedMultiVector.");
172  }
173 
175  virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value) {
176  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::sumIntoLocalValue:Not (yet) supported by BlockedMultiVector.");
177  }
178 
180  virtual void putScalar(const Scalar &value) {
181  for(size_t r = 0; r < getMapExtractor()->NumMaps(); r++) {
182  getMultiVector(r)->putScalar(value);
183  }
184  }
185 
187 
189 
190 
192  virtual Teuchos::RCP< const Vector > getVector(size_t j) const {
193  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::getVector: Not (yet) supported by BlockedMultiVector.");
194  return Teuchos::null;
195  }
196 
198  virtual Teuchos::RCP< Vector> getVectorNonConst(size_t j) {
199  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::getVectorNonConst: Not (yet) supported by BlockedMultiVector.");
200  return Teuchos::null;
201  }
202 
204  virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const {
205  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::getData: Not (yet) supported by BlockedMultiVector.");
206  return Teuchos::null;
207  }
208 
210  virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j) {
211  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::getDataNonConst: Not (yet) supported by BlockedMultiVector.");
212  return Teuchos::null;
213  }
214 
216 
218 
219 
221  virtual void dot(const MultiVector&A, const Teuchos::ArrayView< Scalar > &dots) const {
222  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::dot: Not (yet) supported by BlockedMultiVector.");
223  }
224 
226  virtual void abs(const MultiVector&A) {
227  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::abs: Not (yet) supported by BlockedMultiVector.");
228  }
229 
231  virtual void reciprocal(const MultiVector&A) {
232  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::reciprocal: Not (yet) supported by BlockedMultiVector.");
233  }
234 
236  virtual void scale(const Scalar &alpha) {
237  for (size_t r = 0; r < getMapExtractor()->NumMaps(); ++r) {
238  if(getMultiVector(r)!=Teuchos::null) {
239  getMultiVector(r)->scale(alpha);
240  }
241  }
242  }
243 
245  virtual void scale (Teuchos::ArrayView< const Scalar > alpha) {
246  for (size_t r = 0; r < getMapExtractor()->NumMaps(); ++r) {
247  if(getMultiVector(r)!=Teuchos::null) {
248  getMultiVector(r)->scale(alpha);
249  }
250  }
251  }
252 
254  virtual void update(const Scalar &alpha, const MultiVector&A, const Scalar &beta) {
255  Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
256  Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(rcpA);
257  TEUCHOS_TEST_FOR_EXCEPTION(numVectors_ != rcpA->getNumVectors(),Xpetra::Exceptions::RuntimeError,"BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector).");
258  if(bA != Teuchos::null) {
259  TEUCHOS_TEST_FOR_EXCEPTION(bThyraMode_ != bA->getMapExtractor()->getThyraMode(), Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different thyra mode).");
260  TEUCHOS_TEST_FOR_EXCEPTION(getMapExtractor()->NumMaps() != bA->getMapExtractor()->NumMaps(), Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors).");
261  for(size_t r = 0; r < getMapExtractor()->NumMaps(); r++) {
262  XPETRA_TEST_FOR_EXCEPTION(getMultiVector(r)->getMap()->isSameAs(*(bA->getMultiVector(r)->getMap()))==false, Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different maps in partial vector " << r << ").");
263  getMultiVector(r)->update(alpha, *(bA->getMultiVector(r)), beta);
264  }
265  } else {
266  XPETRA_TEST_FOR_EXCEPTION(getMapExtractor()->getFullMap()->isSameAs(*(rcpA->getMap()))==false, Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (maps of full vector do not match with map in MapExtractor).");
267  for(size_t r = 0; r < getMapExtractor()->NumMaps(); r++) {
268  Teuchos::RCP<const MultiVector> part = getMapExtractor()->ExtractVector(rcpA, r, bThyraMode_);
269  getMultiVector(r)->update(alpha, *part, beta);
270  }
271  }
272  }
273 
275  virtual void update(const Scalar &alpha, const MultiVector&A, const Scalar &beta, const MultiVector&B, const Scalar &gamma) {
276  Teuchos::RCP<const MultiVector> rcpA = Teuchos::rcpFromRef(A);
277  Teuchos::RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
278  Teuchos::RCP<const BlockedMultiVector> bA = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(rcpA);
279  Teuchos::RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(rcpB);
280  if(bA != Teuchos::null && bB != Teuchos::null) {
281  TEUCHOS_TEST_FOR_EXCEPTION(bThyraMode_ != bA->getMapExtractor()->getThyraMode(), Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector A).");
282  TEUCHOS_TEST_FOR_EXCEPTION(getMapExtractor()->NumMaps() != bA->getMapExtractor()->NumMaps(), Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector A).");
283  TEUCHOS_TEST_FOR_EXCEPTION(numVectors_ != bA->getNumVectors(),Xpetra::Exceptions::RuntimeError,"BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector A).");
284  TEUCHOS_TEST_FOR_EXCEPTION(bThyraMode_ != bB->getMapExtractor()->getThyraMode(), Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different thyra mode in vector B).");
285  TEUCHOS_TEST_FOR_EXCEPTION(getMapExtractor()->NumMaps() != bB->getMapExtractor()->NumMaps(), Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different number of partial vectors in vector B).");
286  TEUCHOS_TEST_FOR_EXCEPTION(numVectors_ != bB->getNumVectors(),Xpetra::Exceptions::RuntimeError,"BlockedMultiVector::update: update with incompatible vector (different number of vectors in multivector in vector B).");
287 
288  for(size_t r = 0; r < getMapExtractor()->NumMaps(); r++) {
289  XPETRA_TEST_FOR_EXCEPTION(getMultiVector(r)->getMap()->isSameAs(*(bA->getMultiVector(r)->getMap()))==false, Xpetra::Exceptions::RuntimeError, "BlockedMultiVector::update: update with incompatible vector (different maps in partial vector " << r << ").");
290  getMultiVector(r)->update(alpha, *(bA->getMultiVector(r)), beta, *(bB->getMultiVector(r)), gamma);
291  }
292  return;
293  }
294  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::update: only supports update with other BlockedMultiVector.");
295  }
296 
298  virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const {
299  typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
300  Array<Magnitude> temp_norms(getNumVectors());
301  std::fill(temp_norms.begin(),temp_norms.end(),ScalarTraits<Magnitude>::zero());
302  for (size_t r = 0; r < getMapExtractor()->NumMaps(); ++r) {
303  if(getMultiVector(r)!=Teuchos::null) {
304  getMultiVector(r)->norm1(temp_norms);
305  for (size_t c = 0; c < getNumVectors(); ++c)
306  norms[c] += temp_norms[c];
307  }
308  }
309  }
310 
312  virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const {
313  typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
314  Array<Magnitude> results(getNumVectors());
315  Array<Magnitude> temp_norms(getNumVectors());
316  std::fill(results.begin(),results.end(),ScalarTraits<Magnitude>::zero());
317  std::fill(temp_norms.begin(),temp_norms.end(),ScalarTraits<Magnitude>::zero());
318  for (size_t r = 0; r < getMapExtractor()->NumMaps(); ++r) {
319  if(getMultiVector(r)!=Teuchos::null) {
320  getMultiVector(r)->norm2(temp_norms);
321  for (size_t c = 0; c < getNumVectors(); ++c)
322  results[c] += temp_norms[c] * temp_norms[c];
323  }
324  }
325  for (size_t c = 0; c < getNumVectors(); ++c)
326  norms[c] = Teuchos::ScalarTraits<Magnitude >::squareroot(results[c]);
327  }
328 
330  virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const {
331  typedef typename ScalarTraits<Scalar>::magnitudeType Magnitude;
332  Array<Magnitude> temp_norms(getNumVectors());
333  std::fill(temp_norms.begin(),temp_norms.end(),ScalarTraits<Magnitude>::zero());
334  for (size_t r = 0; r < getMapExtractor()->NumMaps(); ++r) {
335  if(getMultiVector(r)!=Teuchos::null) {
336  getMultiVector(r)->normInf(temp_norms);
337  for (size_t c = 0; c < getNumVectors(); ++c)
338  norms[c] = std::max(norms[c],temp_norms[c]);
339  }
340  }
341  }
342 
344  virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const {
345  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::meanValue: Not (yet) supported by BlockedMultiVector.");
346  }
347 
349  virtual void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector&A, const MultiVector&B, const Scalar &beta) {
350  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::multiply: Not (yet) supported by BlockedMultiVector.");
351  }
352 
354  virtual void elementWiseMultiply(Scalar scalarAB, const Vector&A, const MultiVector&B, Scalar scalarThis) {
355  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::elementWiseMultiply: Not (yet) supported by BlockedMultiVector.");
356  }
357 
359 
361 
362 
364  virtual size_t getNumVectors() const {
365  return numVectors_;
366  }
367 
369  virtual size_t getLocalLength() const {
370  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::getLocalLength: routine not implemented. It has no value as one must iterate on the partial vectors.");
371  return 0;
372  }
373 
375  virtual global_size_t getGlobalLength() const {
376  return getMapExtractor()->getFullMap()->getGlobalNumElements();
377  }
378 
380 
382 
383 
385  virtual std::string description() const {
386  return std::string("BlockedMultiVector");
387  }
388 
390  virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const {
391  out << "BlockedMultiVector: " << std::endl;
392  for(size_t r = 0; r < getMapExtractor()->NumMaps(); r++)
393  getMultiVector(r)->describe(out, verbLevel);
394  }
395 
396  virtual void replaceMap(const RCP<const Map>& map) {
397  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::replaceMap: Not supported by BlockedMultiVector.");
398  }
399 
401  virtual void doImport(const DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> &source, const Import&importer, CombineMode CM) {
402  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::doImport: Not supported by BlockedMultiVector.");
403  }
404 
406  virtual void doExport(const DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> &dest, const Import& importer, CombineMode CM) {
407  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::doExport: Not supported by BlockedMultiVector.");
408  }
409 
411  virtual void doImport(const DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> &source, const Export& exporter, CombineMode CM) {
412  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::doImport: Not supported by BlockedMultiVector.");
413  }
414 
416  virtual void doExport(const DistObject<Scalar, LocalOrdinal, GlobalOrdinal, Node> &dest, const Export& exporter, CombineMode CM) {
417  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::doExport: Not supported by BlockedMultiVector.");
418  }
419 
421 
423 
424 
426  virtual void setSeed(unsigned int seed) {
427  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::seed: Not (yet) supported by BlockedMultiVector.");
428  }
429 
430 
431  virtual void randomize(bool bUseXpetraImplementation = false) {
432  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::randomize: Not (yet) supported by BlockedMultiVector.");
433  }
434 
436  virtual void Xpetra_randomize()
437  {
439  }
440 
441 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
442  typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
443  typedef Kokkos::DualView<impl_scalar_type**, Kokkos::LayoutStride,
444  typename node_type::execution_space,
445  Kokkos::MemoryUnmanaged> dual_view_type;
446  typedef typename dual_view_type::host_mirror_space host_execution_space;
447  typedef typename dual_view_type::t_dev::execution_space dev_execution_space;
448 
454  template<class TargetDeviceType>
455  typename Kokkos::Impl::if_c<
456  Kokkos::Impl::is_same<
457  typename dev_execution_space::memory_space,
458  typename TargetDeviceType::memory_space>::value,
459  typename dual_view_type::t_dev_um,
460  typename dual_view_type::t_host_um>::type
461  getLocalView () const {
462  if(Kokkos::Impl::is_same<
463  typename host_execution_space::memory_space,
464  typename TargetDeviceType::memory_space
465  >::value) {
466  return getHostLocalView();
467  } else {
468  return getDeviceLocalView();
469  }
470  }
471 
472  virtual typename dual_view_type::t_host_um getHostLocalView () const {
473  typename dual_view_type::t_host_um test;
474  return test;
475  }
476  virtual typename dual_view_type::t_dev_um getDeviceLocalView() const {
477  typename dual_view_type::t_dev_um test;
478  return test;
479  }
480 
481 #endif
482 
484 
486  Teuchos::RCP< const Map> getMap() const { XPETRA_MONITOR("BlockedMultiVector::getMap"); return getMapExtractor()->getFullMap(); }
487 
489  Teuchos::RCP<MultiVector> getMultiVector(size_t r) const {
490  XPETRA_MONITOR("BlockedMultiVector::getMultiVector(r)");
491  TEUCHOS_TEST_FOR_EXCEPTION(r > getMapExtractor()->NumMaps(), std::out_of_range, "Error, r = " << r << " is too big. The BlockedMultiVector only contains " << getMapExtractor()->NumMaps() << " partial blocks.");
492  return vv_[r];
493  }
494 
496  Teuchos::RCP<MultiVector> getMultiVector(size_t r, bool bThyraMode) const {
497  XPETRA_MONITOR("BlockedMultiVector::getMultiVector(r,bThyraMode)");
498  TEUCHOS_TEST_FOR_EXCEPTION(r > getMapExtractor()->NumMaps(), std::out_of_range, "Error, r = " << r << " is too big. The BlockedMultiVector only contains " << getMapExtractor()->NumMaps() << " partial blocks.");
499  Teuchos::RCP<MultiVector> ret = vv_[r];
500  if(bThyraMode_ != bThyraMode) {
501 #if 0
502  size_t localLength = ret->getLocalLength();
503  size_t numVecs = vv_[r]->getNumVectors();
504  // standard case: bThyraMode_ == true but bThyraMode == false
505  ret = getMapExtractor()->getVector(r,numVecs,bThyraMode);
506  for(size_t k=0; k < numVecs; k++) {
507  Teuchos::ArrayRCP<const Scalar> srcVecData = vv_[r]->getData(k);
508  Teuchos::ArrayRCP<Scalar> targetVecData = ret->getDataNonConst(k);
509  for(size_t i=0; i < localLength; i++) {
510  targetVecData[i] = srcVecData[i];
511  }
512  }
513 #else
514  // deep copy of partial vector
515  Teuchos::RCP<MultiVector> ret2 = MultiVectorFactory::Build(ret->getMap(),ret->getNumVectors());
516  *ret2 = *ret; // deep copy
517  // change map of copy
518  ret2->replaceMap(getMapExtractor()->getMap(r,bThyraMode));
519  return ret2;
520 #endif
521  }
522  return ret;
523  }
524 
526  void setMultiVector(size_t r, Teuchos::RCP<const MultiVector> v, bool bThyraMode) {
527  XPETRA_MONITOR("BlockedMultiVector::setMultiVector");
528  Teuchos::RCP<const MapExtractor> me = getMapExtractor();
529  TEUCHOS_TEST_FOR_EXCEPTION(r >= me->NumMaps(), std::out_of_range, "Error, r = " << r << " is too big. The BlockedMultiVector only contains " << getMapExtractor()->NumMaps() << " partial blocks.");
530  //TEUCHOS_TEST_FOR_EXCEPTION(getMapExtractor()->getMap(r,bThyraMode_)->isSameAs(*(v->getMap()))==false, Xpetra::Exceptions::RuntimeError, "Map of provided partial map and map extractor are not compatible. The size of the provided map is " << v->getMap()->getGlobalNumElements() << " and the expected size is " << getMapExtractor()->getMap(r,bThyraMode_)->getGlobalNumElements() << " or the GIDs are not correct (Thyra versus non-Thyra?)");
531  TEUCHOS_TEST_FOR_EXCEPTION(numVectors_ != v->getNumVectors(),Xpetra::Exceptions::RuntimeError,"The BlockedMultiVectors expects " << getNumVectors() << " vectors. The provided partial multivector has " << v->getNumVectors() << " vectors.");
532  Teuchos::RCP<MultiVector> vv = Teuchos::rcp_const_cast<MultiVector>(v);
533  TEUCHOS_TEST_FOR_EXCEPTION(vv==Teuchos::null, Xpetra::Exceptions::RuntimeError, "Partial vector must not be Teuchos::null");
534  if(bThyraMode_ == bThyraMode) {
535  TEUCHOS_TEST_FOR_EXCEPTION(bThyraMode_ == true && v->getMap()->getMinAllGlobalIndex() > 0, Xpetra::Exceptions::RuntimeError, "BlockedMultiVector is in Thyra mode but partial map starts with GIDs " << v->getMap()->getMinAllGlobalIndex() << " > 0!");
536  XPETRA_TEST_FOR_EXCEPTION(me->getMap(r,bThyraMode_)->isSameAs(*(v->getMap()))==false, Xpetra::Exceptions::RuntimeError, "Map of provided partial map and map extractor are not compatible. The size of the provided map is " << v->getMap()->getGlobalNumElements() << " and the expected size is " << getMapExtractor()->getMap(r,bThyraMode_)->getGlobalNumElements() << " or the GIDs are not correct (Thyra versus non-Thyra?)");
537  vv_[r] = vv;
538  }
539  else {
540  // standard case: bThyraMode_ == true but bThyraMode == false
541  XPETRA_TEST_FOR_EXCEPTION(me->getMap(r,bThyraMode)->isSameAs(*(v->getMap()))==false, Xpetra::Exceptions::RuntimeError, "Map of provided partial map and map extractor are not compatible. The size of the provided map is " << v->getMap()->getGlobalNumElements() << " and the expected size is " << getMapExtractor()->getMap(r,bThyraMode_)->getGlobalNumElements() << " or the GIDs are not correct (Thyra versus non-Thyra?)");
542 #if 0
543  size_t numVecs = v->getNumVectors();
544  Teuchos::RCP<MultiVector> target = me->getVector(r,numVecs,bThyraMode_);
545  size_t localLength = target->getLocalLength();
546  for(size_t k=0; k < numVecs; k++) {
547  Teuchos::ArrayRCP<const Scalar> srcVecData = v->getData(k);
548  Teuchos::ArrayRCP<Scalar> targetVecData = target->getDataNonConst(k);
549  for(size_t i=0; i < localLength; i++) {
550  targetVecData[i] = srcVecData[i];
551  }
552  }
553  vv_[r] = target;
554 #else
555  // deep copy of partial vector
556  Teuchos::RCP<MultiVector> vv2 = MultiVectorFactory::Build(v->getMap(),v->getNumVectors());
557  *vv2 = *vv; // deep copy
558  // change map of copy
559  vv2->replaceMap(getMapExtractor()->getMap(r,bThyraMode_));
560  vv_[r] = vv2;
561 #endif
562  }
563  }
564 
566  RCP<const MapExtractor> getMapExtractor() const { return mapextractor_; }
567 
569  Teuchos::RCP<MultiVector> Merge() const {
570  XPETRA_MONITOR("BlockedMultiVector::Merge");
571  using Teuchos::RCP;
572  using Teuchos::rcp_dynamic_cast;
573  //Scalar one = ScalarTraits<SC>::one();
574 
575  RCP<MultiVector> v = MultiVectorFactory::Build(getMapExtractor()->getFullMap(), getNumVectors());
576  for(size_t r = 0; r < getMapExtractor()->NumMaps(); ++r) {
577  getMapExtractor()->InsertVector(getMultiVector(r),r,v,bThyraMode_);
578  }
579 
580  // TODO plausibility checks
581 
582  return v;
583  }
584 
585 
586  protected:
592  virtual void assign (const MultiVector& rhs) {
593  throw Xpetra::Exceptions::RuntimeError("BlockedMultiVector::assign: Not (yet) supported by BlockedMultiVector.");
594  }
595 
596  private:
597  Teuchos::RCP<const MapExtractor> mapextractor_; // map extractor
598  std::vector<Teuchos::RCP<MultiVector> > vv_;
599  bool bThyraMode_;
600  size_t numVectors_;
601  }; // BlockedMultiVector class
602 
603 } // Xpetra namespace
604 
605 #define XPETRA_BLOCKEDMULTIVECTOR_SHORT
606 #endif // XPETRA_BLOCKEDMULTIVECTOR_HPP
virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Export &exporter, CombineMode CM)
Import (using an Exporter).
Teuchos::RCP< const MapExtractor > mapextractor_
virtual void elementWiseMultiply(Scalar scalarAB, const Vector &A, const MultiVector &B, Scalar scalarThis)
Element-wise multiply of a Vector A with a MultiVector B.
virtual void setSeed(unsigned int seed)
Set seed for Random function.
virtual std::string description() const
A simple one-line description of this object.
LocalOrdinal local_ordinal_type
Definition: Xpetra_Map.hpp:85
Teuchos::RCP< MultiVector > getMultiVector(size_t r, bool bThyraMode) const
return partial multivector associated with block row r
virtual void norm2(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
virtual void norm1(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute 1-norm of each vector in multi-vector.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with the given verbosity level to a FancyOStream.
virtual void dot(const MultiVector &A, const Teuchos::ArrayView< Scalar > &dots) const
Compute dot product of each corresponding pair of vectors, dots[i] = this[i].dot(A[i]).
GlobalOrdinal global_ordinal_type
Definition: Xpetra_Map.hpp:86
std::vector< Teuchos::RCP< MultiVector > > vv_
array containing RCPs of the partial vectors
virtual Teuchos::RCP< const Vector > getVector(size_t j) const
Return a Vector which is a const view of column j.
virtual void multiply(Teuchos::ETransp transA, Teuchos::ETransp transB, const Scalar &alpha, const MultiVector &A, const MultiVector &B, const Scalar &beta)
Matrix-matrix multiplication: this = beta*this + alpha*op(A)*op(B).
Node node_type
Definition: Xpetra_Map.hpp:87
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
BlockedMultiVector(Teuchos::RCP< const MapExtractor > mapExtractor, Teuchos::RCP< const MultiVector > v)
Constructor.
Xpetra namespace
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Import &importer, CombineMode CM)
Export.
virtual global_size_t getGlobalLength() const
Global number of rows in the multivector.
virtual void doImport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &source, const Import &importer, CombineMode CM)
Import.
virtual void update(const Scalar &alpha, const MultiVector &A, const Scalar &beta, const MultiVector &B, const Scalar &gamma)
Update multi-vector with scaled values of A and B, this = gamma*this + alpha*A + beta*B.
Exception throws to report errors in the internal logical of the program.
virtual void reciprocal(const MultiVector &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,j).
virtual void scale(const Scalar &alpha)
Scale the current values of a multi-vector, this = alpha*this.
Teuchos::RCP< MultiVector > getMultiVector(size_t r) const
return partial multivector associated with block row r
virtual void update(const Scalar &alpha, const MultiVector &A, const Scalar &beta)
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual void sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using local (row) index.
virtual Teuchos::ArrayRCP< Scalar > getDataNonConst(size_t j)
View of the local values in a particular vector of this multivector.
Teuchos::RCP< const Map > getMap() const
Access function for the underlying Map this DistObject was constructed with.
size_t numVectors_
number of vectors (columns in multi vector)
virtual Teuchos::RCP< Vector > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.
virtual void abs(const MultiVector &A)
Put element-wise absolute values of input Multi-vector in target: A = abs(this).
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
virtual void replaceMap(const RCP< const Map > &map)
virtual size_t getLocalLength() const
Local number of rows on the calling process.
virtual void assign(const MultiVector &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
virtual void normInf(const Teuchos::ArrayView< typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &norms) const
Compute Inf-norm of each vector in multi-vector.
void setMultiVector(size_t r, Teuchos::RCP< const MultiVector > v, bool bThyraMode)
set partial multivector associated with block row r
virtual void randomize(bool bUseXpetraImplementation=false)
size_t global_size_t
Global size_t object.
Teuchos::RCP< MultiVector > Merge() const
merge BlockedMultiVector blocks to a single MultiVector
virtual size_t getNumVectors() const
Number of columns in the multivector.
virtual void scale(Teuchos::ArrayView< const Scalar > alpha)
Scale the current values of a multi-vector, this[j] = alpha[j]*this[j].
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar &value)
Replace value, using local (row) index.
virtual void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
RCP< const MapExtractor > getMapExtractor() const
access to underlying MapExtractor object
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.
CombineMode
Xpetra::Combine Mode enumerable type.
virtual void doExport(const DistObject< Scalar, LocalOrdinal, GlobalOrdinal, Node > &dest, const Export &exporter, CombineMode CM)
Export (using an Importer).
#define XPETRA_MONITOR(funcName)
BlockedMultiVector(Teuchos::RCP< const MapExtractor > mapExtractor, Teuchos::RCP< MultiVector > v)
virtual void meanValue(const Teuchos::ArrayView< Scalar > &means) const
Compute mean (average) value of each vector in multi-vector. The outcome of this routine is undefined...
BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector &rhs)
Assignment operator: Does a deep copy.
virtual Teuchos::ArrayRCP< const Scalar > getData(size_t j) const
Const view of the local values in a particular vector of this multivector.
virtual void replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Replace value, using global (row) index.
virtual void sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar &value)
Add value to existing value, using global (row) index.
bool bThyraMode_
boolean flag, which is true, if BlockedCrsMatrix has been created using Thyra-style numbering for sub...