|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
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 <assert.h> 00030 00031 #include "AbstractLinAlgPack_VectorSpaceSubSpace.hpp" 00032 #include "AbstractLinAlgPack_VectorMutableSubView.hpp" 00033 #include "Teuchos_TestForException.hpp" 00034 00035 namespace AbstractLinAlgPack { 00036 00037 VectorSpaceSubSpace::VectorSpaceSubSpace( const space_ptr_t& full_space, const Range1D& rng ) 00038 { 00039 this->initialize(full_space,rng); 00040 } 00041 00042 void VectorSpaceSubSpace::initialize( const space_ptr_t& full_space, const Range1D& rng ) 00043 { 00044 #ifdef TEUCHOS_DEBUG 00045 TEST_FOR_EXCEPTION( 00046 full_space.get() == NULL, std::invalid_argument 00047 ,"VectorSpaceSubSpace::initialize(...): Error!" ); 00048 #endif 00049 const index_type n = full_space->dim(); 00050 #ifdef TEUCHOS_DEBUG 00051 TEST_FOR_EXCEPTION( 00052 !rng.full_range() && rng.ubound() > n, std::out_of_range 00053 ,"VectorSpaceSubSpace::initialize(...): Error, " 00054 "rng = [" << rng.lbound() << "," << rng.ubound() << "] is not in the range " 00055 "[1,vec->dim()] = [1," << n << "]" ); 00056 #endif 00057 full_space_ = full_space; 00058 rng_ = rng.full_range() ? Range1D(1,n) : rng; 00059 } 00060 00061 void VectorSpaceSubSpace::set_uninitialized() 00062 { 00063 full_space_ = Teuchos::null; 00064 rng_ = Range1D::Invalid; 00065 } 00066 00067 #ifdef TEUCHOS_DEBUG 00068 void VectorSpaceSubSpace::validate_range(const Range1D& rng) const 00069 { 00070 const index_type n = this->dim(); 00071 TEST_FOR_EXCEPTION( 00072 full_space_.get() == NULL, std::logic_error 00073 ,"VectorSpaceSubSpace::validate_range(rng): Error, Uninitialized" ); 00074 TEST_FOR_EXCEPTION( 00075 full_space_.get() && !rng.full_range() && rng.ubound() > n, std::logic_error 00076 ,"VectorSpaceSubSpace::validate_range(rng): Error, " 00077 "rng = [" << rng.lbound() << "," << rng.ubound() << "] is not in the range " 00078 "[1,this->dim] = [1," << n << "]" ); 00079 } 00080 #endif 00081 00082 // Overridden from VectorSpace 00083 00084 bool VectorSpaceSubSpace::is_compatible(const VectorSpace& another_space) const 00085 { 00086 if( this->dim() == another_space.dim() && this->is_in_core() && another_space.is_in_core() ) 00087 return true; 00088 const VectorSpaceSubSpace 00089 *a_space = dynamic_cast<const VectorSpaceSubSpace*>(&another_space); 00090 if(!a_space) 00091 return false; 00092 return 00093 ( this->full_space_.get() == NULL && a_space->full_space_.get() == NULL ) 00094 || 00095 ( this->rng_ == a_space->rng_ && this->full_space_->is_compatible(*a_space->full_space_) ); 00096 } 00097 00098 bool VectorSpaceSubSpace::is_in_core() const 00099 { 00100 return full_space_->is_in_core(); 00101 } 00102 00103 index_type VectorSpaceSubSpace::dim() const 00104 { 00105 return full_space_.get() ? rng_.size() : 0; 00106 } 00107 00108 VectorSpace::vec_mut_ptr_t VectorSpaceSubSpace::create_member() const 00109 { 00110 namespace rcp = MemMngPack; 00111 if( full_space_.get() ) 00112 return Teuchos::rcp( 00113 new VectorMutableSubView( 00114 full_space_->create_member(), rng_ 00115 ) ); 00116 return Teuchos::null; 00117 } 00118 00119 VectorSpace::space_ptr_t VectorSpaceSubSpace::clone() const 00120 { 00121 namespace rcp = MemMngPack; 00122 if( full_space_.get() ) 00123 return Teuchos::rcp(new VectorSpaceSubSpace( full_space_->clone(), rng_ )); 00124 return Teuchos::rcp(new VectorSpaceSubSpace()); 00125 } 00126 00127 VectorSpace::space_ptr_t VectorSpaceSubSpace::sub_space(const Range1D& rng_in) const 00128 { 00129 namespace rcp = MemMngPack; 00130 if( full_space_.get() == NULL && rng_in == Range1D::Invalid ) 00131 return Teuchos::rcp(this,false); 00132 validate_range(rng_in); 00133 const index_type dim = this->dim(); 00134 const Range1D rng = rng_in.full_range() ? Range1D(1,dim) : rng_in; 00135 if( rng.lbound() == 1 && rng.ubound() == dim ) 00136 return space_ptr_t( this, false ); 00137 const index_type this_offset = rng_.lbound() - 1; 00138 return Teuchos::rcp( 00139 new VectorSpaceSubSpace( 00140 full_space_ 00141 ,Range1D( 00142 this_offset + rng.lbound() 00143 ,this_offset + rng.ubound() ) 00144 ) ); 00145 } 00146 00147 } // end namespace AbstractLinAlgPack
1.7.4