1#ifndef OUTPUT_CSV_TOOL_H
2#define OUTPUT_CSV_TOOL_H
4#define OUTPUT_CSV_TOOL_VERSION "12"
19#include "../../src/GenericManagingModule.h"
20#include "../../src/ModuleFactory.h"
53 static bool m_registered;
54 std::string m_ini_filepath{
"tools/OutputCsvTool.ini"};
55 std::string m_output_filepath{};
56 std::string m_save_mode{};
57 std::vector<std::string>
61 std::string m_start_time_utc{};
63 std::vector<int64_t> m_interval_start_times_seconds{};
64 std::vector<int64_t> m_interval_end_times_seconds{};
65 std::vector<int> m_save_steps{};
66 int m_currentIndex{0};
69 std::ofstream output_file;
72 void _writeDataSurface(
int period);
73 void _utcIntervalToSeconds();
74 void _verifyIntervalIntegrity();
75 bool _checkInterval();
96 bool exec(std::string_view
param)
override;
110 return std::make_shared<OutputCsvTool<T>>(
sim);
112 static std::string
getName() {
return "OutputCsvTool"; };
113 std::string_view
getNameLocal()
const override {
return "OutputCsvTool"; };
124 this->sim->m_simulation_config.getStringParameters(
"ini_folder_path")};
133 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
134 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
135 +
static_cast<std::string
>(
e.what()));
144 numerical_layers = this->sim->m_simulation_config.getIntParameters(
"numerical_layers");
147 this->sim->m_simulation_config.getIntParameters(
"global_number_of_facets");
152 if (this->sim->my_rank == 0)
155 std::ofstream
file(m_output_filepath);
159 std::ofstream
file(m_output_filepath);
161 if (m_save_mode ==
"specific_time_steps" || m_save_mode ==
"specific_time_steps_surface")
166 this->ini_file_data.getDoubleVectorParameters(
"save_time_steps")};
169 m_save_steps.push_back(
static_cast<int>(
save_steps[
i]));
174 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
175 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
176 +
static_cast<std::string
>(
e.what()));
179 if (m_save_mode ==
"time_interval" || m_save_mode ==
"time_interval_surface")
183 m_time_delta = this->sim->m_simulation_config.getDoubleParameters(
"time_delta");
184 m_time_max = this->sim->m_simulation_config.getDoubleParameters(
"time_max");
185 m_start_time_utc = this->ini_file_data.getStringParameters(
"start_time_utc");
186 _utcIntervalToSeconds();
190 std::cerr <<
e.what() <<
'\n';
199 if (
param ==
"InitChain")
203 if (
param ==
"PreTimeStepChain")
205 return preTimeStep();
207 if (
param ==
"PostNonLinIterChain")
209 return postNonLinIter();
211 if (
param ==
"PostTimeStepChain")
213 return postTimeStep();
215 if (
param ==
"OutputChain")
237 if ((m_save_mode ==
"specific_time_steps") && (m_currentIndex < m_save_steps.size())
238 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
247 else if ((m_save_mode ==
"specific_time_steps_surface")
248 && (m_currentIndex < m_save_steps.size())
249 && (m_save_steps[m_currentIndex] ==
this->sim->time_step))
253 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
255 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
259 else if ((m_save_mode ==
"interval")
260 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
268 else if ((m_save_mode ==
"interval_surface")
269 && (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0))
273 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
275 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
278 else if ((m_save_mode ==
"time_interval") && _checkInterval())
286 else if ((m_save_mode ==
"time_interval_surface") && _checkInterval())
290 this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
292 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
298 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
299 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
300 +
static_cast<std::string
>(
e.what()));
316 if (m_save_mode ==
"surface")
320 _writeDataSurface(this->sim->m_simulation_config.getIntParameters(
"numerical_layers"));
324 std::cerr <<
"[OutputCsvTool]: " <<
e.what() <<
'\n';
325 throw BadInput(
static_cast<std::string
>(
"[OutputCsvTool]: ")
326 +
static_cast<std::string
>(
e.what()));
346 output_file.open(m_output_filepath, std::ios::app);
350 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
356 output_file <<
field[
i] << std::setprecision(15) <<
",";
358 output_file <<
field[
field.
size() - 1] << std::setprecision(15) <<
"\n";
362 std::cerr <<
"[OutputCsvTool]: " <<
field_name
364 "loaded or accessable!\n "
368 +
static_cast<std::string
>(
" module "
370 "accessable!\n [OutputCsvTool]: ")
371 +
static_cast<std::string
>(
e.what()));
391 std::cerr <<
"[OutputCsvTool]: Trying to access an unopened file. Please also use init and "
393 "when using MPI I/O.\n";
394 throw std::runtime_error(
395 "[OutputCsvTool]: Trying to access an unopened file. Please also use init and output "
427 + std::to_string(
field.
size() *
this->sim->world_size) +
",";
432 std::cerr <<
"[OutputCsvTool]: " <<
field_name
434 "loaded or accessable!\n "
438 +
static_cast<std::string
>(
" module "
440 "accessable!\n [OutputCsvTool]: ")
441 +
static_cast<std::string
>(
e.what()));
458 output_file.open(m_output_filepath, std::ios::app);
462 output_file <<
field_name <<
"," << this->sim->elapsed_time <<
",";
468 output_file <<
field[
i *
period] << std::setprecision(15) <<
",";
474 std::cerr <<
"[OutputCsvTool]: " <<
field_name
476 "loaded or accessable!\n "
480 +
static_cast<std::string
>(
" module "
482 "accessable!\n [OutputCsvTool]:")
483 +
static_cast<std::string
>(
e.what()));
505 std::cerr <<
"[OutputCsvTool]: Trying to access an unopened file. Please also use init and "
507 "when using MPI I/O.\n";
508 throw std::runtime_error(
509 "[OutputCsvTool]: Trying to access an unopened file. Please also use init and output "
543 std::cerr <<
"[OutputCsvTool]: " <<
field_name
545 "loaded or accessable!\n "
549 +
static_cast<std::string
>(
" module "
551 "accessable!\n [OutputCsvTool]: ")
552 +
static_cast<std::string
>(
e.what()));
574 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
585 + (this->sim->my_rank -
this->sim->number_of_larger_procs)
594 if (this->sim->my_rank <
this->sim->number_of_larger_procs)
604 + (this->sim->my_rank -
this->sim->number_of_larger_procs)
628 if (this->sim->my_rank == 0)
657 this->ini_file_data.getStringVectorParameters(
"interval_start_times_utc")};
659 this->ini_file_data.getStringVectorParameters(
"interval_end_times_utc")};
660 const std::string
format =
"%Y-%m-%dT%H:%M:%S";
672 std::cerr <<
"[OutputCsvTool]: Could not parse the start time stamp: " << m_start_time_utc
673 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
674 throw std::runtime_error(
"[OutputCsvTool]: Could not parse the start time stamp: "
676 +
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n");
688 std::cerr <<
"[OutputCsvTool]: Could not parse the starting interval time stamp: "
690 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
691 throw std::runtime_error(
692 "[OutputCsvTool]: Could not parse the starting interval time stamp: "
706 std::cerr <<
"[OutputCsvTool]: Could not parse the starting interval time stamp: "
708 <<
"!\nPlease use the format YYYY-MM-DDThh:mm:ss\n";
709 throw std::runtime_error(
710 "[OutputCsvTool]: Could not parse the starting interval time stamp: "
720 if (m_interval_start_times_seconds[
i] > m_interval_end_times_seconds[
i])
722 std::cerr <<
"[OutputCsvTool]: Starting time of interval "
725 <<
"! Please ensure that interval start time < interval end time.\n";
726 throw std::runtime_error(
729 +
"! Please ensure that interval start time < interval end time.\n");
736 std::sort(m_interval_start_times_seconds.begin(), m_interval_start_times_seconds.end());
737 std::sort(m_interval_end_times_seconds.begin(), m_interval_end_times_seconds.end());
739 _verifyIntervalIntegrity();
757 if (m_interval_start_times_seconds.size() != m_interval_end_times_seconds.size())
759 std::cerr <<
"[OutputCsvTool]: Start and end intervalls have different amount of time "
761 throw std::runtime_error(
762 "[OutputCsvTool]: Start and end intervalls have different amount of time "
768 for (
int i{0};
i < m_interval_start_times_seconds.
size();
i++)
771 || m_interval_end_times_seconds[
i] < m_start_time_seconds)
778 std::cerr <<
"[OutputCsvTool]: None of the given intervals are within the simulation "
779 "time span! Please provide at least one valid interval.\n";
780 throw std::runtime_error(
781 "[OutputCsvTool]: None of the given intervals are within the simulation time span! "
782 "Please provide at least one valid interval.\n");
787 << m_interval_start_times_seconds.
size()
788 <<
" intervals are outside of the simulation time span and will be ignored\n";
802 while (m_currentIndex < m_interval_start_times_seconds.size())
806 if (m_interval_start_times_seconds[m_currentIndex]
807 <= m_start_time_seconds + this->sim->time_step * m_time_delta
808 && m_interval_end_times_seconds[m_currentIndex]
809 >= m_start_time_seconds +
this->sim->time_step * m_time_delta)
811 if (this->sim->time_step %
this->ini_file_data.getIntParameters(
"interval") == 0)
822 else if (m_interval_end_times_seconds[m_currentIndex]
823 < 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