10 #ifndef THYRA_MULTI_VECTOR_DEFAULT_BASE_DEF_HPP
11 #define THYRA_MULTI_VECTOR_DEFAULT_BASE_DEF_HPP
14 #include "Thyra_MultiVectorDefaultBase_decl.hpp"
15 #include "Thyra_LinearOpDefaultBase.hpp"
16 #include "Thyra_MultiVectorStdOps.hpp"
17 #include "Thyra_VectorSpaceFactoryBase.hpp"
18 #include "Thyra_VectorSpaceBase.hpp"
19 #include "Thyra_VectorBase.hpp"
20 #include "Thyra_AssertOp.hpp"
21 #include "Thyra_DefaultColumnwiseMultiVector.hpp"
22 #include "RTOpPack_TOpAssignScalar.hpp"
23 #include "RTOpPack_ROpDotProd.hpp"
24 #include "RTOpPack_ROpNorm1.hpp"
25 #include "RTOpPack_ROpNorm2.hpp"
26 #include "RTOpPack_ROpNormInf.hpp"
27 #include "RTOpPack_TOpAssignVectors.hpp"
28 #include "RTOpPack_TOpAXPY.hpp"
29 #include "RTOpPack_TOpLinearCombination.hpp"
30 #include "RTOpPack_TOpScaleVector.hpp"
31 #include "Teuchos_Workspace.hpp"
32 #include "Teuchos_Assert.hpp"
33 #include "Teuchos_as.hpp"
42 template<
class Scalar>
43 RCP<MultiVectorBase<Scalar> >
47 &l_domain = *this->domain(),
48 &l_range = *this->range();
50 copy = createMembers(l_range,l_domain.
dim());
51 ::Thyra::assign<Scalar>(copy.
ptr(), *
this);
61 template<
class Scalar>
64 using Teuchos::tuple;
using Teuchos::null;
66 Thyra::applyOp<Scalar>(assign_scalar_op,
71 template<
class Scalar>
74 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
75 RTOpPack::TOpAssignVectors<Scalar> assign_vectors_op;
76 Thyra::applyOp<Scalar>(assign_vectors_op, tuple(ptrInArg(mv)),
77 tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(
this)), null);
81 template<
class Scalar>
84 using Teuchos::tuple;
using Teuchos::null;
86 if (alpha==ST::zero()) {
87 this->assign(ST::zero());
91 if (alpha==ST::one()) {
95 Thyra::applyOp<Scalar>(scale_vector_op,
101 template<
class Scalar>
107 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
109 Thyra::applyOp<Scalar>( axpy_op, tuple(ptrInArg(mv)),
110 tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(
this)), null );
114 template<
class Scalar>
121 using Teuchos::tuple;
using Teuchos::null;
125 const int m = alpha.
size();
127 this->update(alpha[0], *mv[0]);
135 Thyra::applyOp<Scalar>(lin_comb_op, mv,
136 tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(
this)), null );
140 template<
class Scalar>
145 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
146 const int m = this->domain()->dim();
147 RTOpPack::ROpNorm1<Scalar> norm_op;
150 for(
int kc = 0; kc < m; ++kc) {
151 rcp_op_targs[kc] = norm_op.reduct_obj_create();
152 op_targs[kc] = rcp_op_targs[kc].ptr();
154 Thyra::applyOp<Scalar>(norm_op,
155 tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(*
this)),
158 for(
int kc = 0; kc < m; ++kc) {
159 norms[kc] = norm_op(*op_targs[kc]);
164 template<
class Scalar>
169 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
170 const int m = this->domain()->dim();
174 for(
int kc = 0; kc < m; ++kc) {
176 op_targs[kc] = rcp_op_targs[kc].ptr();
178 Thyra::applyOp<Scalar>(norm_op,
179 tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(*
this)),
182 for(
int kc = 0; kc < m; ++kc) {
183 norms[kc] = norm_op(*op_targs[kc]);
188 template<
class Scalar>
194 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
195 const int m = this->domain()->dim();
196 RTOpPack::ROpDotProd<Scalar> dot_op;
199 for(
int kc = 0; kc < m; ++kc ) {
200 rcp_dot_targs[kc] = dot_op.reduct_obj_create();
201 dot_targs[kc] = rcp_dot_targs[kc].ptr();
203 Thyra::applyOp<Scalar>( dot_op,
204 tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(mv), ptrInArg(*
this)),
207 for(
int kc = 0; kc < m; ++kc ) {
208 prods[kc] = dot_op(*dot_targs[kc]);
213 template<
class Scalar>
218 using Teuchos::tuple;
using Teuchos::ptrInArg;
using Teuchos::null;
219 const int m = this->domain()->dim();
220 RTOpPack::ROpNormInf<Scalar> norm_op;
223 for(
int kc = 0; kc < m; ++kc) {
224 rcp_op_targs[kc] = norm_op.reduct_obj_create();
225 op_targs[kc] = rcp_op_targs[kc].ptr();
227 Thyra::applyOp<Scalar>(norm_op,
228 tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(*
this)),
231 for(
int kc = 0; kc < m; ++kc) {
232 norms[kc] = norm_op(*op_targs[kc]);
237 template<
class Scalar>
247 const Range1D colRng = Teuchos::full_range(colRng_in,0,dimDomain-1);
248 if( colRng.
lbound() == 0 && as<Ordinal>(colRng.
ubound()) == dimDomain-1 )
250 if( colRng.
size() ) {
252 Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,colRng.
size());
261 return Teuchos::null;
265 template<
class Scalar>
275 const Range1D colRng = Teuchos::full_range(colRng_in,0,dimDomain-1);
276 if( colRng.
lbound() == 0 && as<Ordinal>(colRng.
ubound()) == dimDomain-1 )
278 if( colRng.
size() ) {
280 Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,colRng.
size());
282 col_vecs[j-colRng.
lbound()] = this->col(j);
289 return Teuchos::null;
293 template<
class Scalar>
302 const int numCols = cols.
size();
306 const char msg_err[] =
"MultiVectorDefaultBase<Scalar>::subView(numCols,cols[]): Error!";
310 Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,numCols);
311 for(
int k = 0; k < numCols; ++k ) {
312 const int col_k = cols[k];
315 !( 0 <= col_k && col_k < dimDomain ), std::invalid_argument
316 ,msg_err <<
" col["<<k<<
"] = " << col_k <<
" is not in the range [0,"<<(dimDomain-1)<<
"]!"
323 this->range(), l_range.
smallVecSpcFcty()->createVecSpc(numCols), col_vecs
329 template<
class Scalar>
338 const int numCols = cols.
size();
342 const char msg_err[] =
"MultiVectorDefaultBase<Scalar>::subView(numCols,cols[]): Error!";
346 Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,numCols);
347 for(
int k = 0; k < numCols; ++k ) {
348 const int col_k = cols[k];
351 !( 0 <= col_k && col_k < dimDomain ), std::invalid_argument
352 ,msg_err <<
" col["<<k<<
"] = " << col_k <<
" is not in the range [0,"<<(dimDomain-1)<<
"]!"
355 col_vecs[k] = this->col(col_k);
359 this->range(), l_range.
smallVecSpcFcty()->createVecSpc(numCols), col_vecs
365 template<
class Scalar>
371 const Ordinal prim_global_offset_in
379 const int num_multi_vecs = multi_vecs.size();
380 const int num_targ_multi_vecs = targ_multi_vecs.size();
395 Workspace<RCP<const VectorBase<Scalar> > > vecs_s(wss, num_multi_vecs);
396 Workspace<Ptr<const VectorBase<Scalar> > > vecs(wss, num_multi_vecs);
397 Workspace<RCP<VectorBase<Scalar> > > targ_vecs_s(wss, num_targ_multi_vecs);
398 Workspace<Ptr<VectorBase<Scalar> > > targ_vecs(wss, num_targ_multi_vecs);
400 for(
Ordinal j = 0; j < sec_dim; ++j) {
402 {
for(
Ordinal k = 0; k < as<Ordinal>(num_multi_vecs); ++k) {
403 vecs_s[k] = multi_vecs[k]->col(j);
404 vecs[k] = vecs_s[k].ptr();
406 {
for(
Ordinal k = 0; k < as<Ordinal>(num_targ_multi_vecs); ++k) {
407 targ_vecs_s[k] = targ_multi_vecs[k]->col(j);
408 targ_vecs[k] = targ_vecs_s[k].ptr();
416 prim_global_offset_in);
424 template<
class Scalar>
431 const Ordinal prim_global_offset_in
447 const int reduct_objs_size = (!
is_null(reduct_obj) ? sec_dim : 0);
448 Workspace<RCP<RTOpPack::ReductTarget> > rcp_reduct_objs(wss, reduct_objs_size);
449 Workspace<Ptr<RTOpPack::ReductTarget> > reduct_objs(wss, reduct_objs_size);
451 for(
Ordinal k = 0; k < sec_dim; ++k) {
453 reduct_objs[k] = rcp_reduct_objs[k].ptr();
459 prim_op, multi_vecs, targ_multi_vecs, reduct_objs,
460 prim_global_offset_in);
465 for (
Ordinal k = 0; k < sec_dim; ++k) {
472 template<
class Scalar>
480 rangeDim = this->range()->dim(),
481 domainDim = this->domain()->dim();
487 !(rowRng.
ubound() < rangeDim), std::out_of_range
488 ,
"MultiVectorDefaultBase<Scalar>::acquireDetachedMultiVectorViewImpl(...): Error, rowRng = ["
489 <<rowRng.
lbound()<<
","<<rowRng.
ubound()<<
"] is not in the range = [0,"
493 !(colRng.ubound() < domainDim), std::out_of_range
494 ,
"MultiVectorDefaultBase<Scalar>::acquireDetachedMultiVectorViewImpl(...): Error, colRng = ["
495 <<colRng.lbound()<<
","<<colRng.ubound()<<
"] is not in the range = [0,"
496 <<(domainDim-1)<<
"]!"
503 for(
int k = colRng.lbound(); k <= colRng.ubound(); ++k ) {
505 col_k->acquireDetachedView( rowRng, &sv );
506 for(
int i = 0; i < rowRng.
size(); ++i )
507 values[ i + k*rowRng.
size() ] = sv[i];
508 col_k->releaseDetachedView( &sv );
522 template<
class Scalar>
532 template<
class Scalar>
553 template<
class Scalar>
560 sub_mv==NULL, std::logic_error,
561 "MultiVectorDefaultBase<Scalar>::commitNonconstDetachedMultiVectorViewImpl(...): Error!"
569 col_k->acquireDetachedView( rowRng, &msv );
570 for(
int i = 0; i < rowRng.size(); ++i )
571 msv[i] = sub_mv->
values()[ i + k*rowRng.size() ];
572 col_k->commitDetachedView( &msv );
582 #endif // THYRA_MULTI_VECTOR_DEFAULT_BASE_DEF_HPP
virtual RCP< MultiVectorBase< Scalar > > clone_mv() const
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)
Ordinal colOffset() const
Ordinal numSubCols() const
bool is_null(const boost::shared_ptr< T > &p)
virtual void releaseDetachedMultiVectorViewImpl(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
virtual void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Default implementation of assign(MV) using RTOps.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
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.
const ArrayRCP< Scalar > values() const
Abstract interface for objects that represent a space for vectors.
virtual void assignImpl(Scalar alpha)
Default implementation of assign(scalar) using RTOps.
Ordinal globalOffset() const
RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols) const
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.
virtual void mvSingleReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const RTOpPack::RTOpT< Scalar > &secondary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal primary_global_offset) const
virtual RCP< const VectorSpaceFactoryBase< Scalar > > smallVecSpcFcty() const =0
Return a VectorSpaceFactoryBase object for the creation of (usually serial) vector spaces with a smal...
Abstract interface for finite-dimensional dense vectors.
Default subclass for MultiVectorBase implemented using columns of separate abstract vectors...
virtual void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Default implementation of norms_1 using RTOps.
void reduce_reduct_objs(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols)
Teuchos::RCP< ReductTarget > reduct_obj_create() const
virtual void scaleImpl(Scalar alpha)
Default implementation of scale using RTOps.
TypeTo as(const TypeFrom &t)
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
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Default implementation of norms_2 using RTOps.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Default implementation of norms_inf using RTOps.
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.