1#ifndef OUTPUT_CSV_TOOL_H
2#define OUTPUT_CSV_TOOL_H
15#include "../../src/GenericManagingModule.h"
16#include "../../src/ModuleFactory.h"
49 static bool m_registered;
50 std::string m_ini_filepath{
"tools/OutputCsvTool.ini"};
51 std::string m_output_filepath{};
52 std::string m_save_mode{};
53 std::vector<std::string>
57 std::vector<int> m_save_steps{};
58 int m_currentIndex{0};
59 std::ofstream output_file;
62 void _writeDataSurface(
int period);
83 bool exec(std::string_view
param)
override;
97 return std::make_shared<OutputCsvTool<T>>(
sim);
99 static std::string
getName() {
return "OutputCsvTool"; };
100 std::string_view
getNameLocal()
const override {
return "OutputCsvTool"; };
111 this->sim->m_simulation_config.getStringParameters(
"ini_folder_path")};
120 std::cerr <<
e.what() <<
'\n';
129 numerical_layers = this->sim->m_simulation_config.getIntParameters(
"numerical_layers");
132 this->sim->m_simulation_config.getIntParameters(
"global_number_of_facets");
137 if (this->sim->my_rank == 0)
140 std::ofstream
file(m_output_filepath);
144 std::ofstream
file(m_output_filepath);
146 if (m_save_mode ==
"specific_time_steps")
151 this->ini_file_data.getDoubleVectorParameters(
"save_time_steps")};
154 m_save_steps.push_back(
static_cast<int>(
save_steps[
i]));
159 std::cerr <<
e.what() <<
'\n';
168 if (
param ==
"InitChain")
172 if (
param ==
"PreTimeStepChain")
174 return preTimeStep();
176 if (
param ==
"PostNonLinIterChain")
178 return postNonLinIter();
180 if (
param ==
"PostTimeStepChain")
182 return postTimeStep();
184 if (
param ==
"OutputChain")
204 if ((m_save_mode ==
"specific_time_steps") && (m_currentIndex < m_save_steps.size())
205 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
214 else if ((m_save_mode ==
"specific_time_steps_surface")
215 && (m_currentIndex < m_save_steps.size())
216 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
221 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
225 else if ((m_save_mode ==
"interval")
226 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
234 else if ((m_save_mode ==
"interval_surface")
235 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
240 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
244 if (this->sim->elapsed_time +
this->sim->m_simulation_config.getIntParameters(
"time_delta")
245 >
this->sim->m_simulation_config.getIntParameters(
"time_max")
266 if (m_save_mode ==
"surface")
268 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
287 output_file.open(m_output_filepath, std::ios::app);
291 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
295 output_file <<
field[
i] << std::setprecision(15) <<
",";
297 output_file <<
field[
field.
size() - 1] << std::setprecision(15) <<
"\n";
316 std::cerr <<
"Trying to access an unopened file. Please also use init and output chains "
317 "when using MPI I/O.\n";
318 throw std::runtime_error(
319 "Trying to access an unopened file. Please also use init and output chains when using "
348 + std::to_string(
field.
size() *
this->sim->world_size) +
",";
365 output_file.open(m_output_filepath, std::ios::app);
369 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
373 output_file <<
field[
i *
period] << std::setprecision(15) <<
",";
396 std::cerr <<
"Trying to access an unopened file. Please also use init and output chains "
397 "when using MPI I/O.\n";
398 throw std::runtime_error(
399 "Trying to access an unopened file. Please also use init and output chains when using "
445 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
456 + (this->sim->my_rank -
this->sim->number_of_larger_procs) *
field.
size())
464 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
474 + (this->sim->my_rank -
this->sim->number_of_larger_procs))
497 if (this->sim->my_rank == 0)
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:92
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
std::pair< int, int > size() const
Function that returns the size of the matrix as a pair in (rows, columns) format.
Definition GenericMatrix.h:118
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