Thyra_VectorSpaceDefaultBase.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_VECTOR_SPACE_DEFAULT_BASE_HPP
00030 #define THYRA_VECTOR_SPACE_DEFAULT_BASE_HPP
00031 
00032 #include "Thyra_VectorSpaceDefaultBaseDecl.hpp"
00033 #include "Thyra_VectorSpaceBase.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 #include "Thyra_MultiVectorStdOps.hpp"
00036 #include "Thyra_DefaultColumnwiseMultiVector.hpp"
00037 
00038 namespace Thyra {
00039 
00040 // Helper classes
00041 
00042 template<class Scalar>
00043 class CopyVectorViewBack {
00044 public:
00045   CopyVectorViewBack( const VectorBase<Scalar> *v, const RTOpPack::SubVectorView<Scalar>  &raw_v )
00046     :v_(v), raw_v_(raw_v)
00047     {}
00048   ~CopyVectorViewBack()
00049     {
00050       RTOpPack::ConstSubVectorView<Scalar> sv;
00051       v_->acquireDetachedView(Range1D(),&sv);
00052       RTOpPack::assign_entries( &raw_v_, sv );
00053       v_->releaseDetachedView(&sv);
00054     }
00055 private:
00056   const VectorBase<Scalar>                   *v_;
00057   const RTOpPack::SubVectorView<Scalar>  raw_v_;
00058 };
00059 
00060 template<class Scalar>
00061 class CopyMultiVectorViewBack {
00062 public:
00063   CopyMultiVectorViewBack( const MultiVectorBase<Scalar> *mv, const RTOpPack::SubMultiVectorView<Scalar>  &raw_mv )
00064     :mv_(mv), raw_mv_(raw_mv)
00065     {}
00066   ~CopyMultiVectorViewBack()
00067     {
00068       RTOpPack::ConstSubMultiVectorView<Scalar> smv;
00069       mv_->acquireDetachedView(Range1D(),Range1D(),&smv);
00070       RTOpPack::assign_entries( &raw_mv_, smv );
00071       mv_->releaseDetachedView(&smv);
00072     }
00073 private:
00074   const MultiVectorBase<Scalar>                       *mv_;
00075   const RTOpPack::SubMultiVectorView<Scalar>  raw_mv_;
00076 };
00077 
00078 // Overridden protected functions from VectorSpaceBase
00079 
00080 template<class Scalar>
00081 Teuchos::RCP<MultiVectorBase<Scalar> > 
00082 VectorSpaceDefaultBase<Scalar>::createMembers(int numMembers) const
00083 {
00084   return Teuchos::rcp(new DefaultColumnwiseMultiVector<Scalar> (Teuchos::rcp(this,false),this->smallVecSpcFcty()->createVecSpc(numMembers)));
00085 }
00086 
00087 template<class Scalar>
00088 Teuchos::RCP<VectorBase<Scalar> >
00089 VectorSpaceDefaultBase<Scalar>::createMemberView( const RTOpPack::SubVectorView<Scalar> &raw_v ) const
00090 {
00091 #ifdef TEUCHOS_DEBUG
00092   TEST_FOR_EXCEPT( raw_v.subDim() != this->dim() );
00093 #endif
00094   // Create a vector
00095   Teuchos::RCP<VectorBase<Scalar> > v = this->createMember();
00096   // Copy initial values in raw_v into vector
00097   RTOpPack::SubVectorView<Scalar> sv;
00098   v->acquireDetachedView(Range1D(),&sv);
00099   RTOpPack::assign_entries( &sv, raw_v );
00100   v->commitDetachedView(&sv);
00101   // Setup smart pointer to vector to copy view back out just before vector is destroyed
00102   Teuchos::set_extra_data(
00103     Teuchos::rcp(new CopyVectorViewBack<Scalar>(&*v,raw_v))
00104     ,"CopyVectorViewBack"
00105     ,&v
00106     ,Teuchos::PRE_DESTROY
00107     );
00108   return v;
00109 }
00110 
00111 template<class Scalar>
00112 Teuchos::RCP<const VectorBase<Scalar> >
00113 VectorSpaceDefaultBase<Scalar>::createMemberView( const RTOpPack::ConstSubVectorView<Scalar> &raw_v ) const
00114 {
00115 #ifdef TEUCHOS_DEBUG
00116   TEST_FOR_EXCEPT( raw_v.subDim() != this->dim() );
00117 #endif
00118   // Create a vector
00119   Teuchos::RCP<VectorBase<Scalar> > v = this->createMember();
00120   // Copy initial values in raw_v into vector
00121   RTOpPack::SubVectorView<Scalar> sv;
00122   v->acquireDetachedView(Range1D(),&sv);
00123   RTOpPack::assign_entries( &sv, raw_v );
00124   v->commitDetachedView(&sv);
00125   return v;
00126 }
00127 
00128 template<class Scalar>
00129 Teuchos::RCP<MultiVectorBase<Scalar> >
00130 VectorSpaceDefaultBase<Scalar>::createMembersView( const RTOpPack::SubMultiVectorView<Scalar> &raw_mv ) const
00131 {
00132 #ifdef TEUCHOS_DEBUG
00133   TEST_FOR_EXCEPT( raw_mv.subDim() != this->dim() );
00134 #endif
00135   // Create a multi-vector
00136   Teuchos::RCP< MultiVectorBase<Scalar> > mv = this->createMembers(raw_mv.numSubCols());
00137   // Copy initial values in raw_mv into multi-vector
00138   RTOpPack::SubMultiVectorView<Scalar> smv;
00139   mv->acquireDetachedView(Range1D(),Range1D(),&smv);
00140   RTOpPack::assign_entries( &smv, raw_mv );
00141   mv->commitDetachedView(&smv);
00142   // Setup smart pointer to multi-vector to copy view back out just before multi-vector is destroyed
00143   Teuchos::set_extra_data(
00144     Teuchos::rcp(new CopyMultiVectorViewBack<Scalar>(&*mv,raw_mv))
00145     ,"CopyMultiVectorViewBack"
00146     ,&mv
00147     ,Teuchos::PRE_DESTROY
00148     );
00149   return mv;
00150 }
00151 
00152 template<class Scalar>
00153 Teuchos::RCP<const MultiVectorBase<Scalar> >
00154 VectorSpaceDefaultBase<Scalar>::createMembersView( const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv ) const
00155 {
00156 #ifdef TEUCHOS_DEBUG
00157   TEST_FOR_EXCEPT( raw_mv.subDim() != this->dim() );
00158 #endif
00159   // Create a multi-vector
00160   Teuchos::RCP< MultiVectorBase<Scalar> > mv = this->createMembers(raw_mv.numSubCols());
00161   // Copy values in raw_mv into multi-vector
00162   RTOpPack::SubMultiVectorView<Scalar> smv;
00163   mv->acquireDetachedView(Range1D(),Range1D(),&smv);
00164   RTOpPack::assign_entries( &smv, raw_mv );
00165   mv->commitDetachedView(&smv);
00166   return mv;
00167 }
00168 
00169 } // end namespace Thyra
00170 
00171 #endif // THYRA_VECTOR_SPACE_DEFAULT_BASE_HPP

Generated on Tue Oct 20 12:47:27 2009 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.4.7