1#ifndef OUTPUT_CSV_TOOL_H
2#define OUTPUT_CSV_TOOL_H
4#define OUTPUT_CSV_TOOL_VERSION "13"
20#include "../../src/GenericManagingModule.h"
21#include "../../src/ModuleFactory.h"
54 static bool m_registered;
55 std::string m_ini_filepath{
"tools/OutputCsvTool.ini"};
56 std::string m_output_filepath{};
57 std::string m_save_mode{};
58 std::vector<std::string>
62 std::string m_start_time_utc{};
64 std::vector<int64_t> m_interval_start_times_seconds{};
65 std::vector<int64_t> m_interval_end_times_seconds{};
66 std::vector<int> m_save_steps{};
67 int m_currentIndex{0};
70 std::ofstream output_file;
73 void _writeDataSurface(
int period);
74 void _utcIntervalToSeconds();
75 void _verifyIntervalIntegrity();
76 bool _checkInterval();
97 bool exec(std::string_view
param)
override;
111 return std::make_shared<OutputCsvTool<T>>(
sim);
113 static std::string
getName() {
return "OutputCsvTool"; };
114 std::string_view
getNameLocal()
const override {
return "OutputCsvTool"; };
125 this->sim->m_simulation_config.getStringParameters(
"ini_folder_path")};
134 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
135 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
136 +
static_cast<std::string
>(
e.what()));
145 numerical_layers = this->sim->m_simulation_config.getIntParameters(
"numerical_layers");
148 this->sim->m_simulation_config.getIntParameters(
"global_number_of_facets");
153 if (this->sim->my_rank == 0)
156 std::ofstream
file(m_output_filepath);
160 std::ofstream
file(m_output_filepath);
162 if (m_save_mode ==
"specific_time_steps" || m_save_mode ==
"specific_time_steps_surface")
167 this->ini_file_data.getDoubleVectorParameters(
"save_time_steps")};
170 m_save_steps.push_back(
static_cast<int>(
save_steps[
i]));
175 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
176 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
177 +
static_cast<std::string
>(
e.what()));
180 if (m_save_mode ==
"time_interval" || m_save_mode ==
"time_interval_surface")
184 m_time_delta = this->sim->m_simulation_config.getDoubleParameters(
"time_delta");
185 m_time_max = this->sim->m_simulation_config.getDoubleParameters(
"time_max");
186 m_start_time_utc = this->ini_file_data.getStringParameters(
"start_time_utc");
187 _utcIntervalToSeconds();
191 std::cerr <<
e.what() <<
'\n';
200 if (
param ==
"InitChain")
204 if (
param ==
"PreTimeStepChain")
206 return preTimeStep();
208 if (
param ==
"PostNonLinIterChain")
210 return postNonLinIter();
212 if (
param ==
"PostTimeStepChain")
214 return postTimeStep();
216 if (
param ==
"OutputChain")
238 if ((m_save_mode ==
"specific_time_steps") && (m_currentIndex < m_save_steps.size())
239 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
248 else if ((m_save_mode ==
"specific_time_steps_surface")
249 && (m_currentIndex < m_save_steps.size())
250 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
254 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
256 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
260 else if ((m_save_mode ==
"interval")
261 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
269 else if ((m_save_mode ==
"interval_surface")
270 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
274 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
276 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
279 else if ((m_save_mode ==
"time_interval") && _checkInterval())
287 else if ((m_save_mode ==
"time_interval_surface") && _checkInterval())
291 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
293 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
299 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
300 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
301 +
static_cast<std::string
>(
e.what()));
317 if (m_save_mode ==
"surface")
321 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
325 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
326 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
327 +
static_cast<std::string
>(
e.what()));
347 output_file.open(m_output_filepath, std::ios::app);
351 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
357 output_file <<
field[
i] << std::setprecision(15) <<
",";
359 output_file <<
field[
field.
size() - 1] << std::setprecision(15) <<
"\n";
363 std::cerr <<
"[OutputCsvTool]: " <<
field_name
365 "loaded or accessable!\n "
369 +
static_cast<std::string
>(
" module "
371 "accessable!\n [OutputCsvTool]: ")
372 +
static_cast<std::string
>(
e.what()));
393 std::cerr <<
"[OutputCsvTool]: Trying to access an unopened file. Please also use init and "
395 "when using MPI I/O.\n";
396 throw std::runtime_error(
397 "[OutputCsvTool]: Trying to access an unopened file. Please also use init and output "
429 + std::to_string(
field.
size() *
this->sim->world_size) +
",";
434 std::cerr <<
"[OutputCsvTool]: " <<
field_name
436 "loaded or accessable!\n "
440 +
static_cast<std::string
>(
" module "
442 "accessable!\n [OutputCsvTool]: ")
443 +
static_cast<std::string
>(
e.what()));
460 output_file.open(m_output_filepath, std::ios::app);
464 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
470 output_file <<
field[
i *
period] << std::setprecision(15) <<
",";
476 std::cerr <<
"[OutputCsvTool]: " <<
field_name
478 "loaded or accessable!\n "
482 +
static_cast<std::string
>(
" module "
484 "accessable!\n [OutputCsvTool]:")
485 +
static_cast<std::string
>(
e.what()));
507 std::cerr <<
"[OutputCsvTool]: Trying to access an unopened file. Please also use init and "
509 "when using MPI I/O.\n";
510 throw std::runtime_error(
511 "[OutputCsvTool]: Trying to access an unopened file. Please also use init and output "
545 std::cerr <<
"[OutputCsvTool]: " <<
field_name
547 "loaded or accessable!\n "
551 +
static_cast<std::string
>(
" module "
553 "accessable!\n [OutputCsvTool]: ")
554 +
static_cast<std::string
>(
e.what()));
576 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
588 + (this->sim->my_rank -
this->sim->number_of_larger_procs)
597 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
608 (this->sim->number_of_larger_procs * (
field.
size() + 1)
609 + (this->sim->my_rank -
this->sim->number_of_larger_procs) *
field.
size())
633 if (this->sim->my_rank == 0)
662 this->ini_file_data.getStringVectorParameters(
"interval_start_times_utc")};
664 this->ini_file_data.getStringVectorParameters(
"interval_end_times_utc")};
665 const std::string
format =
"%Y-%m-%dT%H:%M:%S";
677 std::cerr <<
"[OutputCsvTool]: Could not parse the start time stamp: " << m_start_time_utc
678 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
679 throw std::runtime_error(
"[OutputCsvTool]: Could not parse the start time stamp: "
681 +
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n");
693 std::cerr <<
"[OutputCsvTool]: Could not parse the starting interval time stamp: "
695 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
696 throw std::runtime_error(
697 "[OutputCsvTool]: Could not parse the starting interval time stamp: "
711 std::cerr <<
"[OutputCsvTool]: Could not parse the starting interval time stamp: "
713 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
714 throw std::runtime_error(
715 "[OutputCsvTool]: Could not parse the starting interval time stamp: "
725 if (m_interval_start_times_seconds[
i] > m_interval_end_times_seconds[
i])
727 std::cerr <<
"[OutputCsvTool]: Starting time of interval "
730 <<
"! Please ensure that interval start time < interval end time.\n";
731 throw std::runtime_error(
734 +
"! Please ensure that interval start time < interval end time.\n");
741 std::sort(m_interval_start_times_seconds.begin(), m_interval_start_times_seconds.end());
742 std::sort(m_interval_end_times_seconds.begin(), m_interval_end_times_seconds.end());
744 _verifyIntervalIntegrity();
762 if (m_interval_start_times_seconds.size() != m_interval_end_times_seconds.size())
764 std::cerr <<
"[OutputCsvTool]: Start and end intervalls have different amount of time "
766 throw std::runtime_error(
767 "[OutputCsvTool]: Start and end intervalls have different amount of time "
773 for (
int i{0};
i < m_interval_start_times_seconds.
size();
i++)
776 || m_interval_end_times_seconds[
i] < m_start_time_seconds)
783 std::cerr <<
"[OutputCsvTool]: None of the given intervals are within the simulation "
784 "time span! Please provide at least one valid interval.\n";
785 throw std::runtime_error(
786 "[OutputCsvTool]: None of the given intervals are within the simulation time span! "
787 "Please provide at least one valid interval.\n");
792 << m_interval_start_times_seconds.
size()
793 <<
" intervals are outside of the simulation time span and will be ignored\n";
807 while (m_currentIndex < m_interval_start_times_seconds.size())
811 if (m_interval_start_times_seconds[m_currentIndex]
812 <= m_start_time_seconds + this->sim->time_step * m_time_delta
813 && m_interval_end_times_seconds[m_currentIndex]
814 >= m_start_time_seconds +
this->sim->time_step * m_time_delta)
816 if (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0)
827 else if (m_interval_end_times_seconds[m_currentIndex]
828 < 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:75