33 #ifndef __H__LIB_ALGEBRA__OPERATOR__CONVERGENCE_CHECK_IMPL__
34 #define __H__LIB_ALGEBRA__OPERATOR__CONVERGENCE_CHECK_IMPL__
48 template <
typename TVector>
51 : m_initialDefect(0.0), m_currentDefect(0.0), m_lastDefect(0.0), m_currentStep(0),
52 m_ratesProduct(1), m_maxSteps(200), m_minDefect(10e-8), m_relReduction(10e-10),
53 m_verbose(true), m_offset(0), m_symbol(
'%'), m_name(
"Iteration"), m_info(
""),
54 m_supress_unsuccessful(false)
57 template <
typename TVector>
60 : m_initialDefect(0.0), m_currentDefect(0.0), m_lastDefect(0.0), m_currentStep(0),
61 m_ratesProduct(1), m_maxSteps(maxSteps), m_minDefect(minDefect), m_relReduction(relReduction),
62 m_verbose(true), m_offset(0), m_symbol(
'%'), m_name(
"Iteration"), m_info(
""),
63 m_supress_unsuccessful(false)
66 template <
typename TVector>
69 : m_initialDefect(0.0), m_currentDefect(0.0), m_lastDefect(0.0), m_currentStep(0),
70 m_ratesProduct(1), m_maxSteps(maxSteps), m_minDefect(minDefect), m_relReduction(relReduction),
71 m_verbose(
verbose), m_offset(0), m_symbol(
'%'), m_name(
"Iteration"), m_info(
""),
72 m_supress_unsuccessful(false)
75 template <
typename TVector>
78 : m_initialDefect(0.0), m_currentDefect(0.0), m_lastDefect(0.0), m_currentStep(0),
79 m_ratesProduct(1), m_maxSteps(maxSteps), m_minDefect(minDefect), m_relReduction(relReduction),
80 m_verbose(
verbose), m_offset(0), m_symbol(
'%'), m_name(
"Iteration"), m_info(
""),
81 m_supress_unsuccessful(supressUnsuccessful)
84 template <
typename TVector>
88 m_initialDefect = initialDefect;
89 m_currentDefect = m_initialDefect;
99 int num_line_length = 50;
101 int max_length = std::max(m_name.length(), m_info.length());
102 int space_left = std::max(num_line_length - max_length - num_sym, 0);
107 int pre_space = (int)(max_length -(
int)m_name.length()) / 2;
109 UG_LOG(
" "<< m_name <<
" ");
110 UG_LOG(
repeat(
' ', max_length - pre_space -m_name.length()));
115 if(m_info.length() > 0)
118 UG_LOG(
" "<< m_info <<
" ");
127 print_offset();
UG_LOG(
" Iter Defect Rate \n");
128 print_offset();
UG_LOG(std::setw(4) << step() <<
": "
129 << std::scientific << defect() <<
" -------\n");
133 template <
typename TVector>
136 start_defect(d.norm());
139 template <
typename TVector>
142 m_lastDefect = m_currentDefect;
143 m_currentDefect = newDefect;
145 m_ratesProduct *= newDefect/m_lastDefect;
149 print_offset();
UG_LOG(std::setw(4) << step() <<
": " << std::scientific << defect() <<
150 " " << defect()/m_lastDefect <<
"\n");
151 _defects.push_back(defect());
155 template <
typename TVector>
158 update_defect(d.norm());
161 template <
typename TVector>
164 if(!is_valid_number(m_currentDefect))
return true;
165 if(step() >= m_maxSteps)
return true;
166 if(defect() < m_minDefect)
return true;
167 if(reduction() < m_relReduction)
return true;
171 template <
typename TVector>
174 bool success =
false;
176 if(defect() < m_minDefect)
180 print_offset();
UG_LOG(
"Absolute defect norm " << m_minDefect <<
" reached after " << step() <<
" steps.\n");
185 if(reduction() < m_relReduction)
189 print_offset();
UG_LOG(
"Relative reduction " << m_relReduction <<
" reached after " << step() <<
" steps.\n");
194 if (m_verbose && is_valid_number(m_currentDefect))
196 print_offset();
UG_LOG(
"Average reduction over " << step() <<
" steps: " << pow(reduction(), 1.0/step()) <<
"\n");
201 if (!is_valid_number(m_currentDefect))
204 print_offset();
UG_LOG(
"Current defect " << m_currentDefect <<
" is not a valid number.\n");
207 if(step() >= m_maxSteps){
210 print_offset();
UG_LOG(
"Maximum numbers of "<< m_maxSteps <<
" iterations reached without convergence.\n");
212 if (m_supress_unsuccessful)
return true;
220 if(success) {
UG_LOG(
" Iteration converged ");}
221 else {
UG_LOG(
" Iteration not successful ");}
228 template <
typename TVector>
238 template <
typename TVector>
246 template <
typename TVector>
253 if (value == 0.0)
return true;
254 else return (value >= std::numeric_limits<number>::min()
255 && value <= std::numeric_limits<number>::max()
256 && value == value && value >= 0.0);
location verbose
Definition: checkpoint_util.lua:128
bool is_valid_number(number value)
Definition: convergence_check_impl.h:247
void update_defect(number newDefect)
sets the update for the current defect
Definition: convergence_check_impl.h:140
void update(const TVector &d)
computes the defect and sets it a the next defect value
Definition: convergence_check_impl.h:156
void print_offset()
Definition: convergence_check_impl.h:229
StdConvCheck()
Definition: convergence_check_impl.h:50
void start(const TVector &d)
computes the start defect and set it
Definition: convergence_check_impl.h:134
bool iteration_ended()
Definition: convergence_check_impl.h:162
bool post()
Definition: convergence_check_impl.h:172
void print_line(std::string line)
prints a line
Definition: convergence_check_impl.h:239
void start_defect(number initialDefect)
sets the given start defect
Definition: convergence_check_impl.h:85
string repeat(char c, int nr)
Builds a string with specified repetitions of given character.
Definition: string_util.cpp:346
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124