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/convergence_table.h>
4#include <deal.II/base/table_handler.h>
5
6#include <algorithm>
7#include <map>
8#include <string>
9
10namespace MeltPoolDG
11{
12 template <typename number>
14 {
15 public:
17 {
18 CellStatistics(const unsigned int n_cells = 0,
19 const number cell_size_min = 0,
20 const number cell_size_max = 0)
21 : n_calls(1)
22 , n_cells_averaged(static_cast<number>(n_cells))
23 , cells_min(n_cells)
24 , cells_max(n_cells)
27 {}
28
29 unsigned int n_calls;
31 unsigned int cells_min;
32 unsigned int cells_max;
33
36 };
37
38 static void
39 add_info(const std::string label,
40 const unsigned int n_cells,
41 const number min_cell_size,
42 const number max_cell_size)
43 {
44 const auto ptr = stat_cells.find(label);
45
46 if (ptr == stat_cells.end())
47 {
48 stat_cells[label] = CellStatistics(n_cells, min_cell_size, max_cell_size);
49 }
50 else
51 {
52 ptr->second.n_calls += 1;
53
54 const number n = static_cast<number>(ptr->second.n_calls);
55
56 ptr->second.n_cells_averaged +=
57 (static_cast<number>(n_cells) - ptr->second.n_cells_averaged) / n;
58
59 ptr->second.cells_min = std::min(ptr->second.cells_min, n_cells);
60 ptr->second.cells_max = std::max(ptr->second.cells_max, n_cells);
61
62 ptr->second.cell_size_min = std::min(ptr->second.cell_size_min, min_cell_size);
63
64 ptr->second.cell_size_max = std::max(ptr->second.cell_size_max, max_cell_size);
65 }
66 }
67
68 template <typename StreamType>
69 static void
70 print(StreamType &ss)
71 {
72 dealii::ConvergenceTable table;
73
74 for (const auto &entry : stat_cells)
75 {
76 table.add_value("label", entry.first);
77 table.add_value("no. calls", entry.second.n_calls);
78 table.add_value("n_cells avg", static_cast<number>(entry.second.n_cells_averaged));
79 table.set_precision("n_cells avg", 2);
80 table.add_value("n_cells min", entry.second.cells_min);
81 table.add_value("n_cells max", entry.second.cells_max);
82
83 table.add_value("cell size min", entry.second.cell_size_min);
84 table.add_value("cell size max", entry.second.cell_size_max);
85 table.set_scientific("cell size min", 4);
86 table.set_scientific("cell size max", 4);
87 }
88
89 if (ss.is_active())
90 table.write_text(ss.get_stream(), dealii::TableHandler::TextOutputFormat::org_mode_table);
91 }
92
93 static CellStatistics
94 get_statistics(const std::string &label)
95 {
96 const auto iterator = stat_cells.find(label);
97
98 AssertThrow(iterator != stat_cells.end(),
99 dealii::ExcMessage("Unknown CellMonitor label: " + label));
100
101 return iterator->second;
102 }
103
104 static void
106 {
107 stat_cells.clear();
108 }
109
110 private:
111 inline static std::map<std::string, CellStatistics> stat_cells;
112 };
113} // namespace MeltPoolDG
Definition cell_monitor.hpp:14
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:39
static void print(StreamType &ss)
Definition cell_monitor.hpp:70
static std::map< std::string, CellStatistics > stat_cells
Definition cell_monitor.hpp:111
static void clear()
Definition cell_monitor.hpp:105
static CellStatistics get_statistics(const std::string &label)
Definition cell_monitor.hpp:94
Interface for a general preconditioner.
Definition boundary_condition_functions.hpp:17
Definition cell_monitor.hpp:17
unsigned int cells_max
Definition cell_monitor.hpp:32
unsigned int n_calls
Definition cell_monitor.hpp:29
number cell_size_min
Definition cell_monitor.hpp:34
number n_cells_averaged
Definition cell_monitor.hpp:30
CellStatistics(const unsigned int n_cells=0, const number cell_size_min=0, const number cell_size_max=0)
Definition cell_monitor.hpp:18
number cell_size_max
Definition cell_monitor.hpp:35
unsigned int cells_min
Definition cell_monitor.hpp:31