IterationPack_IterQuantityAccessContiguousDecl.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 // Change Log:
00030 //  11/18/99:
00031 //    * last_updated() Added
00032 //    * set_not_updated(k) Added
00033 //    * resize(n) Added
00034 //    * Lazy initialization implemented.
00035 //  12/20/01:
00036 //      * AbstractFactory added to handle memory management
00037 
00038 #ifndef ITER_QUANITY_ACCESS_CONTIGUOUS_DECL_H
00039 #define ITER_QUANITY_ACCESS_CONTIGUOUS_DECL_H
00040 
00041 #include <vector>
00042 #include <limits>
00043 
00044 #include "IterationPack_IterQuantityAccess.hpp"
00045 #include "Teuchos_AbstractFactoryStd.hpp"
00046 
00047 namespace IterationPack {
00048 
00049 // ToDo: Use an implementation subclass for the operations to avoid code blot.
00050 
00072 template<class T_info>
00073 class IterQuantityAccessContiguous : public IterQuantityAccess<T_info> {
00074 public:
00075 
00077   typedef IterQuantityAccess<T_info> base_t;
00078 
00080   typedef Teuchos::RCP<
00081     const Teuchos::AbstractFactory<T_info> >          abstract_factory_ptr_t;
00083   typedef Teuchos::AbstractFactoryStd<T_info,T_info>    abstract_factory_std_t;
00084 
00087 
00101   IterQuantityAccessContiguous(
00102     int                              num_quantities
00103     ,const std::string&              name
00104 #ifdef _MIPS_CXX // MipsPro 7.3.1.1 tries to instantiate the default type even when one is specified?
00105     ,const abstract_factory_ptr_t&   abstract_factory
00106 #else
00107     ,const abstract_factory_ptr_t&   abstract_factory  = Teuchos::rcp(new abstract_factory_std_t())
00108 #endif
00109     );
00110 
00121   void set_factory( const abstract_factory_ptr_t& abstract_factory );
00122 
00129   void resize( int num_quantities );
00130 
00132   ~IterQuantityAccessContiguous();
00133 
00135 
00138 
00140   int num_quantities() const;
00141 
00143 
00146 
00148   IterQuantity* clone() const;
00150   const char* name() const; 
00152   bool has_storage_k(int offset) const;
00154   bool updated_k(int offset) const;
00156   int last_updated() const;
00158   void set_not_updated_k(int offset);
00160   void set_all_not_updated();
00162   bool will_loose_mem(int offset, int set_offset) const;
00164   void next_iteration();
00166   void print_concrete_type( std::ostream& out ) const;
00167 
00169 
00172 
00174   T_info& get_k(int offset);
00176   const T_info& get_k(int offset) const;
00178   T_info& set_k(int offset);
00180   T_info& set_k(int set_offset, int get_offset);
00181 
00183 
00184 private:
00185 
00186   // ///////////////////////////////////////////////
00187   // Private types
00188 
00189   //
00190   typedef std::vector<bool>                                                       updated_t;
00191   //
00192   typedef std::vector<typename abstract_factory_ptr_t::element_type::obj_ptr_t>   store_t;
00193   //
00194   typedef std::vector<T_info*>                                                    quantities_t;
00195 
00196   // ///////////////////////////////////////////////
00197   // Private data members
00198 
00199   // number of contigous iterations memory is reserved for.
00200   int num_quantities_;
00201   // The name of the quantity (useful for debugging)
00202   std::string name_;
00203   // The abstract factory used to create the objects themselves
00204   abstract_factory_ptr_t   abstract_factory_;
00205   // The highest offset for iteration we are providing storage for.  We are providing
00206   // storage for iterations:
00207   //   [ k + max_offset_, k + max_offset_ - 1, ..., k + max_offset_ - num_quanities_ + 1 ].
00208   // For max_offset_ == 1 and num_quantities_  == 3:  [ k+1, k, k-1 ].
00209   int max_offset_;  
00210   // Flags for if the iteration quanity was updated.
00211   //    updated_[max_offset - offset]
00212   //        for offset = max_offset, max_offset - 1, ..., max_offset_ - num_quanities_ + 1
00213   // returns true if and only if the quantity (k + offset) has been updated.
00214   updated_t     updated_;
00215   // Storage vector for the iteration quantities
00216   store_t       store_;
00217   // The vector of pointers to the storage quantities
00218   quantities_t  quantities_;
00219 
00220   // ///////////////////////////////////////////////
00221   // Private member functions
00222 
00223   // Returns true if storage is initialized and false otherwise.
00224   bool is_initialized() const;
00225 
00226   // Called to make sure that we are initialized before a
00227   // nonconst operation is performed.
00228   void lazy_initialization();
00229 
00230   // Called to release current memory
00231   void release_mem();
00232 
00233   // Not defined and not to be called
00234   IterQuantityAccessContiguous();
00235   IterQuantityAccessContiguous(const IterQuantityAccessContiguous&);
00236   IterQuantityAccessContiguous& operator=(const IterQuantityAccessContiguous&);
00237 
00238 };  // end class IterQuantityAccessContiguous
00239 
00240 // /////////////////////////////////////////////////////////////
00241 // Inline members
00242 
00243 template <class T_info>
00244 inline
00245 int IterQuantityAccessContiguous<T_info>::num_quantities() const
00246 { 
00247   return num_quantities_; 
00248 }
00249 
00250 } // end namespace IterationPack
00251 
00252 #endif  // ITER_QUANITY_ACCESS_CONTIGUOUS_DECL_H

Generated on Wed May 12 21:50:28 2010 for IterationPack: General framework for building iterative algorithms by  doxygen 1.4.7