MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
IterationPack::AlgorithmState Class Reference

Abstacts a set of iteration quantities for an iterative algorithm. More...

#include <IterationPack_AlgorithmState.hpp>

Inheritance diagram for IterationPack::AlgorithmState:
Inheritance graph
[legend]

Classes

class  AlreadyExists
 Thrown if name already exists. More...
 
class  DoesNotExist
 Thrown if name or id does not exist. More...
 

Public Member Functions

virtual ~AlgorithmState ()
 

Private Types

typedef std::vector< IQ_ptriq_t
 
typedef std::map< std::string,
iq_id_type
iq_name_to_id_t
 

Private Member Functions

iq_name_to_id_t::iterator find_and_assert (const std::string &iq_name)
 
iq_name_to_id_t::const_iterator find_and_assert (const std::string &iq_name) const
 

Private Attributes

int k_
 
iq_t iq_
 
IterQuantityiteration_quantities
 
iq_name_to_id_t iq_name_to_id_
 

Public types

enum  { DOES_NOT_EXIST = INT_MAX }
 
typedef size_t iq_id_type
 
typedef Teuchos::RCP
< IterQuantity
IQ_ptr
 

Constructors

 AlgorithmState (size_t reserve_size=0)
 Construct with an initial guess for the number of iteration quantities. More...
 

Iteration counter

void k (int k)
 
int k () const
 
int incr_k ()
 

Iteration quantity setup

virtual size_t num_iter_quant () const
 Return the number of iteration quantities. More...
 
virtual iq_id_type set_iter_quant (const std::string &iq_name, const IQ_ptr &iq)
 Inserts the iteration quantity through a RCP<...> object. More...
 
virtual void erase_iter_quant (const std::string &iq_name)
 Removes the iteration quantity with name iq_name. More...
 
virtual iq_id_type get_iter_quant_id (const std::string &iq_name) const
 Return the iteration quantity id (iq_id) for the iteration quantity. More...
 
virtual IQ_ptrget_iter_quant (iq_id_type iq_id)
 Returns the RCP<...> for the iteration quantiy with iq_id. More...
 
virtual const IQ_ptrget_iter_quant (iq_id_type iq_id) const
 

Iteration quantity access

virtual IterQuantityiter_quant (const std::string &iq_name)
 Iteration quantity encapsulation object access with via iq_name. More...
 
virtual const IterQuantityiter_quant (const std::string &iq_name) const
 
virtual IterQuantityiter_quant (iq_id_type iq_id)
 Iteration quantity encapsulation object access via iq_id. More...
 
virtual const IterQuantityiter_quant (iq_id_type iq_id) const
 

Iteration incrementation

virtual void next_iteration (bool incr_k=true)
 iteration quantity forwarding. More...
 

Miscellaneous

virtual void dump_iter_quant (std::ostream &out) const
 iteration quantity information dumping. More...
 

Detailed Description

Abstacts a set of iteration quantities for an iterative algorithm.

This object encapsulates a set of iteration quantity access objects. The concrete types of the IterQuantity objects are expected to be subclasses of IterQuantityAccess. It is therefore up the the clients to determine the concrete types of these iteration quantity access objects and to use dynamic_cast<...> (or static_cast<...> if you are sure) to access the IterQuantityAccess<...> object and therefore the iteration quantities themselves. Each iteration quantity (IQ) access object must have a unique name associated with it. IQ objects are given to the state object by clients through the set_iter_quant() method at which point the IQ object will be given a unique id that will never change change until the IQ object is removed using erase_iter_quant(). Memory management is performed using the Teuchos::RCP smart reference counting poiner class. The id of any IQ object (iq_id) can be obtained from its name by calling iq_id = get_iter_quant_id(iq_name). If an IQ object with the name iq_name does not exist then get_iter_quant_id(iq_name) will return DOES_NOT_EXIST. The IQ objects themselves can be accesed in O(log(num_iter_quant())) time using iter_quant(iq_name) or in O(1) time using iter_quant(iq_id). Therefore, the access of IQ objects using iq_id is an optimization for faster access and the client should never have to lookup iq_name given iq_id. The mapping only works from iq_name to iq_id, not the other way around. It is guaranteed that as long as erase_iter_quant(iq_id) is not called that each iq_id that &iter_quant(iq_id) == &iter_quant( get_iter_quant(iq_name) ) will true. For iq_name, if get_iter_quant_id(iq_name) == DOES_NOT_EXIST then iter_quant(iq_name) will throw the exception DoesNotExist.

