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

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