Chi-Tech
PostProcessorPrinter_01_printcsvfile.cc
Go to the documentation of this file.
2
4#include "chi_utils.h"
5
6#include <set>
7#include <algorithm>
8
9namespace chi
10{
11
13{
14 const auto scalar_pps = GetScalarPostProcessorsList(event);
15 const auto vector_pps = GetVectorPostProcessorsList(event);
16 const auto arbitr_pps = GetArbitraryPostProcessorsList(event);
17
18 std::ofstream csvfile;
19 csvfile.open(csv_filename_, std::ios::out);
20
21 PrintScalarPPsToCSV(csvfile, scalar_pps);
22 PrintVectorPPsToCSV(csvfile, vector_pps);
23 PrintArbitraryPPsToCSV(csvfile, arbitr_pps);
24
25 csvfile.close();
26}
27
29 std::ofstream& csvfile, const std::vector<const PostProcessor*>& pp_list)
30{
31 csvfile << "Scalar Post-Processors\n";
32
33 //======================================== Establish unique time history sizes
34 std::set<size_t> unq_time_histsizes;
35
36 for (const auto& pp : pp_list)
37 {
38 const size_t time_histsize = pp->GetTimeHistory().size();
39 unq_time_histsizes.insert(time_histsize);
40 }
41
42 //======================================== Subscribe pps to unique time
43 // hist sizes
44 std::map<size_t, std::vector<const PostProcessor*>> pp_timehist_size_subs;
45 for (size_t time_histsize : unq_time_histsizes)
46 {
47 auto& subs = pp_timehist_size_subs[time_histsize];
48 for (const auto& pp : pp_list)
49 if (pp->GetTimeHistory().size() == time_histsize) subs.push_back(pp);
50 }
51
52 //======================================== For each timeline. Build the table
53 for (const auto& [timehistsize, pp_sub_list] : pp_timehist_size_subs)
54 {
55 const auto value_matrix =
56 BuildPPHistoryMatrix(timehistsize, timehistsize, pp_sub_list);
57 for (const auto& row : value_matrix)
58 {
59 for (const auto& entry : row)
60 {
61 csvfile << entry;
62 if (&entry != &row.back()) csvfile << ",";
63 }
64 csvfile << "\n";
65 }
66 } // for each thing in pp_timehist_size_subs
67}
68
70 std::ofstream& csvfile, const std::vector<const PostProcessor*>& pp_list)
71{
72 csvfile << "Vector Post-Processors\n";
73
74 for (const auto& pp : pp_list)
75 {
76 csvfile << pp->Name() << "\n";
77 const size_t timehistsize = pp->GetTimeHistory().size();
78 const auto value_matrix =
79 BuildPPHistoryMatrix(timehistsize, timehistsize, {pp});
80 for (const auto& row : value_matrix)
81 {
82 for (const auto& entry : row)
83 {
84 auto entry_star = entry;
85 std::replace(entry_star.begin(), entry_star.end(), ' ', ',');
86 csvfile << entry_star;
87 if (&entry != &row.back()) csvfile << ",";
88 }
89 csvfile << "\n";
90 }
91 }
92}
93
95 std::ofstream& csvfile, const std::vector<const PostProcessor*>& pp_list)
96{
97 csvfile << "Arbitrary Post-Processors\n";
98
99 for (const auto& pp : pp_list)
100 {
101 csvfile << pp->Name() << "\n";
102 const size_t timehistsize = pp->GetTimeHistory().size();
103 const auto value_matrix =
104 BuildPPHistoryMatrix(timehistsize, timehistsize, {pp});
105 for (const auto& row : value_matrix)
106 {
107 for (const auto& entry : row)
108 {
109 auto entry_star = entry;
110
111 csvfile << entry_star;
112 if (&entry != &row.back()) csvfile << ",";
113 }
114 csvfile << "\n";
115 }
116 }
117}
118
119} // namespace chi
static void PrintScalarPPsToCSV(std::ofstream &csvfile, const std::vector< const PostProcessor * > &pp_list)
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 void PrintArbitraryPPsToCSV(std::ofstream &csvfile, const std::vector< const PostProcessor * > &pp_list)
void PrintCSVFile(const Event &event) const
std::string csv_filename_
static std::vector< std::vector< std::string > > BuildPPHistoryMatrix(size_t timehistsize, size_t time_history_limit, const std::vector< const PostProcessor * > &pp_sub_list)
static void PrintVectorPPsToCSV(std::ofstream &csvfile, const std::vector< const PostProcessor * > &pp_list)