10 #ifndef THYRA_VECTOR_DEFAULT_BASE_DEF_HPP
11 #define THYRA_VECTOR_DEFAULT_BASE_DEF_HPP
18 #include "Thyra_VectorDefaultBase_decl.hpp"
19 #include "Thyra_VectorSpaceFactoryBase.hpp"
20 #include "Thyra_VectorBase.hpp"
21 #include "Thyra_VectorStdOps.hpp"
22 #include "Thyra_MultiVectorDefaultBase.hpp"
23 #include "Thyra_AssertOp.hpp"
24 #include "Thyra_MultiVectorBase.hpp"
25 #include "Thyra_DetachedVectorView.hpp"
26 #include "RTOpPack_ROpGetSubVector.hpp"
27 #include "RTOpPack_TOpSetSubVector.hpp"
28 #include "RTOpPack_ROpNorm1.hpp"
29 #include "RTOpPack_ROpNorm2.hpp"
30 #include "RTOpPack_ROpWeightedNorm2.hpp"
31 #include "RTOpPack_ROpNormInf.hpp"
32 #include "RTOpPack_TOpAbs.hpp"
33 #include "RTOpPack_TOpAssignVectors.hpp"
34 #include "RTOpPack_TOpAXPY.hpp"
35 #include "RTOpPack_TOpEleWiseScale.hpp"
36 #include "RTOpPack_TOpLinearCombination.hpp"
37 #include "RTOpPack_TOpScaleVector.hpp"
38 #include "RTOpPack_TOpReciprocal.hpp"
39 #include "RTOpPack_TOpRandomize.hpp"
40 #include "Teuchos_Assert.hpp"
43 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
44 # include "Teuchos_VerboseObject.hpp"
45 # define THYRA_VECTOR_VERBOSE_OUT_STATEMENT \
46 RCP<Teuchos::FancyOStream> dbgout = Teuchos::VerboseObjectBase::getDefaultOStream()
47 #endif // THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
57 template<
class Scalar>
60 std::ostringstream oss;
64 oss <<
"{space=NULL}";
68 oss <<
"{dim=" << dim <<
"}";
74 template<
class Scalar>
84 *out << this->description() <<
"\n";
85 if (this->space()->dim()) {
90 *out << i <<
":" << dvv[i] << std::endl;
99 template<
class Scalar>
103 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
104 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
105 *dbgout <<
"\nThyra::VectorDefaultBase<"
107 <<
">::range() called!\n";
109 return this->space();
113 template<
class Scalar>
117 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
118 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
119 *dbgout <<
"\nThyra::VectorDefaultBase<"
121 <<
">::domain() called!\n";
124 domain_ = range()->smallVecSpcFcty()->createVecSpc(1);
133 template<
class Scalar>
137 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
138 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
139 *dbgout <<
"\nThyra::VectorDefaultBase<"
141 <<
">::clone_mv() called!\n";
143 return this->clone_v();
150 template<
class Scalar>
154 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
155 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
156 *dbgout <<
"\nThyra::VectorDefaultBase<"
158 <<
">::clone_v() called!\n";
161 ::Thyra::assign<Scalar>(copy.
ptr(), *
this);
169 template<
class Scalar>
176 template<
class Scalar>
179 using Teuchos::tuple;
using Teuchos::null;
181 Thyra::applyOp<Scalar>(random_vector_op,
188 template<
class Scalar>
191 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
192 RTOpPack::TOpAbs<Scalar> abs_op;
193 Thyra::applyOp<Scalar>(abs_op, tuple(ptrInArg(x)),
194 tuple<Ptr<VectorBase<Scalar> > >(ptr(
this)), null);
198 template<
class Scalar>
201 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
202 RTOpPack::TOpReciprocal<Scalar> recip_op;
203 Thyra::applyOp<Scalar>(recip_op, tuple(ptrInArg(x)),
204 tuple<Ptr<VectorBase<Scalar> > >(ptr(
this)), null);
208 template<
class Scalar>
211 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
213 Thyra::applyOp<Scalar>(scale_op, tuple(ptrInArg(x)),
214 tuple<Ptr<VectorBase<Scalar> > >(ptr(
this)), null);
218 template<
class Scalar>
227 template<
class Scalar>
235 for (
Ordinal i = 0; i < x.size(); ++i)
237 this->linear_combination(alpha, mv(), beta);
241 template<
class Scalar>
245 this->dots(x, Teuchos::arrayView(&prod, 1));
250 template<
class Scalar>
255 this->norms_1(Teuchos::arrayView(&norm, 1));
260 template<
class Scalar>
265 this->norms_2(Teuchos::arrayView(&norm, 1));
270 template<
class Scalar>
274 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
277 Thyra::applyOp<Scalar>(norm_op,
281 return norm_op(*norm_targ);
284 template<
class Scalar>
289 this->norms_inf(Teuchos::arrayView(&norm, 1));
297 template<
class Scalar>
301 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
302 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
303 *dbgout <<
"\nThyra::VectorDefaultBase<"
315 template<
class Scalar>
319 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
320 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
321 *dbgout <<
"\nThyra::VectorDefaultBase<"
323 <<
">::contigSubViewImpl(col_rng) const called!\n";
325 validateColRng(col_rng);
330 template<
class Scalar>
334 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
335 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
336 *dbgout <<
"\nThyra::VectorDefaultBase<"
338 <<
">::nonconstContigSubViewImpl(col_rng) called!\n";
340 validateColRng(col_rng);
345 template<
class Scalar>
350 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
351 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
352 *dbgout <<
"\nThyra::VectorDefaultBase<"
354 <<
">::nonContigSubViewImpl(cols) called!\n";
356 validateColIndexes(cols);
361 template<
class Scalar>
366 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
367 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
368 *dbgout <<
"\nThyra::VectorDefaultBase<"
370 <<
">::nonconstNonContigSubViewImpl(cols) called!\n";
372 validateColIndexes(cols);
377 template<
class Scalar>
384 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
385 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
386 *dbgout <<
"\nThyra::VectorDefaultBase<"
388 <<
">::acquireDetachedMultiVectorViewImpl() const called!\n";
393 validateColRng(colRng);
395 this->acquireDetachedView(rowRng,&sv);
403 template<
class Scalar>
413 template<
class Scalar>
420 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
421 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
422 *dbgout <<
"\nThyra::VectorDefaultBase<"
424 <<
">::acquireNonconstDetachedMultiVectorViewImpl() called!\n";
429 validateColRng(colRng);
431 this->acquireDetachedView(rowRng,&sv);
439 template<
class Scalar>
444 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
445 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
446 *dbgout <<
"\nThyra::VectorDefaultBase<"
448 <<
">::commitNonconstDetachedMultiVectorViewImpl() called!\n";
455 this->commitDetachedView(&sv);
463 template<
class Scalar>
469 using Teuchos::tuple;
473 !(rng.
ubound() < this->space()->dim()), std::out_of_range
474 ,
"VectorDefaultBase<Scalar>::acquireDetachedVectorViewImpl(rng,...):"
476 <<
"] is not in range = [0,"<<(this->space()->dim()-1)<<
"]" );
482 reduct_obj = get_sub_vector_op.reduct_obj_create();
484 ::Thyra::applyOp<Scalar>(get_sub_vector_op, tuple(Teuchos::ptr<
const VectorBase<Scalar> >(
this))(),
485 Teuchos::null, reduct_obj.ptr());
487 *sub_vec_inout = get_sub_vector_op(*reduct_obj);
491 template<
class Scalar>
501 template<
class Scalar>
519 Teuchos::arcp_const_cast<Scalar>(sub_vec.
values()), sub_vec.
stride()
524 template<
class Scalar>
539 template<
class Scalar>
543 ::Thyra::applyOp<Scalar>(set_sub_vector_op, Teuchos::null,
551 template<
class Scalar>
555 return ( ST::isComplex ? ( M_trans==
NOTRANS || M_trans==
CONJTRANS ) :
true );
559 template<
class Scalar>
574 "VectorDefaultBase<Scalar>::apply()", *
this, M_trans, X, &*Y);
579 for (
Ordinal col_j = 0; col_j < numCols; ++col_j) {
586 if( M_trans ==
NOTRANS || (M_trans ==
CONJ && !ST::isComplex) ) {
588 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
589 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
590 *dbgout <<
"\nThyra::VectorDefaultBase<"
592 <<
">::apply(...) : y = beta*y + alpha*m*x (x is a scalar!)\n";
594 Vt_S( y.
ptr(), beta );
595 Vp_StV( y.
ptr(), Scalar(alpha*get_ele(*x,0)), *this );
597 else if( M_trans ==
CONJTRANS || (M_trans ==
TRANS && !ST::isComplex) ) {
599 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
600 THYRA_VECTOR_VERBOSE_OUT_STATEMENT;
601 *dbgout <<
"\nThyra::VectorDefaultBase<"
603 <<
">::apply(...) : y = beta*y + alpha*m'*x (y is a scalar!)\n";
606 if( beta == ST::zero() ) {
607 y_inout = ST::zero();
610 y_inout = beta*get_ele(*y,0);
612 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_SPMD_APPLY_OP_DUMP)
613 RTOpPack::show_spmd_apply_op_dump =
true;
615 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT)
616 RTOpPack::rtop_helpers_dump_all =
true;
618 y_inout += alpha * this->space()->scalarProd(*
this, *x);
619 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_SPMD_APPLY_OP_DUMP)
620 RTOpPack::show_spmd_apply_op_dump =
false;
622 #if defined(THYRA_VECTOR_VERBOSE_TO_ERROR_OUT) && defined(RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT)
623 RTOpPack::rtop_helpers_dump_all =
false;
625 set_ele(0, y_inout, y.
ptr());
626 #ifdef THYRA_VECTOR_VERBOSE_TO_ERROR_OUT
628 <<
"\nThyra::VectorDefaultBase<"<<ST::name()<<
">::apply(...) : y_inout = "
634 "VectorBase<"<<ST::name()<<
">::apply(M_trans,...): Error, M_trans="
635 <<
toString(M_trans)<<
" not supported!" );
646 template<
class Scalar>
659 template<
class Scalar>
661 void VectorDefaultBase<Scalar>::validateColIndexes(
662 const ArrayView<const int>&cols )
const
675 #endif // THYRA_VECTOR_DEFAULT_BASE_DEF_HPP
virtual Scalar dotImpl(const VectorBase< Scalar > &x) const
Default implementation of dot using RTOps.
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
virtual void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Implemented in terms of this->acquireDetachedView().
#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...
virtual std::string description() const
Default description that gives the label, type, and dimenstion .
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Generates a default outputting for all vectors.
virtual void releaseDetachedVectorViewImpl(RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
basic_FancyOStream< char > FancyOStream
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Use the non-transposed operator.
T_To & dyn_cast(T_From &from)
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm1Impl() const
Default implementation of norm_1 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.
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)...
const ArrayRCP< Scalar > values() const
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2Impl() const
Default implementation of norm_2 using RTOps.
virtual void absImpl(const VectorBase< Scalar > &x)
Default implementation of abs using RTOps.
RCP< VectorBase< Scalar > > clone_v() const
Simply creates a new vector and copies the contents from *this.
static std::string name()
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
Ordinal globalOffset() const
Use the transposed operator.
virtual RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->space().
virtual RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols) const
Returns Teuchos::rcp(this,false).
const ArrayRCP< Scalar > values() const
virtual void releaseDetachedMultiVectorViewImpl(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
Implemented in terms of this->releaseDetachedView().
virtual void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
Implemented in terms of this->acquireDetachedView().
Convenient node subclass for concrete VectorBase subclasses that relies on a default MultiVectorBase ...
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.
Teuchos_Ordinal subDim() const
Returns the dimension of the explicit view.
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)
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
virtual std::string description() const
Abstract interface for finite-dimensional dense vectors.
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
bool opSupportedImpl(EOpTransp M_trans) const
For complex Scalar types returns true for NOTRANS and CONJTRANS and for real types returns true for a...
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.
virtual RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &col_rng) const
Returns Teuchos::rcp(this,false).
Ordinal globalOffset() const
virtual void assignVecImpl(const VectorBase< Scalar > &x)
Default implementation of assign(vector) using RTOps.
Teuchos::RCP< ReductTarget > reduct_obj_create() const
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 Teuchos::ScalarTraits< Scalar >::magnitudeType normInfImpl() const
Default implementation of norm_inf using RTOps.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const
Returns a DefaultSerialVectorSpace object with dimension 1.
virtual Teuchos::ScalarTraits< Scalar >::magnitudeType norm2WeightedImpl(const VectorBase< Scalar > &x) const
Default implementation of norm_2 (weighted) using RTOps.
virtual void acquireDetachedVectorViewImpl(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
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 setSubVectorImpl(const RTOpPack::SparseSubVectorT< Scalar > &sub_vec)
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.
virtual RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols)
Returns Teuchos::rcp(this,false).
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const ArrayRCP< const Scalar > values() const
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)