IterationPack: General framework for building iterative algorithms  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IterationPack_IterQuantityAccessContiguousDecl.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 //
42 // Change Log:
43 // 11/18/99:
44 // * last_updated() Added
45 // * set_not_updated(k) Added
46 // * resize(n) Added
47 // * Lazy initialization implemented.
48 // 12/20/01:
49 // * AbstractFactory added to handle memory management
50 
51 #ifndef ITER_QUANITY_ACCESS_CONTIGUOUS_DECL_H
52 #define ITER_QUANITY_ACCESS_CONTIGUOUS_DECL_H
53 
54 #include <vector>
55 #include <limits>
56 
57 #include "IterationPack_IterQuantityAccess.hpp"
58 #include "Teuchos_AbstractFactoryStd.hpp"
59 
60 namespace IterationPack {
61 
62 // ToDo: Use an implementation subclass for the operations to avoid code blot.
63 
85 template<class T_info>
87 public:
88 
91 
93  typedef Teuchos::RCP<
97 
100 
115  int num_quantities
116  ,const std::string& name
117 #ifdef _MIPS_CXX // MipsPro 7.3.1.1 tries to instantiate the default type even when one is specified?
118  ,const abstract_factory_ptr_t& abstract_factory
119 #else
120  ,const abstract_factory_ptr_t& abstract_factory = Teuchos::rcp(new abstract_factory_std_t())
121 #endif
122  );
123 
134  void set_factory( const abstract_factory_ptr_t& abstract_factory );
135 
142  void resize( int num_quantities );
143 
146 
148 
151 
153  int num_quantities() const;
154 
156 
159 
161  IterQuantity* clone() const;
163  const char* name() const;
165  bool has_storage_k(int offset) const;
167  bool updated_k(int offset) const;
169  int last_updated() const;
171  void set_not_updated_k(int offset);
173  void set_all_not_updated();
175  bool will_loose_mem(int offset, int set_offset) const;
177  void next_iteration();
179  void print_concrete_type( std::ostream& out ) const;
180 
182 
185 
187  T_info& get_k(int offset);
189  const T_info& get_k(int offset) const;
191  T_info& set_k(int offset);
193  T_info& set_k(int set_offset, int get_offset);
194 
196 
197 private:
198 
199  // ///////////////////////////////////////////////
200  // Private types
201 
202  //
203  typedef std::vector<bool> updated_t;
204  //
205  typedef std::vector<typename abstract_factory_ptr_t::element_type::obj_ptr_t> store_t;
206  //
207  typedef std::vector<T_info*> quantities_t;
208 
209  // ///////////////////////////////////////////////
210  // Private data members
211 
212  // number of contigous iterations memory is reserved for.
213  int num_quantities_;
214  // The name of the quantity (useful for debugging)
215  std::string name_;
216  // The abstract factory used to create the objects themselves
217  abstract_factory_ptr_t abstract_factory_;
218  // The highest offset for iteration we are providing storage for. We are providing
219  // storage for iterations:
220  // [ k + max_offset_, k + max_offset_ - 1, ..., k + max_offset_ - num_quanities_ + 1 ].
221  // For max_offset_ == 1 and num_quantities_ == 3: [ k+1, k, k-1 ].
222  int max_offset_;
223  // Flags for if the iteration quanity was updated.
224  // updated_[max_offset - offset]
225  // for offset = max_offset, max_offset - 1, ..., max_offset_ - num_quanities_ + 1
226  // returns true if and only if the quantity (k + offset) has been updated.
227  updated_t updated_;
228  // Storage vector for the iteration quantities
229  store_t store_;
230  // The vector of pointers to the storage quantities
231  quantities_t quantities_;
232 
233  // ///////////////////////////////////////////////
234  // Private member functions
235 
236  // Returns true if storage is initialized and false otherwise.
237  bool is_initialized() const;
238 
239  // Called to make sure that we are initialized before a
240  // nonconst operation is performed.
241  void lazy_initialization();
242 
243  // Called to release current memory
244  void release_mem();
245 
246  // Not defined and not to be called
250 
251 }; // end class IterQuantityAccessContiguous
252 
253 // /////////////////////////////////////////////////////////////
254 // Inline members
255 
256 template <class T_info>
257 inline
259 {
260  return num_quantities_;
261 }
262 
263 } // end namespace IterationPack
264 
265 #endif // ITER_QUANITY_ACCESS_CONTIGUOUS_DECL_H
void resize(int num_quantities)
Resize the number of contiguous storage locations.
Interface to typed iteration quantities.
int num_quantities() const
Return the number of continous storage locations.
void set_factory(const abstract_factory_ptr_t &abstract_factory)
Set the abstract factory to use to allocate storate.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Iterface for information about Iteration Quantities.
Iteration Quanities subclass for contiguous iterations.
Teuchos::AbstractFactoryStd< T_info, T_info > abstract_factory_std_t
Teuchos::RCP< const Teuchos::AbstractFactory< T_info > > abstract_factory_ptr_t