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