1#ifndef OUTPUT_CSV_TOOL_H
2#define OUTPUT_CSV_TOOL_H
4#define OUTPUT_CSV_TOOL_VERSION "14"
20#include "../../src/GenericManagingModule.h"
21#include "../../src/ModuleFactory.h"
26#include "../../src/MpiCommunicationPatterns.h"
55 static bool m_registered;
56 std::string m_ini_filepath{
"tools/OutputCsvTool.ini"};
57 std::string m_output_filepath{};
58 std::string m_save_mode{};
59 std::vector<std::string>
63 std::string m_start_time_utc{};
65 std::vector<int64_t> m_interval_start_times_seconds{};
66 std::vector<int64_t> m_interval_end_times_seconds{};
67 std::vector<int> m_save_steps{};
68 int m_currentIndex{0};
71 std::ofstream output_file;
74 void _writeDataSurface(
int period);
75 void _utcIntervalToSeconds();
76 void _verifyIntervalIntegrity();
77 bool _checkInterval();
98 bool exec(std::string_view
param)
override;
100 bool init()
override;
112 return std::make_shared<OutputCsvTool<T>>(
sim);
114 static std::string
getName() {
return "OutputCsvTool"; };
115 std::string_view
getNameLocal()
const override {
return "OutputCsvTool"; };
126 this->sim->m_simulation_config.getStringParameters(
"ini_folder_path")};
135 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
136 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
137 +
static_cast<std::string
>(
e.what()));
146 numerical_layers = this->sim->m_simulation_config.getIntParameters(
"numerical_layers");
149 this->sim->m_simulation_config.getIntParameters(
"global_number_of_facets");
154 if (this->sim->my_rank == 0)
157 std::ofstream
file(m_output_filepath);
161 std::ofstream
file(m_output_filepath);
163 if (m_save_mode ==
"specific_time_steps" || m_save_mode ==
"specific_time_steps_surface")
168 this->ini_file_data.getDoubleVectorParameters(
"save_time_steps")};
171 m_save_steps.push_back(
static_cast<int>(
save_steps[
i]));
176 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
177 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
178 +
static_cast<std::string
>(
e.what()));
181 if (m_save_mode ==
"time_interval" || m_save_mode ==
"time_interval_surface")
185 m_time_delta = this->sim->m_simulation_config.getDoubleParameters(
"time_delta");
186 m_time_max = this->sim->m_simulation_config.getDoubleParameters(
"time_max");
187 m_start_time_utc = this->ini_file_data.getStringParameters(
"start_time_utc");
188 _utcIntervalToSeconds();
192 std::cerr <<
e.what() <<
'\n';
201 if (
param ==
"InitChain")
205 if (
param ==
"PreTimeStepChain")
207 return preTimeStep();
209 if (
param ==
"PostNonLinIterChain")
211 return postNonLinIter();
213 if (
param ==
"PostTimeStepChain")
215 return postTimeStep();
217 if (
param ==
"OutputChain")
239 if ((m_save_mode ==
"specific_time_steps") && (m_currentIndex < m_save_steps.size())
240 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
249 else if ((m_save_mode ==
"specific_time_steps_surface")
250 && (m_currentIndex < m_save_steps.size())
251 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
255 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
257 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
261 else if ((m_save_mode ==
"interval")
262 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
270 else if ((m_save_mode ==
"interval_surface")
271 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
275 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
277 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
280 else if ((m_save_mode ==
"time_interval") && _checkInterval())
288 else if ((m_save_mode ==
"time_interval_surface") && _checkInterval())
292 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
294 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
300 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
301 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
302 +
static_cast<std::string
>(
e.what()));
318 if (m_save_mode ==
"surface")
322 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
326 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
327 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
328 +
static_cast<std::string
>(
e.what()));
348 output_file.open(m_output_filepath, std::ios::app);
352 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
358 output_file <<
field[
i] << std::setprecision(15) <<
",";
360 output_file <<
field[
field.
size() - 1] << std::setprecision(15) <<
"\n";
364 std::cerr <<
"[OutputCsvTool]: " <<
field_name
366 "loaded or accessable!\n "
370 +
static_cast<std::string
>(
" module "
372 "accessable!\n [OutputCsvTool]: ")
373 +
static_cast<std::string
>(
e.what()));
394 std::cerr <<
"[OutputCsvTool]: Trying to access an unopened file. Please also use init and "
396 "when using MPI I/O.\n";
397 throw std::runtime_error(
398 "[OutputCsvTool]: Trying to access an unopened file. Please also use init and output "
430 + std::to_string(
field.
size() *
this->sim->world_size) +
",";
435 std::cerr <<
"[OutputCsvTool]: " <<
field_name
437 "loaded or accessable!\n "
441 +
static_cast<std::string
>(
" module "
443 "accessable!\n [OutputCsvTool]: ")
444 +
static_cast<std::string
>(
e.what()));
461 output_file.open(m_output_filepath, std::ios::app);
465 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
471 output_file <<
field[
i *
period] << std::setprecision(15) <<
",";
477 std::cerr <<
"[OutputCsvTool]: " <<
field_name
479 "loaded or accessable!\n "
483 +
static_cast<std::string
>(
" module "
485 "accessable!\n [OutputCsvTool]:")
486 +
static_cast<std::string
>(
e.what()));
508 std::cerr <<
"[OutputCsvTool]: Trying to access an unopened file. Please also use init and "
510 "when using MPI I/O.\n";
511 throw std::runtime_error(
512 "[OutputCsvTool]: Trying to access an unopened file. Please also use init and output "
546 std::cerr <<
"[OutputCsvTool]: " <<
field_name
548 "loaded or accessable!\n "
552 +
static_cast<std::string
>(
" module "
554 "accessable!\n [OutputCsvTool]: ")
555 +
static_cast<std::string
>(
e.what()));
577 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
589 + (this->sim->my_rank -
this->sim->number_of_larger_procs)
598 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
609 (this->sim->number_of_larger_procs * (
field.
size() + 1)
610 + (this->sim->my_rank -
this->sim->number_of_larger_procs) *
field.
size())
634 if (this->sim->my_rank == 0)
663 this->ini_file_data.getStringVectorParameters(
"interval_start_times_utc")};
665 this->ini_file_data.getStringVectorParameters(
"interval_end_times_utc")};
666 const std::string
format =
"%Y-%m-%dT%H:%M:%S";
678 std::cerr <<
"[OutputCsvTool]: Could not parse the start time stamp: " << m_start_time_utc
679 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
680 throw std::runtime_error(
"[OutputCsvTool]: Could not parse the start time stamp: "
682 +
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n");
694 std::cerr <<
"[OutputCsvTool]: Could not parse the starting interval time stamp: "
696 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
697 throw std::runtime_error(
698 "[OutputCsvTool]: Could not parse the starting interval time stamp: "
712 std::cerr <<
"[OutputCsvTool]: Could not parse the starting interval time stamp: "
714 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
715 throw std::runtime_error(
716 "[OutputCsvTool]: Could not parse the starting interval time stamp: "
726 if (m_interval_start_times_seconds[
i] > m_interval_end_times_seconds[
i])
728 std::cerr <<
"[OutputCsvTool]: Starting time of interval "
731 <<
"! Please ensure that interval start time < interval end time.\n";
732 throw std::runtime_error(
735 +
"! Please ensure that interval start time < interval end time.\n");
742 std::sort(m_interval_start_times_seconds.begin(), m_interval_start_times_seconds.end());
743 std::sort(m_interval_end_times_seconds.begin(), m_interval_end_times_seconds.end());
745 _verifyIntervalIntegrity();
763 if (m_interval_start_times_seconds.size() != m_interval_end_times_seconds.size())
765 std::cerr <<
"[OutputCsvTool]: Start and end intervalls have different amount of time "
767 throw std::runtime_error(
768 "[OutputCsvTool]: Start and end intervalls have different amount of time "
774 for (
int i{0};
i < m_interval_start_times_seconds.
size();
i++)
777 || m_interval_end_times_seconds[
i] < m_start_time_seconds)
784 std::cerr <<
"[OutputCsvTool]: None of the given intervals are within the simulation "
785 "time span! Please provide at least one valid interval.\n";
786 throw std::runtime_error(
787 "[OutputCsvTool]: None of the given intervals are within the simulation time span! "
788 "Please provide at least one valid interval.\n");
793 << m_interval_start_times_seconds.
size()
794 <<
" intervals are outside of the simulation time span and will be ignored\n";
808 while (m_currentIndex < m_interval_start_times_seconds.size())
812 if (m_interval_start_times_seconds[m_currentIndex]
813 <= m_start_time_seconds + this->sim->time_step * m_time_delta
814 && m_interval_end_times_seconds[m_currentIndex]
815 >= m_start_time_seconds +
this->sim->time_step * m_time_delta)
817 if (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0)
828 else if (m_interval_end_times_seconds[m_currentIndex]
829 < m_start_time_seconds + this->sim->time_step * m_time_delta)
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:37
CsrSparseMatrix()
Constructor for an empty CsrSparseMatrix object. Leaves all storage arrays empty but sets the flag to...
Definition CsrMatrix.h:94
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:120
static constexpr bool registerModule(std::string name, creation_method module) noexcept
Function that adds a module to the module registry map.
Definition ModuleFactory.h:76