AbstractLinAlgPack_VectorMutableSubView.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 // 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_VectorMutableSubView.hpp"
00030 #include "Teuchos_TestForException.hpp"
00031 #include "Teuchos_Workspace.hpp"
00032 #include "Teuchos_dyn_cast.hpp"
00033 
00034 namespace AbstractLinAlgPack {
00035 
00036 VectorMutableSubView::VectorMutableSubView( const vec_mut_ptr_t& vec, const Range1D& rng )
00037 {
00038   this->initialize(vec,rng);
00039 }
00040 
00041 void VectorMutableSubView::initialize( const vec_mut_ptr_t& vec, const Range1D& rng )
00042 {
00043   namespace rcp = MemMngPack;
00044   VectorSubView::initialize(vec,rng);
00045   full_vec_ = vec;
00046   this->has_changed();
00047 }
00048 
00049 void VectorMutableSubView::set_uninitialized()
00050 {
00051   VectorSubView::set_uninitialized();
00052   full_vec_ = Teuchos::null;
00053   this->has_changed();
00054 }
00055 
00056 // Overriddend form Vector
00057 
00058 Vector::vec_ptr_t VectorMutableSubView::sub_view( const Range1D& rng ) const
00059 {
00060   return VectorSubView::sub_view(rng); // Had to override to resolve conflicit!
00061 }
00062 
00063 // Overridden from VectorMutable
00064 
00065 void VectorMutableSubView::set_ele( index_type i, value_type val )
00066 {
00067   space_impl().validate_range(Range1D(i,i));
00068   full_vec_->set_ele( space_impl().rng().lbound() + i - 1, val );
00069   this->has_changed();
00070 }
00071 
00072 VectorMutable::vec_mut_ptr_t
00073 VectorMutableSubView::sub_view( const Range1D& rng_in )
00074 {
00075   namespace rcp = MemMngPack;
00076   const size_type this_dim = this->dim();
00077   const Range1D rng = RangePack::full_range( rng_in, 1, this_dim );
00078   space_impl().validate_range(rng);
00079   if( rng.lbound() == 1 && rng.ubound() == this_dim )
00080     return Teuchos::rcp(this,false); // Do not own memory!
00081   // Below we will return an object that is not this entire object so
00082   // we must wipe out cache.
00083   this->has_changed();
00084   const index_type this_offset = space_impl().rng().lbound() - 1;
00085   return Teuchos::rcp(
00086     new VectorMutableSubView(
00087       full_vec_
00088       ,Range1D( 
00089         this_offset  + rng.lbound()
00090         ,this_offset + rng.ubound() )
00091       ) );
00092 }
00093 
00094 void VectorMutableSubView::get_sub_vector( const Range1D& rng_in, RTOpPack::MutableSubVector* sub_vec )
00095 {
00096 #ifdef TEUCHOS_DEBUG
00097   TEST_FOR_EXCEPTION( !sub_vec, std::logic_error ,"VectorMutableSubView::get_sub_vector(...): Error!" );
00098 #endif
00099   const index_type this_dim = this->dim();
00100   const Range1D rng = RangePack::full_range(rng_in,1,this_dim);
00101   space_impl().validate_range(rng);
00102   const index_type this_offset = space_impl().rng().lbound() - 1;
00103   full_vec_->get_sub_vector( rng + this_offset, sub_vec );
00104   sub_vec->setGlobalOffset( sub_vec->globalOffset() - this_offset );
00105 }
00106 
00107 void VectorMutableSubView::commit_sub_vector( RTOpPack::MutableSubVector* sub_vec )
00108 {
00109 #ifdef TEUCHOS_DEBUG
00110   TEST_FOR_EXCEPTION( !sub_vec, std::logic_error, "VectorMutableSubView::commit_sub_vector(...): Error!" );
00111 #endif
00112   const index_type this_offset = space_impl().rng().lbound() - 1;
00113   sub_vec->setGlobalOffset( sub_vec->globalOffset() + this_offset );
00114   full_vec_->commit_sub_vector( sub_vec );
00115   this->has_changed();
00116 }
00117 
00118 void VectorMutableSubView::set_sub_vector( const RTOpPack::SparseSubVector& sub_vec_in )
00119 {
00120   const index_type            this_offset = space_impl().rng().lbound() - 1;
00121   RTOpPack::SparseSubVector   sub_vec = sub_vec_in;
00122   sub_vec.setGlobalOffset( sub_vec.globalOffset() + this_offset );
00123   full_vec_->set_sub_vector( sub_vec );
00124   this->has_changed();
00125 }
00126 
00127 } // end namespace AbstractLinAlgPack

Generated on Tue Jul 13 09:30:50 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7