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_DECL_HPP
00030 #define THYRA_VECTOR_DECL_HPP
00031
00032 #include "Teuchos_Handle.hpp"
00033 #include "Thyra_ConfigDefs.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 #include "Thyra_VectorStdOps.hpp"
00036 #include "Thyra_VecOpMacros.hpp"
00037 #include "RTOpPack_Types.hpp"
00038 #include "Teuchos_VerboseObject.hpp"
00039 #include "Teuchos_as.hpp"
00040
00041
00042 namespace Thyra
00043 {
00044
00045 template <class Scalar> class VectorSpace;
00046
00047 template <class Scalar> class Vector;
00048
00049 template <class Scalar, class Node1, class Node2> class LC2;
00050 template <class Scalar, class Node> class OpTimesLC;
00051 template <class Scalar> class ConvertibleToVector;
00052
00058 enum LCSign {LCAdd = 1, LCSubtract = -1};
00059
00064 template<class Scalar>
00065 inline Scalar convertTo( const LCSign sign )
00066 {
00067 typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
00068 return Teuchos::as<ScalarMag>(sign);
00069 }
00070
00091 template <class Scalar, class TargetType> class Converter
00092 {
00093 public:
00095 virtual ~Converter(){;}
00096
00098 virtual TargetType convert() const = 0 ;
00099
00101 virtual void evalInto(Vector<Scalar>& acceptor) const = 0 ;
00102
00104 virtual bool containsVector(const Thyra::VectorBase<Scalar>* vec) const = 0 ;
00105
00109 virtual void addInto(Vector<Scalar>& other, Thyra::LCSign sign) const = 0 ;
00110 };
00111
00117 template <class Scalar>
00118 class ConstVector : public virtual Teuchos::ConstHandle<VectorBase<Scalar> >,
00119 public virtual Converter<Scalar, ConstVector<Scalar> >
00120 {
00121 public:
00122
00123 TEUCHOS_CONST_HANDLE_CTORS(ConstVector<Scalar>, VectorBase<Scalar>);
00124
00126 ConstVector(const Thyra::ConvertibleToVector<Scalar>& x);
00127
00129 ConstVector<Scalar> convert() const
00130 {
00131 return *this;
00132 }
00133
00137 bool containsVector(const Thyra::VectorBase<Scalar>* vec) const ;
00138
00140 void evalInto(Vector<Scalar>& other) const ;
00141
00143 void addInto(Vector<Scalar>& other, Thyra::LCSign sign) const ;
00145
00149 virtual Scalar operator[](Ordinal globalIndex) const ;
00151
00156 int numBlocks() const ;
00157
00161 ConstVector<Scalar> getBlock(Ordinal i) const ;
00163
00164 };
00165
00170 template <class Scalar>
00171 Ordinal dim(const ConstVector<Scalar>& x) ;
00172
00177 template <class Scalar> inline
00178 VectorSpace<Scalar> space(const ConstVector<Scalar>& x);
00179
00184 template <class Scalar>
00185 std::ostream& operator<<(std::ostream& os, const ConstVector<Scalar>& v);
00186
00187
00188
00189
00190
00191 template <class Scalar> inline
00192 ConstVector<Scalar> toVector(const Converter<Scalar, ConstVector<Scalar> >& x)
00193 {return x.convert();}
00194
00200 template <class Scalar>
00201 class Vector : public Teuchos::Handle<VectorBase<Scalar> >,
00202 public ConstVector<Scalar>
00203 {
00204 public:
00205
00206 TEUCHOS_HANDLE_CTORS(Vector<Scalar>, VectorBase<Scalar>);
00207
00209 Vector( const VectorSpace<Scalar> &space );
00210
00212 class IndexObject
00213 {
00214 public:
00215 IndexObject(const Teuchos::RCP<VectorBase<Scalar> >& v, Ordinal i)
00216 : v_(v), count_(new int), i_(i)
00217 {
00218 *count_ = 1;
00219 val_ = valGotten_ = get_ele(*v_,i_);
00220 }
00221 IndexObject(const IndexObject& other)
00222 : v_(other.v_), count_(other.count_),
00223 valGotten_(other.valGotten_), val_(other.val_), i_(other.i_)
00224 {
00225 *Teuchos::VerboseObjectBase::getDefaultOStream()
00226 << "IO copy ctor" << std::endl;
00227 (*count_)++;
00228 }
00230 ~IndexObject()
00231 {
00232 if (--(*count_)==0)
00233 {
00234 if( val_ != valGotten_ )
00235 set_ele( i_, val_, &*v_ );
00236 delete count_;
00237 }
00238 }
00240 operator Scalar () const {return val_;}
00242 IndexObject& operator=(const Scalar& value)
00243 {
00244 val_ = value;
00245 return *this;
00246 }
00247 private:
00248 Teuchos::RCP<VectorBase<Scalar> > v_;
00249 int* count_;
00250 Scalar valGotten_;
00251 Scalar val_;
00252 Ordinal i_;
00253
00254 IndexObject();
00255
00256 IndexObject& operator=(const IndexObject& other);
00257 };
00258
00260 template<class Node1, class Node2>
00261 Vector(const Thyra::LC2<Scalar, Node1, Node2>& x);
00262
00264 template<class Node>
00265 Vector(const Thyra::OpTimesLC<Scalar, Node>& x);
00266
00268 template<class Node1, class Node2>
00269 Vector& operator=(const Thyra::LC2<Scalar, Node1, Node2>& x);
00270
00272 template<class Node1, class Node2>
00273 Vector& operator+=(const Thyra::LC2<Scalar, Node1, Node2>& x);
00274
00276 template<class Node>
00277 Vector& operator=(const Thyra::OpTimesLC<Scalar, Node>& x);
00278
00280 template<class Node>
00281 Vector& operator+=(const Thyra::OpTimesLC<Scalar, Node>& x);
00282
00284 Vector<Scalar>& acceptCopyOf(const ConstVector<Scalar>& x);
00285
00287 Scalar operator[](Ordinal globalIndex) const
00288 {
00289 return ConstVector<Scalar>::operator[](globalIndex);
00290 }
00291
00297 IndexObject operator[](Ordinal globalIndex)
00298 {
00299 return IndexObject(this->ptr(), globalIndex);
00300 }
00301
00305 void setBlock(int i, const ConstVector<Scalar>& v);
00306
00308 void setBlock(int i, const Vector<Scalar>& v);
00309
00311 Vector<Scalar> getBlock(int i);
00313
00314 };
00315
00316
00317 THYRA_UNARY_VECTOR_OP_DECL(copy, copyInto, assign, "copy");
00318
00325 template <class Scalar> inline
00326 Thyra::Vector<Scalar> formVector(const Thyra::Vector<Scalar>& x) {return x;}
00327
00332 template <class Scalar> inline
00333 Thyra::Vector<Scalar> formVector(const Thyra::ConstVector<Scalar>& x)
00334 {return copy(x);}
00335
00336 }
00337
00338 #endif