AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
AbstractLinAlgPack_VectorSpace.cpp
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include "AbstractLinAlgPack_VectorSpace.hpp"
00030 #include "AbstractLinAlgPack_VectorSpaceSubSpace.hpp"
00031 #include "AbstractLinAlgPack_VectorSpaceFactory.hpp"
00032 #include "AbstractLinAlgPack_VectorMutable.hpp"
00033 #include "AbstractLinAlgPack_MultiVectorMutable.hpp"
00034 #include "AbstractLinAlgPack_InnerProductDot.hpp"
00035 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp"
00036 #include "Teuchos_TestForException.hpp"
00037 
00038 namespace AbstractLinAlgPack {
00039 
00040 // Constructors / initializers
00041 
00042 VectorSpace::VectorSpace( const inner_prod_ptr_t& inner_prod )
00043 {
00044   this->inner_prod(inner_prod);
00045 }
00046 
00047 void VectorSpace::inner_prod( const inner_prod_ptr_t& inner_prod )
00048 {
00049   if(inner_prod.get()) {
00050     inner_prod_ = inner_prod;
00051   } else {
00052     inner_prod_ = Teuchos::rcp(new InnerProductDot());
00053   }
00054 }
00055 
00056 const VectorSpace::inner_prod_ptr_t
00057 VectorSpace::inner_prod() const
00058 {
00059   return inner_prod_;
00060 }
00061 
00062 // Virtual functions with default implementations
00063 
00064 bool VectorSpace::is_in_core() const
00065 {
00066   return false;
00067 }
00068 
00069 VectorSpace::space_fcty_ptr_t
00070 VectorSpace::small_vec_spc_fcty() const
00071 {
00072   return Teuchos::null;
00073 }
00074 
00075 VectorSpace::vec_mut_ptr_t
00076 VectorSpace::create_member(const value_type& alpha) const
00077 {
00078   namespace mmp = MemMngPack;
00079   vec_mut_ptr_t vec = this->create_member();
00080   *vec = alpha;
00081   return vec;
00082 }
00083 
00084 VectorSpace::multi_vec_mut_ptr_t
00085 VectorSpace::create_members(size_type num_vecs) const
00086 {
00087   return Teuchos::null;
00088 }
00089 
00090 VectorSpace::space_ptr_t
00091 VectorSpace::sub_space(const Range1D& rng_in) const
00092 {
00093   namespace mmp = MemMngPack;
00094   const index_type dim = this->dim();
00095   const Range1D    rng = rng_in.full_range() ? Range1D(1,dim) : rng_in;
00096 #ifdef TEUCHOS_DEBUG
00097   TEST_FOR_EXCEPTION(
00098     rng.ubound() > dim, std::out_of_range
00099     ,"VectorSpace::sub_space(rng): Error, rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
00100     "is not in the range [1,this->dim()] = [1,"<<dim<<"]" );
00101 #endif  
00102   if( rng.lbound() == 1 && rng.ubound() == dim )
00103     return space_ptr_t( this, false );
00104   return Teuchos::rcp(
00105     new VectorSpaceSubSpace(
00106       Teuchos::rcp( this, false )
00107       ,rng ) );
00108 }
00109 
00110 VectorSpace::space_ptr_t
00111 VectorSpace::space(
00112   const GenPermMatrixSlice  &P
00113   ,BLAS_Cpp::Transp         P_trans
00114   ) const
00115 {
00116   const index_type
00117     dim = BLAS_Cpp::rows( P.rows(), P.cols(), P_trans );
00118   space_fcty_ptr_t  vec_spc_fcty = this->small_vec_spc_fcty();
00119   if(vec_spc_fcty.get())
00120     return vec_spc_fcty->create_vec_spc(dim);
00121   return Teuchos::null;
00122 }
00123 
00124 // Overridden from AbstractFactory<>
00125 
00126 VectorSpace::obj_ptr_t VectorSpace::create() const
00127 {
00128   return this->create_member();
00129 }
00130 
00131 } // end namespace AbstractLinAlgPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends