Chi-Tech
PostProcessorPrinter_xx_utils.cc
Go to the documentation of this file.
2
5
6#include "chi_runtime.h"
7#include "chi_log.h"
8
9#include <string>
10
11namespace chi
12{
13
14// ##################################################################
15std::vector<const PostProcessor*>
17{
18 std::vector<const PostProcessor*> scalar_pp_list;
19 for (const auto& pp : Chi::postprocessor_stack)
20 {
21 const auto& scope = pp->PrintScope();
22
23 // Check whether the pp wants to be printed on this event
24 if (std::find(scope.begin(), scope.end(), event.Name()) == scope.end())
25 continue;
26
27 if (pp->Type() == PPType::SCALAR) scalar_pp_list.push_back(&(*pp));
28 }
29
30 return scalar_pp_list;
31}
32
33// ##################################################################
34std::vector<const PostProcessor*>
36{
37 std::vector<const PostProcessor*> scalar_pp_list;
38 for (const auto& pp : Chi::postprocessor_stack)
39 {
40 const auto& scope = pp->PrintScope();
41
42 // Check whether the pp wants to be printed on this event
43 if (std::find(scope.begin(), scope.end(), event.Name()) == scope.end())
44 continue;
45
46 if (pp->Type() == PPType::VECTOR) scalar_pp_list.push_back(&(*pp));
47 }
48
49 return scalar_pp_list;
50}
51
52// ##################################################################
53std::vector<const PostProcessor*>
55{
56 std::vector<const PostProcessor*> scalar_pp_list;
57 for (const auto& pp : Chi::postprocessor_stack)
58 {
59 const auto& scope = pp->PrintScope();
60
61 // Check whether the pp wants to be printed on this event
62 if (std::find(scope.begin(), scope.end(), event.Name()) == scope.end())
63 continue;
64
65 if (pp->Type() == PPType::ARBITRARY) scalar_pp_list.push_back(&(*pp));
66 }
67
68 return scalar_pp_list;
69}
70
71// ##################################################################
72std::vector<std::vector<std::string>>
74 size_t timehistsize,
75 size_t time_history_limit,
76 const std::vector<const PostProcessor*>& pp_sub_list)
77{
78 if (pp_sub_list.empty()) return {};
79
80 //+2 top header + bottom header
81 const size_t num_rows =
82 std::min(size_t(time_history_limit + 2), timehistsize + 2);
83 const size_t num_cols = pp_sub_list.size() + 1; //+1 time column
84 const size_t offset =
85 std::max(0, int(timehistsize) - int(time_history_limit));
86
87 const auto& front_time_hist = pp_sub_list.front()->GetTimeHistory();
88
89 typedef std::vector<std::string> VecStr;
90 typedef std::vector<VecStr> MatStr;
91 MatStr value_matrix(num_rows, VecStr(num_cols, ""));
92
93 // Do the header first
94 value_matrix[0][0] = "Time";
95 for (size_t j = 1; j <= pp_sub_list.size(); ++j)
96 value_matrix[0][j] = pp_sub_list.at(j - 1)->Name();
97
98 // Now the time values
99 for (size_t t = 0; t < (num_rows - 2); ++t)
100 {
101 for (size_t j = 0; j <= pp_sub_list.size(); ++j)
102 {
103 if (j == 0)
104 value_matrix[t + 1][j] =
105 std::to_string(front_time_hist[t + offset].time_);
106 else
107 {
108 const auto& pp = pp_sub_list.at(j - 1);
109 value_matrix[t + 1][j] =
110 pp->ConvertValueToString(pp->GetTimeHistory().at(t + offset).value_);
111 }
112 } // for j
113 } // for t
114
115 // Now the last row
116 {
117 size_t t = num_rows - 1;
118 value_matrix[t][0] = "Latest";
119 for (size_t j = 0; j < pp_sub_list.size(); ++j)
120 {
121 const auto& pp = pp_sub_list.at(j);
122 value_matrix[t][j + 1] = pp->ConvertValueToString(pp->GetValue());
123 }
124 }
125
126 return value_matrix;
127}
128
129} // namespace chi
static std::vector< chi::PostProcessorPtr > postprocessor_stack
Definition: chi_runtime.h:98
const std::string & Name() const
Definition: Event.cc:18
static std::vector< const PostProcessor * > GetArbitraryPostProcessorsList(const Event &event)
static std::vector< const PostProcessor * > GetVectorPostProcessorsList(const Event &event)
static std::vector< const PostProcessor * > GetScalarPostProcessorsList(const Event &event)
static std::vector< std::vector< std::string > > BuildPPHistoryMatrix(size_t timehistsize, size_t time_history_limit, const std::vector< const PostProcessor * > &pp_sub_list)