include/meltpooldg/utilities/dof_monitor.hpp Source File

Developer Documentation: include/meltpooldg/utilities/dof_monitor.hpp Source File
Developer Documentation
dof_monitor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <deal.II/base/table_handler.h>
4
6
7namespace MeltPoolDG
8{
9 template <typename number>
11 {
12 private:
14 {
15 DoFStatistics(const unsigned int n_dofs = 0)
16 : n_calls(1)
17 , dofs_accumulated(n_dofs)
18 , dofs_min(n_dofs)
19 , dofs_max(n_dofs)
20 {}
21
22 unsigned int n_calls;
23 unsigned int dofs_accumulated;
24 unsigned int dofs_min;
25 unsigned int dofs_max;
26 };
27
28 public:
29 static void
30 add_n_dofs(const std::string label, const unsigned int n_dofs)
31 {
32 const auto ptr = stat_dofs.find(label);
33
34 if (ptr == stat_dofs.end())
35 {
36 stat_dofs[label] = DoFStatistics(n_dofs);
37 }
38 else
39 {
40 ptr->second.n_calls += 1;
41 ptr->second.dofs_accumulated += n_dofs;
42 ptr->second.dofs_min = std::min(ptr->second.dofs_min, n_dofs);
43 ptr->second.dofs_max = std::max(ptr->second.dofs_max, n_dofs);
44 }
45 }
46
47 template <typename StreamType>
48 static void
49 print(StreamType &ss, const std::string &title)
50 {
51 dealii::TableHandler table;
52
53 for (const auto &entry : stat_dofs)
54 {
55 table.add_value("label", entry.first);
56 table.add_value("no. calls", entry.second.n_calls);
57 table.add_value("n_dof avg",
58 static_cast<number>(entry.second.dofs_accumulated) /
59 entry.second.n_calls);
60 table.set_precision("n_dof avg", 2);
61 table.add_value("n_dof min", entry.second.dofs_min);
62 table.add_value("n_dof max", entry.second.dofs_max);
63 }
64
65 if (ss.is_active())
66 Journal::print_table(ss, title, table);
67 }
68
69 static bool
71 {
72 return not stat_dofs.empty();
73 }
74
75
76 private:
77 inline static std::map<std::string, DoFStatistics> stat_dofs;
78 };
79} // namespace MeltPoolDG
Definition dof_monitor.hpp:11
static std::map< std::string, DoFStatistics > stat_dofs
Definition dof_monitor.hpp:77
static bool has_statistics()
Definition dof_monitor.hpp:70
static void add_n_dofs(const std::string label, const unsigned int n_dofs)
Definition dof_monitor.hpp:30
static void print(StreamType &ss, const std::string &title)
Definition dof_monitor.hpp:49
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 dof_monitor.hpp:14
unsigned int n_calls
Definition dof_monitor.hpp:22
unsigned int dofs_max
Definition dof_monitor.hpp:25
unsigned int dofs_accumulated
Definition dof_monitor.hpp:23
DoFStatistics(const unsigned int n_dofs=0)
Definition dof_monitor.hpp:15
unsigned int dofs_min
Definition dof_monitor.hpp:24