|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // *********************************************************************** 00002 // 00003 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00004 // Copyright (2004) Sandia Corporation 00005 // 00006 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00007 // license for use of this work by or on behalf of the U.S. Government. 00008 // 00009 // This library is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU Lesser General Public License as 00011 // published by the Free Software Foundation; either version 2.1 of the 00012 // License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, but 00015 // WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00022 // USA 00023 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00024 // 00025 // *********************************************************************** 00026 // @HEADER 00027 00028 #ifndef THYRA_LISTED_MULTI_VECTOR_RANDOMIZER_HPP 00029 #define THYRA_LISTED_MULTI_VECTOR_RANDOMIZER_HPP 00030 00031 #include "Thyra_MultiVectorRandomizerBase.hpp" 00032 #include "Thyra_MultiVectorStdOps.hpp" 00033 00034 namespace Thyra { 00035 00045 template<class Scalar> 00046 class ListedMultiVectorRandomizer : public MultiVectorRandomizerBase<Scalar> { 00047 public: 00048 00050 ListedMultiVectorRandomizer( 00051 const Teuchos::RCP<const MultiVectorBase<Scalar> > multiVecs[] 00052 ,const int numMultiVecs 00053 ); 00054 00056 void initialize( 00057 const Teuchos::RCP<const MultiVectorBase<Scalar> > multiVecs[] 00058 ,const int numMultiVecs 00059 ); 00060 00063 00065 bool isCompatible( const VectorSpaceBase<Scalar> &space ) const; 00067 void randomize( MultiVectorBase<Scalar> *mv ); 00068 00070 00071 private: 00072 00073 typedef std::vector<Teuchos::RCP<const MultiVectorBase<Scalar> > > multiVecs_t; 00074 00075 multiVecs_t multiVecs_; 00076 00077 int curr_mv_i_; 00078 00079 }; 00080 00081 // ////////////////////////////// 00082 // Definitions 00083 00084 template<class Scalar> 00085 ListedMultiVectorRandomizer<Scalar>::ListedMultiVectorRandomizer( 00086 const Teuchos::RCP<const MultiVectorBase<Scalar> > multiVecs[] 00087 ,const int numMultiVecs 00088 ) 00089 { 00090 initialize(multiVecs,numMultiVecs); 00091 } 00092 00093 template<class Scalar> 00094 void ListedMultiVectorRandomizer<Scalar>::initialize( 00095 const Teuchos::RCP<const MultiVectorBase<Scalar> > multiVecs[] 00096 ,const int numMultiVecs 00097 ) 00098 { 00099 multiVecs_.resize(numMultiVecs); 00100 std::copy( multiVecs, multiVecs + numMultiVecs, multiVecs_.begin() ); 00101 curr_mv_i_ = 0; 00102 } 00103 00104 // Overridden from MultiVectorRandomizerBase 00105 00106 template<class Scalar> 00107 bool ListedMultiVectorRandomizer<Scalar>::isCompatible( const VectorSpaceBase<Scalar> &space ) const 00108 { 00109 return multiVecs_[curr_mv_i_]->range()->isCompatible(space); 00110 } 00111 00112 template<class Scalar> 00113 void ListedMultiVectorRandomizer<Scalar>::randomize( MultiVectorBase<Scalar> *mv ) 00114 { 00115 #ifdef TEUCHOS_DEBUG 00116 TEST_FOR_EXCEPT( mv==NULL ); 00117 TEST_FOR_EXCEPT( multiVecs_.size()==0 ); 00118 #endif 00119 const Teuchos::RCP<const MultiVectorBase<Scalar> > currMV = multiVecs_[curr_mv_i_]; 00120 #ifdef TEUCHOS_DEBUG 00121 THYRA_ASSERT_VEC_SPACES("ListedMultiVectorRandomizer<Scalar>::randomize(mv)", *currMV->range(), *mv->range() ); 00122 THYRA_ASSERT_VEC_SPACES("ListedMultiVectorRandomizer<Scalar>::randomize(mv)", *currMV->domain(), *mv->domain() ); 00123 #endif 00124 Thyra::assign( mv, *currMV ); 00125 if( curr_mv_i_ == static_cast<int>(multiVecs_.size()) - 1 ) 00126 curr_mv_i_ = 0; 00127 else 00128 ++curr_mv_i_; 00129 } 00130 00131 } // namespace Thyra 00132 00133 #endif // THYRA_LISTED_MULTI_VECTOR_RANDOMIZER_HPP
1.7.4