Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_BlockedVector_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// Tobias Wiesner (tawiesn@sandia.gov)
42// Ray Tuminaro (rstumin@sandia.gov)
43//
44// ***********************************************************************
45//
46// @HEADER
47#ifndef XPETRA_BLOCKEDVECTOR_DEF_HPP
48#define XPETRA_BLOCKEDVECTOR_DEF_HPP
49
51
52#include "Xpetra_BlockedMultiVector.hpp"
53#include "Xpetra_Exceptions.hpp"
54
55
56
57namespace Xpetra {
58
59
60
61template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
64 : Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(map, 1, zeroOut)
65{ }
66
67
68template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74
75
76template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
78BlockedVector( Teuchos::RCP<const Xpetra::MapExtractor<Scalar, LocalOrdinal, GlobalOrdinal, Node> > mapExtractor,
80 : Xpetra::BlockedMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>(mapExtractor, v)
81{ }
82
83
84template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
88
89
90template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
91BlockedVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>&
94{
95 assign(rhs); // dispatch to protected virtual method
96 return *this;
97}
98
99
100template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
101void
103replaceGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value)
104{
105 BlockedMultiVector::replaceGlobalValue(globalRow, vectorIndex, value);
106}
107
108
109template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
110void
112sumIntoGlobalValue(GlobalOrdinal globalRow, size_t vectorIndex, const Scalar& value)
113{
114 BlockedMultiVector::sumIntoGlobalValue(globalRow, vectorIndex, value);
115}
116
117
118template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
119void
121replaceLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value)
122{
123 BlockedMultiVector::replaceLocalValue(myRow, vectorIndex, value);
124}
125
126
127template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
128void
130sumIntoLocalValue(LocalOrdinal myRow, size_t vectorIndex, const Scalar& value)
131{
132 BlockedMultiVector::sumIntoLocalValue(myRow, vectorIndex, value);
133}
134
135
136template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
137void
139replaceGlobalValue(GlobalOrdinal globalRow, const Scalar& value)
140{
141 BlockedMultiVector::replaceGlobalValue(globalRow, 0, value);
142}
143
144
145template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
146void
148sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar& value)
149{
150 BlockedMultiVector::sumIntoGlobalValue(globalRow, 0, value);
151}
152
153template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
154void
156replaceLocalValue(LocalOrdinal myRow, const Scalar& value)
157{
158 BlockedMultiVector::replaceLocalValue(myRow, 0, value);
159}
160
161template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
162void
164sumIntoLocalValue(LocalOrdinal myRow, const Scalar& value)
165{
166 BlockedMultiVector::sumIntoLocalValue(myRow, 0, value);
167}
168
169template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
170void
172putScalar(const Scalar& value)
173{
174 BlockedMultiVector::putScalar(value);
175}
176
177template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
180getVector(size_t j) const
181{
182 return BlockedMultiVector::getVector(j);
183}
184
185template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
188getVectorNonConst(size_t j)
189{
190 return BlockedMultiVector::getVectorNonConst(j);
191}
192
193template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
196getData(size_t j) const
197{
198 return BlockedMultiVector::getData(j);
199}
200
201template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
204getDataNonConst(size_t j)
205{
206 return BlockedMultiVector::getDataNonConst(j);
207}
208
209template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
210void
212dot(const MultiVector& A, const Teuchos::ArrayView<Scalar>& dots) const
213{
214 BlockedMultiVector::dot(A, dots);
215 return;
216}
217
218template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
219Scalar
227
228template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
229void
236
237template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
238void
245
246template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
247void
249scale(const Scalar& alpha)
250{
251 BlockedMultiVector::scale(alpha);
252 return;
253}
254
255template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
256void
259{
260 BlockedMultiVector::scale(alpha);
261 return;
262}
263
264template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
265void
267update(const Scalar& alpha,
269 const Scalar& beta)
270{
271 BlockedMultiVector::update(alpha, A, beta);
272 return;
273}
274
275template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
276void
278update(const Scalar& alpha,
280 const Scalar& beta,
282 const Scalar& gamma)
283{
284 BlockedMultiVector::update(alpha, A, beta, B, gamma);
285 return;
286}
287
288template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
298
299template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
309
310
311template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
321
322
323template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
324void
330
331
332template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
333void
339
340
341template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
342void
348
349
350template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
351void
353meanValue(const Teuchos::ArrayView<Scalar>& /* means */) const
354{
355 throw Xpetra::Exceptions::RuntimeError("BlockedVector::meanValue: Not (yet) supported by BlockedVector.");
356}
357
358
359template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
360Scalar
362meanValue() const
363{
364 throw Xpetra::Exceptions::RuntimeError("BlockedVector::meanValue: Not (yet) supported by BlockedVector.");
365}
366
367
368template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
369void
371multiply(Teuchos::ETransp /* transA */,
372 Teuchos::ETransp /* transB */,
373 const Scalar& /* alpha */,
376 const Scalar& /* beta */)
377{
378 throw Xpetra::Exceptions::RuntimeError("BlockedVector::multiply: Not (yet) supported by BlockedVector.");
379}
380
381
382template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
383void
385multiply(Teuchos::ETransp /* transA */,
386 Teuchos::ETransp /* transB */,
387 const Scalar& /* alpha */,
390 const Scalar& /* beta */)
391{
392 throw Xpetra::Exceptions::RuntimeError("BlockedVector::multiply: Not (yet) supported by BlockedVector.");
393}
394
395
396template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
397void
399elementWiseMultiply( Scalar /* scalarAB */,
402 Scalar /* scalarThis */)
403{
404 throw Xpetra::Exceptions::RuntimeError("BlockedVector::elementWiseMultiply: Not (yet) supported by BlockedVector.");
405}
406
407
408template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
409void
411elementWiseMultiply( Scalar /* scalarAB */,
414 Scalar /* scalarThis */)
415{
416 XPETRA_TEST_FOR_EXCEPTION(B.getMap()->isSameAs(*(this->getMap())) == false,
418 "BlockedVector::elementWiseMultipy: B must have same blocked map than this.");
419 TEUCHOS_TEST_FOR_EXCEPTION(A.getMap()->getLocalNumElements() != B.getMap()->getLocalNumElements(),
421 "BlockedVector::elementWiseMultipy: A has "
422 << A.getMap()->getLocalNumElements() << " elements, B has " << B.getMap()->getLocalNumElements()
423 << ".");
424 TEUCHOS_TEST_FOR_EXCEPTION(A.getMap()->getGlobalNumElements() != B.getMap()->getGlobalNumElements(),
426 "BlockedVector::elementWiseMultipy: A has " << A.getMap()->getGlobalNumElements()
427 << " elements, B has "
428 << B.getMap()->getGlobalNumElements() << ".");
429
433 RCP<const BlockedVector> bbmvec = Teuchos::rcp_dynamic_cast<const BlockedVector>(bmvec);
434 TEUCHOS_TEST_FOR_EXCEPTION(bbmvec.is_null() == true,
436 "BlockedVector::elementWiseMultipy: B must be a BlockedVector.");
437
438 // TODO implement me
439 /*RCP<Xpetra::MapExtractor<Scalar,LocalOrdinal,GlobalOrdinal,Node> > me = Teuchos::rcp(new
440 Xpetra::MapExtractor<Scalar,LocalOrdinal,GlobalOrdinal,Node>(bmap));
441
442 for(size_t m = 0; m < bmap->getNumMaps(); m++) {
443 // TODO introduce BlockedVector objects and "skip" this expensive ExtractVector call
444 RCP<const Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > pd = me->ExtractVector(rcpA,m,bmap->getThyraMode());
445 XPETRA_TEST_FOR_EXCEPTION(pd->getMap()->isSameAs(*(this->getBlockedMap()->getMap(m,bmap->getThyraMode())))==false,
446 Xpetra::Exceptions::RuntimeError, "BlockedVector::elementWiseMultipy: sub map of B does not fit with sub map of this.");
447 this->getMultiVector(m,bmap->getThyraMode())->elementWiseMultiply(scalarAB,*pd,*(bbmvec->getMultiVector(m,bmap->getThyraMode())),scalarThis);
448 }*/
449}
450
451
452template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
453size_t
459
460
461template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
462size_t
464getLocalLength() const
465{
467 "BlockedVector::getLocalLength: routine not implemented. It has no value as one must iterate on the partial vectors.");
469}
470
471
472template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
475getGlobalLength() const
476{
477 return this->getBlockedMap()->getFullMap()->getGlobalNumElements();
478}
479
480
481template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
482bool
485{
487 "BlockedVector::isSameSize: routine not implemented. It has no value as one must iterate on the partial vectors.");
489}
490
491
492template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
493std::string
495description() const
496{
497 return std::string("BlockedVector");
498}
499
500
501template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
502void
505{
506 out << description() << std::endl;
507 for(size_t r = 0; r < this->getBlockedMap()->getNumMaps(); r++)
508 {
509 getMultiVector(r)->describe(out, verbLevel);
510 }
511}
512
513
514template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
515void
517replaceMap(const RCP<const Map>& map)
518{
519 BlockedMultiVector::replaceMap(map);
520}
521
522
523template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
524void
527 const Import& /* importer */,
528 CombineMode /* CM */)
529{
530 throw Xpetra::Exceptions::RuntimeError("BlockedVector::doImport: Not supported by BlockedVector.");
531}
532
533
534template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
535void
538 const Import& /* importer */,
539 CombineMode /* CM */)
540{
541 throw Xpetra::Exceptions::RuntimeError("BlockedVector::doExport: Not supported by BlockedVector.");
542}
543
544
545template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
546void
549 const Export& /* exporter */,
550 CombineMode /* CM */)
551{
552 throw Xpetra::Exceptions::RuntimeError("BlockedVector::doImport: Not supported by BlockedVector.");
553}
554
555
556template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
557void
560 const Export& /* exporter */,
561 CombineMode /* CM */)
562{
563 throw Xpetra::Exceptions::RuntimeError("BlockedVector::doExport: Not supported by BlockedVector.");
564}
565
566
567template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
568void
570setSeed(unsigned int seed)
571{
572 for(size_t r = 0; r < this->getBlockedMap()->getNumMaps(); ++r)
573 {
574 getMultiVector(r)->setSeed(seed);
575 }
576}
577
578
579template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
580void
582randomize(bool bUseXpetraImplementation)
583{
584 for(size_t r = 0; r < this->getBlockedMap()->getNumMaps(); ++r)
585 {
586 getMultiVector(r)->randomize(bUseXpetraImplementation);
587 }
588}
589
590
591template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
592void
594randomize(const Scalar& minVal, const Scalar& maxVal, bool bUseXpetraImplementation)
595{
596 for(size_t r = 0; r < this->getBlockedMap()->getNumMaps(); ++r)
597 {
598 getMultiVector(r)->randomize(minVal, maxVal, bUseXpetraImplementation);
599 }
600}
601
602
603template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
604void
612
613
614template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
615void
623
624 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
627 getMap() const
628 {
629 XPETRA_MONITOR("BlockedVector::getMap");
630 return this->getBlockedMap();
631 }
632
633
634 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
637 getMultiVector(size_t r) const
638 {
639 return BlockedMultiVector::getMultiVector(r);
640 }
641
642
643 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
646 getMultiVector(size_t r, bool bThyraMode) const
647 {
648 return BlockedMultiVector::getMultiVector(r, bThyraMode);
649 }
650
651
652 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
653 void
655 setMultiVector(size_t r,
657 bool bThyraMode)
658 {
659 BlockedMultiVector::setMultiVector(r, v, bThyraMode);
660 return;
661 }
662
663
664 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
667 Merge() const
668 {
669 return BlockedMultiVector::Merge();
670 }
671
672
673 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
674 void
680
681
682 // template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
683 // virtual void BlockedVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::
684 // assign (const XpetrA::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& rhs)
685 // {
686 // throw Xpetra::Exceptions::RuntimeError("BlockedVector::assign: Not supported by BlockedVector.");
687 // }
688
689} // Xpetra namespace
690
691
692#endif // XPETRA_BLOCKEDVECTOR_DEF_HPP
#define XPETRA_MONITOR(funcName)
#define XPETRA_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
bool is_null() const
BlockedMultiVector(const Teuchos::RCP< const BlockedMap > &map, size_t NumVectors, bool zeroOut=true)
Teuchos::RCP< const Xpetra::BlockedMap< LocalOrdinal, GlobalOrdinal, KokkosClassic::DefaultNode::DefaultNodeType > > getBlockedMap() const
virtual std::string description() const
A simple one-line description of this object.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of vector.
BlockedVector(const Teuchos::RCP< const BlockedMap > &map, bool zeroOut=true)
Constructor.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Compute 1-norm of vector.
virtual void assign(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Implementation of the assignment operator (operator=); does a deep copy.
Teuchos::RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getMultiVector(size_t r) const
return partial Vector associated with block row r
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm in vector.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
Exception throws to report errors in the internal logical of the program.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
basic_FancyOStream< char > FancyOStream
Xpetra namespace
size_t global_size_t
Global size_t object.
CombineMode
Xpetra::Combine Mode enumerable type.