Make ensureOutputDirExists() callable outside readDeck.cpp, and use it.

This is necessary because when using Damaris we must have the output dir ready
when we initialize Damaris. In the existing code, this was ensured only
from the setupLogging() call.
This commit is contained in:
Atgeirr Flø Rasmussen
2022-10-07 14:32:46 +02:00
committed by Elyes Ahmed
parent fae71df32d
commit 926c213628
3 changed files with 24 additions and 18 deletions

View File

@@ -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);

View File

@@ -93,23 +93,6 @@ namespace {
->setMessageLimiter(std::make_shared<Opm::MessageLimiter>(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

View File

@@ -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_,