46 #include "IterationPack_AlgorithmState.hpp"
47 #include "Teuchos_Assert.hpp"
53 T my_max(
const T& v1,
const T& v2 ) {
return v1 > v2 ? v1 : v2; }
55 inline void output_spaces(std::ostream& out,
int spaces)
56 {
for(
int i = 0; i < spaces; ++i) out <<
' '; }
59 namespace IterationPack {
62 const std::string& iq_name,
const IQ_ptr& iq)
65 iq.
get() == NULL, std::invalid_argument
66 ,
"AlgorithmState::set_iter_quant(...) : The iteration quantity witht the name = \'" << iq_name
67 <<
"\' being inserted has iq.get() == NULL!" );
69 std::pair<iq_name_to_id_t::iterator,bool>
70 r = iq_name_to_id_.insert(iq_name_to_id_t::value_type(iq_name,new_id));
74 ,
"AlgorithmState::set_iter_quant(...) : An iteration quantity with the name \""
75 << iq_name <<
"\" already exists with the iq_id = " << (*r.first).second );
81 iq_name_to_id_t::iterator itr = find_and_assert(iq_name);
83 iq_[iq_id] = Teuchos::null;
84 iq_name_to_id_.erase( itr );
90 IQ_ptr &_iq = iq_.at(iq_id);
96 catch(
const std::out_of_range& excpt) {
99 catch(
const std::range_error& excpt) {
104 ,
"AlgorithmState::iter_quant(iq_id) : Error, the iteration quantity iq_id = "
105 << iq_id <<
" does not exist. "
106 << ( iq_id < iq_.size()
107 ?
"This iteration quantity was set and then erased."
108 :
"This iteration quantity was never set by the client." ) );
117 if(incr_k) this->
incr_k();
118 for(iq_t::iterator itr = iq_.begin(); itr != iq_.end(); ++itr)
119 if(itr->get()) (*itr)->next_iteration();
128 {
for( iq_name_to_id_t::const_iterator itr = iq_name_to_id_.begin();
129 itr != iq_name_to_id_.end(); ++itr )
131 name_w_max = my_max( (
int)name_w_max, (
int)(*itr).first.length() );
134 const int name_w = name_w_max + 4, id_w = 6;
135 const char gap[] =
" ";
138 << std::left << setw(name_w) <<
"iq_name"
139 << std::right << setw(id_w) <<
"iq_id"
140 << gap << std::left <<
"concrete type of iq / concrete type of object\n";
142 out << std::left << setw(name_w) <<
"-----"
143 << std::right << setw(id_w) <<
"------"
144 << gap << std::left <<
"---------------------------------------------\n";
146 {
for( iq_name_to_id_t::const_iterator itr = iq_name_to_id_.begin();
147 itr != iq_name_to_id_.end(); ++itr )
149 out << std::left << setw(name_w) << (*itr).first
150 << std::right << setw(id_w) << (*itr).second
151 << gap << std::left <<
typeName(*iq_[(*itr).second]) << endl
152 << std::left << setw(name_w) <<
""
153 << std::right << setw(id_w) <<
""
155 iq_[(*itr).second]->print_concrete_type(out);
162 AlgorithmState::iq_name_to_id_t::iterator AlgorithmState::find_and_assert(
163 const std::string& iq_name)
165 iq_name_to_id_t::iterator itr = iq_name_to_id_.find(iq_name);
166 if(itr == iq_name_to_id_.end())
169 ,
"AlgorithmState::find_and_assert(iq_name) : The iteration "
170 "quantity with the name \"" << iq_name <<
"\" does not exist" );
174 AlgorithmState::iq_name_to_id_t::const_iterator AlgorithmState::find_and_assert(
175 const std::string& iq_name)
const
177 iq_name_to_id_t::const_iterator itr = iq_name_to_id_.find(iq_name);
178 if(itr == iq_name_to_id_.end())
181 ,
"AlgorithmState::find_and_assert(iq_name) : The iteration "
182 "quantity with the name \"" << iq_name <<
"\" does not exist" );
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void erase_iter_quant(const std::string &iq_name)
Removes the iteration quantity with name iq_name.
Thrown if name or id does not exist.
virtual void dump_iter_quant(std::ostream &out) const
iteration quantity information dumping.
virtual iq_id_type set_iter_quant(const std::string &iq_name, const IQ_ptr &iq)
Inserts the iteration quantity through a RCP<...> object.
Iterface for information about Iteration Quantities.
virtual IterQuantity & iter_quant(const std::string &iq_name)
Iteration quantity encapsulation object access with via iq_name.
Abstacts a set of iteration quantities for an iterative algorithm.
Thrown if name already exists.
virtual void next_iteration(bool incr_k=true)
iteration quantity forwarding.
std::string typeName(const T &t)