ug4
mg_stats.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG_mg_stats
34 #define __H__UG_mg_stats
35 
36 #include <string>
37 #include <vector>
38 #include "common/util/table.h"
39 
40 namespace ug{
41 
43 template <typename TDomain, typename TAlgebra>
44 class MGStats {
45  public:
48 
49 
51  enum Stage {
56  INVALID // always last!
57  };
58 
59  static const int NUM_STAGES = INVALID + 1;
60 
61  MGStats();
62 
64 
65  void set_exit_on_error(bool exitOnError);
66 
68 
69  void set_write_err_vecs(bool writeErrVecs);
70 
72 
73  void set_write_err_diffs(bool writeErrDiffs);
74 
76 
80  void set_active_stages(const std::vector<int>& activeStages);
81 
83 
85  void set_filename_prefix(const char* filename);
86 
88  void save_stats_to_file();
89 
91  void save_stats_to_file(const char* filename);
92 
94  void print();
95 
97  void clear();
98 
100 
108  void set_defect(grid_func_t& gf, int lvl, Stage stage);
109 
111  const char* stage_name(Stage stage) {
112  const char* stageNames[] = { "BEFORE_PRE_SMOOTH",
113  "AFTER_PRE_SMOOTH",
114  "BEFORE_POST_SMOOTH",
115  "AFTER_POST_SMOOTH",
116  "INVALID"};
117  return stageNames[stage];
118  }
119 
121  const char* stage_norm_name(Stage stage) {
122  const char* stageNames[] = { "|bef pre smth|",
123  "|aft pre smth|",
124  "|bef post smth|",
125  "|aft post smth|",
126  "|INVALID|"};
127  return stageNames[stage];
128  }
129 
130  private:
131  void level_required(int lvl);
132  void write_header(int maxLvl);
133 
134  struct FuncEntry{
140  };
141 
142  std::vector<FuncEntry> m_funcs;
147  int m_maxLvl;
148  std::string m_filenamePrefix;
152 };
153 
154 
155 }// end of namespace
156 
158 // include implementation
159 #include "mg_stats_impl.hpp"
160 
161 
162 #endif //__H__UG_mg_stats
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
Records statistics on how individual parts of a multigrid method worked.
Definition: mg_stats.h:44
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
bool m_writeErrVecs
Definition: mg_stats.h:150
bool m_writeErrDiffs
Definition: mg_stats.h:151
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
std::vector< FuncEntry > m_funcs
Definition: mg_stats.h:142
MGStats()
Definition: mg_stats_impl.hpp:43
void level_required(int lvl)
Definition: mg_stats_impl.hpp:248
const char * stage_norm_name(Stage stage)
returns the name of the norm of a given stage as a string
Definition: mg_stats.h:121
GridFunction< TDomain, TAlgebra > grid_func_t
Definition: mg_stats.h:46
void write_header(int maxLvl)
Definition: mg_stats_impl.hpp:257
StringTable m_stats
Definition: mg_stats.h:144
Stage
Defines at which stage data is recorded in a given multigrid cycle.
Definition: mg_stats.h:51
@ AFTER_PRE_SMOOTH
Definition: mg_stats.h:53
@ BEFORE_PRE_SMOOTH
Definition: mg_stats.h:52
@ AFTER_POST_SMOOTH
Definition: mg_stats.h:55
@ INVALID
Definition: mg_stats.h:56
@ BEFORE_POST_SMOOTH
Definition: mg_stats.h:54
static const int NUM_STAGES
Definition: mg_stats.h:59
bool m_exitOnError
Definition: mg_stats.h:149
int m_maxLvl
Definition: mg_stats.h:147
int m_statsRow
Definition: mg_stats.h:145
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
SmartPtr< grid_func_t > sp_grid_func_t
Definition: mg_stats.h:47
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
const char * stage_name(Stage stage)
returns the name of a given stage as a string
Definition: mg_stats.h:111
int m_lastLvlWritten
Definition: mg_stats.h:146
std::string m_filenamePrefix
Definition: mg_stats.h:148
double number
Definition: types.h:124
the ug namespace
Definition: mg_stats.h:134
FuncEntry()
Definition: mg_stats.h:135
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