MOOCHO (Single Doxygen Collection) Version of the Day
AbstractLinAlgPack_VectorSpaceSerial.cpp
Go to the documentation of this file.
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <assert.h>
00043 
00044 #include "AbstractLinAlgPack_VectorSpaceSerial.hpp"
00045 #include "AbstractLinAlgPack_VectorSpaceFactorySerial.hpp"
00046 #include "AbstractLinAlgPack_VectorMutableDense.hpp"
00047 #include "AbstractLinAlgPack_MultiVectorMutableDense.hpp"
00048 #include "AbstractLinAlgPack_VectorMutable.hpp"
00049 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp"
00050 #include "DenseLinAlgPack_DVectorClass.hpp"
00051 #include "Teuchos_Assert.hpp"
00052 
00053 #ifdef TEUCHOS_DEBUG
00054 #define CLASS_MEMBER_PTRS \
00055 const VectorSpaceSerial  *_this = this; \
00056 const size_type *_dim = &dim_;
00057 #else
00058 #define CLASS_MEMBER_PTRS
00059 #endif
00060 
00061 namespace AbstractLinAlgPack {
00062 
00063 VectorSpaceSerial::VectorSpaceSerial( size_type dim )
00064 {
00065   CLASS_MEMBER_PTRS
00066   initialize(dim);
00067 }
00068 
00069 void VectorSpaceSerial::initialize( size_type dim )
00070 {
00071   CLASS_MEMBER_PTRS
00072   dim_ = dim;
00073 }
00074 
00075 // Overridden from VectorSpace
00076 
00077 bool VectorSpaceSerial::is_compatible(const VectorSpace& a_vec_space ) const
00078 {
00079   CLASS_MEMBER_PTRS
00080   return this->dim() == a_vec_space.dim() && a_vec_space.is_in_core();
00081 }
00082 
00083 bool VectorSpaceSerial::is_in_core() const
00084 {
00085   return true;
00086 }
00087 
00088 index_type VectorSpaceSerial::dim() const
00089 {
00090   CLASS_MEMBER_PTRS
00091   return dim_;
00092 }
00093 
00094 VectorSpace::space_fcty_ptr_t
00095 VectorSpaceSerial::small_vec_spc_fcty() const
00096 {
00097   CLASS_MEMBER_PTRS
00098   return Teuchos::rcp(new VectorSpaceFactorySerial());
00099 }
00100 
00101 VectorSpace::space_ptr_t
00102 VectorSpaceSerial::clone() const
00103 {
00104   CLASS_MEMBER_PTRS
00105   namespace mmp = MemMngPack;
00106   return Teuchos::rcp( new VectorSpaceSerial( dim_  ) );
00107 }
00108 
00109 VectorSpace::vec_mut_ptr_t
00110 VectorSpaceSerial::create_member() const
00111 {
00112   CLASS_MEMBER_PTRS
00113   namespace mmp = MemMngPack;
00114   return Teuchos::rcp(new VectorMutableDense(dim_));
00115 }
00116 
00117 VectorSpace::multi_vec_mut_ptr_t
00118 VectorSpaceSerial::create_members(size_type num_vecs) const
00119 {
00120   CLASS_MEMBER_PTRS
00121   namespace mmp = MemMngPack;
00122   return Teuchos::rcp(new MultiVectorMutableDense(dim_,num_vecs));
00123 }
00124 
00125 VectorSpace::space_ptr_t
00126 VectorSpaceSerial::sub_space(const Range1D& rng_in) const
00127 {
00128   CLASS_MEMBER_PTRS
00129   namespace mmp = MemMngPack;
00130   const size_type this_dim = this->dim();
00131   const Range1D rng = RangePack::full_range( rng_in, 1, this_dim );
00132 #ifdef TEUCHOS_DEBUG
00133   TEUCHOS_TEST_FOR_EXCEPTION(
00134     rng.ubound() > this_dim, std::out_of_range
00135     ,"VectorSpaceSerial::sub_view(...) : Error, "
00136     "rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
00137     "is not in the range [1,this->dim()] = [1," << this_dim );
00138 #endif
00139   if( rng == Range1D(1,this_dim) )
00140     return Teuchos::rcp( this, false );
00141   return Teuchos::rcp( new VectorSpaceSerial( rng.size() ) ); 
00142 }
00143 
00144 VectorSpace::space_ptr_t
00145 VectorSpaceSerial::space(
00146   const GenPermMatrixSlice  &P
00147   ,BLAS_Cpp::Transp         P_trans
00148   ) const
00149 {
00150   CLASS_MEMBER_PTRS
00151   return Teuchos::rcp( new VectorSpaceSerial( BLAS_Cpp::rows( P.rows(), P.cols(), P_trans ) ) ); 
00152 }
00153 
00154 } // end namespace AbstractLinAlgPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines