include/meltpooldg/utilities/cell_monitor.hpp Source File

Developer Documentation: include/meltpooldg/utilities/cell_monitor.hpp Source File
Developer Documentation
cell_monitor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <deal.II/base/table_handler.h>
4
6
7#include <algorithm>
8#include <map>
9#include <string>
10
11namespace MeltPoolDG
12{
13 template <typename number>
15 {
16 public:
18 {
19 CellStatistics(const unsigned int n_cells = 0,
20 const number cell_size_min = 0,
21 const number cell_size_max = 0)
22 : n_calls(1)
23 , n_cells_averaged(static_cast<number>(n_cells))
24 , cells_min(n_cells)
25 , cells_max(n_cells)
28 {}
29
30 unsigned int n_calls;
32 unsigned int cells_min;
33 unsigned int cells_max;
34
37 };
38
39 static void
40 add_info(const std::string label,
41 const unsigned int n_cells,
42 const number min_cell_size,
43 const number max_cell_size)
44 {
45 const auto ptr = stat_cells.find(label);
46
47 if (ptr == stat_cells.end())
48 {
49 stat_cells[label] = CellStatistics(n_cells, min_cell_size, max_cell_size);
50 }
51 else
52 {
53 ptr->second.n_calls += 1;
54
55 const number n = static_cast<number>(ptr->second.n_calls);
56
57 ptr->second.n_cells_averaged +=
58 (static_cast<number>(n_cells) - ptr->second.n_cells_averaged) / n;
59
60 ptr->second.cells_min = std::min(ptr->second.cells_min, n_cells);
61 ptr->second.cells_max = std::max(ptr->second.cells_max, n_cells);
62
63 ptr->second.cell_size_min = std::min(ptr->second.cell_size_min, min_cell_size);
64
65 ptr->second.cell_size_max = std::max(ptr->second.cell_size_max, max_cell_size);
66 }
67 }
68
69 template <typename StreamType>
70 static void
71 print(StreamType &ss, const std::string &title)
72 {
73 dealii::TableHandler table;
74
75 for (const auto &entry : stat_cells)
76 {
77 table.add_value("label", entry.first);
78 table.add_value("no. calls", entry.second.n_calls);
79 table.add_value("n_cells avg", static_cast<number>(entry.second.n_cells_averaged));
80 table.set_precision("n_cells avg", 2);
81 table.add_value("n_cells min", entry.second.cells_min);
82 table.add_value("n_cells max", entry.second.cells_max);
83
84 table.add_value("cell size min", entry.second.cell_size_min);
85 table.add_value("cell size max", entry.second.cell_size_max);
86 table.set_scientific("cell size min", true);
87 table.set_scientific("cell size max", true);
88 }
89
90 if (ss.is_active())
91 Journal::print_table(ss, title, table);
92 }
93
94 static CellStatistics
95 get_statistics(const std::string &label)
96 {
97 const auto iterator = stat_cells.find(label);
98
99 AssertThrow(iterator != stat_cells.end(),
100 dealii::ExcMessage("Unknown CellMonitor label: " + label));
101
102 return iterator->second;
103 }
104
105 static void
107 {
108 stat_cells.clear();
109 }
110
111 static bool
113 {
114 return not stat_cells.empty();
115 }
116
117 private:
118 inline static std::map<std::string, CellStatistics> stat_cells;
119 };
120} // namespace MeltPoolDG
Definition cell_monitor.hpp:15
static void add_info(const std::string label, const unsigned int n_cells, const number min_cell_size, const number max_cell_size)
Definition cell_monitor.hpp:40
static std::map< std::string, CellStatistics > stat_cells
Definition cell_monitor.hpp:118
static void clear()
Definition cell_monitor.hpp:106
static void print(StreamType &ss, const std::string &title)
Definition cell_monitor.hpp:71
static CellStatistics get_statistics(const std::string &label)
Definition cell_monitor.hpp:95
static bool has_statistics()
Definition cell_monitor.hpp:112
void print_table(const ConditionalOStream &pcout, const std::string &title, const dealii::TableHandler &table)
Print a multi-line preconfigured table inside a single bordered box with a title row.
Definition journal.cpp:49
Interface for a general preconditioner.
Definition boundary_condition_functions.hpp:17
Definition cell_monitor.hpp:18
unsigned int cells_max
Definition cell_monitor.hpp:33
unsigned int n_calls
Definition cell_monitor.hpp:30
number cell_size_min
Definition cell_monitor.hpp:35
number n_cells_averaged
Definition cell_monitor.hpp:31
CellStatistics(const unsigned int n_cells=0, const number cell_size_min=0, const number cell_size_max=0)
Definition cell_monitor.hpp:19
number cell_size_max
Definition cell_monitor.hpp:36
unsigned int cells_min
Definition cell_monitor.hpp:32