AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
AbstractLinAlgPack_Vector.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 // 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 #ifndef ALAP_VECTOR_HPP
00030 #define ALAP_VECTOR_HPP
00031 
00032 #include <iosfwd>
00033 
00034 #include "AbstractLinAlgPack_Types.hpp"
00035 #include "RTOpPack_RTOpT.hpp"
00036 
00037 namespace AbstractLinAlgPack {
00038 
00106 void apply_op(
00107   const RTOpPack::RTOp       &op
00108   ,const size_t              num_vecs
00109   ,const Vector*             vecs[]
00110   ,const size_t              num_targ_vecs
00111   ,VectorMutable*            targ_vecs[]
00112   ,RTOpPack::ReductTarget    *reduct_obj
00113   ,const index_type          first_ele      = 1
00114   ,const index_type          sub_dim        = 0
00115   ,const index_type          global_offset  = 0
00116   );
00117 
00174 class Vector {
00175 public:
00176 
00178   typedef Teuchos::RCP<const Vector>   vec_ptr_t;
00180   typedef Teuchos::RCP<VectorMutable>  vec_mut_ptr_t;
00181 
00183   friend
00184   void apply_op(
00185     const RTOpPack::RTOp       &op
00186     ,const size_t              num_vecs
00187     ,const Vector*             vecs[]
00188     ,const size_t              num_targ_vecs
00189     ,VectorMutable*            targ_vecs[]
00190     ,RTOpPack::ReductTarget    *reduct_obj
00191     ,const index_type          first_ele
00192     ,const index_type          sub_dim
00193     ,const index_type          global_offset
00194     );
00195 
00197   Vector();
00199   virtual ~Vector() {}
00200 
00203 
00211   virtual const VectorSpace& space() const = 0;
00212 
00213 protected:
00214 
00227   virtual void apply_op(
00228     const RTOpPack::RTOp       &op
00229     ,const size_t              num_vecs
00230     ,const Vector*             vecs[]
00231     ,const size_t              num_targ_vecs
00232     ,VectorMutable*            targ_vecs[]
00233     ,RTOpPack::ReductTarget    *reduct_obj
00234     ,const index_type          first_ele
00235     ,const index_type          sub_dim
00236     ,const index_type          global_offset
00237     ) const = 0;
00238 
00240 
00241 public:
00242 
00245 
00253   virtual index_type dim() const;
00254 
00261   virtual index_type nz() const;
00262 
00279   virtual std::ostream& output(
00280     std::ostream& out, bool print_dim = true, bool newline = true
00281     ,index_type global_offset = 0
00282     ) const;
00283 
00293   virtual vec_mut_ptr_t clone() const;
00294 
00306   virtual value_type get_ele(index_type i) const;
00307 
00348   virtual vec_ptr_t sub_view( const Range1D& rng ) const;
00349 
00351 
00354   vec_ptr_t sub_view( const index_type& l, const index_type& u ) const;
00355 
00358 
00361   virtual value_type norm_1() const;
00364   virtual value_type norm_2() const;
00367   virtual value_type norm_inf() const;
00368   
00370 
00373 
00378   virtual value_type inner_product( const Vector& v ) const;
00379 
00381 
00384 
00426   virtual void get_sub_vector( const Range1D& rng, RTOpPack::SubVector* sub_vec ) const;
00427 
00442   virtual void free_sub_vector( RTOpPack::SubVector* sub_vec ) const;
00443 
00445 
00467   virtual void has_changed() const;
00468 
00469 protected:
00470 
00473 
00479   virtual void finalize_apply_op(
00480     const size_t num_targ_vecs, VectorMutable** targ_vecs
00481     ) const;
00482 
00484 
00485 private:
00486 
00487   mutable index_type  num_nonzeros_;  
00488   mutable value_type  norm_1_, norm_2_, norm_inf_;  
00489 
00490 }; // end class Vector
00491 
00492 // ////////////////////////////////////////////////
00493 // Inline functions
00494 
00495 inline
00496 Vector::vec_ptr_t
00497 Vector::sub_view( const index_type& l, const index_type& u ) const
00498 {
00499   return this->sub_view(Range1D(l,u));
00500 }
00501 
00502 } // end namespace AbstractLinAlgPack
00503 
00504 #endif  // ALAP_VECTOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends