From 71929413ce5e4270b9d1ab5099c016e43dbfde44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Wed, 26 Jun 2024 22:56:59 +0200 Subject: [PATCH] Change file naming scheme Place rank before timestep and add leading zeroes in the file names. This helps ParaView deduce the order correctly. --- input/in.lj | 2 +- src/vtk_writer.h | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/input/in.lj b/input/in.lj index 6d804d1..20198eb 100644 --- a/input/in.lj +++ b/input/in.lj @@ -21,6 +21,6 @@ comm_modify cutoff * 20 fix 1 all nve thermo 10 -dump dmpvtk all vtk 10 dump_*%.vtu +dump dmpvtk all vtk 10 dump%_*.vtu run 100 diff --git a/src/vtk_writer.h b/src/vtk_writer.h index 7335975..88d54a6 100644 --- a/src/vtk_writer.h +++ b/src/vtk_writer.h @@ -13,13 +13,26 @@ #define VTK_DOMAIN_WRITER_H #include +#include #include #include +namespace +{ + +std::string set_width( const int value, const unsigned width = 3 ) +{ + std::ostringstream oss; + oss << std::setw( width ) << std::setfill( '0' ) << value; + return oss.str(); +} + +} // namespace + namespace VTKWriter { // Write PVTU -void writeDomainParallelFile( MPI_Comm comm, int time_step, +void writeDomainParallelFile( MPI_Comm comm, const std::string &time_step, std::string &basename ) { // Should only be called from a single rank @@ -41,8 +54,8 @@ void writeDomainParallelFile( MPI_Comm comm, int time_step, "NumberOfComponents=\"3\"/>\n" ); fprintf( file, "\t\n" ); for ( int i = 0; i < size; ++i ) - fprintf( file, "\t\n", basename.c_str(), - time_step, i ); + fprintf( file, "\t\n", basename.c_str(), + i, time_step.c_str() ); fprintf( file, "\n" ); fprintf( file, "\n" ); fclose( file ); @@ -57,11 +70,13 @@ void writeDomain( MPI_Comm comm, int time_step, { int rank; MPI_Comm_rank( comm, &rank ); + + auto time_step_fixed = set_width( time_step ); if ( rank == 1 ) - writeDomainParallelFile( comm, time_step, basename ); + writeDomainParallelFile( comm, time_step_fixed, basename ); std::stringstream filename; // todo(sschulz): properly format, according to max rank - filename << basename << "_" << time_step << "_" << rank << ".vtu"; + filename << basename << "_" << rank << "_" << time_step_fixed << ".vtu"; FILE *file = fopen( filename.str().c_str(), "w" ); fprintf( file, "\n" ); fprintf( file, " -void writeParticles( MPI_Comm comm, const int step, t_System *system, +void writeParticles( MPI_Comm comm, const int time_step, t_System *system, std::string filename, std::ofstream &err ) { int rank; MPI_Comm_rank( comm, &rank ); + auto time_step_fixed = set_width( time_step ); // Write parallel file if ( rank == 1 ) - writeParticlesParallelFile( comm, step, filename ); + writeParticlesParallelFile( comm, time_step_fixed, filename ); // Prepare actual filename // todo(sschulz): Separate filename construction into function size_t pos = 0; pos = filename.find( "*", pos ); if ( std::string::npos == pos ) log_err( err, "VTK output file does not contain required '*'" ); - std::stringstream time_string; - time_string << step; - filename.replace( pos, 1, time_string.str() ); + filename.replace( pos, 1, time_step_fixed ); pos = 0; pos = filename.find( "%", pos ); if ( std::string::npos == pos )