Thyra_MultiVectorDefaultBase.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 // 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_MULTI_VECTOR_DEFAULT_BASE_HPP
00030 #define THYRA_MULTI_VECTOR_DEFAULT_BASE_HPP
00031 
00032 #include "Thyra_MultiVectorDefaultBaseDecl.hpp"
00033 #include "Thyra_MultiVectorBase.hpp"
00034 #include "Thyra_MultiVectorStdOps.hpp"
00035 #include "Thyra_VectorSpaceBase.hpp"
00036 #include "Thyra_VectorBase.hpp"
00037 #include "Thyra_AssertOp.hpp"
00038 #include "Thyra_MultiVectorCols.hpp"
00039 #include "Teuchos_Workspace.hpp"
00040 #include "Teuchos_TestForException.hpp"
00041 
00042 namespace Thyra {
00043 
00044 
00045 // Sub-view methods
00046 
00047 template<class Scalar>
00048 Teuchos::RefCountPtr<const MultiVectorBase<Scalar> >
00049 MultiVectorDefaultBase<Scalar>::subView( const Range1D& colRng_in ) const
00050 {
00051   using Teuchos::Workspace;
00052   Teuchos::WorkspaceStore        *wss      = Teuchos::get_default_workspace_store().get();
00053   const VectorSpaceBase<Scalar>  &domain   = *this->domain();
00054   const VectorSpaceBase<Scalar>  &range    = *this->range();
00055   const Index                    dimDomain = domain.dim();
00056   const Range1D                  colRng    = RangePack::full_range(colRng_in,1,dimDomain);
00057   if( colRng.lbound() == 1 && static_cast<Index>(colRng.ubound()) == dimDomain )
00058     return Teuchos::rcp(this,false); // Takes all of the columns!
00059   if( colRng.size() ) {
00060     // We have to create a view of a subset of the columns
00061     Workspace< Teuchos::RefCountPtr< VectorBase<Scalar> > >  col_vecs(wss,colRng.size());
00062     for( Index j = colRng.lbound(); j <= colRng.ubound(); ++j )
00063       col_vecs[j-colRng.lbound()] = Teuchos::rcp_const_cast<VectorBase<Scalar> >(this->col(j));
00064     return Teuchos::rcp(new MultiVectorCols<Scalar>(this->range(),range.smallVecSpcFcty()->createVecSpc(colRng.size()),&col_vecs[0]));
00065   }
00066   return Teuchos::null; // There was an empty set in colRng_in!
00067 }
00068 
00069 template<class Scalar>
00070 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00071 MultiVectorDefaultBase<Scalar>::subView( const Range1D& colRng_in )
00072 {
00073   using Teuchos::Workspace;
00074   Teuchos::WorkspaceStore        *wss      = Teuchos::get_default_workspace_store().get();
00075   const VectorSpaceBase<Scalar>  &domain   = *this->domain();
00076   const VectorSpaceBase<Scalar>  &range    = *this->range();
00077   const Index                    dimDomain = domain.dim();
00078   const Range1D                  colRng    = RangePack::full_range(colRng_in,1,dimDomain);
00079   if( colRng.lbound() == 1 && static_cast<Index>(colRng.ubound()) == dimDomain )
00080     return Teuchos::rcp(this,false); // Takes all of the columns!
00081   if( colRng.size() ) {
00082     // We have to create a view of a subset of the columns
00083     Workspace< Teuchos::RefCountPtr< VectorBase<Scalar> > >  col_vecs(wss,colRng.size());
00084     for( Index j = colRng.lbound(); j <= colRng.ubound(); ++j )
00085       col_vecs[j-colRng.lbound()] = this->col(j);
00086     return Teuchos::rcp(new MultiVectorCols<Scalar>(this->range(),range.smallVecSpcFcty()->createVecSpc(colRng.size()),&col_vecs[0]));
00087   }
00088   return Teuchos::null; // There was an empty set in colRng_in!
00089 }
00090 
00091 template<class Scalar>
00092 Teuchos::RefCountPtr<const MultiVectorBase<Scalar> >
00093 MultiVectorDefaultBase<Scalar>::subView( const int numCols, const int cols[] ) const
00094 {
00095   using Teuchos::Workspace;
00096   Teuchos::WorkspaceStore        *wss      = Teuchos::get_default_workspace_store().get();
00097   const VectorSpaceBase<Scalar>  &range    = *this->range();
00098 #ifdef _DEBUG
00099   const VectorSpaceBase<Scalar>  &domain   = *this->domain();
00100   const Index                    dimDomain = domain.dim();
00101   const char msg_err[] = "MultiVectorDefaultBase<Scalar>::subView(numCols,cols[]): Error!";
00102    TEST_FOR_EXCEPTION( numCols < 1 || dimDomain < numCols, std::invalid_argument, msg_err );
00103 #endif
00104   // We have to create a view of a subset of the columns
00105   Workspace< Teuchos::RefCountPtr< VectorBase<Scalar> > > col_vecs(wss,numCols);
00106   for( int k = 0; k < numCols; ++k ) {
00107     const int col_k = cols[k];
00108 #ifdef _DEBUG
00109     TEST_FOR_EXCEPTION(
00110       col_k < 1 || dimDomain < col_k, std::invalid_argument
00111       ,msg_err << " col["<<k<<"] = " << col_k << " is not in the range [1,"<<dimDomain<<"]!"
00112       );
00113 #endif
00114     col_vecs[k] = Teuchos::rcp_const_cast<VectorBase<Scalar> >(this->col(col_k));
00115   }
00116   return Teuchos::rcp(new MultiVectorCols<Scalar>(this->range(),range.smallVecSpcFcty()->createVecSpc(numCols),&col_vecs[0]));
00117 }
00118 
00119 template<class Scalar>
00120 Teuchos::RefCountPtr<MultiVectorBase<Scalar> >
00121 MultiVectorDefaultBase<Scalar>::subView( const int numCols, const int cols[] )
00122 {
00123   using Teuchos::Workspace;
00124   Teuchos::WorkspaceStore        *wss      = Teuchos::get_default_workspace_store().get();
00125   const VectorSpaceBase<Scalar>  &range    = *this->range();
00126 #ifdef _DEBUG
00127   const VectorSpaceBase<Scalar>  &domain   = *this->domain();
00128   const Index                    dimDomain = domain.dim();
00129   const char msg_err[] = "MultiVectorDefaultBase<Scalar>::subView(numCols,cols[]): Error!";
00130    TEST_FOR_EXCEPTION( numCols < 1 || dimDomain < numCols, std::invalid_argument, msg_err );
00131 #endif
00132   // We have to create a view of a subset of the columns
00133   Workspace< Teuchos::RefCountPtr< VectorBase<Scalar> > > col_vecs(wss,numCols);
00134   for( int k = 0; k < numCols; ++k ) {
00135     const int col_k = cols[k];
00136 #ifdef _DEBUG
00137     TEST_FOR_EXCEPTION(
00138       col_k < 1 || dimDomain < col_k, std::invalid_argument
00139       ,msg_err << " col["<<k<<"] = " << col_k << " is not in the range [1,"<<dimDomain<<"]!"
00140       );
00141 #endif
00142     col_vecs[k] = this->col(col_k);
00143   }
00144   return Teuchos::rcp(new MultiVectorCols<Scalar>(this->range(),range.smallVecSpcFcty()->createVecSpc(numCols),&col_vecs[0]));
00145 }
00146 
00147 } // end namespace Thyra
00148 
00149 #endif // THYRA_MULTI_VECTOR_DEFAULT_BASE_HPP

Generated on Thu Sep 18 12:39:52 2008 for Thyra ANA Operator/VectorBase Interfaces and Related Software by doxygen 1.3.9.1