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