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
00040
00041 namespace Thyra
00042 {
00043
00044 template <class Scalar> class VectorSpace;
00045
00046 template <class Scalar> class Vector;
00047
00048 template <class Scalar, class Node1, class Node2> class LC2;
00049 template <class Scalar, class Node> class OpTimesLC;
00050 template <class Scalar> class ConvertibleToVector;
00051
00057 enum LCSign {LCAdd = 1, LCSubtract = -1};
00058
00079 template <class Scalar, class TargetType> class Converter
00080 {
00081 public:
00083 virtual ~Converter(){;}
00084
00086 virtual TargetType convert() const = 0 ;
00087
00089 virtual void evalInto(Vector<Scalar>& acceptor) const = 0 ;
00090
00092 virtual bool containsVector(const Thyra::VectorBase<Scalar>* vec) const = 0 ;
00093
00097 virtual void addInto(Vector<Scalar>& other, Thyra::LCSign sign) const = 0 ;
00098 };
00099
00105 template <class Scalar>
00106 class ConstVector : public virtual Teuchos::ConstHandle<VectorBase<Scalar> >,
00107 public virtual Converter<Scalar, ConstVector<Scalar> >
00108 {
00109 public:
00110
00111 TEUCHOS_CONST_HANDLE_CTORS(ConstVector<Scalar>, VectorBase<Scalar>);
00112
00114 ConstVector(const Thyra::ConvertibleToVector<Scalar>& x);
00115
00117 ConstVector<Scalar> convert() const
00118 {
00119 return *this;
00120 }
00121
00125 bool containsVector(const Thyra::VectorBase<Scalar>* vec) const ;
00126
00128 void evalInto(Vector<Scalar>& other) const ;
00129
00131 void addInto(Vector<Scalar>& other, Thyra::LCSign sign) const ;
00133
00137 virtual Scalar operator[](Index globalIndex) const ;
00139
00144 int numBlocks() const ;
00145
00149 ConstVector<Scalar> getBlock(Index i) const ;
00151
00152 };
00153
00158 template <class Scalar>
00159 Index dim(const ConstVector<Scalar>& x) ;
00160
00165 template <class Scalar> inline
00166 VectorSpace<Scalar> space(const ConstVector<Scalar>& x);
00167
00172 template <class Scalar>
00173 std::ostream& operator<<(std::ostream& os, const ConstVector<Scalar>& v);
00174
00175
00176
00177
00178
00179 template <class Scalar> inline
00180 ConstVector<Scalar> toVector(const Converter<Scalar, ConstVector<Scalar> >& x)
00181 {return x.convert();}
00182
00188 template <class Scalar>
00189 class Vector : public Teuchos::Handle<VectorBase<Scalar> >,
00190 public ConstVector<Scalar>
00191 {
00192 public:
00193
00194 TEUCHOS_HANDLE_CTORS(Vector<Scalar>, VectorBase<Scalar>);
00195
00197 Vector( const VectorSpace<Scalar> &space );
00198
00200 class IndexObject
00201 {
00202 public:
00203 IndexObject(const Teuchos::RCP<VectorBase<Scalar> >& v, Index i)
00204 : v_(v), count_(new int), i_(i)
00205 {
00206 *count_ = 1;
00207 val_ = valGotten_ = get_ele(*v_,i_);
00208 }
00209 IndexObject(const IndexObject& other)
00210 : v_(other.v_), count_(other.count_),
00211 valGotten_(other.valGotten_), val_(other.val_), i_(other.i_)
00212 {
00213 *Teuchos::VerboseObjectBase::getDefaultOStream()
00214 << "IO copy ctor" << std::endl;
00215 (*count_)++;
00216 }
00218 ~IndexObject()
00219 {
00220 if (--(*count_)==0)
00221 {
00222 if( val_ != valGotten_ )
00223 set_ele( i_, val_, &*v_ );
00224 delete count_;
00225 }
00226 }
00228 operator Scalar () const {return val_;}
00230 IndexObject& operator=(const Scalar& value)
00231 {
00232 val_ = value;
00233 return *this;
00234 }
00235 private:
00236 Teuchos::RCP<VectorBase<Scalar> > v_;
00237 int* count_;
00238 Scalar valGotten_;
00239 Scalar val_;
00240 Index i_;
00241
00242 IndexObject();
00243
00244 IndexObject& operator=(const IndexObject& other);
00245 };
00246
00248 template<class Node1, class Node2>
00249 Vector(const Thyra::LC2<Scalar, Node1, Node2>& x);
00250
00252 template<class Node>
00253 Vector(const Thyra::OpTimesLC<Scalar, Node>& x);
00254
00256 template<class Node1, class Node2>
00257 Vector& operator=(const Thyra::LC2<Scalar, Node1, Node2>& x);
00258
00260 template<class Node1, class Node2>
00261 Vector& operator+=(const Thyra::LC2<Scalar, Node1, Node2>& x);
00262
00264 template<class Node>
00265 Vector& operator=(const Thyra::OpTimesLC<Scalar, Node>& x);
00266
00268 template<class Node>
00269 Vector& operator+=(const Thyra::OpTimesLC<Scalar, Node>& x);
00270
00272 Vector<Scalar>& acceptCopyOf(const ConstVector<Scalar>& x);
00273
00275 Scalar operator[](Index globalIndex) const
00276 {
00277 return ConstVector<Scalar>::operator[](globalIndex);
00278 }
00279
00285 IndexObject operator[](Index globalIndex)
00286 {
00287 return IndexObject(this->ptr(), globalIndex);
00288 }
00289
00293 void setBlock(int i, const ConstVector<Scalar>& v);
00294
00296 void setBlock(int i, const Vector<Scalar>& v);
00297
00299 Vector<Scalar> getBlock(int i);
00301
00302 };
00303
00304
00305 THYRA_UNARY_VECTOR_OP_DECL(copy, copyInto, assign, "copy");
00306
00313 template <class Scalar> inline
00314 Thyra::Vector<Scalar> formVector(const Thyra::Vector<Scalar>& x) {return x;}
00315
00320 template <class Scalar> inline
00321 Thyra::Vector<Scalar> formVector(const Thyra::ConstVector<Scalar>& x)
00322 {return copy(x);}
00323
00324 }
00325
00326 #endif