Thyra_SpmdLinearOpBase.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_SPMD_LINEAR_OP_BASE_HPP
00030 #define THYRA_SPMD_LINEAR_OP_BASE_HPP
00031 
00032 #include "Thyra_SpmdLinearOpBaseDecl.hpp"
00033 #include "Thyra_SingleScalarEuclideanLinearOpBase.hpp"
00034 #include "Thyra_DefaultSpmdVectorSpace.hpp"
00035 #include "Thyra_DetachedVectorView.hpp"
00036 #include "Thyra_DetachedMultiVectorView.hpp"
00037 
00038 namespace Thyra {
00039 
00040 // Overridden from EuclideanLinearOpBase
00041 
00042 template<class Scalar>
00043 Teuchos::RefCountPtr< const ScalarProdVectorSpaceBase<Scalar> >
00044 SpmdLinearOpBase<Scalar>::rangeScalarProdVecSpc() const
00045 {
00046   return sp_range_;
00047 }
00048 
00049 template<class Scalar>
00050 Teuchos::RefCountPtr< const ScalarProdVectorSpaceBase<Scalar> >
00051 SpmdLinearOpBase<Scalar>::domainScalarProdVecSpc() const
00052 {
00053   return sp_domain_;
00054 }
00055 
00056 template<class Scalar>
00057 void SpmdLinearOpBase<Scalar>::euclideanApply(
00058   const ETransp                     M_trans
00059   ,const MultiVectorBase<Scalar>    &X
00060   ,MultiVectorBase<Scalar>          *Y
00061   ,const Scalar                     alpha
00062   ,const Scalar                     beta
00063   ) const
00064 {
00065 #ifdef TEUCHOS_DEBUG
00066   THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(
00067     "SpmdLinearOpBase<Scalar>::euclideanApply()",*this,M_trans,X,Y
00068     );
00069 #endif
00070   const Teuchos::RefCountPtr<const SpmdVectorSpaceBase<Scalar> >
00071     &Op_range  = ( M_trans == NOTRANS ? range_  : domain_ ),
00072     &Op_domain = ( M_trans == NOTRANS ? domain_ : range_  );
00073   const Index
00074     localOffsetRange  = Op_range->localOffset(), 
00075     localDimRange     = Op_range->localSubDim(),
00076     localOffsetDomain = Op_domain->localOffset(), 
00077     localDimDomain    = Op_domain->localSubDim(); 
00078   const ConstDetachedMultiVectorView<Scalar>
00079     local_X_ev(X,Range1D(localOffsetDomain,localOffsetDomain+localDimDomain-1));
00080   const DetachedMultiVectorView<Scalar>
00081     local_Y_ev(*Y,Range1D(localOffsetRange,localOffsetRange+localDimRange-1));
00082   this->euclideanApply(M_trans,local_X_ev.smv(),&local_Y_ev.smv(),alpha,beta);
00083 }
00084 
00085 // protected
00086 
00087 // Constructors/initializers/accessors
00088 
00089 template<class Scalar>
00090 SpmdLinearOpBase<Scalar>::SpmdLinearOpBase()
00091   :forceUnitStride_(true)
00092 {}
00093 
00094 template<class Scalar>
00095 void SpmdLinearOpBase<Scalar>::setSpaces(
00096   const Teuchos::RefCountPtr<const SpmdVectorSpaceBase<Scalar> >     &range
00097   ,const Teuchos::RefCountPtr<const SpmdVectorSpaceBase<Scalar> >    &domain
00098   )
00099 {
00100   // Validate input
00101 #ifdef TEUCHOS_DEBUG
00102   TEST_FOR_EXCEPT(range.get()==NULL);
00103   TEST_FOR_EXCEPT(domain.get()==NULL);
00104 #endif
00105   Teuchos::RefCountPtr<const ScalarProdVectorSpaceBase<Scalar> >
00106     sp_range = Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(range,true),
00107     sp_domain = Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(domain,true);
00108   // Set state
00109   range_  = range;
00110   domain_ = domain;
00111   sp_range_  = sp_range;
00112   sp_domain_ = sp_domain;
00113 }
00114 
00115 template<class Scalar>
00116 void SpmdLinearOpBase<Scalar>::setLocalDimensions(
00117   const Teuchos::RefCountPtr<const Teuchos::Comm<Index> >     &comm
00118   ,const Index                                                localDimRange
00119   ,const Index                                                localDimDomain
00120   )
00121 {
00122 #ifdef TEUCHOS_DEBUG
00123   TEST_FOR_EXCEPT( localDimRange <= 0 );
00124   TEST_FOR_EXCEPT( localDimDomain <= 0 );
00125 #endif
00126   Teuchos::RefCountPtr<const DefaultSpmdVectorSpace<Scalar> >
00127     range  = Teuchos::rcp(new DefaultSpmdVectorSpace<Scalar>(comm,localDimRange,-1)),
00128     domain = Teuchos::rcp(new DefaultSpmdVectorSpace<Scalar>(comm,localDimDomain,-1));
00129   range_  = range;
00130   domain_ = domain;
00131   sp_range_  = range;
00132   sp_domain_ = domain;
00133 }
00134 
00135 // Virtual functions to be overridden by subclasses
00136 
00137 template<class Scalar>
00138 void SpmdLinearOpBase<Scalar>::euclideanApply(
00139   const ETransp                                     M_trans
00140   ,const RTOpPack::ConstSubMultiVectorView<Scalar>  &local_X
00141   ,const RTOpPack::SubMultiVectorView<Scalar>       *local_Y
00142   ,const Scalar                                     alpha
00143   ,const Scalar                                     beta
00144   ) const
00145 {
00146   for(Index j = 0; j < local_X.numSubCols(); ++j ) {
00147     const RTOpPack::ConstSubVectorView<Scalar>
00148       local_X_j = local_X.col(j);
00149     const RTOpPack::SubVectorView<Scalar>
00150       local_Y_j = local_Y->col(j);
00151     this->euclideanApply(M_trans,local_X_j,&local_Y_j,alpha,beta);
00152   }
00153 }
00154 
00155 } // end namespace Thyra
00156 
00157 #endif  // THYRA_SPMD_LINEAR_OP_BASE_HPP

Generated on Thu Sep 18 12:33:03 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1