The next_iteration() operation is called by the algorithm to call next_iteration() on each of the IQ objects.

The dump_iter_quant(out) operation prints out a list of all of the IQ objects of thier iq_name, iq_name and concrete type.

The default copy constructor, and assignment operator functions are allowed since they have the proper semantics.

Definition at line 93 of file IterationPack_AlgorithmState.hpp.

Member Typedef Documentation

Definition at line 100 of file IterationPack_AlgorithmState.hpp.

Definition at line 102 of file IterationPack_AlgorithmState.hpp.

typedef std::vector<IQ_ptr> IterationPack::AlgorithmState::iq_t
private

Definition at line 259 of file IterationPack_AlgorithmState.hpp.

typedef std::map<std::string,iq_id_type> IterationPack::AlgorithmState::iq_name_to_id_t
private

Definition at line 260 of file IterationPack_AlgorithmState.hpp.

Member Enumeration Documentation

anonymous enum

Enumerator
DOES_NOT_EXIST 

Definition at line 104 of file IterationPack_AlgorithmState.hpp.

Constructor & Destructor Documentation

virtual IterationPack::AlgorithmState::~AlgorithmState ( )
inlinevirtual

Definition at line 117 of file IterationPack_AlgorithmState.hpp.

IterationPack::AlgorithmState::AlgorithmState ( size_t  reserve_size = 0)
inlineexplicit

Construct with an initial guess for the number of iteration quantities.

The iteration counter k is default constructed to zero.

Definition at line 297 of file IterationPack_AlgorithmState.hpp.

Member Function Documentation

void IterationPack::AlgorithmState::k ( int  k)
inline

Definition at line 304 of file IterationPack_AlgorithmState.hpp.

int IterationPack::AlgorithmState::k ( ) const
inline

Definition at line 308 of file IterationPack_AlgorithmState.hpp.

int IterationPack::AlgorithmState::incr_k ( )
inline

Definition at line 312 of file IterationPack_AlgorithmState.hpp.

size_t IterationPack::AlgorithmState::num_iter_quant ( ) const
inlinevirtual

Return the number of iteration quantities.

Definition at line 318 of file IterationPack_AlgorithmState.hpp.

AlgorithmState::iq_id_type IterationPack::AlgorithmState::set_iter_quant ( const std::string &  iq_name,
const IQ_ptr iq 
)
virtual

Inserts the iteration quantity through a RCP<...> object.

Time = O(log(num_iter_quant)), Space = O(1).

If an iteration quantity already exists with the name iq_name then a AlreadyExists exception will be thrown. Otherwise the function will return the iq_id assigned to the inserted interation quantity.

Preconditions:

  • iq.get() != NULL (thorw std::invalid_argument)
  • get_iter_quant_id(iq_name) == DOES_NOT_EXIST (throw AlreadyExists)

Definition at line 61 of file IterationPack_AlgorithmState.cpp.

void IterationPack::AlgorithmState::erase_iter_quant ( const std::string &  iq_name)
virtual

Removes the iteration quantity with name iq_name.

Time = O(log(num_iter_quant)), Space = O(1).

If get_iter_quant(iq_name).count() == 1 then the IterQuantity object pointed to will be deleted. Subsequently, the iq_id returned from set_iter_quant(...) when iq_name was set is no longer valid.

Preconditions:

  • get_iter_quant_id(iq_name) != DOES_NOT_EXIST (throw DoesNotExist)

Definition at line 80 of file IterationPack_AlgorithmState.cpp.

