52 #ifndef BELOS_THYRA_ADAPTER_HPP
53 #define BELOS_THYRA_ADAPTER_HPP
55 #include "BelosConfigDefs.hpp"
56 #include "BelosMultiVecTraits.hpp"
57 #include "BelosOperatorTraits.hpp"
59 #include <Thyra_DetachedMultiVectorView.hpp>
60 #include <Thyra_MultiVectorBase.hpp>
61 #include <Thyra_MultiVectorStdOps.hpp>
62 #ifdef HAVE_BELOS_TSQR
64 #endif // HAVE_BELOS_TSQR
80 template<
class ScalarType>
81 class MultiVecTraits< ScalarType, Thyra::MultiVectorBase<ScalarType> >
84 typedef Thyra::MultiVectorBase<ScalarType>
TMVB;
109 int numvecs = mv.domain()->dim();
113 Thyra::assign(cc.
ptr(), mv);
124 int numvecs = index.size();
130 Thyra::assign(cc.
ptr(), *view);
137 const int numVecs = index.
size();
143 Thyra::assign (cc.
ptr(), *view);
154 int numvecs = index.size();
170 for (
int i=0; i<numvecs; i++) {
171 if (lb+i != index[i]) contig =
false;
176 const Thyra::Range1D rng(lb,lb+numvecs-1);
178 cc = mv.subView(rng);
182 cc = mv.subView(index);
195 return mv.subView (index);
206 int numvecs = index.size();
222 for (
int i=0; i<numvecs; i++) {
223 if (lb+i != index[i]) contig =
false;
228 const Thyra::Range1D rng(lb,lb+numvecs-1);
230 cc = mv.subView(rng);
234 cc = mv.subView(index);
247 return mv.subView (index);
257 {
return mv.range()->dim(); }
261 {
return mv.domain()->dim(); }
272 const ScalarType beta,
TMVB& mv )
274 using Teuchos::arrayView;
using Teuchos::arcpFromArrayView;
279 B_thyra = Thyra::createMembersView(
287 Thyra::apply<ScalarType>(A, Thyra::NOTRANS, *B_thyra, Teuchos::outArg(mv), alpha, beta);
293 const ScalarType beta,
const TMVB&
B,
TMVB& mv )
296 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::inoutArg;
298 Thyra::linear_combination<ScalarType>(
299 tuple(alpha, beta)(), tuple(ptrInArg(A), ptrInArg(B))(), ST::zero(), inoutArg(mv));
305 { Thyra::scale(alpha, Teuchos::inoutArg(mv)); }
309 static void MvScale (
TMVB& mv,
const std::vector<ScalarType>& alpha)
311 for (
unsigned int i=0; i<alpha.size(); i++) {
312 Thyra::scale<ScalarType> (alpha[i], mv.col(i).ptr());
321 using Teuchos::arrayView;
using Teuchos::arcpFromArrayView;
323 int m = A.domain()->dim();
324 int n = mv.domain()->dim();
327 B_thyra = Thyra::createMembersView(
334 Thyra::apply<ScalarType>(A, Thyra::CONJTRANS, mv, B_thyra.
ptr(), alpha);
341 { Thyra::dots(mv, A, Teuchos::arrayViewFromVector(b)); }
351 static void MvNorm(
const TMVB& mv, std::vector<magType>& normvec,
352 NormType type = TwoNorm )
353 { Thyra::norms_2(mv, Teuchos::arrayViewFromVector(normvec)); }
365 int numvecs = index.size();
366 std::vector<int> indexA(numvecs);
367 int numAcols = A.domain()->dim();
368 for (
int i=0; i<numvecs; i++) {
373 if ( numAcols < numvecs ) {
378 else if ( numAcols > numvecs ) {
380 indexA.resize( numAcols );
387 Thyra::assign(reldest.
ptr(), *relsource);
393 const int numColsA = A.domain()->dim();
394 const int numColsMv = mv.domain()->dim();
396 const bool validIndex = index.
lbound() >= 0 && index.
ubound() < numColsMv;
398 const bool validSource = index.
size() <= numColsA;
400 if (! validIndex || ! validSource)
402 std::ostringstream os;
403 os <<
"Belos::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar> "
404 ">::SetBlock(A, [" << index.
lbound() <<
", " << index.
ubound()
407 os.str() <<
"Range lower bound must be nonnegative.");
409 os.str() <<
"Range upper bound must be less than "
410 "the number of columns " << numColsA <<
" in the "
411 "'mv' output argument.");
413 os.str() <<
"Range must have no more elements than"
414 " the number of columns " << numColsA <<
" in the "
415 "'A' input argument.");
423 if (index.
lbound() == 0 && index.
ubound()+1 == numColsMv)
424 mv_view = Teuchos::rcpFromRef (mv);
426 mv_view = mv.subView (index);
432 if (index.
size() == numColsA)
433 A_view = Teuchos::rcpFromRef (A);
438 Thyra::assign(mv_view.
ptr(), *A_view);
444 const int numColsA = A.domain()->dim();
445 const int numColsMv = mv.domain()->dim();
446 if (numColsA > numColsMv)
448 std::ostringstream os;
449 os <<
"Belos::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar>"
450 " >::Assign(A, mv): ";
452 os.str() <<
"Input multivector 'A' has "
453 << numColsA <<
" columns, but output multivector "
454 "'mv' has only " << numColsMv <<
" columns.");
458 if (numColsA == numColsMv) {
459 Thyra::assign (Teuchos::outArg (mv), A);
463 Thyra::assign (mv_view.
ptr(), A);
473 Thyra::randomize<ScalarType>(
476 Teuchos::outArg(mv));
483 Thyra::assign (Teuchos::outArg (mv), alpha);
498 #ifdef HAVE_BELOS_TSQR
505 #endif // HAVE_BELOS_TSQR
521 template<
class ScalarType>
522 class OperatorTraits <ScalarType,
523 Thyra::MultiVectorBase<ScalarType>,
524 Thyra::LinearOpBase<ScalarType> >
527 typedef Thyra::MultiVectorBase<ScalarType>
TMVB;
528 typedef Thyra::LinearOpBase<ScalarType>
TLOB;
550 ETrans trans = NOTRANS)
552 Thyra::EOpTransp whichOp;
560 whichOp = Thyra::NOTRANS;
561 else if (trans ==
TRANS)
562 whichOp = Thyra::TRANS;
564 whichOp = Thyra::CONJTRANS;
567 "Belos::OperatorTraits::Apply (Thyra specialization): "
568 "'trans' argument must be neither NOTRANS=" <<
NOTRANS
570 <<
", but instead has an invalid value of " << trans <<
".");
571 Thyra::apply<ScalarType>(Op, whichOp, x, Teuchos::outArg(y));
586 return Op.opSupported (Thyra::TRANS) &&
587 (! STS::isComplex || Op.opSupported (Thyra::CONJTRANS));
Thyra::LinearOpBase< ScalarType > TLOB
static int GetNumberVecs(const TMVB &mv)
Obtain the number of vectors in mv.
Thyra::MultiVectorBase< ScalarType > TMVB
static void MvPrint(const TMVB &mv, std::ostream &os)
Print the mv multi-std::vector to the os output stream.
Thyra::MultiVectorBase< ScalarType > TMVB
Stub adaptor from Thyra::MultiVectorBase to TSQR.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::ScalarTraits< ScalarType > ST
static Teuchos::RCP< TMVB > CloneCopy(const TMVB &mv, const std::vector< int > &index)
Creates a new MultiVectorBase and copies the selected contents of mv into the new std::vector (deep c...
static void Assign(const TMVB &A, TMVB &mv)
static void MvTransMv(const ScalarType alpha, const TMVB &A, const TMVB &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
static void MvScale(TMVB &mv, const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
static void MvDot(const TMVB &mv, const TMVB &A, std::vector< ScalarType > &b)
Compute a std::vector b where the components are the individual dot-products of the i-th columns of A...
ST::magnitudeType magType
static Teuchos::RCP< TMVB > CloneCopy(const TMVB &mv)
Creates a new MultiVectorBase and copies contents of mv into the new std::vector (deep copy)...
static void MvScale(TMVB &mv, const ScalarType alpha)
Scale each element of the vectors in *this with alpha.
static void MvTimesMatAddMv(const ScalarType alpha, const TMVB &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, TMVB &mv)
Update mv with .
static Teuchos::RCP< const TMVB > CloneView(const TMVB &mv, const std::vector< int > &index)
Creates a new const MultiVectorBase that shares the selected contents of mv (shallow copy)...
static Teuchos::RCP< TMVB > CloneCopy(const TMVB &mv, const Teuchos::Range1D &index)
static void Apply(const TLOB &Op, const TMVB &x, TMVB &y, ETrans trans=NOTRANS)
Apply Op to x, storing the result in y.
static void MvRandom(TMVB &mv)
Replace the vectors in mv with random vectors.
static int GetVecLength(const TMVB &mv)
Obtain the std::vector length of mv.
static Teuchos::RCP< TMVB > CloneViewNonConst(TMVB &mv, const Teuchos::Range1D &index)
OrdinalType numCols() const
static void SetBlock(const TMVB &A, const std::vector< int > &index, TMVB &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index...
static void SetBlock(const TMVB &A, const Teuchos::Range1D &index, TMVB &mv)
static void MvNorm(const TMVB &mv, std::vector< magType > &normvec, NormType type=TwoNorm)
Compute the 2-norm of each individual std::vector of mv. Upon return, normvec[i] holds the value of ...
static bool HasApplyTranspose(const TLOB &Op)
Whether the operator implements applying the transpose.
static Teuchos::RCP< TMVB > CloneViewNonConst(TMVB &mv, const std::vector< int > &index)
Creates a new MultiVectorBase that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< const TMVB > CloneView(const TMVB &mv, const Teuchos::Range1D &index)
OrdinalType stride() const
static Teuchos::RCP< TMVB > Clone(const TMVB &mv, const int numvecs)
Creates a new empty MultiVectorBase containing numvecs columns.
static void MvAddMv(const ScalarType alpha, const TMVB &A, const ScalarType beta, const TMVB &B, TMVB &mv)
Replace mv with .
OrdinalType numRows() const