|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
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_MULTI_VECTOR_PRODUCT_VECTOR_HPP 00030 #define THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP 00031 00032 00033 #include "Thyra_DefaultMultiVectorProductVector_decl.hpp" 00034 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp" 00035 #include "Thyra_AssertOp.hpp" 00036 #include "Teuchos_Assert.hpp" 00037 00038 00039 namespace Thyra { 00040 00041 00042 // Constructors/initializers/accessors 00043 00044 00045 template <class Scalar> 00046 DefaultMultiVectorProductVector<Scalar>::DefaultMultiVectorProductVector() 00047 { 00048 uninitialize(); 00049 } 00050 00051 00052 template <class Scalar> 00053 void DefaultMultiVectorProductVector<Scalar>::initialize( 00054 const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace_in, 00055 const RCP<MultiVectorBase<Scalar> > &multiVec 00056 ) 00057 { 00058 #ifdef TEUCHOS_DEBUG 00059 TEST_FOR_EXCEPT(is_null(productSpace_in)); 00060 TEST_FOR_EXCEPT(is_null(multiVec)); 00061 THYRA_ASSERT_VEC_SPACES( 00062 "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace,multiVec)", 00063 *multiVec->range(), *productSpace_in->getBlock(0) 00064 ); 00065 TEUCHOS_ASSERT_EQUALITY( multiVec->domain()->dim(), productSpace_in->numBlocks()); 00066 #endif 00067 00068 numBlocks_ = productSpace_in->numBlocks(); 00069 00070 productSpace_ = productSpace_in; 00071 00072 multiVec_ = multiVec; 00073 00074 } 00075 00076 00077 template <class Scalar> 00078 void DefaultMultiVectorProductVector<Scalar>::initialize( 00079 const RCP<const DefaultMultiVectorProductVectorSpace<Scalar> > &productSpace_in, 00080 const RCP<const MultiVectorBase<Scalar> > &multiVec 00081 ) 00082 { 00083 #ifdef TEUCHOS_DEBUG 00084 TEST_FOR_EXCEPT(is_null(productSpace_in)); 00085 TEST_FOR_EXCEPT(is_null(multiVec)); 00086 THYRA_ASSERT_VEC_SPACES( 00087 "DefaultMultiVectorProductVector<Scalar>::initialize(productSpace_in,multiVec)", 00088 *multiVec->range(), *productSpace_in->getBlock(0) 00089 ); 00090 TEUCHOS_ASSERT_EQUALITY( multiVec->domain()->dim(), productSpace_in->numBlocks() ); 00091 #endif 00092 00093 numBlocks_ = productSpace_in->numBlocks(); 00094 00095 productSpace_ = productSpace_in; 00096 00097 multiVec_ = multiVec; 00098 00099 } 00100 00101 00102 template <class Scalar> 00103 RCP<MultiVectorBase<Scalar> > 00104 DefaultMultiVectorProductVector<Scalar>::getNonconstMultiVector() 00105 { 00106 return multiVec_.getNonconstObj(); 00107 } 00108 00109 00110 template <class Scalar> 00111 RCP<const MultiVectorBase<Scalar> > 00112 DefaultMultiVectorProductVector<Scalar>::getMultiVector() const 00113 { 00114 return multiVec_.getConstObj(); 00115 } 00116 00117 00118 template <class Scalar> 00119 void DefaultMultiVectorProductVector<Scalar>::uninitialize() 00120 { 00121 numBlocks_ = 0; 00122 productSpace_ = Teuchos::null; 00123 multiVec_.uninitialize(); 00124 } 00125 00126 00127 // Overridden from Teuchos::Describable 00128 00129 00130 template<class Scalar> 00131 std::string DefaultMultiVectorProductVector<Scalar>::description() const 00132 { 00133 std::ostringstream oss; 00134 oss 00135 << Teuchos::Describable::description() 00136 << "{" 00137 << "dim="<<this->space()->dim() 00138 << ",numColumns = "<<numBlocks_ 00139 << "}"; 00140 return oss.str(); 00141 } 00142 00143 template<class Scalar> 00144 void DefaultMultiVectorProductVector<Scalar>::describe( 00145 Teuchos::FancyOStream &out_arg, 00146 const Teuchos::EVerbosityLevel verbLevel 00147 ) const 00148 { 00149 typedef Teuchos::ScalarTraits<Scalar> ST; 00150 using Teuchos::OSTab; 00151 using Teuchos::describe; 00152 RCP<FancyOStream> out = rcp(&out_arg,false); 00153 OSTab tab(out); 00154 switch(verbLevel) { 00155 case Teuchos::VERB_DEFAULT: 00156 case Teuchos::VERB_LOW: 00157 *out << this->description() << std::endl; 00158 break; 00159 case Teuchos::VERB_MEDIUM: 00160 case Teuchos::VERB_HIGH: 00161 case Teuchos::VERB_EXTREME: 00162 { 00163 *out 00164 << Teuchos::Describable::description() << "{" 00165 << "dim=" << this->space()->dim() 00166 << "}\n"; 00167 OSTab tab2(out); 00168 *out << "multiVec = " << Teuchos::describe(*multiVec_.getConstObj(),verbLevel); 00169 break; 00170 } 00171 default: 00172 TEST_FOR_EXCEPT(true); // Should never get here! 00173 } 00174 } 00175 00176 00177 // Overridden from ProductVectorBase 00178 00179 00180 template <class Scalar> 00181 RCP<VectorBase<Scalar> > 00182 DefaultMultiVectorProductVector<Scalar>::getNonconstVectorBlock(const int k) 00183 { 00184 #ifdef TEUCHOS_DEBUG 00185 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ ); 00186 #endif 00187 return multiVec_.getNonconstObj()->col(k); 00188 } 00189 00190 00191 template <class Scalar> 00192 RCP<const VectorBase<Scalar> > 00193 DefaultMultiVectorProductVector<Scalar>::getVectorBlock(const int k) const 00194 { 00195 #ifdef TEUCHOS_DEBUG 00196 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ ); 00197 #endif 00198 return multiVec_.getConstObj()->col(k); 00199 } 00200 00201 00202 // Overridden from ProductMultiVectorBase 00203 00204 00205 template <class Scalar> 00206 RCP<const ProductVectorSpaceBase<Scalar> > 00207 DefaultMultiVectorProductVector<Scalar>::productSpace() const 00208 { 00209 return productSpace_; 00210 } 00211 00212 00213 template <class Scalar> 00214 bool DefaultMultiVectorProductVector<Scalar>::blockIsConst(const int k) const 00215 { 00216 #ifdef TEUCHOS_DEBUG 00217 TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE( k, 0, numBlocks_ ); 00218 #endif 00219 return multiVec_.isConst(); 00220 } 00221 00222 00223 template <class Scalar> 00224 RCP<MultiVectorBase<Scalar> > 00225 DefaultMultiVectorProductVector<Scalar>::getNonconstMultiVectorBlock(const int k) 00226 { 00227 return getNonconstVectorBlock(k); 00228 } 00229 00230 00231 template <class Scalar> 00232 RCP<const MultiVectorBase<Scalar> > 00233 DefaultMultiVectorProductVector<Scalar>::getMultiVectorBlock(const int k) const 00234 { 00235 return getVectorBlock(k); 00236 } 00237 00238 00239 // Overridden public functions from VectorBase 00240 00241 00242 template <class Scalar> 00243 RCP< const VectorSpaceBase<Scalar> > 00244 DefaultMultiVectorProductVector<Scalar>::space() const 00245 { 00246 return productSpace_; 00247 } 00248 00249 00250 // protected 00251 00252 00253 // Overridden protected functions from VectorBase 00254 00255 00256 template <class Scalar> 00257 void DefaultMultiVectorProductVector<Scalar>::applyOpImpl( 00258 const RTOpPack::RTOpT<Scalar> &op, 00259 const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs, 00260 const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs, 00261 const Ptr<RTOpPack::ReductTarget> &reduct_obj, 00262 const Ordinal global_offset 00263 ) const 00264 { 00265 this->getDefaultProductVector()->applyOp( 00266 op, vecs, targ_vecs, reduct_obj, global_offset ); 00267 } 00268 00269 00270 template <class Scalar> 00271 void DefaultMultiVectorProductVector<Scalar>::acquireDetachedVectorViewImpl( 00272 const Range1D& rng_in, RTOpPack::ConstSubVectorView<Scalar>* sub_vec 00273 ) const 00274 { 00275 this->getDefaultProductVector()->acquireDetachedView(rng_in,sub_vec); 00276 } 00277 00278 00279 template <class Scalar> 00280 void DefaultMultiVectorProductVector<Scalar>::releaseDetachedVectorViewImpl( 00281 RTOpPack::ConstSubVectorView<Scalar>* sub_vec 00282 ) const 00283 { 00284 this->getDefaultProductVector()->releaseDetachedView(sub_vec); 00285 } 00286 00287 00288 template <class Scalar> 00289 void DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl( 00290 const Range1D& rng_in, RTOpPack::SubVectorView<Scalar>* sub_vec 00291 ) 00292 { 00293 TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::acquireNonconstDetachedVectorViewImpl(...)!"); 00294 } 00295 00296 00297 template <class Scalar> 00298 void DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl( 00299 RTOpPack::SubVectorView<Scalar>* sub_vec 00300 ) 00301 { 00302 TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::commitNonconstDetachedVectorViewImpl(...)!"); 00303 } 00304 00305 00306 template <class Scalar> 00307 void DefaultMultiVectorProductVector<Scalar>::setSubVectorImpl( 00308 const RTOpPack::SparseSubVectorT<Scalar>& sub_vec 00309 ) 00310 { 00311 TEST_FOR_EXCEPT("ToDo: Implement DefaultMultiVectorProductVector<Scalar>::setSubVector(...)!"); 00312 } 00313 00314 00315 // private 00316 00317 00318 template <class Scalar> 00319 RCP<const DefaultProductVector<Scalar> > 00320 DefaultMultiVectorProductVector<Scalar>::getDefaultProductVector() const 00321 { 00322 00323 // This function exists since in general we can not create views of a column 00324 // vectors and expect the changes to be mirrored in the mulit-vector 00325 // automatically. Later, we might be able to change this once we have a 00326 // Thyra::MultiVectorBase::hasDirectColumnVectorView() function and it 00327 // returns true. Until then, this is the safe way to do this ... 00328 00329 Array<RCP<const VectorBase<Scalar> > > vecArray; 00330 for ( int k = 0; k < numBlocks_; ++k) { 00331 vecArray.push_back(multiVec_.getConstObj()->col(k)); 00332 } 00333 00334 return Thyra::defaultProductVector<Scalar>( 00335 productSpace_->getDefaultProductVectorSpace(), 00336 &vecArray[0] 00337 ); 00338 00339 } 00340 00341 00342 } // namespace Thyra 00343 00344 00345 #endif // THYRA_DEFAULT_MULTI_VECTOR_PRODUCT_VECTOR_HPP
1.7.4