Skip to content

Commit

Permalink
[partmesh] Create output directory.
Browse files Browse the repository at this point in the history
Prints a warning on error, e.g.:

warning: Could not create output directory _out. Error code 17, File exists
  • Loading branch information
bilke committed May 6, 2024
1 parent 9186f19 commit 2dd5b1f
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>

#include <filesystem>

#ifdef USE_PETSC
#include <mpi.h>
#endif
Expand Down Expand Up @@ -115,6 +117,21 @@ int main(int argc, char* argv[])
OGS_FATAL("spdlog logger error occurred.");
});

const auto output_directory = output_directory_arg.getValue();
{
std::error_code mkdir_err;
if (std::filesystem::create_directories(output_directory, mkdir_err))
{
INFO("Output directory {:s} created.", output_directory);
}
else if (mkdir_err.value() != 0)
{
WARN(
"Could not create output directory {:s}. Error code {:d}, {:s}",
output_directory, mkdir_err.value(), mkdir_err.message());
}
}

BaseLib::RunTime run_timer;
run_timer.start();
BaseLib::CPUTime CPU_timer;
Expand All @@ -130,7 +147,7 @@ int main(int argc, char* argv[])
mesh_ptr->getNumberOfElements());

std::string const output_file_name_wo_extension = BaseLib::joinPaths(
output_directory_arg.getValue(),
output_directory,
BaseLib::extractBaseNameWithoutExtension(mesh_input.getValue()));

if (ogs2metis_flag.getValue())
Expand Down Expand Up @@ -219,7 +236,7 @@ int main(int argc, char* argv[])

std::string const other_mesh_output_file_name_wo_extension =
BaseLib::joinPaths(
output_directory_arg.getValue(),
output_directory,
BaseLib::extractBaseNameWithoutExtension(filename));
auto partitions = mesh_partitioner.partitionOtherMesh(*mesh);

Expand Down

0 comments on commit 2dd5b1f

Please sign in to comment.