00001
00002
00003
00004
00005 #ifndef PLAYA_BLOCK_VECTOR_BASE_IMPL_HPP
00006 #define PLAYA_BLOCK_VECTOR_BASE_IMPL_HPP
00007
00008 #include "PlayaDefs.hpp"
00009 #include "PlayaTabs.hpp"
00010 #include "PlayaBlockVectorBaseDecl.hpp"
00011 #include "PlayaVectorDecl.hpp"
00012
00013 namespace Playa
00014 {
00015
00016 template <class Scalar> inline
00017 bool BlockVectorBase<Scalar>::hasMoreChunks() const
00018 {
00019 if (currentBlock_ < this->numBlocks()-1)
00020 {
00021 return true;
00022 }
00023 if (currentBlock_ == this->numBlocks()-1)
00024 {
00025 return this->getBlock(currentBlock_).hasMoreChunks();
00026 }
00027 return false;
00028 }
00029
00030 template <class Scalar> inline
00031 ConstDataChunk<Scalar> BlockVectorBase<Scalar>::nextConstChunk() const
00032 {
00033 if (!this->getBlock(currentBlock_).hasMoreChunks())
00034 {
00035 currentBlock_++;
00036 }
00037 return this->getBlock(currentBlock_).nextConstChunk();
00038 }
00039
00040
00041 template <class Scalar> inline
00042 NonConstDataChunk<Scalar> BlockVectorBase<Scalar>::nextChunk()
00043 {
00044 if (!this->getBlock(currentBlock_).hasMoreChunks())
00045 {
00046 currentBlock_++;
00047 }
00048 return this->getNonConstBlock(currentBlock_).nextChunk();
00049 }
00050
00051 template <class Scalar> inline
00052 void BlockVectorBase<Scalar>::rewind() const
00053 {
00054 Tabs tab;
00055 currentBlock_ = 0;
00056 for (int b=0; b<this->numBlocks(); b++)
00057 {
00058 this->getBlock(b).rewind();
00059 }
00060 }
00061
00062 template <class Scalar> inline
00063 void BlockVectorBase<Scalar>::update(const Scalar& alpha,
00064 const VectorBase<Scalar>* other,
00065 const Scalar& gamma)
00066 {
00067 const BlockVectorBase<Scalar>* bvo
00068 = dynamic_cast<const BlockVectorBase<Scalar>* >(other);
00069 for (int b=0; b<this->numBlocks(); b++)
00070 {
00071 this->getNonConstBlock(b).update(alpha, bvo->getBlock(b), gamma);
00072 }
00073 }
00074
00075 template <class Scalar> inline
00076 void BlockVectorBase<Scalar>::update(
00077 const Scalar& alpha, const VectorBase<Scalar>* x,
00078 const Scalar& beta, const VectorBase<Scalar>* y,
00079 const Scalar& gamma)
00080 {
00081 const BlockVectorBase<Scalar>* bx
00082 = dynamic_cast<const BlockVectorBase<Scalar>* >(x);
00083 const BlockVectorBase<Scalar>* by
00084 = dynamic_cast<const BlockVectorBase<Scalar>* >(y);
00085
00086 for (int b=0; b<this->numBlocks(); b++)
00087 {
00088 this->getNonConstBlock(b).ptr()->update(
00089 alpha, bx->getBlock(b).ptr().get(),
00090 beta, by->getBlock(b).ptr().get(),
00091 gamma);
00092 }
00093 }
00094
00095
00096 template <class Scalar> inline
00097 void BlockVectorBase<Scalar>::update(
00098 const Scalar& alpha, const VectorBase<Scalar>* x,
00099 const Scalar& beta, const VectorBase<Scalar>* y,
00100 const Scalar& gamma, const VectorBase<Scalar>* z,
00101 const Scalar& delta)
00102 {
00103 const BlockVectorBase<Scalar>* bx
00104 = dynamic_cast<const BlockVectorBase<Scalar>* >(x);
00105 const BlockVectorBase<Scalar>* by
00106 = dynamic_cast<const BlockVectorBase<Scalar>* >(y);
00107 const BlockVectorBase<Scalar>* bz
00108 = dynamic_cast<const BlockVectorBase<Scalar>* >(z);
00109
00110 for (int b=0; b<this->numBlocks(); b++)
00111 {
00112 this->getNonConstBlock(b).ptr()->update(
00113 alpha, bx->getBlock(b).ptr().get(),
00114 beta, by->getBlock(b).ptr().get(),
00115 gamma, bz->getBlock(b).ptr().get(),
00116 delta);
00117 }
00118 }
00119
00120 template <class Scalar> inline
00121 Scalar BlockVectorBase<Scalar>::dot(
00122 const VectorBase<Scalar>* other) const
00123 {
00124 const BlockVectorBase<Scalar>* bx
00125 = dynamic_cast<const BlockVectorBase<Scalar>* >(other);
00126
00127 Scalar rtn = 0.0;
00128
00129 for (int b=0; b<this->numBlocks(); b++)
00130 {
00131 rtn += this->getBlock(b).ptr()->dot(bx->getBlock(b).ptr().get());
00132 }
00133 return rtn;
00134 }
00135
00136 template <class Scalar> inline
00137 Scalar BlockVectorBase<Scalar>::norm2() const
00138 {
00139 Scalar rtn = 0.0;
00140
00141 for (int b=0; b<this->numBlocks(); b++)
00142 {
00143 Scalar tmp = 0.0;
00144 tmp = this->getBlock(b).ptr()->norm2();
00145 rtn += tmp*tmp;
00146 }
00147 return sqrt(rtn);
00148 }
00149
00150
00151 template <class Scalar> inline
00152 std::string BlockVectorBase<Scalar>::description() const
00153 {
00154 std::ostringstream oss;
00155 oss << "BlockVector[";
00156 for (int i=0; i<this->numBlocks(); i++)
00157 {
00158 if (i > 0) oss << ", ";
00159 oss << this->getBlock(i).description();
00160 }
00161 oss << "]";
00162 return oss.str();
00163 }
00164
00165
00166 }
00167
00168 #endif