PlayaDefaultBlockVectorImpl.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                 Playa: Programmable Linear Algebra
00005 //                 Copyright 2012 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef PLAYA_DEFAULT_BLOCK_VECTOR_IMPL_HPP
00043 #define PLAYA_DEFAULT_BLOCK_VECTOR_IMPL_HPP
00044 
00045 #include "PlayaDefaultBlockVectorDecl.hpp"
00046 #include "PlayaDefaultBlockVectorSpaceDecl.hpp"
00047 #include "PlayaExceptions.hpp"
00048 
00049 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00050 #include "PlayaVectorImpl.hpp"
00051 #include "PlayaBlockIteratorImpl.hpp"
00052 #include "PlayaVectorSpaceBaseImpl.hpp"
00053 #include "PlayaDefaultBlockVectorSpaceImpl.hpp"
00054 #include "PlayaBlockVectorBaseImpl.hpp"
00055 #endif
00056 
00057 
00058 
00059 
00060 
00061 namespace Playa
00062 {
00063 template <class Scalar> inline
00064 DefaultBlockVector<Scalar>
00065 ::DefaultBlockVector(const VectorSpace<Scalar>& space)
00066   : BlockVectorBase<Scalar>(), space_(space), blocks_(space.numBlocks())
00067 {
00068   for (int i=0; i<space.numBlocks(); i++)
00069   {
00070     blocks_[i] = space.getBlock(i).createMember();
00071   }
00072 }
00073 
00074 template <class Scalar> inline
00075 DefaultBlockVector<Scalar>
00076 ::DefaultBlockVector(const VectorSpace<Scalar>& space, 
00077     const Array<Vector<Scalar> >& blocks)
00078   : BlockVectorBase<Scalar>(), space_(space), blocks_(blocks)
00079 {}
00080 
00081 template <class Scalar> inline
00082 void DefaultBlockVector<Scalar>::setBlock(int b, const Vector<Scalar>& block)
00083 {
00084   PLAYA_BOUNDSCHECK(b, 0, space_.numBlocks(), 
00085     "DefaultBlockVector::setBlock()");
00086 
00087   TEUCHOS_TEST_FOR_EXCEPTION(
00088     block.space() != space_.getBlock(b),
00089     RuntimeError,
00090     "inconsistent block spaces in setBlock: \n" 
00091     "old=" << space_.getBlock(b) << std::endl
00092     << "new=" << block.space());
00093   
00094   blocks_[b] = block;
00095 }
00096 
00097 
00098 template <class Scalar> inline
00099 const Vector<Scalar>& DefaultBlockVector<Scalar>::getBlock(int b) const 
00100 {
00101   PLAYA_BOUNDSCHECK(b, 0, space_.numBlocks(), 
00102     "const DefaultBlockVector::setBlock()");
00103 
00104   return blocks_[b];
00105 }
00106 
00107 template <class Scalar> inline
00108 Vector<Scalar> DefaultBlockVector<Scalar>::getNonConstBlock(int b) 
00109 {
00110   PLAYA_BOUNDSCHECK(b, 0, space_.numBlocks(), 
00111     "non-const DefaultBlockVector::setBlock()");
00112 
00113   return blocks_[b];
00114 }
00115 
00116 
00117 
00118 /** \relates Vector */
00119 template <class Scalar> inline
00120 Vector<Scalar> blockVector(
00121   const Vector<Scalar>& v1)
00122 {
00123   Array<Vector<Scalar> > x(1);
00124   x[0] = v1;
00125   return blockVector<Scalar>(x);
00126 }
00127 
00128 
00129 /** \relates Vector */
00130 template <class Scalar> inline
00131 Vector<Scalar> blockVector(
00132   const Vector<Scalar>& v1,
00133   const Vector<Scalar>& v2)
00134 {
00135   Array<Vector<Scalar> > x(2);
00136   x[0] = v1;
00137   x[1] = v2;
00138   return blockVector<Scalar>(x);
00139 }
00140 
00141 /** \relates Vector */
00142 template <class Scalar> inline
00143 Vector<Scalar> blockVector(
00144   const Vector<Scalar>& v1,
00145   const Vector<Scalar>& v2,
00146   const Vector<Scalar>& v3)
00147 {
00148   Array<Vector<Scalar> > x(3);
00149   x[0] = v1;
00150   x[1] = v2;
00151   x[2] = v3;
00152   return blockVector<Scalar>(x);
00153 }
00154 
00155 /** \relates Vector */
00156 template <class Scalar> inline
00157 Vector<Scalar> blockVector(
00158   const Vector<Scalar>& v1,
00159   const Vector<Scalar>& v2,
00160   const Vector<Scalar>& v3,
00161   const Vector<Scalar>& v4)
00162 {
00163   Array<Vector<Scalar> > x(4);
00164   x[0] = v1;
00165   x[1] = v2;
00166   x[2] = v3;
00167   x[3] = v4;
00168   return blockVector<Scalar>(x);
00169 }
00170 
00171 /** \relates Vector */
00172 template <class Scalar> inline
00173 Vector<Scalar> blockVector(const Array<Vector<Scalar> >& x)
00174 {
00175   Array<VectorSpace<Scalar> > spaces(x.size());
00176   for (int i=0; i<x.size(); i++) spaces[i] = x[i].space();
00177 
00178   VectorSpace<Scalar> bs = blockSpace(spaces);
00179   RCP<VectorBase<Scalar> > rtn = rcp(new DefaultBlockVector<Scalar>(bs, x));
00180   return rtn;
00181 }
00182 
00183 
00184   
00185 
00186 }
00187 
00188 #endif

Site Contact