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
63 # include <Thyra_TsqrAdaptor.hpp>
64 #endif // HAVE_BELOS_TSQR
80 template<
class ScalarType>
81 class MultiVecTraits< ScalarType, Thyra::MultiVectorBase<ScalarType> >
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;
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;
247 return mv.subView (index);
257 return Teuchos::as<ptrdiff_t>(mv.
range()->dim());
262 {
return mv.
domain()->dim(); }
273 const ScalarType beta,
TMVB& mv )
275 using Teuchos::arrayView;
using Teuchos::arcpFromArrayView;
280 B_thyra = Thyra::createMembersView(
288 Thyra::apply<ScalarType>(A,
Thyra::NOTRANS, *B_thyra, Teuchos::outArg(mv), alpha, beta);
294 const ScalarType beta,
const TMVB& B,
TMVB& mv )
297 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::inoutArg;
299 Thyra::linear_combination<ScalarType>(
300 tuple(alpha, beta)(), tuple(ptrInArg(A), ptrInArg(B))(), ST::zero(), inoutArg(mv));
306 { Thyra::scale(alpha, Teuchos::inoutArg(mv)); }
310 static void MvScale (
TMVB& mv,
const std::vector<ScalarType>& alpha)
312 for (
unsigned int i=0; i<alpha.size(); i++) {
313 Thyra::scale<ScalarType> (alpha[i], mv.
col(i).ptr());
322 using Teuchos::arrayView;
using Teuchos::arcpFromArrayView;
324 int m = A.
domain()->dim();
325 int n = mv.
domain()->dim();
328 B_thyra = Thyra::createMembersView(
341 static void MvDot(
const TMVB& mv,
const TMVB& A, std::vector<ScalarType>& b )
342 { Thyra::dots(mv, A, Teuchos::arrayViewFromVector(b)); }
352 static void MvNorm(
const TMVB& mv, std::vector<magType>& normvec,
353 NormType type = TwoNorm ) {
355 Thyra::norms_2(mv, Teuchos::arrayViewFromVector(normvec));
356 else if(type == OneNorm)
357 Thyra::norms_1(mv, Teuchos::arrayViewFromVector(normvec));
358 else if(type == InfNorm)
359 Thyra::norms_inf(mv, Teuchos::arrayViewFromVector(normvec));
362 "Belos::MultiVecTraits::MvNorm (Thyra specialization): "
363 "invalid norm type. Must be either TwoNorm, OneNorm or InfNorm");
376 int numvecs = index.size();
377 std::vector<int> indexA(numvecs);
378 int numAcols = A.
domain()->dim();
379 for (
int i=0; i<numvecs; i++) {
384 if ( numAcols < numvecs ) {
389 else if ( numAcols > numvecs ) {
391 indexA.resize( numAcols );
398 Thyra::assign(reldest.
ptr(), *relsource);
404 const int numColsA = A.domain()->dim();
405 const int numColsMv = mv.domain()->dim();
407 const bool validIndex = index.
lbound() >= 0 && index.
ubound() < numColsMv;
409 const bool validSource = index.
size() <= numColsA;
411 if (! validIndex || ! validSource)
413 std::ostringstream os;
414 os <<
"Belos::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar> "
415 ">::SetBlock(A, [" << index.
lbound() <<
", " << index.
ubound()
418 os.str() <<
"Range lower bound must be nonnegative.");
420 os.str() <<
"Range upper bound must be less than "
421 "the number of columns " << numColsA <<
" in the "
422 "'mv' output argument.");
424 os.str() <<
"Range must have no more elements than"
425 " the number of columns " << numColsA <<
" in the "
426 "'A' input argument.");
434 if (index.
lbound() == 0 && index.
ubound()+1 == numColsMv)
435 mv_view = Teuchos::rcpFromRef (mv);
437 mv_view = mv.subView (index);
443 if (index.
size() == numColsA)
444 A_view = Teuchos::rcpFromRef (A);
449 Thyra::assign(mv_view.
ptr(), *A_view);
453 Assign (
const TMVB& A, TMVB& mv)
455 const int numColsA = A.domain()->dim();
456 const int numColsMv = mv.domain()->dim();
457 if (numColsA > numColsMv)
459 std::ostringstream os;
460 os <<
"Belos::MultiVecTraits<Scalar, Thyra::MultiVectorBase<Scalar>"
461 " >::Assign(A, mv): ";
463 os.str() <<
"Input multivector 'A' has "
464 << numColsA <<
" columns, but output multivector "
465 "'mv' has only " << numColsMv <<
" columns.");
469 if (numColsA == numColsMv) {
470 Thyra::assign (Teuchos::outArg (mv), A);
474 Thyra::assign (mv_view.
ptr(), A);
484 Thyra::randomize<ScalarType>(
487 Teuchos::outArg(mv));
494 Thyra::assign (Teuchos::outArg (mv), alpha);
509 #ifdef HAVE_BELOS_TSQR
516 #endif // HAVE_BELOS_TSQR
532 template<
class ScalarType>
533 class OperatorTraits <ScalarType,
534 Thyra::MultiVectorBase<ScalarType>,
572 else if (trans ==
TRANS)
578 "Belos::OperatorTraits::Apply (Thyra specialization): "
579 "'trans' argument must be neither NOTRANS=" <<
NOTRANS
581 <<
", but instead has an invalid value of " << trans <<
".");
582 Thyra::apply<ScalarType>(Op, whichOp, x, Teuchos::outArg(y));