Thyra_DefaultSpmdVectorSpace.hpp

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::RCP<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::RCP<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 VectorSpace
00104 
00105 template<class Scalar>
00106 Teuchos::RCP<VectorBase<Scalar> >
00107 DefaultSpmdVectorSpace<Scalar>::createMember() const
00108 {
00109   return Teuchos::rcp(
00110     new DefaultSpmdVector<Scalar>(
00111       Teuchos::rcp(this,false)
00112       ,Teuchos::rcp(
00113         localSubDim_ ? new Scalar[localSubDim_] : 0
00114         ,Teuchos::DeallocArrayDelete<Scalar>()
00115         ,true
00116         )
00117       ,1
00118       )
00119     );
00120 }
00121 
00122 template<class Scalar>
00123 Teuchos::RCP< MultiVectorBase<Scalar> >
00124 DefaultSpmdVectorSpace<Scalar>::createMembers(int numMembers) const
00125 {
00126   return Teuchos::rcp(
00127     new DefaultSpmdMultiVector<Scalar>(
00128       Teuchos::rcp(this,false)
00129       ,Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
00130         this->smallVecSpcFcty()->createVecSpc(numMembers),true
00131         )
00132       )
00133     );
00134 }
00135 
00136 template<class Scalar>
00137 Teuchos::RCP<VectorBase<Scalar> >
00138 DefaultSpmdVectorSpace<Scalar>::createMemberView(
00139   const RTOpPack::SubVectorView<Scalar> &raw_v
00140   ) const
00141 {
00142 #ifdef TEUCHOS_DEBUG
00143   TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
00144 #endif
00145   return Teuchos::rcp(
00146     new DefaultSpmdVector<Scalar>(
00147       Teuchos::rcp(this,false)
00148       ,Teuchos::rcp( raw_v.values(), false )
00149       ,raw_v.stride()
00150       )
00151     );
00152 }
00153 
00154 template<class Scalar>
00155 Teuchos::RCP<const VectorBase<Scalar> >
00156 DefaultSpmdVectorSpace<Scalar>::createMemberView(
00157   const RTOpPack::ConstSubVectorView<Scalar> &raw_v
00158   ) const
00159 {
00160 #ifdef TEUCHOS_DEBUG
00161   TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
00162 #endif
00163   return Teuchos::rcp(
00164     new DefaultSpmdVector<Scalar>(
00165       Teuchos::rcp(this,false)
00166       ,Teuchos::rcp( const_cast<Scalar*>(raw_v.values()), false )
00167       ,raw_v.stride()
00168       )
00169     );
00170 }
00171 
00172 template<class Scalar>
00173 Teuchos::RCP<MultiVectorBase<Scalar> >
00174 DefaultSpmdVectorSpace<Scalar>::createMembersView( const RTOpPack::SubMultiVectorView<Scalar> &raw_mv ) const
00175 {
00176 #ifdef TEUCHOS_DEBUG
00177   TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
00178 #endif
00179   return Teuchos::rcp(
00180     new DefaultSpmdMultiVector<Scalar>(
00181       Teuchos::rcp(this,false)
00182       ,Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true)
00183       ,Teuchos::rcp( raw_mv.values(), false )
00184       ,raw_mv.leadingDim()
00185       )
00186     );
00187 }
00188 
00189 template<class Scalar>
00190 Teuchos::RCP<const MultiVectorBase<Scalar> >
00191 DefaultSpmdVectorSpace<Scalar>::createMembersView( const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv ) const
00192 {
00193 #ifdef TEUCHOS_DEBUG
00194   TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
00195 #endif
00196   return Teuchos::rcp(
00197     new DefaultSpmdMultiVector<Scalar>(
00198       Teuchos::rcp(this,false)
00199       ,Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true)
00200       ,Teuchos::rcp( const_cast<Scalar*>(raw_mv.values()), false )
00201       ,raw_mv.leadingDim()
00202       )
00203     );
00204 }
00205 
00206 template<class Scalar>
00207 bool DefaultSpmdVectorSpace<Scalar>::hasInCoreView(
00208   const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
00209   ) const
00210 {
00211   const Range1D rng = full_range(rng_in,0,this->dim()-1);
00212   const Index localOffset = this->localOffset();
00213   return ( localOffset<=rng.lbound() && rng.ubound()<localOffset+localSubDim_ );
00214 }
00215 
00216 template<class Scalar>
00217 Teuchos::RCP< const VectorSpaceBase<Scalar> >
00218 DefaultSpmdVectorSpace<Scalar>::clone() const
00219 {
00220   return Teuchos::rcp(
00221     new DefaultSpmdVectorSpace<Scalar>(comm_,localSubDim_,this->dim())
00222     );
00223 }
00224 
00225 // Overridden from SpmdVectorSpaceDefaultBase
00226 
00227 template<class Scalar>
00228 Teuchos::RCP<const Teuchos::Comm<Index> >
00229 DefaultSpmdVectorSpace<Scalar>::getComm() const
00230 {
00231   return comm_;
00232 }
00233 
00234 template<class Scalar>
00235 Index DefaultSpmdVectorSpace<Scalar>::localSubDim() const
00236 {
00237   return localSubDim_;
00238 }
00239 
00240 } // end namespace Thyra
00241 
00242 #endif // THYRA_SPMD_VECTOR_SPACE_STD_HPP

Generated on Tue Oct 20 12:46:58 2009 for Thyra Operator/Vector Support by doxygen 1.4.7