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>
231 return multiVec_.isConst();
235 template <
class Scalar>
239 return getNonconstVectorBlock(k);
243 template <
class Scalar>
247 return getVectorBlock(k);
254 template <
class Scalar>
258 return productSpace_;
268 template <
class Scalar>
274 for(
int k = 0; k < numBlocks_; ++k) {
275 multiVec_.getNonconstObj()->col(k)->randomize(l, u);
280 template <
class Scalar>
292 for(
int k = 0; k < numBlocks_; ++k) {
293 multiVec_.getNonconstObj()->
col(k)->abs(*pv->getVectorBlock(k));
301 template <
class Scalar>
313 for(
int k = 0; k < numBlocks_; ++k) {
314 multiVec_.getNonconstObj()->
col(k)->reciprocal(*pv->getVectorBlock(k));
322 template <
class Scalar>
334 for(
int k = 0; k < numBlocks_; ++k) {
335 multiVec_.getNonconstObj()->
col(k)->ele_wise_scale(*pv->getVectorBlock(k));
343 template <
class Scalar>
357 typename ST::magnitudeType norm = ST::magnitude(ST::zero());
358 for(
int k = 0; k < numBlocks_; ++k) {
359 typename ST::magnitudeType subNorm
360 = multiVec_.getConstObj()->col(k)->norm_2(*pv->getVectorBlock(k));
361 norm += subNorm*subNorm;
363 return ST::magnitude(ST::squareroot(norm));
370 template <
class Scalar>
379 this->getDefaultProductVector()->applyOp(
380 op, vecs, targ_vecs, reduct_obj, global_offset );
384 template <
class Scalar>
389 this->getDefaultProductVector()->acquireDetachedView(rng_in,sub_vec);
393 template <
class Scalar>
398 this->getDefaultProductVector()->releaseDetachedView(sub_vec);
402 template <
class Scalar>
407 TEUCHOS_TEST_FOR_EXCEPT(
"ToDo: Implement DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(...)!");
411 template <
class Scalar>
416 TEUCHOS_TEST_FOR_EXCEPT(
"ToDo: Implement DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(...)!");
420 template <
class Scalar>
432 template <
class Scalar>
435 multiVec_.getNonconstObj()->assign(alpha);
439 template <
class Scalar>
451 for(
int k = 0; k < numBlocks_; ++k) {
452 multiVec_.getNonconstObj()->
col(k)->assign(*pv->getMultiVectorBlock(k));
460 template <
class Scalar>
463 multiVec_.getNonconstObj()->scale(alpha);
467 template <
class Scalar>
480 for(
int k = 0; k < numBlocks_; ++k) {
481 multiVec_.getNonconstObj()->
col(k)->update(alpha, *pv->getMultiVectorBlock(k));
489 template <
class Scalar>
498 for (
Ordinal i = 0; i < mv.size(); ++i) {
505 bool allCastsSuccessful =
true;
507 for (
Ordinal i = 0; i < mv.size(); ++i) {
510 allCastsSuccessful =
false;
515 if (allCastsSuccessful) {
518 for (
int k = 0; k < numBlocks_; ++k) {
519 for (
Ordinal i = 0; i < pvs.size(); ++i) {
520 blocks_rcp[i] = pvs[i]->getMultiVectorBlock(k);
521 blocks[i] = blocks_rcp[i].ptr();
523 multiVec_.getNonconstObj()->col(k)->linear_combination(alpha, blocks(), beta);
531 template <
class Scalar>
546 for(
int k = 0; k < numBlocks_; ++k) {
548 multiVec_.getConstObj()->col(k)->dots(*pv->getMultiVectorBlock(k), Teuchos::arrayView(&prod, 1));
557 template <
class Scalar>
566 norms[0] = ST::magnitude(ST::zero());
567 for(
int k = 0; k < numBlocks_; ++k) {
568 norms[0] += multiVec_.getConstObj()->col(k)->norm_1();
573 template <
class Scalar>
582 norms[0] = ST::magnitude(ST::zero());
583 for(
int k = 0; k < numBlocks_; ++k) {
584 typename ST::magnitudeType subNorm = multiVec_.getConstObj()->col(k)->norm_2();
585 norms[0] += subNorm*subNorm;
587 norms[0] = ST::magnitude(ST::squareroot(norms[0]));
591 template <
class Scalar>
600 norms[0] = ST::magnitude(ST::zero());
601 for(
int k = 0; k < numBlocks_; ++k) {
602 typename ST::magnitudeType subNorm = multiVec_.getConstObj()->col(k)->norm_inf();
603 if (subNorm > norms[0])
612 template <
class Scalar>
624 for (
int k = 0; k < numBlocks_; ++k) {
625 vecArray.
push_back(multiVec_.getConstObj()->col(k));
628 return Thyra::defaultProductVector<Scalar>(
629 productSpace_->getDefaultProductVectorSpace(),
639 #endif // THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP