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

Generated on Wed May 12 21:42:27 2010 for Thyra Operator/Vector Support by  doxygen 1.4.7