Thyra Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
00043 #define THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
00044 
00045 #include "Thyra_DefaultSpmdVectorSpace_decl.hpp"
00046 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
00047 #include "Thyra_VectorSpaceFactoryBase.hpp"
00048 #include "Thyra_DefaultSpmdMultiVector.hpp"
00049 #include "Thyra_DefaultSpmdVector.hpp"
00050 #include "Teuchos_CommHelpers.hpp"
00051 
00052 
00053 namespace Thyra {
00054 
00055 
00056 template<class Scalar>
00057 RCP<DefaultSpmdVectorSpace<Scalar> >
00058 DefaultSpmdVectorSpace<Scalar>::create()
00059 { 
00060   const RCP<DefaultSpmdVectorSpace<Scalar> > vs(new DefaultSpmdVectorSpace<Scalar>);
00061   vs->weakSelfPtr_ = vs.create_weak();
00062   return vs;
00063 }
00064 
00065 
00066 template<class Scalar>
00067 void DefaultSpmdVectorSpace<Scalar>::initialize(
00068   const Ordinal dim_in
00069   )
00070 {
00071   this->initialize(Teuchos::null, dim_in, dim_in);
00072 }
00073 
00074 
00075 template<class Scalar>
00076 void DefaultSpmdVectorSpace<Scalar>::initialize(
00077   const RCP<const Teuchos::Comm<Ordinal> > &comm
00078   ,const Ordinal localSubDim_in, const Ordinal globalDim
00079   )
00080 {
00081 #ifdef TEUCHOS_DEBUG
00082   TEUCHOS_TEST_FOR_EXCEPT( !( localSubDim_in >= 0 ) );
00083 #endif
00084   comm_ = comm;
00085   localSubDim_ = localSubDim_in;
00086   if (!is_null(comm)) {
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 
00098 template<class Scalar>
00099 void DefaultSpmdVectorSpace<Scalar>::uninitialize()
00100 {
00101   comm_         = Teuchos::null;
00102   localSubDim_  = 0;
00103 }
00104 
00105 
00106 // Overridden from VectorSpace
00107 
00108 
00109 template<class Scalar>
00110 RCP<VectorBase<Scalar> >
00111 DefaultSpmdVectorSpace<Scalar>::createMember() const
00112 {
00113   ArrayRCP<Scalar> values;
00114   if (localSubDim_)
00115     values = Teuchos::arcp<Scalar>(localSubDim_);
00116   return Teuchos::rcp(
00117     new DefaultSpmdVector<Scalar>(
00118       weakSelfPtr_.create_strong(),
00119       values,
00120       1 // stride
00121       )
00122     );
00123 }
00124 
00125 
00126 template<class Scalar>
00127 RCP< MultiVectorBase<Scalar> >
00128 DefaultSpmdVectorSpace<Scalar>::createMembers(int numMembers) const
00129 {
00130   return Teuchos::rcp(
00131     new DefaultSpmdMultiVector<Scalar>(
00132       weakSelfPtr_.create_strong(),
00133       Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
00134         this->smallVecSpcFcty()->createVecSpc(numMembers),true
00135         )
00136       )
00137     );
00138 }
00139 
00140 
00141 template<class Scalar>
00142 RCP<VectorBase<Scalar> >
00143 DefaultSpmdVectorSpace<Scalar>::createMemberView(
00144   const RTOpPack::SubVectorView<Scalar> &raw_v
00145   ) const
00146 {
00147 #ifdef TEUCHOS_DEBUG
00148   TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
00149 #endif
00150   return Teuchos::rcp(
00151     new DefaultSpmdVector<Scalar>(
00152       weakSelfPtr_.create_strong(),
00153       Teuchos::arcp(raw_v.values().get(),0,raw_v.subDim(),false),
00154       raw_v.stride()
00155       )
00156     );
00157 }
00158 
00159 
00160 template<class Scalar>
00161 RCP<const VectorBase<Scalar> >
00162 DefaultSpmdVectorSpace<Scalar>::createMemberView(
00163   const RTOpPack::ConstSubVectorView<Scalar> &raw_v
00164   ) const
00165 {
00166 #ifdef TEUCHOS_DEBUG
00167   TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
00168 #endif
00169   return Teuchos::rcp(
00170     new DefaultSpmdVector<Scalar>(
00171       weakSelfPtr_.create_strong(),
00172       Teuchos::arcp(const_cast<Scalar*>(raw_v.values().get()),0,raw_v.subDim(),false),
00173       raw_v.stride()
00174       )
00175     );
00176 }
00177 
00178 
00179 template<class Scalar>
00180 RCP<MultiVectorBase<Scalar> >
00181 DefaultSpmdVectorSpace<Scalar>::createMembersView(
00182   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv
00183   ) const
00184 {
00185 #ifdef TEUCHOS_DEBUG
00186   TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
00187 #endif
00188   return Teuchos::rcp(
00189     new DefaultSpmdMultiVector<Scalar>(
00190       weakSelfPtr_.create_strong(),
00191       Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
00192         this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true),
00193       Teuchos::arcp(raw_mv.values().get(),0,raw_mv.leadingDim()*raw_mv.numSubCols(),false),
00194       raw_mv.leadingDim()
00195       )
00196     );
00197 }
00198 
00199 
00200 template<class Scalar>
00201 RCP<const MultiVectorBase<Scalar> >
00202 DefaultSpmdVectorSpace<Scalar>::createMembersView(
00203   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv
00204   ) const
00205 {
00206 #ifdef TEUCHOS_DEBUG
00207   TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
00208 #endif
00209   return Teuchos::rcp(
00210     new DefaultSpmdMultiVector<Scalar>(
00211       weakSelfPtr_.create_strong(),
00212       Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
00213         this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true),
00214       Teuchos::arcp(
00215         const_cast<Scalar*>(raw_mv.values().get()),
00216         0,raw_mv.leadingDim()*raw_mv.numSubCols(),false),
00217       raw_mv.leadingDim()
00218       )
00219     );
00220 }
00221 
00222 
00223 template<class Scalar>
00224 bool DefaultSpmdVectorSpace<Scalar>::hasInCoreView(
00225   const Range1D& rng_in, const EViewType viewType, const EStrideType strideType
00226   ) const
00227 {
00228   const Range1D rng = full_range(rng_in,0,this->dim()-1);
00229   const Ordinal l_localOffset = this->localOffset();
00230   return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+localSubDim_ );
00231 }
00232 
00233 
00234 template<class Scalar>
00235 RCP< const VectorSpaceBase<Scalar> >
00236 DefaultSpmdVectorSpace<Scalar>::clone() const
00237 {
00238   return defaultSpmdVectorSpace<Scalar>(comm_,localSubDim_,this->dim());
00239 }
00240 
00241 
00242 // Overridden from SpmdVectorSpaceDefaultBase
00243 
00244 
00245 template<class Scalar>
00246 RCP<const Teuchos::Comm<Ordinal> >
00247 DefaultSpmdVectorSpace<Scalar>::getComm() const
00248 {
00249   return comm_;
00250 }
00251 
00252 
00253 template<class Scalar>
00254 Ordinal DefaultSpmdVectorSpace<Scalar>::localSubDim() const
00255 {
00256   return localSubDim_;
00257 }
00258 
00259 
00260 // private
00261 
00262 
00263 template<class Scalar>
00264 DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace()
00265   :localSubDim_(-1), numProc_(-1), procRank_(-1)
00266 {
00267   // The base classes should automatically default initialize to a safe
00268   // uninitialized state.
00269 }
00270 
00271 
00272 // Deprecated
00273 
00274 template<class Scalar>
00275 DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace(
00276   const Ordinal dim_in
00277   )
00278   :localSubDim_(-1), numProc_(-1), procRank_(-1)
00279 {
00280   initialize(dim_in);
00281   weakSelfPtr_ = Teuchos::rcpFromRef(*this);
00282 }
00283 
00284 template<class Scalar>
00285 DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace(
00286   const RCP<const Teuchos::Comm<Ordinal> > &comm,
00287   const Ordinal my_localSubDim, const Ordinal globalDim
00288   )
00289   :localSubDim_(-1), numProc_(-1), procRank_(-1)
00290 {
00291   initialize(comm, my_localSubDim, globalDim);
00292   weakSelfPtr_ = Teuchos::rcpFromRef(*this);
00293 }
00294 
00295 
00296 } // end namespace Thyra
00297 
00298 
00299 #endif // THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines