33 #ifndef __H__UG_mg_stats_impl
34 #define __H__UG_mg_stats_impl
41 template <
typename TDomain,
typename TAlgebra>
47 m_filenamePrefix(
"mgstats"),
49 m_writeErrVecs(false),
50 m_writeErrDiffs(false)
57 template <
typename TDomain,
typename TAlgebra>
61 m_exitOnError = exitOnError;
65 template <
typename TDomain,
typename TAlgebra>
69 m_writeErrVecs = writeErrVecs;
72 template <
typename TDomain,
typename TAlgebra>
76 m_writeErrDiffs = writeErrDiffs;
79 template <
typename TDomain,
typename TAlgebra>
83 m_filenamePrefix = filename;
86 template <
typename TDomain,
typename TAlgebra>
90 for(
int i = 0; i < NUM_STAGES; ++i)
91 m_stageIsActive[i] =
false;
93 for(
size_t i = 0; i < activeStages.size(); ++i){
94 if(activeStages[i] >= 0 && (
int)activeStages[i] < NUM_STAGES)
95 m_stageIsActive[activeStages[i]] =
true;
98 m_stageIsActive[INVALID] =
false;
101 template <
typename TDomain,
typename TAlgebra>
105 std::string filename =
mkstr(m_filenamePrefix <<
".log");
106 save_stats_to_file(filename.c_str());
109 template <
typename TDomain,
typename TAlgebra>
117 std::ofstream out(filename);
118 UG_COND_THROW(!out,
"MGStats: Couldn't open '" << filename <<
"' for writing.");
119 out << m_stats << std::endl;
127 template <
typename TDomain,
typename TAlgebra>
131 UG_LOG(m_stats << std::endl);
134 template <
typename TDomain,
typename TAlgebra>
142 template <
typename TDomain,
typename TAlgebra>
149 if(!m_stageIsActive[stage])
155 if(stage == INVALID){
168 if(stage <= fe.stage && lvl >= m_lastLvlWritten){
170 m_lastLvlWritten = -1;
173 UG_LOG(
" >>> mg-stats row: " << m_statsRow << std::endl);
178 const int r = m_statsRow;
180 m_lastLvlWritten = lvl;
183 m_stats(r, 0) =
mkstr(r);
184 m_stats(r, 1) = stage_norm_name(stage);
191 const number norm = newFunc.norm();
192 m_stats(r, 2 + m_maxLvl - lvl) =
mkstr(norm);
194 if((fe.
stage < stage) && (norm > fe.
norm)){
197 std::string filename;
200 filename =
mkstr(m_filenamePrefix <<
"-row-" << r <<
"-lvl-"
201 << lvl <<
"--" << fe.
stage <<
"-"
202 << stage_name(fe.
stage) <<
".vec");
207 filename =
mkstr(m_filenamePrefix <<
"-row-" << r <<
"-lvl-"
208 << lvl <<
"--" << stage <<
"-"
209 << stage_name(stage) <<
".vec");
215 filename =
mkstr(m_filenamePrefix <<
"-row-" << r <<
"-lvl-"
216 << lvl <<
"-diff--" << stage <<
"-"
217 << stage_name(fe.
stage) <<
"-"
218 << stage_name(stage) <<
".vec");
223 mkstr(
"MGStats: Defect deteriorated on level " << lvl
224 <<
" between stages '" << stage_name(fe.
stage) <<
"' and '"
225 << stage_name(stage) <<
"'. (MGStats row: " << r <<
")");
228 save_stats_to_file();
233 UG_LOG(errMsg << std::endl);
246 template <
typename TDomain,
typename TAlgebra>
250 if((
int)m_funcs.size() <= lvl)
251 m_funcs.resize(lvl + 1);
255 template <
typename TDomain,
typename TAlgebra>
260 m_stats(m_statsRow, 0) =
"row";
261 m_stats(m_statsRow, 1) =
"stage";
262 for(
int i = 0; i < maxLvl; ++i){
263 m_stats(m_statsRow, i+2) =
mkstr(
"lvl " << maxLvl - i);
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:212
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
size_t num_indices() const
return the number of indices distributed (proc local)
Definition: grid_function.h:303
SmartPtr< this_type > clone_without_values() const
clone excluding values
Definition: grid_function.h:219
void set_exit_on_error(bool exitOnError)
If enabled, a deterioration of the norm of the defect leads to an error.
Definition: mg_stats_impl.hpp:59
void set_write_err_vecs(bool writeErrVecs)
If enabled, involved defects are written to file if the defect deteriorates.
Definition: mg_stats_impl.hpp:67
void save_stats_to_file()
saves current stats to filenamePrefix.log
Definition: mg_stats_impl.hpp:103
void clear()
clears the current stats
Definition: mg_stats_impl.hpp:136
void set_active_stages(const std::vector< int > &activeStages)
sets the active stages. All other stages will be ignored.
Definition: mg_stats_impl.hpp:88
MGStats()
Definition: mg_stats_impl.hpp:43
void level_required(int lvl)
Definition: mg_stats_impl.hpp:248
void write_header(int maxLvl)
Definition: mg_stats_impl.hpp:257
Stage
Defines at which stage data is recorded in a given multigrid cycle.
Definition: mg_stats.h:51
@ INVALID
Definition: mg_stats.h:56
static const int NUM_STAGES
Definition: mg_stats.h:59
void set_defect(grid_func_t &gf, int lvl, Stage stage)
set the defect on a certain level for a given stage
Definition: mg_stats_impl.hpp:144
bool m_stageIsActive[NUM_STAGES]
Definition: mg_stats.h:143
void set_filename_prefix(const char *filename)
sets the prefix with which files are written
Definition: mg_stats_impl.hpp:81
void set_write_err_diffs(bool writeErrDiffs)
If enabled, a diff bettween defects involved is written to file if the defect deteriorates.
Definition: mg_stats_impl.hpp:74
void print()
prints the current stats
Definition: mg_stats_impl.hpp:129
int ProcRank()
returns the rank of the process
Definition: pcl_base.cpp:83
function table print(data, style)
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
void SaveVectorForConnectionViewer(TGridFunction &b, const char *filename)
Definition: grid_function_util.h:828
void SaveVectorDiffForConnectionViewer(TGridFunction &b, TGridFunction &bCompare, const char *filename)
Definition: grid_function_util.h:833
#define mkstr(s)
Comfortable (but not necessarily efficient) string building.
Definition: stringify.h:100
Definition: mg_stats.h:134
number norm
Definition: mg_stats.h:139
Stage stage
Definition: mg_stats.h:138
sp_grid_func_t func
Definition: mg_stats.h:136
sp_grid_func_t tmpFunc
Definition: mg_stats.h:137