Thyra_DefaultVectorMultiVector.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_VECTOR_MULTI_VECTOR_HPP
00030 #define THYRA_VECTOR_MULTI_VECTOR_HPP
00031 
00032 // Define to make some verbose output
00033 //#define THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00034 
00035 #include "Thyra_DefaultVectorMultiVectorDecl.hpp"
00036 #include "Thyra_VectorBase.hpp"
00037 #include "Thyra_MultiVectorBase.hpp"
00038 #include "Teuchos_Workspace.hpp"
00039 
00040 namespace Thyra {
00041 
00042 // Constructors/initializers/accessors
00043 
00044 template<class Scalar>
00045 DefaultVectorMultiVector<Scalar>::DefaultVectorMultiVector()
00046 {}
00047 
00048 template<class Scalar>
00049 DefaultVectorMultiVector<Scalar>::DefaultVectorMultiVector(
00050   const Teuchos::RefCountPtr<MultiVectorBase<Scalar> > &mv
00051   )
00052 {
00053   initialize(mv);
00054 }
00055 
00056 template<class Scalar>
00057 void DefaultVectorMultiVector<Scalar>::initialize(
00058   const Teuchos::RefCountPtr<MultiVectorBase<Scalar> > &mv
00059   )
00060 {
00061 #ifdef TEUCHOS_DEBUG
00062   TEST_FOR_EXCEPTION( mv.get() == NULL, std::invalid_argument, "Error!" );
00063   TEST_FOR_EXCEPTION( mv->domain().get() == NULL, std::invalid_argument, "Error!" );
00064   TEST_FOR_EXCEPTION( mv->domain()->dim() != 1, std::invalid_argument, "Error!" );
00065 #endif
00066   mv_ = mv;
00067 }
00068 
00069 template<class Scalar>
00070 void DefaultVectorMultiVector<Scalar>::uninitialize(
00071   Teuchos::RefCountPtr<MultiVectorBase<Scalar> > *mv
00072   )
00073 {
00074   if(mv) *mv = mv_;
00075   mv_ = Teuchos::null;
00076 }
00077 
00078 // Overridden from LinearOpBase (forwarded to this->mv())
00079 
00080 template<class Scalar>
00081 Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> >
00082 DefaultVectorMultiVector<Scalar>::range() const
00083 {
00084   return (mv_.get() ? mv_->range() : Teuchos::null );
00085 }
00086 
00087 template<class Scalar>
00088 Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> >
00089 DefaultVectorMultiVector<Scalar>::domain() const
00090 {
00091   return (mv_.get() ? mv_->domain() : Teuchos::null );
00092 }
00093 
00094 template<class Scalar>
00095 bool DefaultVectorMultiVector<Scalar>::opSupported(ETransp M_trans) const
00096 {
00097   return mv_->opSupported(M_trans);
00098 }
00099 
00100 template<class Scalar>
00101 void DefaultVectorMultiVector<Scalar>::apply(
00102   const ETransp                     M_trans
00103   ,const MultiVectorBase<Scalar>    &X
00104   ,MultiVectorBase<Scalar>          *Y
00105   ,const Scalar                     alpha
00106   ,const Scalar                     beta
00107   ) const
00108 {
00109   mv_->apply(M_trans,X,Y,alpha,beta);
00110 }
00111 
00112 // Overridden from MultiVectorBase (forwarded to this->mv())
00113 
00114 template<class Scalar>
00115 Teuchos::RefCountPtr<VectorBase<Scalar> >
00116 DefaultVectorMultiVector<Scalar>::col(Index j)
00117 {
00118   return mv_->col(j);
00119 }
00120 
00121 template<class Scalar>
00122 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00123 DefaultVectorMultiVector<Scalar>::clone_mv() const
00124 {
00125   return mv_->clone_mv();
00126 }
00127 
00128 template<class Scalar>
00129 Teuchos::RefCountPtr<const MultiVectorBase<Scalar> >
00130 DefaultVectorMultiVector<Scalar>::subView( const Range1D& col_rng ) const
00131 {
00132   return mv_->subView(col_rng);
00133 }
00134 
00135 template<class Scalar>
00136 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00137 DefaultVectorMultiVector<Scalar>::subView( const Range1D& col_rng )
00138 {
00139   return mv_->subView(col_rng);
00140 }
00141 
00142 template<class Scalar>
00143 Teuchos::RefCountPtr<const MultiVectorBase<Scalar> >
00144 DefaultVectorMultiVector<Scalar>::subView( const int numCols, const int cols[] ) const
00145 {
00146   return mv_->subView(numCols,cols);
00147 }
00148 
00149 template<class Scalar>
00150 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00151 DefaultVectorMultiVector<Scalar>::subView( const int numCols, const int cols[] )
00152 {
00153   return mv_->subView(numCols,cols);
00154 }
00155 
00156 template<class Scalar>
00157 void DefaultVectorMultiVector<Scalar>::applyOp(
00158   const RTOpPack::RTOpT<Scalar>   &primary_op
00159   ,const int                      num_multi_vecs
00160   ,const MultiVectorBase<Scalar>* multi_vecs[]
00161   ,const int                      num_targ_multi_vecs
00162   ,MultiVectorBase<Scalar>*       targ_multi_vecs[]
00163   ,RTOpPack::ReductTarget*        reduct_objs[]
00164   ,const Index                    primary_first_ele
00165   ,const Index                    primary_sub_dim
00166   ,const Index                    primary_global_offset
00167   ,const Index                    secondary_first_ele
00168   ,const Index                    secondary_sub_dim
00169   ) const
00170 {
00171   mv_->applyOp(
00172     primary_op,num_multi_vecs,multi_vecs,num_targ_multi_vecs,targ_multi_vecs,reduct_objs
00173     ,primary_first_ele,primary_sub_dim,primary_global_offset,secondary_first_ele,secondary_sub_dim
00174     );
00175 }
00176 
00177 template<class Scalar>
00178 void DefaultVectorMultiVector<Scalar>::applyOp(
00179   const RTOpPack::RTOpT<Scalar>   &primary_op
00180   ,const RTOpPack::RTOpT<Scalar>  &secondary_op
00181   ,const int                      num_multi_vecs
00182   ,const MultiVectorBase<Scalar>* multi_vecs[]
00183   ,const int                      num_targ_multi_vecs
00184   ,MultiVectorBase<Scalar>*       targ_multi_vecs[]
00185   ,RTOpPack::ReductTarget         *reduct_obj
00186   ,const Index                    primary_first_ele
00187   ,const Index                    primary_sub_dim
00188   ,const Index                    primary_global_offset
00189   ,const Index                    secondary_first_ele
00190   ,const Index                    secondary_sub_dim
00191   ) const
00192 {
00193   mv_->applyOp(
00194     primary_op,secondary_op,num_multi_vecs,multi_vecs,num_targ_multi_vecs,targ_multi_vecs,reduct_obj
00195     ,primary_first_ele,primary_sub_dim,primary_global_offset,secondary_first_ele,secondary_sub_dim
00196     );
00197 }
00198 
00199 template<class Scalar>
00200 void DefaultVectorMultiVector<Scalar>::acquireDetachedView(
00201   const Range1D                       &rowRng
00202   ,const Range1D                      &colRng
00203   ,RTOpPack::ConstSubMultiVectorView<Scalar>  *sub_mv
00204   ) const
00205 {
00206   mv_->acquireDetachedView(rowRng,colRng,sub_mv);
00207 }
00208 
00209 template<class Scalar>
00210 void DefaultVectorMultiVector<Scalar>::releaseDetachedView( RTOpPack::ConstSubMultiVectorView<Scalar>* sub_mv ) const
00211 {
00212   mv_->releaseDetachedView(sub_mv);
00213 }
00214 
00215 template<class Scalar>
00216 void DefaultVectorMultiVector<Scalar>::acquireDetachedView(
00217   const Range1D                                &rowRng
00218   ,const Range1D                               &colRng
00219   ,RTOpPack::SubMultiVectorView<Scalar>    *sub_mv
00220   )
00221 {
00222   mv_->acquireDetachedView(rowRng,colRng,sub_mv);
00223 }
00224 
00225 template<class Scalar>
00226 void DefaultVectorMultiVector<Scalar>::commitDetachedView( RTOpPack::SubMultiVectorView<Scalar>* sub_mv )
00227 {
00228   mv_->commitDetachedView(sub_mv);
00229 }
00230 
00231 // Overridden from VectorBase
00232 
00233 template<class Scalar>
00234 Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> >
00235 DefaultVectorMultiVector<Scalar>::space() const
00236 {
00237 #ifdef THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00238   std::cerr << "\nVectorMultiVector<Scalar>::space() const called!\n";
00239 #endif
00240   return ( mv_.get() ? mv_->range() : Teuchos::null );
00241 }
00242 
00243 template<class Scalar>
00244 void DefaultVectorMultiVector<Scalar>::applyOp(
00245   const RTOpPack::RTOpT<Scalar>   &op
00246   ,const int                      num_vecs
00247   ,const VectorBase<Scalar>*      vecs[]
00248   ,const int                      num_targ_vecs
00249   ,VectorBase<Scalar>*            targ_vecs[]
00250   ,RTOpPack::ReductTarget         *reduct_obj
00251   ,const Index                    first_ele
00252   ,const Index                    sub_dim
00253   ,const Index                    global_offset
00254   ) const
00255 {
00256 #ifdef THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00257   std::cerr << "\nVectorMultiVector<Scalar>::applyOp() const called!\n";
00258 #endif
00259   using Teuchos::Workspace;
00260   Teuchos::WorkspaceStore* wss = Teuchos::get_default_workspace_store().get();
00261   // Get MultiVectorBase arguments
00262   Workspace<const MultiVectorBase<Scalar>*> multi_vecs(wss,num_vecs,false);
00263   for( int k = 0; k < num_vecs; ++k ) {
00264     const DefaultVectorMultiVector<Scalar> *v_mv = dynamic_cast<const DefaultVectorMultiVector<Scalar>*>(vecs[k]);
00265     multi_vecs[k] = ( v_mv ? &*v_mv->mv() : vecs[k] );
00266   }
00267   Workspace<MultiVectorBase<Scalar>*> targ_multi_vecs(wss,num_targ_vecs,false);
00268   for( int k = 0; k < num_targ_vecs; ++k ) {
00269     DefaultVectorMultiVector<Scalar> *v_mv = dynamic_cast<DefaultVectorMultiVector<Scalar>*>(targ_vecs[k]);
00270     targ_multi_vecs[k] = ( v_mv ? &*v_mv->mv() : targ_vecs[k] );
00271   }
00272   RTOpPack::ReductTarget* reduct_objs[] = { reduct_obj };
00273   Thyra::applyOp(
00274     op
00275     ,num_vecs,num_vecs?&multi_vecs[0]:NULL
00276     ,num_targ_vecs,num_targ_vecs?&targ_multi_vecs[0]:NULL
00277     ,reduct_objs
00278     ,first_ele,sub_dim,global_offset
00279     ,1,0
00280     );
00281 }
00282 
00283 template<class Scalar>
00284 void DefaultVectorMultiVector<Scalar>::acquireDetachedView( const Range1D& rng, RTOpPack::ConstSubVectorView<Scalar>* sub_vec ) const
00285 {
00286 #ifdef THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00287   std::cerr << "\nVectorMultiVector<Scalar>::acquireDetachedView() const called!\n";
00288 #endif
00289 #ifdef TEUCHOS_DEBUG
00290   TEST_FOR_EXCEPT(sub_vec==NULL);
00291 #endif
00292   RTOpPack::ConstSubMultiVectorView<Scalar> sub_mv;
00293   mv_->acquireDetachedView(rng,Range1D(),&sub_mv);
00294   sub_vec->initialize(sub_mv.globalOffset(),sub_mv.subDim(),sub_mv.values(),1);
00295 }
00296 
00297 template<class Scalar>
00298 void DefaultVectorMultiVector<Scalar>::releaseDetachedView( RTOpPack::ConstSubVectorView<Scalar>* sub_vec ) const
00299 {
00300 #ifdef THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00301   std::cerr << "\nVectorMultiVector<Scalar>::releaseDetachedView() const called!\n";
00302 #endif
00303 #ifdef TEUCHOS_DEBUG
00304   TEST_FOR_EXCEPT(sub_vec==NULL);
00305 #endif
00306   RTOpPack::ConstSubMultiVectorView<Scalar> sub_mv(sub_vec->globalOffset(),sub_vec->subDim(),0,1,sub_vec->values(),sub_vec->subDim());
00307   mv_->releaseDetachedView(&sub_mv);
00308   sub_vec->set_uninitialized();
00309 }
00310 
00311 template<class Scalar>
00312 void DefaultVectorMultiVector<Scalar>::acquireDetachedView( const Range1D& rng, RTOpPack::SubVectorView<Scalar>* sub_vec )
00313 {
00314 #ifdef THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00315   std::cerr << "\nVectorMultiVector<Scalar>::acquireDetachedView() called!\n";
00316 #endif
00317 #ifdef TEUCHOS_DEBUG
00318   TEST_FOR_EXCEPT(sub_vec==NULL);
00319 #endif
00320   RTOpPack::SubMultiVectorView<Scalar> sub_mv;
00321   mv_->acquireDetachedView(rng,Range1D(),&sub_mv);
00322   sub_vec->initialize(sub_mv.globalOffset(),sub_mv.subDim(),sub_mv.values(),1);
00323 }
00324 
00325 template<class Scalar>
00326 void DefaultVectorMultiVector<Scalar>::commitDetachedView( RTOpPack::SubVectorView<Scalar>* sub_vec )
00327 {
00328 #ifdef THYRA_VECTOR_MULTI_VECTOR_VERBOSE_TO_ERROR_OUT
00329   std::cerr << "\nVectorMultiVector<Scalar>::commitDetachedView() called!\n";
00330 #endif
00331 #ifdef TEUCHOS_DEBUG
00332   TEST_FOR_EXCEPT(sub_vec==NULL);
00333 #endif
00334   RTOpPack::SubMultiVectorView<Scalar> sub_mv(sub_vec->globalOffset(),sub_vec->subDim(),0,1,sub_vec->values(),sub_vec->subDim());
00335   mv_->commitDetachedView(&sub_mv);
00336   sub_vec->set_uninitialized();
00337 }
00338 
00339 } // end namespace Thyra
00340 
00341 #endif // THYRA_VECTOR_MULTI_VECTOR_HPP

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