AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
AbstractLinAlgPack_VectorMutableBlocked.hpp
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 #ifndef VECTOR_WITH_OP_MUTABLE_BLOCK_STD_H
00043 #define VECTOR_WITH_OP_MUTABLE_BLOCK_STD_H
00044 
00045 #include <vector>
00046 
00047 #include "AbstractLinAlgPack_VectorMutable.hpp"
00048 #include "AbstractLinAlgPack_VectorSpaceBlocked.hpp"
00049 
00050 namespace AbstractLinAlgPack {
00051 
00081 class VectorMutableBlocked : virtual public VectorMutable
00082 {
00083 public:
00084 
00086   typedef Teuchos::RCP<const VectorSpaceBlocked>  vec_space_comp_ptr_t;
00087 
00090   VectorMutableBlocked(
00091     VectorMutable::vec_mut_ptr_t*  vecs
00092     ,const vec_space_comp_ptr_t&         vec_space
00093     );
00094 
00111   void initialize(
00112     VectorMutable::vec_mut_ptr_t*  vecs
00113     ,const vec_space_comp_ptr_t&         vec_space
00114     );
00115 
00118   const VectorSpaceBlocked& block_space() const;
00119 
00122   const Vector& get_vector(int k) const;
00123 
00126   VectorMutable& get_vector(int k);
00127 
00129 
00132 
00134   index_type dim() const;
00136   const VectorSpace& space() const;
00138   void apply_op(
00139     const RTOpPack::RTOp& op
00140     ,const size_t num_vecs, const Vector* vecs[]
00141     ,const size_t num_targ_vecs, VectorMutable* targ_vecs[]
00142     ,RTOpPack::ReductTarget *reduct_obj
00143     ,const index_type first_ele, const index_type sub_dim, const index_type global_offset
00144     ) const;
00146   index_type nz() const;
00148   std::ostream& output(
00149     std::ostream& out, bool print_dim, bool newline
00150     ,index_type global_offset 
00151     ) const;
00153   value_type get_ele(index_type i) const;
00155   value_type norm_1() const;
00157   value_type norm_inf() const;
00159   value_type inner_product( const Vector& ) const;
00161   void get_sub_vector( const Range1D& rng, RTOpPack::SubVector* sub_vec ) const;
00163   void free_sub_vector( RTOpPack::SubVector* sub_vec ) const;
00164 
00166 
00169 
00171   vec_mut_ptr_t sub_view( const Range1D& rng );
00173   void axpy( value_type alpha, const Vector& x );
00175   VectorMutable& operator=(value_type);
00177   VectorMutable& operator=(const Vector&);
00179   void set_ele( index_type i, value_type val );
00181   void set_sub_vector( const RTOpPack::SparseSubVector& sub_vec );
00182 
00184 
00185 protected:
00186 
00190   void has_changed() const;
00192 
00193 private:
00194 
00195   // ////////////////////////////////////
00196   // Private types
00197   
00198   typedef std::vector<VectorMutable::vec_mut_ptr_t>   vecs_t; 
00199 
00200   // ////////////////////////////////////
00201   // Private data members
00202 
00203 #ifdef DOXYGEN_COMPILE
00204   VectorMutable        *vectors;
00205   VectorSpaceBlocked    *block_vector_space;
00206 #else
00207   vecs_t                 vecs_;        
00208   vec_space_comp_ptr_t   vec_space_;   
00209 #endif
00210   mutable index_type     nz_; 
00211   mutable value_type     norm_1_, norm_inf_;   
00212 
00213   // ////////////////////////////////////
00214   // Private member functions
00215 
00217   void assert_in_range(int k) const;
00218 
00220   void assert_initialized() const;
00221 
00222   // not defined and not to be called!
00223   VectorMutableBlocked();
00224   VectorMutableBlocked(const VectorMutableBlocked&);
00225   VectorMutableBlocked& operator=(const VectorMutableBlocked&);
00226 
00227 }; // end class VectorMutableBlocked
00228 
00229 // ////////////////////////////////////
00230 // Inline members
00231 
00232 inline
00233 const VectorSpaceBlocked&
00234 VectorMutableBlocked::block_space() const
00235 {
00236   assert_initialized();
00237   return *vec_space_;
00238 }
00239 
00240 inline
00241 const Vector&
00242 VectorMutableBlocked::get_vector(int k) const
00243 {
00244   assert_in_range(k);
00245   return *vecs_[k];
00246 }
00247 
00248 inline
00249 VectorMutable&
00250 VectorMutableBlocked::get_vector(int k)
00251 {
00252   assert_in_range(k);
00253   return *vecs_[k];
00254 }
00255 
00256 } // end namespace AbstractLinAlgPack
00257 
00258 #endif  // VECTOR_WITH_OP_MUTABLE_BLOCK_STD_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends