From c624590e268a278f23478b7b50c38f5cca57ce8c Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 5 Sep 2022 16:17:49 +0200 Subject: [PATCH] ENH: stricter handling of missing timeActivatedFileUpdate files (#2573) - previously threw FatalError, which downgrades to a Warning only when loading the functionObject. Now throw a FatalIOError so that missing control files are treated as a critical error. --- .../timeActivatedFileUpdate.C | 27 ++++++++++++------- .../timeActivatedFileUpdate.H | 1 - 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C index b2941a218fe..2067c283d66 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C @@ -77,7 +77,7 @@ void Foam::functionObjects::timeActivatedFileUpdate::updateFile() if (Pstream::master() || time_.distributed()) { - // Slaves do not copy if running non-distributed + // Copy on master only for non-distributed fileName tmpFile(fileToUpdate_ + Foam::name(pid())); Foam::cp(srcFile, tmpFile); Foam::mv(tmpFile, fileToUpdate_); @@ -98,7 +98,7 @@ Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate ) : timeFunctionObject(name, runTime), - fileToUpdate_("unknown-fileToUpdate"), + fileToUpdate_(), timeVsFile_(), lastIndex_(-1), modified_(false) @@ -122,26 +122,33 @@ bool Foam::functionObjects::timeActivatedFileUpdate::read lastIndex_ = -1; fileToUpdate_.expand(); + if (fileToUpdate_.empty() || timeVsFile_.empty()) + { + FatalIOErrorInFunction(dict) + << "Bad entries for fileToUpdate and/or timeVsFile" << endl + << exit(FatalIOError); + } + Info<< type() << " " << name() << " output:" << nl - << " time vs file list:" << endl; + << " time vs file list:" << nl; - forAll(timeVsFile_, i) + for (auto& tuple : timeVsFile_) { - timeVsFile_[i].second().expand(); - const fileName& srcFile = timeVsFile_[i].second(); + fileName& srcFile = tuple.second(); + srcFile.expand(); // Report case-relative path for information - Info<< " " << timeVsFile_[i].first() << tab - << time_.relativePath(srcFile, true) << endl; + Info<< " " << tuple.first() << tab + << time_.relativePath(srcFile, true) << nl; if (Pstream::master() || time_.distributed()) { if (!Foam::isFile(srcFile)) { // Report full path on error - FatalErrorInFunction + FatalIOErrorInFunction(dict) << "File not found: " << srcFile << endl - << exit(FatalError); + << exit(FatalIOError); } } } diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H index ae772b9c9b5..757428e117f 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H @@ -74,7 +74,6 @@ SourceFiles #include "timeFunctionObject.H" #include "Tuple2.H" -#include "Switch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -- GitLab