42 #ifndef THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
43 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
46 #include "Thyra_DefaultMultiVectorProductVector_decl.hpp"
47 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
48 #include "Thyra_AssertOp.hpp"
49 #include "Teuchos_Assert.hpp"
58 template <
class Scalar>
65 template <
class Scalar>
75 "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace,multiVec)",
76 *multiVec->range(), *productSpace_in->getBlock(0)
81 numBlocks_ = productSpace_in->numBlocks();
83 productSpace_ = productSpace_in;
90 template <
class Scalar>
100 "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace_in,multiVec)",
101 *multiVec->range(), *productSpace_in->getBlock(0)
106 numBlocks_ = productSpace_in->numBlocks();
108 productSpace_ = productSpace_in;
110 multiVec_ = multiVec;
115 template <
class Scalar>
119 return multiVec_.getNonconstObj();
123 template <
class Scalar>
127 return multiVec_.getConstObj();
131 template <
class Scalar>
135 productSpace_ = Teuchos::null;
136 multiVec_.uninitialize();
143 template<
class Scalar>
146 std::ostringstream oss;
150 <<
"dim="<<this->space()->dim()
151 <<
",numColumns = "<<numBlocks_
156 template<
class Scalar>
163 using Teuchos::describe;
169 *out << this->description() << std::endl;
177 <<
"dim=" << this->space()->dim()
180 *out <<
"multiVec = " << Teuchos::describe(*multiVec_.getConstObj(),verbLevel);
192 template <
class Scalar>
199 return multiVec_.getNonconstObj()->col(k);
203 template <
class Scalar>
210 return multiVec_.getConstObj()->col(k);
217 template <
class Scalar>
221 return productSpace_;
225 template <
class Scalar>
233 return multiVec_.isConst();
237 template <
class Scalar>
241 return getNonconstVectorBlock(k);
245 template <
class Scalar>
249 return getVectorBlock(k);
256 template <
class Scalar>
260 return productSpace_;
270 template <
class Scalar>
276 for(
int k = 0; k < numBlocks_; ++k) {
277 multiVec_.getNonconstObj()->col(k)->randomize(l, u);
282 template <
class Scalar>
294 for(
int k = 0; k < numBlocks_; ++k) {
295 multiVec_.getNonconstObj()->
col(k)->abs(*pv->getVectorBlock(k));
303 template <
class Scalar>
315 for(
int k = 0; k < numBlocks_; ++k) {
316 multiVec_.getNonconstObj()->
col(k)->reciprocal(*pv->getVectorBlock(k));
324 template <
class Scalar>
336 for(
int k = 0; k < numBlocks_; ++k) {
337 multiVec_.getNonconstObj()->
col(k)->ele_wise_scale(*pv->getVectorBlock(k));
345 template <
class Scalar>
359 typename ST::magnitudeType norm = ST::magnitude(ST::zero());
360 for(
int k = 0; k < numBlocks_; ++k) {
361 typename ST::magnitudeType subNorm
362 = multiVec_.getConstObj()->col(k)->norm_2(*pv->getVectorBlock(k));
363 norm += subNorm*subNorm;
365 return ST::magnitude(ST::squareroot(norm));
372 template <
class Scalar>
381 this->getDefaultProductVector()->applyOp(
382 op, vecs, targ_vecs, reduct_obj, global_offset );
386 template <
class Scalar>
391 this->getDefaultProductVector()->acquireDetachedView(rng_in,sub_vec);
395 template <
class Scalar>
400 this->getDefaultProductVector()->releaseDetachedView(sub_vec);
404 template <
class Scalar>
409 TEUCHOS_TEST_FOR_EXCEPT(
"ToDo: Implement DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(...)!");
413 template <
class Scalar>
418 TEUCHOS_TEST_FOR_EXCEPT(
"ToDo: Implement DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(...)!");
422 template <
class Scalar>
434 template <
class Scalar>
437 multiVec_.getNonconstObj()->assign(alpha);
441 template <
class Scalar>
453 for(
int k = 0; k < numBlocks_; ++k) {
454 multiVec_.getNonconstObj()->
col(k)->assign(*pv->getMultiVectorBlock(k));
462 template <
class Scalar>
465 multiVec_.getNonconstObj()->scale(alpha);
469 template <
class Scalar>
482 for(
int k = 0; k < numBlocks_; ++k) {
483 multiVec_.getNonconstObj()->
col(k)->update(alpha, *pv->getMultiVectorBlock(k));
491 template <
class Scalar>
500 for (
Ordinal i = 0; i < mv.size(); ++i) {
507 bool allCastsSuccessful =
true;
509 for (
Ordinal i = 0; i < mv.size(); ++i) {
512 allCastsSuccessful =
false;
517 if (allCastsSuccessful) {
520 for (
int k = 0; k < numBlocks_; ++k) {
521 for (
Ordinal i = 0; i < pvs.size(); ++i) {
522 blocks_rcp[i] = pvs[i]->getMultiVectorBlock(k);
523 blocks[i] = blocks_rcp[i].ptr();
525 multiVec_.getNonconstObj()->col(k)->linear_combination(alpha, blocks(), beta);
533 template <
class Scalar>
548 for(
int k = 0; k < numBlocks_; ++k) {
550 multiVec_.getConstObj()->col(k)->dots(*pv->getMultiVectorBlock(k), Teuchos::arrayView(&prod, 1));
559 template <
class Scalar>
568 norms[0] = ST::magnitude(ST::zero());
569 for(
int k = 0; k < numBlocks_; ++k) {
570 norms[0] += multiVec_.getConstObj()->col(k)->norm_1();
575 template <
class Scalar>
584 norms[0] = ST::magnitude(ST::zero());
585 for(
int k = 0; k < numBlocks_; ++k) {
586 typename ST::magnitudeType subNorm = multiVec_.getConstObj()->col(k)->norm_2();
587 norms[0] += subNorm*subNorm;
589 norms[0] = ST::magnitude(ST::squareroot(norms[0]));
593 template <
class Scalar>
602 norms[0] = ST::magnitude(ST::zero());
603 for(
int k = 0; k < numBlocks_; ++k) {
604 typename ST::magnitudeType subNorm = multiVec_.getConstObj()->col(k)->norm_inf();
605 if (subNorm > norms[0])
614 template <
class Scalar>
626 for (
int k = 0; k < numBlocks_; ++k) {
627 vecArray.
push_back(multiVec_.getConstObj()->col(k));
630 return Thyra::defaultProductVector<Scalar>(
631 productSpace_->getDefaultProductVectorSpace(),
641 #endif // THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
Base interface for product multi-vectors.
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible...
bool is_null(const boost::shared_ptr< T > &p)
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Base interface for product vectors.
basic_OSTab< char > OSTab
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< const VectorBase< Scalar > > getVectorBlock(const int k) const
void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
virtual void assignImpl(Scalar alpha)
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Default implementation of assign(MV) using RTOps.
virtual void eleWiseScaleImpl(const VectorBase< Scalar > &x)
Default implementation of ele_wise_scale using RTOps.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
Default implementation of reciprocal using RTOps.
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Default implementation of linear_combination using RTOps.
virtual void absImpl(const VectorBase< Scalar > &x)
Default implementation of abs using RTOps.
Concrete implementation of a product vector which is really composed out of the columns of a multi-ve...
RCP< const MultiVectorBase< Scalar > > getMultiVectorBlock(const int k) const
bool blockIsConst(const int k) const
virtual void scaleImpl(Scalar alpha)
std::string description() const
void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)
RCP< const ProductVectorSpaceBase< Scalar > > productSpace() const
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
virtual void absImpl(const VectorBase< Scalar > &x)
void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
virtual std::string description() const
Abstract interface for finite-dimensional dense vectors.
RCP< const MultiVectorBase< Scalar > > getMultiVector() const
Standard concrete implementation of a product vector space that creates product vectors fromed implic...
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
void initialize(const RCP< const DefaultMultiVectorProductVectorSpace< Scalar > > &productSpace, const RCP< MultiVectorBase< Scalar > > &multiVec)
Initialize with a non-const multi-vector.
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
bool nonnull(const boost::shared_ptr< T > &p)
DefaultMultiVectorProductVector()
Construct to uninitialized.
void push_back(const value_type &x)
RCP< MultiVectorBase< Scalar > > getNonconstMultiVector()
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Default implementation of norm_2 (weighted) using RTOps.
void applyOpImpl(const RTOpPack::RTOpT< Scalar > &op, const ArrayView< const Ptr< const VectorBase< Scalar > > > &vecs, const ArrayView< const Ptr< VectorBase< Scalar > > > &targ_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal global_offset) const
virtual void randomizeImpl(Scalar l, Scalar u)
RCP< MultiVectorBase< Scalar > > getNonconstMultiVectorBlock(const int k)
RCP< const VectorSpaceBase< Scalar > > space() const
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
RCP< VectorBase< Scalar > > getNonconstVectorBlock(const int k)
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.
virtual void reciprocalImpl(const VectorBase< Scalar > &x)
void setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)