AlgorithmState::iq_id_type IterationPack::AlgorithmState::get_iter_quant_id ( const std::string &  iq_name) const
inlinevirtual

Return the iteration quantity id (iq_id) for the iteration quantity.

If an iteration quantity with the name iq_name does not exist, then the value DOES_NOT_EXIST is returned.

Time = O(log(num_iter_quant)), Space = O(1).

Definition at line 323 of file IterationPack_AlgorithmState.hpp.

AlgorithmState::IQ_ptr & IterationPack::AlgorithmState::get_iter_quant ( iq_id_type  iq_id)
inlinevirtual

Returns the RCP<...> for the iteration quantiy with iq_id.

If this iq_id does not correspond to a valid iteration quantity object then a DoesNotExist exception will be thrown. If iq_id was returned from get_iter_quant_id(iq_name), this iq_id may become invalid if a client called erase_iter_quant(iq_name) in the mean time.

Time = O(1), Space = O(1).

Definition at line 331 of file IterationPack_AlgorithmState.hpp.

const AlgorithmState::IQ_ptr & IterationPack::AlgorithmState::get_iter_quant ( iq_id_type  iq_id) const
inlinevirtual

Definition at line 336 of file IterationPack_AlgorithmState.hpp.

IterQuantity & IterationPack::AlgorithmState::iter_quant ( const std::string &  iq_name)
inlinevirtual

Iteration quantity encapsulation object access with via iq_name.

Time = O(log(num_iter_quant())), Space = O(1).

Preconditions:

  • get_iter_quant_id(iq_name) != DOES_NOT_EXIST (throw DoesNotExist)

Definition at line 343 of file IterationPack_AlgorithmState.hpp.

const IterQuantity & IterationPack::AlgorithmState::iter_quant ( const std::string &  iq_name) const
inlinevirtual

Definition at line 348 of file IterationPack_AlgorithmState.hpp.

IterQuantity & IterationPack::AlgorithmState::iter_quant ( iq_id_type  iq_id)
virtual

Iteration quantity encapsulation object access via iq_id.

Time = O(1), Space = O(1).

If the IQ object with iq_id does not exist then a DoesNotExist exception will be thrown.

Definition at line 87 of file IterationPack_AlgorithmState.cpp.

const IterQuantity & IterationPack::AlgorithmState::iter_quant ( iq_id_type  iq_id) const
virtual

Definition at line 112 of file IterationPack_AlgorithmState.cpp.

void IterationPack::AlgorithmState::next_iteration ( bool  incr_k = true)
virtual

iteration quantity forwarding.

Definition at line 116 of file IterationPack_AlgorithmState.cpp.

void IterationPack::AlgorithmState::dump_iter_quant ( std::ostream &  out) const
virtual

iteration quantity information dumping.

This function outputs a list with columns:

iq_name iq_id concrete type

for each iteration quantity object.

Definition at line 122 of file IterationPack_AlgorithmState.cpp.

AlgorithmState::iq_name_to_id_t::iterator IterationPack::AlgorithmState::find_and_assert ( const std::string &  iq_name)
private

Definition at line 162 of file IterationPack_AlgorithmState.cpp.

AlgorithmState::iq_name_to_id_t::const_iterator IterationPack::AlgorithmState::find_and_assert ( const std::string &  iq_name) const
private

Definition at line 174 of file IterationPack_AlgorithmState.cpp.

Member Data Documentation

int IterationPack::AlgorithmState::k_
private

Definition at line 265 of file IterationPack_AlgorithmState.hpp.

iq_t IterationPack::AlgorithmState::iq_
private

Definition at line 267 of file IterationPack_AlgorithmState.hpp.

IterQuantity* IterationPack::AlgorithmState::iteration_quantities
private

Definition at line 277 of file IterationPack_AlgorithmState.hpp.

iq_name_to_id_t IterationPack::AlgorithmState::iq_name_to_id_
private

Definition at line 280 of file IterationPack_AlgorithmState.hpp.


The documentation for this class was generated from the following files: