00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef THYRA_VECTOR_BASE_DECL_HPP
00030 #define THYRA_VECTOR_BASE_DECL_HPP
00031
00032
00033 #include "Thyra_OperatorVectorTypes.hpp"
00034 #include "Thyra_MultiVectorBaseDecl.hpp"
00035 #include "RTOpPack_RTOpT.hpp"
00036 #include "RTOpPack_SparseSubVectorT.hpp"
00037
00038
00039 namespace Thyra {
00040
00041
00132 template<class Scalar>
00133 class VectorBase : virtual public MultiVectorBase<Scalar>
00134 {
00135 public:
00136
00137 #ifdef THYRA_INJECT_USING_DECLARATIONS
00138 using MultiVectorBase<Scalar>::apply;
00139 #endif
00140
00143
00160 virtual RCP< const VectorSpaceBase<Scalar> > space() const = 0;
00161
00163
00166
00171 void applyOp(
00172 const RTOpPack::RTOpT<Scalar> &op,
00173 const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00174 const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00175 const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00176 const Index first_ele_offset,
00177 const Index sub_dim,
00178 const Index global_offset
00179 ) const
00180 { applyOpImpl(op,vecs,targ_vecs,reduct_obj,
00181 first_ele_offset,sub_dim,global_offset); }
00182
00184
00187
00202 virtual RCP<VectorBase<Scalar> > clone_v() const = 0;
00203
00205
00208
00213 void acquireDetachedView(
00214 const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00215 ) const
00216 { acquireDetachedVectorViewImpl(rng,sub_vec); }
00217
00222 void releaseDetachedView(
00223 RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00224 ) const
00225 { releaseDetachedVectorViewImpl(sub_vec); }
00226
00231 void acquireDetachedView(
00232 const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00233 )
00234 { acquireNonconstDetachedVectorViewImpl(rng,sub_vec); }
00235
00240 void commitDetachedView(
00241 RTOpPack::SubVectorView<Scalar>* sub_vec
00242 )
00243 { commitNonconstDetachedVectorViewImpl(sub_vec); }
00244
00249 void setSubVector(
00250 const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00251 )
00252 { setSubVectorImpl(sub_vec); }
00253
00255
00256 protected:
00257
00260
00277 virtual void applyOpImpl(
00278 const RTOpPack::RTOpT<Scalar> &op,
00279 const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00280 const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00281 const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00282 const Index first_ele_offset,
00283 const Index sub_dim,
00284 const Index global_offset
00285 ) const = 0;
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00344 virtual void acquireDetachedVectorViewImpl(
00345 const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00346 ) const = 0;
00347
00367 virtual void releaseDetachedVectorViewImpl(
00368 RTOpPack::ConstSubVectorView<Scalar>* sub_vec
00369 ) const = 0;
00370
00419 virtual void acquireNonconstDetachedVectorViewImpl(
00420 const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec
00421 ) = 0;
00422
00445 virtual void commitNonconstDetachedVectorViewImpl(
00446 RTOpPack::SubVectorView<Scalar>* sub_vec
00447 ) = 0;
00448
00472 virtual void setSubVectorImpl(
00473 const RTOpPack::SparseSubVectorT<Scalar>& sub_vec
00474 ) = 0;
00475
00477
00478 public:
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498 };
00499
00500
00585 template<class Scalar>
00586 inline
00587 void applyOp(
00588 const RTOpPack::RTOpT<Scalar> &op,
00589 const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00590 const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00591 const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00592 const Index first_ele_offset = 0,
00593 const Index sub_dim = -1,
00594 const Index global_offset = 0
00595 )
00596 {
00597 if (vecs.size())
00598 vecs[0]->applyOp(
00599 op, vecs, targ_vecs, reduct_obj, first_ele_offset, sub_dim, global_offset);
00600 else if (targ_vecs.size())
00601 targ_vecs[0]->applyOp(
00602 op, vecs, targ_vecs, reduct_obj, first_ele_offset, sub_dim, global_offset);
00603 }
00604
00605
00610 template<class Scalar>
00611 inline
00612 void applyOp(
00613 const RTOpPack::RTOpT<Scalar> &op,
00614 const int num_vecs,
00615 const VectorBase<Scalar>*const vecs_in[],
00616 const int num_targ_vecs,
00617 VectorBase<Scalar>*const targ_vecs_inout[],
00618 RTOpPack::ReductTarget *reduct_obj,
00619 const Index first_ele_offset = 0,
00620 const Index sub_dim = -1,
00621 const Index global_offset = 0
00622 )
00623 {
00624 using Teuchos::ptr;
00625 Array<Ptr<const VectorBase<Scalar> > > vecs(num_vecs);
00626 for ( int k = 0; k < num_vecs; ++k )
00627 vecs[k] = ptr(vecs_in[k]);
00628 Array<Ptr<VectorBase<Scalar> > > targ_vecs(num_targ_vecs);
00629 for ( int k = 0; k < num_targ_vecs; ++k )
00630 targ_vecs[k] = ptr(targ_vecs_inout[k]);
00631 applyOp<Scalar>(op, vecs(), targ_vecs(), ptr(reduct_obj),
00632 first_ele_offset, sub_dim, global_offset );
00633 }
00634
00635
00636 }
00637
00638
00639 #endif // THYRA_VECTOR_BASE_DECL_HPP