Chi-Tech
PostProcessorPrinter_00.cc
Go to the documentation of this file.
5
7
8#include "chi_runtime.h"
9#include "chi_log.h"
10
11#include <algorithm>
12
13/**Small utility macro for joining two words.*/
14#define JoinWordsA(x, y) x##y
15/**IDK why this is needed. Seems like counter doesnt work properly without it*/
16#define JoinWordsB(x, y) JoinWordsA(x, y)
17
18std::shared_ptr<chi::PPPrinterSubscribeHelper>
20 std::make_shared<PPPrinterSubscribeHelper>(
21 PostProcessorPrinter::GetInstance());
22
23static char JoinWordsB(unique_var_name_ppp_, __COUNTER__) =
25
26namespace chi
27{
28
29// ##################################################################
31 PostProcessorPrinter& printer_ref)
32 : printer_ref_(printer_ref)
33{
34}
35
36// ##################################################################
37/**Overrides base class to forward the call to the printer.*/
39{
41}
42
43// ##################################################################
45 : events_on_which_to_print_postprocs_({"SolverInitialized",
46 "SolverAdvanced",
47 "SolverExecuted",
48 "ProgramExecuted"})
49{
50}
51
52// ##################################################################
54{
55 static PostProcessorPrinter instance;
56
57 return instance;
58}
59
60// ##################################################################
62{
63 auto helper_ptr = PostProcessorPrinter::helper_ptr_;
64
65 auto& publisher = SystemWideEventPublisher::GetInstance();
66 auto subscriber_ptr = std::dynamic_pointer_cast<EventSubscriber>(helper_ptr);
67
69 not subscriber_ptr,
70 "Failure to cast chi::PPPrinterSubscribeHelper to chi::EventSubscriber");
71
72 publisher.AddSubscriber(subscriber_ptr);
73
74 return 0;
75}
76
77// ##################################################################
79{
81}
82
83// ##################################################################
85 const std::vector<std::string>& events)
86{
88}
89
90// ##################################################################
92{
94}
95
96// ##################################################################
98{
100}
101
102// ##################################################################
104{
106}
107
108// ##################################################################
110{
112}
113
114// ##################################################################
116{
117 table_column_limit_ = std::max(limit, size_t(80));
118}
119
120// ##################################################################
122{
123 time_history_limit_ = std::min(limit, size_t(1000));
124}
125
126// ##################################################################
127void PostProcessorPrinter::SetCSVFilename(const std::string& csv_filename)
128{
129 csv_filename_ = csv_filename;
130}
131
132// ##################################################################
134{
135 {
137 auto it = std::find(vec.begin(), vec.end(), event.Name());
138 if (it != vec.end()) PrintPostProcessors(event);
139 }
140}
141
142// ##################################################################
144{
145 const auto scalar_pps = GetScalarPostProcessorsList(event);
146 {
148 PrintPPsLatestValuesOnly("SCALAR", scalar_pps, event);
149 else
151 "SCALAR", scalar_pps, event, per_column_size_scalars_);
152
153 // If we are not printing the latest values, then how would we get values
154 // suitable for regression tests. This is how.
155 if (print_scalar_time_history_ and event.Name() == "ProgramExecuted")
156 PrintPPsLatestValuesOnly("SCALAR", scalar_pps, event);
157 }
158
159 const auto vector_pps = GetVectorPostProcessorsList(event);
160 {
162 PrintPPsLatestValuesOnly("VECTOR", vector_pps, event);
163 else
165 "VECTOR", vector_pps, event, per_column_size_vectors_);
166
167 // If we are not printing the latest values, then how would we get values
168 // suitable for regression tests. This is how.
169 if (print_vector_time_history_ and event.Name() == "ProgramExecuted")
170 PrintPPsLatestValuesOnly("VECTOR", vector_pps, event);
171 }
172
173 if (not csv_filename_.empty() and event.Name() == "ProgramExecuted")
174 PrintCSVFile(event);
175}
176
177// ##################################################################
178/**A manual means to print a post processor.*/
180 const std::vector<const PostProcessor*>& pp_list) const
181{
182 std::stringstream outstr;
183
184 typedef std::pair<std::string, std::string> PPNameAndVal;
185 std::vector<PPNameAndVal> scalar_ppnames_and_vals;
186 for (const auto& pp : pp_list)
187 {
188 const auto& value = pp->GetValue();
189 const auto value_str = pp->ConvertValueToString(value);
190
191 scalar_ppnames_and_vals.emplace_back(pp->Name(), value_str);
192 } // for pp
193
194 if (not scalar_ppnames_and_vals.empty())
195 {
197 outstr << PrintPPsHorizontal(scalar_ppnames_and_vals, 0);
199 outstr << PrintPPsVertical(scalar_ppnames_and_vals, 0);
200 }
201
202 return outstr.str();
203}
204
205} // namespace chi
#define JoinWordsB(x, y)
#define ChiLogicalErrorIf(condition, message)
const std::string & Name() const
Definition: Event.cc:18
PPPrinterSubscribeHelper(PostProcessorPrinter &printer_ref)
PostProcessorPrinter & printer_ref_
void ReceiveEventUpdate(const Event &event) override
void SetPrintScalarTimeHistory(bool value)
static std::shared_ptr< PPPrinterSubscribeHelper > helper_ptr_
bool per_column_size_vectors_
ScalarPPTableFormat scalar_pp_table_format_
static std::vector< const PostProcessor * > GetVectorPostProcessorsList(const Event &event)
static PostProcessorPrinter & GetInstance()
static std::string PrintPPsVertical(const std::vector< std::pair< std::string, std::string > > &scalar_ppnames_and_vals, int event_code)
static std::vector< const PostProcessor * > GetScalarPostProcessorsList(const Event &event)
void SetTimeHistoryLimit(size_t limit)
static char SubscribeToSystemWideEventPublisher()
void SetScalarPerColumnSize(bool value)
void ReceiveEventUpdate(const Event &event)
bool print_vector_time_history_
void PrintCSVFile(const Event &event) const
void SetPrintVectorTimeHistory(bool value)
void PrintPPsLatestValuesOnly(const std::string &pps_typename, const std::vector< const PostProcessor * > &pp_list, const Event &event) const
void SetCSVFilename(const std::string &csv_filename)
bool print_scalar_time_history_
static std::string PrintPPsHorizontal(const std::vector< std::pair< std::string, std::string > > &scalar_ppnames_and_vals, int)
bool per_column_size_scalars_
void PrintPostProcessors(const Event &event) const
std::string csv_filename_
std::string GetPrintedPostProcessors(const std::vector< const PostProcessor * > &pp_list) const
void SetScalarPPTableFormat(ScalarPPTableFormat format)
void SetTableColumnLimit(size_t limit)
void PrintPPsTimeHistory(const std::string &pps_typename, const std::vector< const PostProcessor * > &pp_list, const Event &event, bool per_column_sizes=false) const
size_t time_history_limit_
std::vector< std::string > events_on_which_to_print_postprocs_
void SetEventsOnWhichPrintPPs(const std::vector< std::string > &events)
size_t table_column_limit_
PostProcessorPrinter()
void SetVectorPerColumnSize(bool value)
static SystemWideEventPublisher & GetInstance()