diff --git a/opm/simulators/flow/Main.hpp b/opm/simulators/flow/Main.hpp index 97b777bb8..bad2bdb15 100644 --- a/opm/simulators/flow/Main.hpp +++ b/opm/simulators/flow/Main.hpp @@ -435,6 +435,7 @@ private: deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName); outputDir = EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir); } + ensureOutputDirExists(outputDir); #if HAVE_DAMARIS enableDamarisOutput_ = EWOMS_GET_PARAM(PreTypeTag, bool, EnableDamarisOutput); diff --git a/opm/simulators/utils/readDeck.cpp b/opm/simulators/utils/readDeck.cpp index 21c587d4b..1448e8cba 100644 --- a/opm/simulators/utils/readDeck.cpp +++ b/opm/simulators/utils/readDeck.cpp @@ -93,23 +93,6 @@ namespace { ->setMessageLimiter(std::make_shared(10, limits)); } - void ensureOutputDirExists_(const std::string& cmdline_output_dir) - { - namespace fs = std::filesystem; - - if (! fs::is_directory(cmdline_output_dir)) { - try { - fs::create_directories(cmdline_output_dir); - } - catch (...) { - throw std::runtime_error { - fmt::format("Creation of output directory '{}' failed", - cmdline_output_dir) - }; - } - } - } - void loadObjectsFromRestart(const Opm::Deck& deck, const Opm::Parser& parser, const Opm::ParseContext& parseContext, @@ -376,6 +359,24 @@ namespace { // --------------------------------------------------------------------------- + +void Opm::ensureOutputDirExists(const std::string& cmdline_output_dir) +{ + namespace fs = std::filesystem; + + if (! fs::is_directory(cmdline_output_dir)) { + try { + fs::create_directories(cmdline_output_dir); + } + catch (...) { + throw std::runtime_error { + fmt::format("Creation of output directory '{}' failed", + cmdline_output_dir) + }; + } + } +} + // Setup the OpmLog backends Opm::FileOutputMode Opm::setupLogging(const int mpi_rank_, @@ -387,7 +388,7 @@ Opm::setupLogging(const int mpi_rank_, const bool allRanksDbgLog) { if (!cmdline_output_dir.empty()) { - ensureOutputDirExists_(cmdline_output_dir); + ensureOutputDirExists(cmdline_output_dir); } // create logFile diff --git a/opm/simulators/utils/readDeck.hpp b/opm/simulators/utils/readDeck.hpp index b5ed3d49b..bc5701d0b 100644 --- a/opm/simulators/utils/readDeck.hpp +++ b/opm/simulators/utils/readDeck.hpp @@ -57,6 +57,10 @@ enum class FileOutputMode { OUTPUT_ALL = 3, }; +// Ensure that a directory exists, creating it if it does not. +void +ensureOutputDirExists(const std::string& cmdline_output_dir); + // Setup the OpmLog backends FileOutputMode setupLogging(int mpi_rank_,