1#ifndef OUTPUT_CSV_TOOL_H
2#define OUTPUT_CSV_TOOL_H
15#include "../../src/GenericManagingModule.h"
16#include "../../src/ModuleFactory.h"
44 static bool m_registered;
45 std::string m_ini_filepath{
"tools/OutputCsvTool.ini"};
46 std::string m_output_filepath{};
47 std::string m_save_mode{};
48 std::vector<std::string>
52 std::vector<int> m_save_steps{};
53 int m_currentIndex{0};
54 std::ofstream output_file;
57 void _writeDataSurface(
int period);
62 bool exec(std::string_view param)
override;
64 bool init()
override {
return true; };
76 return std::make_shared<OutputCsvTool<T>>(
sim);
78 static std::string
getName() {
return "OutputCsvTool"; };
79 std::string_view
getNameLocal()
const override {
return "OutputCsvTool"; };
89 std::string ini_folder_path{
99 std::cerr << e.
what() <<
'\n';
107 std::ofstream file(m_output_filepath);
109 if (m_save_mode ==
"specific_time_steps")
113 std::vector<double> save_steps{
114 this->ini_file_data.getDoubleVectorParameters(
"save_time_steps")};
115 for (
int i{0}; i < save_steps.size(); i++)
117 m_save_steps.push_back(
static_cast<int>(save_steps[i]));
122 std::cerr << e.
what() <<
'\n';
131 if (param ==
"InitChain")
135 if (param ==
"PreTimeStepChain")
137 return preTimeStep();
139 if (param ==
"PostNonLinIterChain")
141 return postNonLinIter();
143 if (param ==
"PostTimeStepChain")
145 return postTimeStep();
147 if (param ==
"OutputChain")
157 if ((m_save_mode ==
"specific_time_steps") && (m_currentIndex < m_save_steps.size())
158 && (m_save_steps[m_currentIndex] == this->sim->time_step))
163 else if ((m_save_mode ==
"specific_time_steps_surface")
164 && (m_currentIndex < m_save_steps.size())
165 && (m_save_steps[m_currentIndex] == this->sim->time_step))
167 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
170 else if ((m_save_mode ==
"interval")
171 && (this->sim->time_step % this->ini_file_data.getIntParameters(
"interval") == 0))
175 else if ((m_save_mode ==
"interval_surface")
176 && (this->sim->time_step % this->ini_file_data.getIntParameters(
"interval") == 0))
178 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
186 if (m_save_mode ==
"surface")
188 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
200 output_file.open(m_output_filepath, std::ios::app);
202 for (
const auto& field_name : m_save_fields)
204 output_file << field_name <<
"," << this->sim->elapsed_time <<
",";
205 const std::valarray<T>& field{this->sim->getField(field_name)};
206 for (
int i{0}; i < field.size() - 1; i++)
208 output_file << field[i] << std::setprecision(15) <<
",";
210 output_file << field[field.size() - 1] << std::setprecision(15) <<
"\n";
219 output_file.open(m_output_filepath, std::ios::app);
221 for (
const auto& field_name : m_save_fields)
223 output_file << field_name <<
"," << this->sim->elapsed_time <<
",";
224 const std::valarray<T>& field{this->sim->getField(field_name)};
225 for (
int i{0}; i < static_cast<int>(field.size() / period) - 1; i++)
227 output_file << field[i * period] << std::setprecision(15) <<
",";
229 output_file << field[field.size() - period] << std::setprecision(15) <<
"\n";
Abstract base class for the managing modules. Managing modules are the highest tier of modules and ar...
Definition GenericManagingModule.h:29
InputManager ini_file_data
Definition GenericManagingModule.h:38
SimulationClassBase< T > * sim
Definition GenericManagingModule.h:31
std::vector< std::string > m_generic_submodules
Definition GenericManagingModule.h:36
Abstract base class for the submodules. Submodules are below managing modules and will only be run by...
Definition GenericSubmodule.h:25
static constexpr bool registerModule(std::string name, creation_method module) noexcept
Function that adds a module to the module registry map.
Definition ModuleFactory.h:68
Definition SimulationClassBase.h:15
InputManager m_simulation_config
Definition SimulationClassBase.h:24