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
82 template<
class ScalarType>
83 class MultiVecTraits< ScalarType, Thyra::MultiVectorBase<ScalarType> >
86 typedef Thyra::MultiVectorBase<ScalarType>
TMVB;
111 int numvecs = mv.domain()->dim();
115 Thyra::assign(cc.
ptr(), mv);
126 int numvecs = index.size();
132 Thyra::assign(cc.
ptr(), *view);
139 const int numVecs = index.
size();
145 Thyra::assign (cc.
ptr(), *view);
156 int numvecs = index.size();
172 for (
int i=0; i<numvecs; i++) {
173 if (lb+i != index[i]) contig =
false;
178 const Thyra::Range1D rng(lb,lb+numvecs-1);
180 cc = mv.subView(rng);
184 cc = mv.subView(index);
197 return mv.subView (index);
208 int numvecs = index.size();
224 for (
int i=0; i<numvecs; i++) {
225 if (lb+i != index[i]) contig =
false;
230 const Thyra::Range1D rng(lb,lb+numvecs-1);
232 cc = mv.subView(rng);
236 cc = mv.subView(index);
249 return mv.subView (index);
259 return Teuchos::as<ptrdiff_t>(mv.range()->dim());
264 {
return mv.domain()->dim(); }
275 const ScalarType beta,
TMVB& mv )
277 using Teuchos::arrayView;
using Teuchos::arcpFromArrayView;
283 auto vs = A.domain();
286 B_thyra = vs->createCachedMembersView(
293 Thyra::apply<ScalarType>(A, Thyra::NOTRANS, *B_thyra, Teuchos::outArg(mv), alpha, beta);
299 const ScalarType beta,
const TMVB&
B,
TMVB& mv )
301 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::inoutArg;
305 Thyra::linear_combination<ScalarType>(
315 Thyra::scale(alpha, Teuchos::inoutArg(mv));
320 static void MvScale (
TMVB& mv,
const std::vector<ScalarType>& alpha)
324 for (
unsigned int i=0; i<alpha.size(); i++) {
325 Thyra::scale<ScalarType> (alpha[i], mv.col(i).ptr());
334 using Teuchos::arrayView;
using Teuchos::arcpFromArrayView;
339 int m = A.domain()->dim();
340 int n = mv.domain()->dim();
341 auto vs = A.domain();
344 B_thyra = vs->createCachedMembersView(
350 Thyra::apply<ScalarType>(A, Thyra::CONJTRANS, mv, B_thyra.
ptr(), alpha);
360 Thyra::dots(mv, A, Teuchos::arrayViewFromVector(b));
371 static void MvNorm(
const TMVB& mv, std::vector<magType>& normvec,
372 NormType type = TwoNorm ) {
376 Thyra::norms_2(mv, Teuchos::arrayViewFromVector(normvec));
377 else if(type == OneNorm)
378 Thyra::norms_1(mv, Teuchos::arrayViewFromVector(normvec));
379 else if(type == InfNorm)
380 Thyra::norms_inf(mv, Teuchos::arrayViewFromVector(normvec));
383 "Belos::MultiVecTraits::MvNorm (Thyra specialization): "
384 "invalid norm type. Must be either TwoNorm, OneNorm or InfNorm");
397 int numvecs = index.size();
398 std::vector<int> indexA(numvecs);
399 int numAcols = A.domain()->dim();
400 for (
int i=0; i<numvecs; i++) {
405 if ( numAcols < numvecs ) {
410 else if ( numAcols > numvecs ) {
412 indexA.resize( numAcols );
419 Thyra::assign(reldest.
ptr(), *relsource);
425 const int numColsA = A.domain()->dim();
426 const int numColsMv = mv.domain()->dim();
428 const bool validIndex = index.
lbound() >= 0 && index.
ubound() < numColsMv;
430 const bool validSource = index.
size() <= numColsA;
432 if (! validIndex || ! validSource)
434 std::ostringstream os;
435 os <<
"Belos::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar> "
436 ">::SetBlock(A, [" << index.
lbound() <<
", " << index.
ubound()
439 os.str() <<
"Range lower bound must be nonnegative.");
441 os.str() <<
"Range upper bound must be less than "
442 "the number of columns " << numColsA <<
" in the "
443 "'mv' output argument.");
445 os.str() <<
"Range must have no more elements than"
446 " the number of columns " << numColsA <<
" in the "
447 "'A' input argument.");
455 if (index.
lbound() == 0 && index.
ubound()+1 == numColsMv)
456 mv_view = Teuchos::rcpFromRef (mv);
458 mv_view = mv.subView (index);
464 if (index.
size() == numColsA)
465 A_view = Teuchos::rcpFromRef (A);
470 Thyra::assign(mv_view.
ptr(), *A_view);
478 const int numColsA = A.domain()->dim();
479 const int numColsMv = mv.domain()->dim();
480 if (numColsA > numColsMv)
482 std::ostringstream os;
483 os <<
"Belos::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar>"
484 " >::Assign(A, mv): ";
486 os.str() <<
"Input multivector 'A' has "
487 << numColsA <<
" columns, but output multivector "
488 "'mv' has only " << numColsMv <<
" columns.");
492 if (numColsA == numColsMv) {
493 Thyra::assign (Teuchos::outArg (mv), A);
497 Thyra::assign (mv_view.
ptr(), A);
507 Thyra::randomize<ScalarType>(
510 Teuchos::outArg(mv));
517 Thyra::assign (Teuchos::outArg (mv), alpha);
532 #ifdef HAVE_BELOS_TSQR
539 #endif // HAVE_BELOS_TSQR
555 template<
class ScalarType>
556 class OperatorTraits <ScalarType,
557 Thyra::MultiVectorBase<ScalarType>,
558 Thyra::LinearOpBase<ScalarType> >
561 typedef Thyra::MultiVectorBase<ScalarType>
TMVB;
562 typedef Thyra::LinearOpBase<ScalarType>
TLOB;
584 ETrans trans = NOTRANS)
586 Thyra::EOpTransp whichOp;
594 whichOp = Thyra::NOTRANS;
595 else if (trans ==
TRANS)
596 whichOp = Thyra::TRANS;
598 whichOp = Thyra::CONJTRANS;
601 "Belos::OperatorTraits::Apply (Thyra specialization): "
602 "'trans' argument must be neither NOTRANS=" <<
NOTRANS
604 <<
", but instead has an invalid value of " << trans <<
".");
605 Thyra::apply<ScalarType>(Op, whichOp, x, Teuchos::outArg(y));
620 return Op.opSupported (Thyra::TRANS) &&
621 (! 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 ptrdiff_t GetGlobalLength(const TMVB &mv)
Obtain the std::vector length of mv.
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 RCP< Time > getNewTimer(const std::string &name)
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 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