10 #ifndef THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
11 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
14 #include "Thyra_DefaultMultiVectorProductVector_decl.hpp"
15 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
16 #include "Thyra_AssertOp.hpp"
17 #include "Teuchos_Assert.hpp"
26 template <
class Scalar>
33 template <
class Scalar>
43 "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace,multiVec)",
44 *multiVec->range(), *productSpace_in->getBlock(0)
49 numBlocks_ = productSpace_in->numBlocks();
51 productSpace_ = productSpace_in;
58 template <
class Scalar>
68 "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace_in,multiVec)",
69 *multiVec->range(), *productSpace_in->getBlock(0)
74 numBlocks_ = productSpace_in->numBlocks();
76 productSpace_ = productSpace_in;
83 template <
class Scalar>
87 return multiVec_.getNonconstObj();
91 template <
class Scalar>
95 return multiVec_.getConstObj();
99 template <
class Scalar>
103 productSpace_ = Teuchos::null;
104 multiVec_.uninitialize();
111 template<
class Scalar>
114 std::ostringstream oss;
118 <<
"dim="<<this->space()->dim()
119 <<
",numColumns = "<<numBlocks_
124 template<
class Scalar>
131 using Teuchos::describe;
137 *out << this->description() << std::endl;
145 <<
"dim=" << this->space()->dim()
148 *out <<
"multiVec = " << Teuchos::describe(*multiVec_.getConstObj(),verbLevel);
160 template <
class Scalar>
167 return multiVec_.getNonconstObj()->col(k);
171 template <
class Scalar>
178 return multiVec_.getConstObj()->col(k);
185 template <
class Scalar>
189 return productSpace_;
193 template <
class Scalar>
201 return multiVec_.isConst();
205 template <
class Scalar>
209 return getNonconstVectorBlock(k);
213 template <
class Scalar>
217 return getVectorBlock(k);
224 template <
class Scalar>
228 return productSpace_;
238 template <
class Scalar>
244 for(
int k = 0; k < numBlocks_; ++k) {
245 multiVec_.getNonconstObj()->col(k)->randomize(l, u);
250 template <
class Scalar>
262 for(
int k = 0; k < numBlocks_; ++k) {
263 multiVec_.getNonconstObj()->
col(k)->abs(*pv->getVectorBlock(k));
271 template <
class Scalar>
283 for(
int k = 0; k < numBlocks_; ++k) {
284 multiVec_.getNonconstObj()->
col(k)->reciprocal(*pv->getVectorBlock(k));
292 template <
class Scalar>
304 for(
int k = 0; k < numBlocks_; ++k) {
305 multiVec_.getNonconstObj()->
col(k)->ele_wise_scale(*pv->getVectorBlock(k));
313 template <
class Scalar>
327 typename ST::magnitudeType norm = ST::magnitude(ST::zero());
328 for(
int k = 0; k < numBlocks_; ++k) {
329 typename ST::magnitudeType subNorm
330 = multiVec_.getConstObj()->col(k)->norm_2(*pv->getVectorBlock(k));
331 norm += subNorm*subNorm;
333 return ST::magnitude(ST::squareroot(norm));
340 template <
class Scalar>
349 this->getDefaultProductVector()->applyOp(
350 op, vecs, targ_vecs, reduct_obj, global_offset );
354 template <
class Scalar>
359 this->getDefaultProductVector()->acquireDetachedView(rng_in,sub_vec);
363 template <
class Scalar>
368 this->getDefaultProductVector()->releaseDetachedView(sub_vec);
372 template <
class Scalar>
377 TEUCHOS_TEST_FOR_EXCEPT(
"ToDo: Implement DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(...)!");
381 template <
class Scalar>
386 TEUCHOS_TEST_FOR_EXCEPT(
"ToDo: Implement DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(...)!");
390 template <
class Scalar>
402 template <
class Scalar>
405 multiVec_.getNonconstObj()->assign(alpha);
409 template <
class Scalar>
421 for(
int k = 0; k < numBlocks_; ++k) {
422 multiVec_.getNonconstObj()->
col(k)->assign(*pv->getMultiVectorBlock(k));
430 template <
class Scalar>
433 multiVec_.getNonconstObj()->scale(alpha);
437 template <
class Scalar>
450 for(
int k = 0; k < numBlocks_; ++k) {
451 multiVec_.getNonconstObj()->
col(k)->update(alpha, *pv->getMultiVectorBlock(k));
459 template <
class Scalar>
468 for (
Ordinal i = 0; i < mv.size(); ++i) {
475 bool allCastsSuccessful =
true;
477 for (
Ordinal i = 0; i < mv.size(); ++i) {
480 allCastsSuccessful =
false;
485 if (allCastsSuccessful) {
488 for (
int k = 0; k < numBlocks_; ++k) {
489 for (
Ordinal i = 0; i < pvs.size(); ++i) {
490 blocks_rcp[i] = pvs[i]->getMultiVectorBlock(k);
491 blocks[i] = blocks_rcp[i].ptr();
493 multiVec_.getNonconstObj()->col(k)->linear_combination(alpha, blocks(), beta);
501 template <
class Scalar>
516 for(
int k = 0; k < numBlocks_; ++k) {
518 multiVec_.getConstObj()->col(k)->dots(*pv->getMultiVectorBlock(k), Teuchos::arrayView(&prod, 1));
527 template <
class Scalar>
536 norms[0] = ST::magnitude(ST::zero());
537 for(
int k = 0; k < numBlocks_; ++k) {
538 norms[0] += multiVec_.getConstObj()->col(k)->norm_1();
543 template <
class Scalar>
552 norms[0] = ST::magnitude(ST::zero());
553 for(
int k = 0; k < numBlocks_; ++k) {
554 typename ST::magnitudeType subNorm = multiVec_.getConstObj()->col(k)->norm_2();
555 norms[0] += subNorm*subNorm;
557 norms[0] = ST::magnitude(ST::squareroot(norms[0]));
561 template <
class Scalar>
570 norms[0] = ST::magnitude(ST::zero());
571 for(
int k = 0; k < numBlocks_; ++k) {
572 typename ST::magnitudeType subNorm = multiVec_.getConstObj()->col(k)->norm_inf();
573 if (subNorm > norms[0])
582 template <
class Scalar>
594 for (
int k = 0; k < numBlocks_; ++k) {
595 vecArray.
push_back(multiVec_.getConstObj()->col(k));
598 return Thyra::defaultProductVector<Scalar>(
599 productSpace_->getDefaultProductVectorSpace(),
609 #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)