42 #ifndef THYRA_VECTOR_DEFAULT_BASE_DEF_HPP 43 #define THYRA_VECTOR_DEFAULT_BASE_DEF_HPP 50 #include "Thyra_VectorDefaultBase_decl.hpp" 51 #include "Thyra_VectorSpaceFactoryBase.hpp" 52 #include "Thyra_VectorBase.hpp" 53 #include "Thyra_VectorStdOps.hpp" 54 #include "Thyra_MultiVectorDefaultBase.hpp" 55 #include "Thyra_AssertOp.hpp" 56 #include "Thyra_MultiVectorBase.hpp" 57 #include "Thyra_DetachedVectorView.hpp" 58 #include "RTOpPack_ROpGetSubVector.hpp" 59 #include "RTOpPack_TOpSetSubVector.hpp" 60 #include "RTOpPack_ROpNorm1.hpp" 61 #include "RTOpPack_ROpNorm2.hpp" 62 #include "RTOpPack_ROpWeightedNorm2.hpp" 63 #include "RTOpPack_ROpNormInf.hpp" 64 #include "RTOpPack_TOpAbs.hpp" 65 #include "RTOpPack_TOpAssignVectors.hpp" 66 #include "RTOpPack_TOpAXPY.hpp" 67 #include "RTOpPack_TOpEleWiseScale.hpp" 68 #include "RTOpPack_TOpLinearCombination.hpp" 69 #include "RTOpPack_TOpScaleVector.hpp" 70 #include "RTOpPack_TOpReciprocal.hpp" 71 #include "RTOpPack_TOpRandomize.hpp" 72 #include "Teuchos_Assert.hpp" 75 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 76 # include "Teuchos_VerboseObject.hpp" 77 # define THYRA_VECTOR_VERBOSE_OUT_STATEMENT \ 78 RCP<Teuchos::FancyOStream> dbgout = Teuchos::VerboseObjectBase::getDefaultOStream() 79 #endif // THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 89 template<
class Scalar>
92 std::ostringstream oss;
96 oss <<
"{space=NULL}";
100 oss <<
"{dim=" << dim <<
"}";
106 template<
class Scalar>
116 *out << this->description() <<
"\n";
117 if (this->space()->dim()) {
122 *out << i <<
":" << dvv[i] << std::endl;
131 template<
class Scalar>
135 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 136 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
137 *dbgout <<
"\nThyra::VectorDefaultBase<" 139 <<
">::range() called!\n";
141 return this->space();
145 template<
class Scalar>
149 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 150 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
151 *dbgout <<
"\nThyra::VectorDefaultBase<" 153 <<
">::domain() called!\n";
156 domain_ = range()->smallVecSpcFcty()->createVecSpc(1);
165 template<
class Scalar>
169 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 170 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
171 *dbgout <<
"\nThyra::VectorDefaultBase<" 173 <<
">::clone_mv() called!\n";
175 return this->clone_v();
182 template<
class Scalar>
186 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 187 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
188 *dbgout <<
"\nThyra::VectorDefaultBase<" 190 <<
">::clone_v() called!\n";
193 ::Thyra::assign<Scalar>(copy.
ptr(), *
this);
201 template<
class Scalar>
208 template<
class Scalar>
211 using Teuchos::tuple;
using Teuchos::null;
213 Thyra::applyOp<Scalar>(random_vector_op,
220 template<
class Scalar>
223 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
224 RTOpPack::TOpAbs<Scalar> abs_op;
225 Thyra::applyOp<Scalar>(abs_op, tuple(ptrInArg(x)),
226 tuple<Ptr<VectorBase<Scalar> > >(ptr(
this)), null);
230 template<
class Scalar>
233 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
234 RTOpPack::TOpReciprocal<Scalar> recip_op;
235 Thyra::applyOp<Scalar>(recip_op, tuple(ptrInArg(x)),
236 tuple<Ptr<VectorBase<Scalar> > >(ptr(
this)), null);
240 template<
class Scalar>
243 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
245 Thyra::applyOp<Scalar>(scale_op, tuple(ptrInArg(x)),
246 tuple<Ptr<VectorBase<Scalar> > >(ptr(
this)), null);
250 template<
class Scalar>
259 template<
class Scalar>
267 for (
Ordinal i = 0; i < x.size(); ++i)
269 this->linear_combination(alpha, mv(), beta);
273 template<
class Scalar>
277 this->dots(x, Teuchos::arrayView(&prod, 1));
282 template<
class Scalar>
287 this->norms_1(Teuchos::arrayView(&norm, 1));
292 template<
class Scalar>
297 this->norms_2(Teuchos::arrayView(&norm, 1));
302 template<
class Scalar>
306 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
309 Thyra::applyOp<Scalar>(norm_op,
313 return norm_op(*norm_targ);
316 template<
class Scalar>
321 this->norms_inf(Teuchos::arrayView(&norm, 1));
329 template<
class Scalar>
333 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 334 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
335 *dbgout <<
"\nThyra::VectorDefaultBase<" 341 return Teuchos::rcp(
this,
false);
345 template<
class Scalar>
349 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 350 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
351 *dbgout <<
"\nThyra::VectorDefaultBase<" 353 <<
">::contigSubViewImpl(col_rng) const called!\n";
355 validateColRng(col_rng);
356 return Teuchos::rcp(
this,
false);
360 template<
class Scalar>
364 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 365 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
366 *dbgout <<
"\nThyra::VectorDefaultBase<" 368 <<
">::nonconstContigSubViewImpl(col_rng) called!\n";
370 validateColRng(col_rng);
371 return Teuchos::rcp(
this,
false);
375 template<
class Scalar>
380 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 381 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
382 *dbgout <<
"\nThyra::VectorDefaultBase<" 384 <<
">::nonContigSubViewImpl(cols) called!\n";
386 validateColIndexes(cols);
387 return Teuchos::rcp(
this,
false);
391 template<
class Scalar>
396 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 397 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
398 *dbgout <<
"\nThyra::VectorDefaultBase<" 400 <<
">::nonconstNonContigSubViewImpl(cols) called!\n";
402 validateColIndexes(cols);
403 return Teuchos::rcp(
this,
false);
407 template<
class Scalar>
414 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 415 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
416 *dbgout <<
"\nThyra::VectorDefaultBase<" 418 <<
">::acquireDetachedMultiVectorViewImpl() const called!\n";
423 validateColRng(colRng);
425 this->acquireDetachedView(rowRng,&sv);
433 template<
class Scalar>
443 template<
class Scalar>
450 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 451 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
452 *dbgout <<
"\nThyra::VectorDefaultBase<" 454 <<
">::acquireNonconstDetachedMultiVectorViewImpl() called!\n";
459 validateColRng(colRng);
461 this->acquireDetachedView(rowRng,&sv);
469 template<
class Scalar>
474 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 475 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
476 *dbgout <<
"\nThyra::VectorDefaultBase<" 478 <<
">::commitNonconstDetachedMultiVectorViewImpl() called!\n";
485 this->commitDetachedView(&sv);
493 template<
class Scalar>
499 using Teuchos::tuple;
503 !(rng.
ubound() < this->space()->dim()), std::out_of_range
504 ,
"VectorDefaultBase<Scalar>::acquireDetachedVectorViewImpl(rng,...):" 506 <<
"] is not in range = [0,"<<(this->space()->dim()-1)<<
"]" );
512 reduct_obj = get_sub_vector_op.reduct_obj_create();
514 ::Thyra::applyOp<Scalar>(get_sub_vector_op, tuple(Teuchos::ptr<
const VectorBase<Scalar> >(
this))(),
515 Teuchos::null, reduct_obj.ptr());
517 *sub_vec_inout = get_sub_vector_op(*reduct_obj);
521 template<
class Scalar>
531 template<
class Scalar>
549 Teuchos::arcp_const_cast<Scalar>(sub_vec.
values()), sub_vec.
stride()
554 template<
class Scalar>
569 template<
class Scalar>
573 ::Thyra::applyOp<Scalar>(set_sub_vector_op, Teuchos::null,
581 template<
class Scalar>
585 return ( ST::isComplex ? ( M_trans==
NOTRANS || M_trans==
CONJTRANS ) :
true );
589 template<
class Scalar>
604 "VectorDefaultBase<Scalar>::apply()", *
this, M_trans, X, &*Y);
609 for (
Ordinal col_j = 0; col_j < numCols; ++col_j) {
616 if( M_trans ==
NOTRANS || (M_trans ==
CONJ && !ST::isComplex) ) {
618 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 619 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
620 *dbgout <<
"\nThyra::VectorDefaultBase<" 622 <<
">::apply(...) : y = beta*y + alpha*m*x (x is a scalar!)\n";
624 Vt_S( y.
ptr(), beta );
625 Vp_StV( y.
ptr(), Scalar(alpha*get_ele(*x,0)), *this );
627 else if( M_trans ==
CONJTRANS || (M_trans ==
TRANS && !ST::isComplex) ) {
629 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 630 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
631 *dbgout <<
"\nThyra::VectorDefaultBase<" 633 <<
">::apply(...) : y = beta*y + alpha*m'*x (y is a scalar!)\n";
636 if( beta == ST::zero() ) {
637 y_inout = ST::zero();
640 y_inout = beta*get_ele(*y,0);
642 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_SPMD_APPLY_OP_DUMP) 643 RTOpPack::show_spmd_apply_op_dump =
true;
645 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT) 646 RTOpPack::rtop_helpers_dump_all =
true;
648 y_inout += alpha * this->space()->scalarProd(*
this, *x);
649 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_SPMD_APPLY_OP_DUMP) 650 RTOpPack::show_spmd_apply_op_dump =
false;
652 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT) 653 RTOpPack::rtop_helpers_dump_all =
false;
655 set_ele(0, y_inout, y.
ptr());
656 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT 658 <<
"\nThyra::VectorDefaultBase<"<<ST::name()<<
">::apply(...) : y_inout = " 664 "VectorBase<"<<ST::name()<<
">::apply(M_trans,...): Error, M_trans=" 665 <<
toString(M_trans)<<
" not supported!" );
676 template<
class Scalar>
687 template<
class Scalar>
701 #endif // THYRA_VECTOR_DEFAULT_BASE_DEF_HPP virtual RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &col_rng) const
Returns Teuchos::rcp(this,false).
RCP< MultiVectorBase< Scalar > > clone_mv() const
Returns this->clone_v().
virtual RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &col_rng)
Returns Teuchos::rcp(this,false).
bool is_null(const boost::shared_ptr< T > &p)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
basic_OSTab< char > OSTab
#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
. Applies vector or its adjoint (transpose) as a linear operator.
basic_FancyOStream< char > FancyOStream
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Use the non-transposed operator.
Teuchos_Ordinal subDim() const
Returns the dimension of the explicit view.
T_To & dyn_cast(T_From &from)
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.
Create an explicit non-mutable (const) view of a VectorBase object.
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
virtual void absImpl(const VectorBase< Scalar > &x)
Default implementation of abs using RTOps.
virtual std::string description() const
Ordinal globalOffset() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Generates a default outputting for all vectors.
static std::string name()
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
virtual void releaseDetachedMultiVectorViewImpl(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Implemented in terms of this->releaseDetachedView().
Use the transposed operator.
const ArrayRCP< const Scalar > values() const
virtual void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
Implemented in terms of this->acquireDetachedView().
virtual void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2Impl() const
Default implementation of norm_2 using RTOps.
Convenient node subclass for concrete VectorBase subclasses that relies on a default MultiVectorBase ...
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
virtual Scalar dotImpl(const VectorBase< Scalar > &x) const
Default implementation of dot using RTOps.
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm1Impl() const
Default implementation of norm_1 using RTOps.
Teuchos::RCP< ReductTarget > reduct_obj_create() const
virtual RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)
Returns Teuchos::rcp(this,false).
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< Scalar > &values_in, Ordinal leadingDim_in)
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< Scalar > &values_in, ptrdiff_t stride_in)
Abstract interface for finite-dimensional dense vectors.
virtual void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
virtual std::string description() const
Default description that gives the label, type, and dimenstion .
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType normInfImpl() const
Default implementation of norm_inf using RTOps.
virtual void assignVecImpl(const VectorBase< Scalar > &x)
Default implementation of assign(vector) using RTOps.
virtual void updateVecImpl(Scalar alpha, const VectorBase< Scalar > &x)
Default implementation of update using RTOps.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
virtual RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->space().
const ArrayRCP< Scalar > values() const
RCP< VectorBase< Scalar > > clone_v() const
Simply creates a new vector and copies the contents from *this.
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< const Scalar > &values_in, Ordinal leadingDim_in)
virtual void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Implemented in terms of this->acquireDetachedView().
const ArrayRCP< Scalar > values() const
virtual void setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)
Ordinal globalOffset() const
virtual RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols) const
Returns Teuchos::rcp(this,false).
virtual void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
Implemented in terms of this->commitDetachedView().
virtual void acquireNonconstDetachedVectorViewImpl(const Range1D &rng, RTOpPack::SubVectorView< Scalar > *sub_vec)
virtual void randomizeImpl(Scalar l, Scalar u)
Default implementation of randomize using RTOps.
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< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols)
Returns Teuchos::rcp(this,false).
virtual RCP< const VectorSpaceBase< Scalar > > domain() const
Returns a DefaultSerialVectorSpace object with dimension 1.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Default implementation of norm_2 (weighted) using RTOps.
virtual void linearCombinationVecImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const VectorBase< Scalar > > > &x, const Scalar &beta)
Default implementation of linear_combination using RTOps.
virtual void commitNonconstDetachedVectorViewImpl(RTOpPack::SubVectorView< Scalar > *sub_vec)