Thyra_DefaultSpmdVectorSpace.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_SPMD_VECTOR_SPACE_STD_HPP
00030 #define THYRA_SPMD_VECTOR_SPACE_STD_HPP
00031 
00032 #include "Thyra_DefaultSpmdVectorSpaceDecl.hpp"
00033 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
00034 #include "Thyra_DefaultSpmdMultiVector.hpp"
00035 #include "Thyra_DefaultSpmdVector.hpp"
00036 
00037 namespace Thyra {
00038 
00039 template<class Scalar>
00040 DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace()
00041   :localSubDim_(0),numProc_(0),procRank_(0)
00042 {
00043   this->updateState();
00044 }
00045 
00046 template<class Scalar>
00047 DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace(
00048   const Index dim
00049   )
00050   :localSubDim_(0),numProc_(0),procRank_(0)
00051 {
00052   initialize(dim);
00053 }
00054 
00055 template<class Scalar>
00056 DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace(
00057   const Teuchos::RefCountPtr<const Teuchos::Comm<Index> > &comm
00058   ,const Index localSubDim, const Index globalDim
00059   )
00060   :localSubDim_(0),numProc_(0),procRank_(0)
00061 {
00062   initialize(comm,localSubDim,globalDim);
00063 }
00064 
00065 template<class Scalar>
00066 void DefaultSpmdVectorSpace<Scalar>::initialize(
00067   const Index dim
00068   )
00069 {
00070   this->initialize(Teuchos::null,dim,dim);
00071 }
00072 
00073 template<class Scalar>
00074 void DefaultSpmdVectorSpace<Scalar>::initialize(
00075   const Teuchos::RefCountPtr<const Teuchos::Comm<Index> > &comm
00076   ,const Index localSubDim, const Index globalDim
00077   )
00078 {
00079 #ifdef TEUCHOS_DEBUG
00080   //TEST_FOR_EXCEPT( !( localSubDim > 0 ) );
00081   TEST_FOR_EXCEPT( !( localSubDim >= 0 ) );
00082 #endif
00083   comm_        = comm;
00084   localSubDim_ = localSubDim;
00085   if( comm.get() ) {
00086     numProc_  = size(*comm);
00087     procRank_ = rank(*comm);
00088   }
00089   else {
00090     numProc_  = 1;
00091     procRank_ = 0;
00092   }
00093   this->updateState(globalDim);
00094 }
00095 
00096 template<class Scalar>
00097 void DefaultSpmdVectorSpace<Scalar>::uninitialize()
00098 {
00099   comm_         = Teuchos::null;
00100   localSubDim_  = 0;
00101 }
00102 
00103 // Overridden from Teuchos::Describable
00104 
00105 template<class Scalar>
00106 std::string DefaultSpmdVectorSpace<Scalar>::description() const
00107 {
00108   return (std::string("DefaultSpmdVectorSpace<")
00109           + Teuchos::ScalarTraits<Scalar>::name() + std::string(">"));
00110 }
00111 
00112 // Overridden from VectorSpace
00113 
00114 template<class Scalar>
00115 Teuchos::RefCountPtr<VectorBase<Scalar> >
00116 DefaultSpmdVectorSpace<Scalar>::createMember() const
00117 {
00118   return Teuchos::rcp(
00119     new DefaultSpmdVector<Scalar>(
00120       Teuchos::rcp(this,false)
00121       ,Teuchos::rcp(
00122         localSubDim_ ? new Scalar[localSubDim_] : 0
00123         ,Teuchos::DeallocArrayDelete<Scalar>()
00124         ,true
00125         )
00126       ,1
00127       )
00128     );
00129 }
00130 
00131 template<class Scalar>
00132 Teuchos::RefCountPtr< MultiVectorBase<Scalar> >
00133 DefaultSpmdVectorSpace<Scalar>::createMembers(int numMembers) const
00134 {
00135   return Teuchos::rcp(
00136     new DefaultSpmdMultiVector<Scalar>(
00137       Teuchos::rcp(this,false)
00138       ,Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
00139         this->smallVecSpcFcty()->createVecSpc(numMembers),true
00140         )
00141       )
00142     );
00143 }
00144 
00145 template<class Scalar>
00146 Teuchos::RefCountPtr<VectorBase<Scalar> >
00147 DefaultSpmdVectorSpace<Scalar>::createMemberView(
00148   const RTOpPack::SubVectorView<Scalar> &raw_v
00149   ) const
00150 {
00151 #ifdef TEUCHOS_DEBUG
00152   TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
00153 #endif
00154   return Teuchos::rcp(
00155     new DefaultSpmdVector<Scalar>(
00156       Teuchos::rcp(this,false)
00157       ,Teuchos::rcp( raw_v.values(), false )
00158       ,raw_v.stride()
00159       )
00160     );
00161 }
00162 
00163 template<class Scalar>
00164 Teuchos::RefCountPtr<const VectorBase<Scalar> >
00165 DefaultSpmdVectorSpace<Scalar>::createMemberView(
00166   const RTOpPack::ConstSubVectorView<Scalar> &raw_v
00167   ) const
00168 {
00169 #ifdef TEUCHOS_DEBUG
00170   TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
00171 #endif
00172   return Teuchos::rcp(
00173     new DefaultSpmdVector<Scalar>(
00174       Teuchos::rcp(this,false)
00175       ,Teuchos::rcp( const_cast<Scalar*>(raw_v.values()), false )
00176       ,raw_v.stride()
00177       )
00178     );
00179 }
00180 
00181 template<class Scalar>
00182 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00183 DefaultSpmdVectorSpace<Scalar>::createMembersView( const RTOpPack::SubMultiVectorView<Scalar> &raw_mv ) const
00184 {
00185 #ifdef TEUCHOS_DEBUG
00186   TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
00187 #endif
00188   return Teuchos::rcp(
00189     new DefaultSpmdMultiVector<Scalar>(
00190       Teuchos::rcp(this,false)
00191       ,Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true)
00192       ,Teuchos::rcp( raw_mv.values(), false )
00193       ,raw_mv.leadingDim()
00194       )
00195     );
00196 }
00197 
00198 template<class Scalar>
00199 Teuchos::RefCountPtr<const MultiVectorBase<Scalar> >
00200 DefaultSpmdVectorSpace<Scalar>::createMembersView( const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv ) const
00201 {
00202 #ifdef TEUCHOS_DEBUG
00203   TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
00204 #endif
00205   return Teuchos::rcp(
00206     new DefaultSpmdMultiVector<Scalar>(
00207       Teuchos::rcp(this,false)
00208       ,Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true)
00209       ,Teuchos::rcp( const_cast<Scalar*>(raw_mv.values()), false )
00210       ,raw_mv.leadingDim()
00211       )
00212     );
00213 }
00214 
00215 template<class Scalar>
00216 bool DefaultSpmdVectorSpace<Scalar>::hasInCoreView(
00217   const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
00218   ) const
00219 {
00220   const Range1D rng = full_range(rng_in,0,this->dim()-1);
00221   const Index localOffset = this->localOffset();
00222   return ( localOffset<=rng.lbound() && rng.ubound()<localOffset+localSubDim_ );
00223 }
00224 
00225 template<class Scalar>
00226 Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> >
00227 DefaultSpmdVectorSpace<Scalar>::clone() const
00228 {
00229   return Teuchos::rcp(
00230     new DefaultSpmdVectorSpace<Scalar>(comm_,localSubDim_,this->dim())
00231     );
00232 }
00233 
00234 // Overridden from SpmdVectorSpaceDefaultBase
00235 
00236 template<class Scalar>
00237 Teuchos::RefCountPtr<const Teuchos::Comm<Index> >
00238 DefaultSpmdVectorSpace<Scalar>::getComm() const
00239 {
00240   return comm_;
00241 }
00242 
00243 template<class Scalar>
00244 Index DefaultSpmdVectorSpace<Scalar>::localSubDim() const
00245 {
00246   return localSubDim_;
00247 }
00248 
00249 } // end namespace Thyra
00250 
00251 #endif // THYRA_SPMD_VECTOR_SPACE_STD_HPP

Generated on Thu Sep 18 12:33:02 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1