42 #ifndef THYRA_DEFAULT_COLUMNWISE_MULTI_VECTOR_DEF_HPP
43 #define THYRA_DEFAULT_COLUMNWISE_MULTI_VECTOR_DEF_HPP
45 #include "Thyra_DefaultColumnwiseMultiVector_decl.hpp"
46 #include "Thyra_MultiVectorDefaultBase.hpp"
47 #include "Thyra_VectorSpaceBase.hpp"
48 #include "Thyra_VectorBase.hpp"
49 #include "Thyra_MultiVectorBase.hpp"
50 #include "Thyra_VectorStdOps.hpp"
51 #include "Thyra_VectorSpaceFactoryBase.hpp"
52 #include "Thyra_AssertOp.hpp"
53 #include "Teuchos_Assert.hpp"
54 #include "Teuchos_as.hpp"
62 template<
class Scalar>
67 template<
class Scalar>
72 this->initialize(col_vec);
76 template<
class Scalar>
83 this->initialize(range_in, domain_in, col_vecs_in);
87 template<
class Scalar>
93 const std::string err_msg =
94 "DefaultColumnwiseMultiVector<Scalar>::initialize(...): Error!";
98 range_ = col_vec->space();
99 domain_ = range_->smallVecSpcFcty()->createVecSpc(1);
101 col_vecs_[0] = col_vec;
105 template<
class Scalar>
113 const std::string err_msg =
114 "DefaultColumnwiseMultiVector<Scalar>::initialize(...): Error!";
121 const int domainDim = domain_in->dim();
125 col_vecs_.reserve(domainDim);
126 if (col_vecs.size()) {
127 for(
Ordinal j = 0; j < domainDim; ++j )
128 col_vecs_.push_back(col_vecs[j]);
131 for(
Ordinal j = 0; j < domainDim; ++j )
132 col_vecs_.push_back(createMember(range_));
137 template<
class Scalar>
141 range_ = Teuchos::null;
142 domain_ = Teuchos::null;
149 template<
class Scalar>
157 template<
class Scalar>
168 template<
class Scalar>
171 const Ordinal m = col_vecs_.size();
172 for (
Ordinal col_j = 0; col_j < m; ++col_j) {
173 col_vecs_[col_j]->assign(alpha);
178 template<
class Scalar>
187 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
188 col_vecs_[col_j]->assign(*mv.
col(col_j));
193 template<
class Scalar>
196 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
197 col_vecs_[col_j]->scale(alpha);
202 template<
class Scalar>
212 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
213 col_vecs_[col_j]->update(alpha, *mv.
col(col_j));
218 template<
class Scalar>
227 for (
Ordinal i = 0; i < mv.size(); ++i) {
234 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
235 for (
Ordinal i = 0; i < mv.size(); ++i) {
236 v_rcp[i] = mv[i]->col(col_j);
237 v[i] = v_rcp[i].ptr();
239 col_vecs_[col_j]->linear_combination(alpha, v(), beta);
244 template<
class Scalar>
255 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
256 prods[col_j] = col_vecs_[col_j]->dot(*mv.
col(col_j));
261 template<
class Scalar>
269 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
270 norms[col_j] = col_vecs_[col_j]->norm_1();
275 template<
class Scalar>
283 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
284 norms[col_j] = col_vecs_[col_j]->norm_2();
289 template<
class Scalar>
297 for (
Ordinal col_j = 0; col_j < col_vecs_.size(); ++col_j) {
298 norms[col_j] = col_vecs_[col_j]->norm_inf();
307 template<
class Scalar>
311 return ( ST::isComplex ? ( M_trans==
NOTRANS || M_trans==
CONJTRANS ) :
true );
315 template<
class Scalar>
326 "MultiVectorBase<Scalar>::apply()", *
this, M_trans, X, &*Y);
328 const Ordinal nc = this->domain()->dim();
330 for (
Ordinal col_j = 0; col_j < m; ++col_j) {
334 Vt_S(y_j.
ptr(), beta);
342 x_j->acquireDetachedView(
Range1D(), &x_sub_vec);
344 for (
Ordinal j = 0; j < nc; ++j )
345 Vp_StV( y_j.
ptr(), Scalar(alpha*x_sub_vec(j)), *this->col(j) );
347 x_j->releaseDetachedView(&x_sub_vec);
358 y_j->acquireDetachedView(
Range1D(), &y_sub_vec);
360 for (
Ordinal j = 0; j < nc; ++j )
361 y_sub_vec(j) += alpha*dot(*this->col(j), *x_j);
363 y_j->commitDetachedView(&y_sub_vec);
372 template<
class Scalar>
377 const int num_cols = col_vecs_.size();
379 !( 0 <= j && j < num_cols ), std::logic_error
380 ,
"Error, j = " << j <<
" does not fall in the range [0,"<<(num_cols-1)<<
"]!"
386 template<
class Scalar>
392 const Ordinal numCols = domain_->dim();
393 const Range1D col_rng = Teuchos::full_range(col_rng_in,0,numCols-1);
396 !( col_rng.
ubound() < numCols ), std::logic_error
397 ,
"DefaultColumnwiseMultiVector<Scalar>::subView(col_rng):"
398 "Error, the input range col_rng = ["<<col_rng.
lbound()
399 <<
","<<col_rng.
ubound()<<
"] "
400 "is not in the range [0,"<<(numCols-1)<<
"]!"
406 domain_->smallVecSpcFcty()->createVecSpc(col_rng.
size()),
416 #endif // THYRA_DEFAULT_COLUMNWISE_MULTI_VECTOR_DEF_HPP
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
RCP< const VectorSpaceBase< Scalar > > range() const
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.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
#define THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(FUNC_NAME, M, M_T, X, Y)
This is a very useful macro that should be used to validate that the spaces for the multi-vector vers...
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
This function is implemented in terms of the multi-vector applyOp() function.
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Use the non-transposed operator.
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
virtual void scaleImpl(Scalar alpha)
Abstract interface for objects that represent a space for vectors.
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
Interface for a collection of column vectors called a multi-vector.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)
Abstract interface for finite-dimensional dense vectors.
void initialize(const RCP< VectorBase< Scalar > > &col_vec)
Initialize given a single vector object.
Default subclass for MultiVectorBase implemented using columns of separate abstract vectors...
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &col_rng)
bool opSupportedImpl(EOpTransp M_trans) const
For complex Scalar types returns true for NOTRANS and CONJTRANS and for real types returns true for a...
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
RCP< const VectorSpaceBase< Scalar > > domain() const
TypeTo as(const TypeFrom &t)
virtual void assignImpl(Scalar alpha)
DefaultColumnwiseMultiVector()
Construct to initialized.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
void uninitialize()
Set uninitialized.
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const