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_IMPL_HPP
00030 #define THYRA_VECTOR_IMPL_HPP
00031
00032 #include "Thyra_VectorDecl.hpp"
00033 #include "Thyra_VectorSpaceImpl.hpp"
00034 #include "Thyra_VectorStdOps.hpp"
00035 #include "Thyra_LinearCombinationImpl.hpp"
00036 #include "Thyra_ProductVectorBase.hpp"
00037 #include "Thyra_DetachedVectorView.hpp"
00038
00039 namespace Thyra
00040 {
00041
00042
00043
00044
00045
00046 template <class Scalar> inline
00047 Scalar ConstVector<Scalar>::operator[](Index globalIndex) const
00048 {
00049 ConstDetachedVectorView<Scalar> view(this->constPtr(), Range1D(0, dim(*this)-1));
00050 return view[globalIndex];
00051 }
00052
00053 template <class Scalar> inline
00054 bool ConstVector<Scalar>::containsVector(const Thyra::VectorBase<Scalar>* vec) const
00055 {
00056 return this->constPtr().get()==vec;
00057 }
00058
00059 template <class Scalar> inline
00060 void ConstVector<Scalar>::evalInto(Vector<Scalar>& acceptor) const
00061 {
00062 acceptor.acceptCopyOf(*this);
00063 }
00064
00065 template <class Scalar> inline
00066 void ConstVector<Scalar>::addInto(Vector<Scalar>& acceptor, LCSign sign) const
00067 {
00068 Scalar s = sign;
00069 Thyra::axpy(s, *this, acceptor);
00070 }
00071
00072 template <class Scalar> inline
00073 std::ostream& operator<<(std::ostream& os, const ConstVector<Scalar>& v)
00074 {
00075 os << v.description() ;
00076 return os;
00077 }
00078
00079
00080
00081
00082
00083 template <class Scalar> inline
00084 Vector<Scalar>::Vector( const VectorSpace<Scalar> &space )
00085 {
00086 *this = createMember(space);
00087 }
00088
00089 template <class Scalar> inline
00090 Vector<Scalar>& Vector<Scalar>::acceptCopyOf(const ConstVector<Scalar>& other)
00091 {
00092 Thyra::VectorBase<Scalar>* p = this->ptr().get();
00093 const Thyra::VectorBase<Scalar>* px = other.constPtr().get();
00094
00095 if (p==0)
00096 {
00097 Vector<Scalar> me = space(other).createMember();
00098 this->ptr() = me.ptr();
00099 }
00100 Thyra::assign(p, *px);
00101 return *this;
00102 }
00103
00104 template <class Scalar> inline
00105 Index dim(const ConstVector<Scalar>& x)
00106 {
00107 return x.constPtr()->space()->dim();
00108 }
00109
00110 template <class Scalar> inline
00111 VectorSpace<Scalar> space(const ConstVector<Scalar>& x)
00112 {
00113 return x.constPtr()->space();
00114 }
00115
00117 THYRA_UNARY_VECTOR_OP(copy, copyInto, assign, "copy")
00118
00119
00120 template <class Scalar> inline
00121 int ConstVector<Scalar>::numBlocks() const
00122 {
00123 const Thyra::ProductVectorSpaceBase<Scalar>* pvs =
00124 dynamic_cast <const Thyra::ProductVectorSpaceBase<Scalar>* >(space(*this).constPtr().get());
00125 if (pvs==0)
00126 {
00127 return 1;
00128 }
00129
00130 return pvs->numBlocks();
00131 }
00132
00133
00134 template <class Scalar> inline
00135 ConstVector<Scalar> ConstVector<Scalar>::getBlock(int i) const
00136 {
00137 const Thyra::ProductVectorBase<Scalar>* pv =
00138 dynamic_cast <const Thyra::ProductVectorBase<Scalar>* >(this->constPtr().get());
00139 if (pv==0)
00140 {
00141 TEST_FOR_EXCEPTION(i != 0, std::runtime_error,
00142 "Nonzero block index " << i << " into a std::vector that is not "
00143 "a product std::vector");
00144 return *this;
00145 }
00146 Teuchos::RCP<const Thyra::VectorBase<Scalar> > b = pv->getVectorBlock(i);
00147 return b;
00148 }
00149
00150
00151 template <class Scalar> inline
00152 Vector<Scalar> Vector<Scalar>::getBlock(int i)
00153 {
00154 Thyra::ProductVectorBase<Scalar>* pv =
00155 dynamic_cast <Thyra::ProductVectorBase<Scalar>* >(this->ptr().get());
00156 if (pv==0)
00157 {
00158 TEST_FOR_EXCEPTION(i != 0, std::runtime_error,
00159 "Nonzero block index " << i << " into a std::vector that is not "
00160 "a product std::vector");
00161 return *this;
00162 }
00163 Teuchos::RCP<Thyra::VectorBase<Scalar> > b = pv->getNonconstVectorBlock(i);
00164 return b;
00165 }
00166
00167
00168 template <class Scalar> inline
00169 void Vector<Scalar>::setBlock(int i, const ConstVector<Scalar>& b)
00170 {
00171 Thyra::DefaultProductVector<Scalar>* pv =
00172 dynamic_cast <Thyra::DefaultProductVector<Scalar>* >(this->ptr().get());
00173 TEST_FOR_EXCEPTION(pv == 0, std::runtime_error,
00174 "setBlock() called on a std::vector that is not a default product std::vector");
00175 pv->setBlock(i, b.constPtr());
00176
00177 }
00178
00179
00180 template <class Scalar> inline
00181 void Vector<Scalar>::setBlock(int i, const Vector<Scalar>& b)
00182 {
00183 Thyra::DefaultProductVector<Scalar>* pv =
00184 dynamic_cast <Thyra::DefaultProductVector<Scalar>* >(this->ptr().get());
00185 TEST_FOR_EXCEPTION(pv == 0, std::runtime_error,
00186 "setBlock() called on a std::vector that is not a default product std::vector");
00187 pv->setNonconstBlock(i, b.ptr());
00188
00189 }
00190
00191 }
00192
00193 #endif // THYRA_VECTOR_IMPL_HPP