Skip to content

Commit db0338a

Browse files
authored
Merge pull request #1481 from rjoussen/fix-pvd-writer
Fix the pvd file writer for restarts from parent directory
2 parents 4956d72 + c6ef732 commit db0338a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/core/io/src/4C_io_vtk_writer_base.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ VtkWriterBase::VtkWriterBase(unsigned int myrank, unsigned int num_processors,
184184
const std::string& restart_name, double restart_time, bool write_binary_output,
185185
LibB64::CompressionLevel compression_level)
186186
: currentPhase_(VAGUE),
187+
path_existing_working_directory_(path_existing_working_directory),
187188
num_timestep_digits_(LibB64::ndigits(max_number_timesteps_to_be_written)),
188189
num_processor_digits_(LibB64::ndigits(num_processors)),
189190
geometry_name_(geometry_name),
@@ -707,7 +708,7 @@ void VtkWriterBase::create_restarted_initial_collection_file_mid_section(
707708

708709
// open collection file
709710
std::ifstream restart_collection_file;
710-
restart_collection_file.open(restartcollectionfilename.c_str(), std::ios::out);
711+
restart_collection_file.open(restartcollectionfilename.c_str(), std::ios::in);
711712

712713
// check if file was found
713714
if (not restart_collection_file) FOUR_C_THROW(" restart collection file could not be found");
@@ -727,10 +728,12 @@ void VtkWriterBase::create_restarted_initial_collection_file_mid_section(
727728
std::filesystem::path p_filename(get_xml_option_value(line, "file"));
728729

729730
// Choose base directory: on absolute restart select its parent directory
730-
// otherwise keep relative with ".")
731+
// otherwise form relative path from current working directory to the restart directory
731732
const std::filesystem::path base_dir =
732-
p_restart.is_absolute() ? p_restart.parent_path()
733-
: (std::filesystem::path(".") / p_restart.parent_path());
733+
p_restart.is_absolute()
734+
? p_restart.parent_path()
735+
: std::filesystem::relative(std::filesystem::absolute(p_restart.parent_path()),
736+
std::filesystem::absolute(path_existing_working_directory_));
734737

735738
// Resolve final path: select absolute file paths, otherwise anchor at base directory
736739
const std::filesystem::path resolved =
@@ -741,7 +744,9 @@ void VtkWriterBase::create_restarted_initial_collection_file_mid_section(
741744
resolved.lexically_normal().generic_string(), readtime);
742745
}
743746
else
747+
{
744748
break;
749+
}
745750
}
746751
}
747752

src/core/io/src/4C_io_vtk_writer_base.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ class VtkWriterBase
312312
//! containing [time value and filename] of all yet written master files
313313
std::stringstream collection_file_midsection_cumulated_content_;
314314

315+
//! full path of the existing working directory where the vtk subdirectory is created.
316+
//! relative or absolute depending on output specification
317+
std::string path_existing_working_directory_;
315318

316319
//! full path of the working directory for all vtk files to be written into
317320
std::string working_directory_full_path_;

0 commit comments

Comments
 (0)