From 794e23e083fe3412cc6e5054e906af5290c3e9e6 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 4 Nov 2021 11:39:39 +0100 Subject: [PATCH] ENH: add error::master() static for low-level messages - a Pstream::master with a Pstream::parRun guard in case Pstream has not yet been initialised, as will be the case for low-level messages during startup. - propagate relativeName handling into IOstreams --- src/OpenFOAM/db/IOobject/IOobjectReadHeader.C | 10 ++--- .../decomposedBlockData/decomposedBlockData.C | 12 +++--- .../db/IOstreams/IOstreams/IOstream.C | 10 ++++- .../db/IOstreams/IOstreams/IOstream.H | 4 ++ src/OpenFOAM/db/dictionary/dictionary.C | 41 ++++++++++--------- src/OpenFOAM/db/dictionary/dictionaryCompat.C | 13 ++---- .../dictionaryEntry/dictionaryEntry.H | 8 +++- src/OpenFOAM/db/dictionary/entry/entry.C | 26 +++++++++--- src/OpenFOAM/db/dictionary/entry/entry.H | 13 +++++- src/OpenFOAM/db/dictionary/entry/entryIO.C | 3 +- .../functionEntries/calcEntry/calcEntry.C | 5 ++- .../functionEntries/codeStream/codeStream.C | 2 +- .../functionEntries/evalEntry/evalEntry.C | 39 +++++++----------- .../functionEntry/functionEntry.C | 15 +++---- .../functionEntry/functionEntry.H | 22 +++++----- .../functionEntries/ifeqEntry/ifeqEntry.C | 4 +- .../includeEntry/includeEntry.C | 6 +-- .../includeEtcEntry/includeEtcEntry.C | 6 +-- .../primitiveEntry/primitiveEntry.H | 6 +++ .../primitiveEntry/primitiveEntryIO.C | 31 +++----------- src/OpenFOAM/db/error/IOerror.C | 15 ++++--- src/OpenFOAM/db/error/error.C | 24 ++++++++--- src/OpenFOAM/db/error/error.H | 11 ++++- src/OpenFOAM/db/error/messageStream.C | 4 +- src/OpenFOAM/global/argList/argList.C | 2 + .../primitives/strings/stringOps/stringOps.C | 6 +-- .../coordinate/systems/coordinateSystemNew.C | 30 +++++++------- .../coordinate/systems/coordinateSystems.C | 15 ++++--- .../coordinate/systems/cylindricalCS.C | 4 +- 29 files changed, 214 insertions(+), 173 deletions(-) diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index 04e9dac79b5..099b2d7e30e 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -84,7 +84,7 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is) { FatalIOErrorInFunction(is) << " stream not open for reading essential object from file " - << is.name() + << is.relativeName() << exit(FatalIOError); } @@ -92,7 +92,7 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is) { SeriousIOErrorInFunction(is) << " stream not open for reading from file " - << is.name() << endl; + << is.relativeName() << endl; } return false; @@ -135,8 +135,8 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is) FatalIOErrorInFunction(is) << " stream failure while reading header" << " on line " << is.lineNumber() - << " of file " << is.name() - << " for essential object" << name() + << " of file " << is.relativeName() + << " for essential object:" << name() << exit(FatalIOError); } @@ -145,7 +145,7 @@ bool Foam::IOobject::readHeader(dictionary& headerDict, Istream& is) InfoInFunction << "Stream failure while reading header" << " on line " << is.lineNumber() - << " of file " << is.name() << endl; + << " of file " << is.relativeName() << endl; } objState_ = BAD; diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index ac00d96cca4..f91e5d83a93 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -259,8 +259,8 @@ Foam::decomposedBlockData::readBlock if (!headerIO.readHeader(*realIsPtr)) { FatalIOErrorInFunction(*realIsPtr) - << "Problem while reading header for object " - << is.name() << nl + << "Problem while reading object header " + << is.relativeName() << nl << exit(FatalIOError); } } @@ -273,8 +273,8 @@ Foam::decomposedBlockData::readBlock if (!headerIO.readHeader(headerStream)) { FatalIOErrorInFunction(headerStream) - << "Problem while reading header for object " - << is.name() << nl + << "Problem while reading object header " + << is.relativeName() << nl << exit(FatalIOError); } streamOptData = static_cast<IOstreamOption>(headerStream); @@ -447,8 +447,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks if (!headerIO.readHeader(*realIsPtr)) { FatalIOErrorInFunction(*realIsPtr) - << "Problem while reading header for object " - << is.name() << nl + << "Problem while reading object header " + << is.relativeName() << nl << exit(FatalIOError); } } diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C index a824586944c..66c6ff87f22 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.C @@ -28,6 +28,7 @@ License #include "IOstream.H" #include "error.H" +#include "argList.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -48,6 +49,12 @@ Foam::fileName& Foam::IOstream::name() } +Foam::fileName Foam::IOstream::relativeName() const +{ + return argList::envRelativePath(this->name()); +} + + bool Foam::IOstream::check(const char* operation) const { return fatalCheck(operation); @@ -61,7 +68,8 @@ bool Foam::IOstream::fatalCheck(const char* operation) const if (!ok) { FatalIOErrorInFunction(*this) - << "error in IOstream " << name() << " for operation " << operation + << "error in IOstream " << relativeName() + << " for operation " << operation << exit(FatalIOError); } diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H index 2ac6ca0b8e8..415fd7d8625 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/IOstream.H @@ -201,6 +201,10 @@ public: //- Return stream name for modification virtual fileName& name(); + //- Return the name of the stream relative to the current case. + // Uses argList::envRelativePath() + fileName relativeName() const; + // Check diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 9ef4d995d68..cef7f9ea244 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -262,7 +262,7 @@ void Foam::dictionary::checkITstream "", // functionName "", // sourceFileName 0, // sourceFileLineNumber - this->name(), // ioFileName + relativeName(), // ioFileName == dictionary name is.lineNumber() // ioStartLineNumber ); @@ -284,7 +284,8 @@ void Foam::dictionary::checkITstream << remaining << " excess tokens in stream" << nl << nl; std::cerr - << "file: " << this->name() + // ioFileName == dictionary name + << "file: " << relativeName() << " at line " << is.lineNumber() << '.' << nl << std::endl; @@ -301,7 +302,7 @@ void Foam::dictionary::checkITstream "", // functionName "", // sourceFileName 0, // sourceFileLineNumber - this->name(), // ioFileName + relativeName(), // ioFileName == dictionary name is.lineNumber() // ioStartLineNumber ) << "Entry '" << keyword @@ -317,7 +318,8 @@ void Foam::dictionary::checkITstream << "' had no tokens in stream" << nl << nl; std::cerr - << "file: " << this->name() + // ioFileName == dictionary name + << "file: " << relativeName() << " at line " << is.lineNumber() << '.' << nl << std::endl; @@ -340,7 +342,7 @@ void Foam::dictionary::raiseBadInput "", // functionName "", // sourceFileName 0, // sourceFileLineNumber - this->name(), // ioFileName + relativeName(), // ioFileName == dictionary name is.lineNumber(), // ioStartLineNumber -1 // ioEndLineNumber ) @@ -401,7 +403,7 @@ const Foam::entry& Foam::dictionary::lookupEntry { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " - << name() << nl + << relativeName() << nl << exit(FatalIOError); } @@ -525,7 +527,7 @@ const Foam::dictionary& Foam::dictionary::subDict { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " - << name() << nl + << relativeName() << nl << exit(FatalIOError); } @@ -545,7 +547,7 @@ Foam::dictionary& Foam::dictionary::subDict { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " - << name() << nl + << relativeName() << nl << exit(FatalIOError); } @@ -574,7 +576,7 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' is not a sub-dictionary in dictionary " - << name() << nl + << relativeName() << nl << exit(FatalIOError); } @@ -585,7 +587,7 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd FatalIOErrorInFunction(*this) << "Failed to insert sub-dictionary '" << keyword << "' in dictionary " - << name() << nl + << relativeName() << nl << exit(FatalIOError); } @@ -613,7 +615,7 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' is not a sub-dictionary in dictionary " - << name() << nl + << relativeName() << nl << exit(FatalIOError); } @@ -622,7 +624,7 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict IOWarningInFunction(*this) << "Entry '" << keyword << "' found but not a sub-dictionary in dictionary " - << name() << endl; + << relativeName() << endl; } // The move constructor properly qualifies the dictionary name @@ -649,7 +651,7 @@ const Foam::dictionary& Foam::dictionary::optionalSubDict IOWarningInFunction(*this) << "Entry '" << keyword << "' found but not a sub-dictionary in dictionary " - << name() << endl; + << relativeName() << endl; } return *this; @@ -737,7 +739,7 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry) IOWarningInFunction(*this) << "Problem replacing entry "<< entryPtr->keyword() - << " in dictionary " << name() << endl; + << " in dictionary " << relativeName() << endl; parent_type::remove(entryPtr); @@ -765,7 +767,8 @@ Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry) IOWarningInFunction(*this) << "Attempt to add entry " << entryPtr->keyword() - << " which already exists in dictionary " << name() << endl; + << " which already exists in dictionary " + << relativeName() << endl; delete entryPtr; return nullptr; @@ -871,7 +874,7 @@ bool Foam::dictionary::merge(const dictionary& dict) { FatalIOErrorInFunction(*this) << "Attempted merge to self, for dictionary " - << name() << nl + << relativeName() << nl << abort(FatalIOError); } @@ -960,7 +963,7 @@ void Foam::dictionary::operator+=(const dictionary& rhs) { FatalIOErrorInFunction(*this) << "Attempted addition to self, for dictionary " - << name() << nl + << relativeName() << nl << abort(FatalIOError); } @@ -977,7 +980,7 @@ void Foam::dictionary::operator|=(const dictionary& rhs) { FatalIOErrorInFunction(*this) << "Attempted |= merging to self, for dictionary " - << name() << nl + << relativeName() << nl << abort(FatalIOError); } @@ -997,7 +1000,7 @@ void Foam::dictionary::operator<<=(const dictionary& rhs) { FatalIOErrorInFunction(*this) << "Attempted addition to self, for dictionary " - << name() << nl + << relativeName() << nl << abort(FatalIOError); } diff --git a/src/OpenFOAM/db/dictionary/dictionaryCompat.C b/src/OpenFOAM/db/dictionary/dictionaryCompat.C index c4668e57bf9..67fc7778667 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryCompat.C +++ b/src/OpenFOAM/db/dictionary/dictionaryCompat.C @@ -50,21 +50,14 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat if (finder.good()) { - // Want single warning (on master), but guard with parRun to avoid - // Pstream::master() when Pstream has not yet been initialized - if - ( - (Pstream::parRun() ? Pstream::master() : true) - && error::warnAboutAge(alt.second) - ) + if (error::warnAboutAge(alt.second) && error::master()) { std::cerr << "--> FOAM IOWarning :" << nl << " Found [v" << alt.second << "] '" << alt.first << "' entry instead of '" << keyword.c_str() << "' in dictionary \"" - << name().c_str() << "\" " - << nl + << relativeName() << '"' << nl << std::endl; error::warnAboutAge("keyword", alt.second); @@ -113,7 +106,7 @@ const Foam::entry& Foam::dictionary::lookupEntryCompat { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " - << name() + << relativeName() << exit(FatalIOError); } diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H index 21ed4be264a..1380f427d67 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H @@ -125,6 +125,12 @@ public: return dictionary::name(); } + //- Return scoped dictionary name relative to the current case + virtual fileName relativeName() const + { + return dictionary::relativeName(); + } + //- Return line number of first token in dictionary virtual label startLineNumber() const; @@ -132,7 +138,7 @@ public: virtual label endLineNumber() const; //- This entry is not a primitive, - // calling this function generates a FatalError + //- calling this function generates a FatalError virtual ITstream& stream() const; diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index 3e5fe338773..a357421a7fd 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,6 +44,20 @@ Foam::entry::inputMode Foam::entry::globalInputMode = inputMode::MERGE; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +void Foam::entry::reportReadWarning +( + const IOstream& is, + const std::string& msg +) +{ + std::cerr + << "--> FOAM Warning :\n" + << " Reading \"" << is.relativeName() + << "\" at line " << is.lineNumber() << '\n' + << " " << msg << std::endl; +} + + void Foam::entry::resetInputMode() { globalInputMode = inputMode::MERGE; @@ -85,7 +99,7 @@ void Foam::entry::raiseBadInput(const ITstream& is) const "", // functionName "", // sourceFileName 0, // sourceFileLineNumber - this->name(), // ioFileName + this->relativeName(), // ioFileName is.lineNumber() // ioStartLineNumber ) << "Entry '" << keyword << "' with invalid input" << nl << nl @@ -110,7 +124,7 @@ void Foam::entry::checkITstream(const ITstream& is) const "", // functionName "", // sourceFileName 0, // sourceFileLineNumber - this->name(), // ioFileName + this->relativeName(), // ioFileName is.lineNumber() // ioStartLineNumber ); @@ -132,7 +146,7 @@ void Foam::entry::checkITstream(const ITstream& is) const << remaining << " excess tokens in stream" << nl << nl; std::cerr - << "file: " << this->name() + << "file: " << this->relativeName() << " at line " << is.lineNumber() << '.' << nl << std::endl; @@ -149,7 +163,7 @@ void Foam::entry::checkITstream(const ITstream& is) const "", // functionName "", // sourceFileName 0, // sourceFileLineNumber - this->name(), // ioFileName + this->relativeName(), // ioFileName is.lineNumber() // ioStartLineNumber ) << "Entry '" << keyword @@ -165,7 +179,7 @@ void Foam::entry::checkITstream(const ITstream& is) const << "' had no tokens in stream" << nl << nl; std::cerr - << "file: " << this->name() + << "file: " << this->relativeName() << " at line " << is.lineNumber() << '.' << nl << std::endl; diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index a180e93c236..e91f8aaca10 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.H @@ -87,7 +87,7 @@ public: private: - // Private data + // Private Data //- Keyword of entry keyType keyword_; @@ -114,6 +114,14 @@ private: void raiseBadInput(const ITstream& is) const; +protected: + + // Protected Member Functions + + //- Report a read warning (on std::cerr) + static void reportReadWarning(const IOstream&, const std::string&); + + public: //- Enable or disable use of function entries and variable expansions. @@ -202,6 +210,9 @@ public: //- Return the entry name for modification virtual fileName& name() = 0; + //- Return the entry name relative to the current case + virtual fileName relativeName() const = 0; + //- Return line number of first token in dictionary virtual label startLineNumber() const = 0; diff --git a/src/OpenFOAM/db/dictionary/entry/entryIO.C b/src/OpenFOAM/db/dictionary/entry/entryIO.C index 48a0d9d83a6..886458d77f8 100644 --- a/src/OpenFOAM/db/dictionary/entry/entryIO.C +++ b/src/OpenFOAM/db/dictionary/entry/entryIO.C @@ -92,10 +92,11 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is) << "--> FOAM Warning :" << nl << " From function " << FUNCTION_NAME << nl << " in file " << __FILE__ << " at line " << __LINE__ << nl - << " Reading " << is.name() << nl + << " Reading " << is.relativeName() << nl << " found " << keyToken << nl << " expected either " << token::END_BLOCK << " or EOF" << std::endl; + return false; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C index 94c128ef7d2..cf3b0734de9 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C @@ -68,8 +68,9 @@ Foam::string Foam::functionEntries::calcEntry::evaluate ) { DetailInfo - << "Using #calc at line " << is.lineNumber() - << " in file " << parentDict.name() << endl; + << "Using #calc - line " + << is.lineNumber() << " in file " + << parentDict.relativeName() << nl; dynamicCode::checkSecurity ( diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 78d33f45537..2eedd92ce76 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -356,7 +356,7 @@ Foam::string Foam::functionEntries::codeStream::evaluate { DetailInfo << "Using #codeStream at line " << is.lineNumber() - << " in file " << parentDict.name() << endl; + << " in file " << parentDict.relativeName() << endl; dynamicCode::checkSecurity ( diff --git a/src/OpenFOAM/db/dictionary/functionEntries/evalEntry/evalEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/evalEntry/evalEntry.C index efce884ea61..89d153a31ae 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/evalEntry/evalEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/evalEntry/evalEntry.C @@ -58,25 +58,6 @@ namespace functionEntries // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // -namespace -{ - // This is akin to a SafeIOWarning, which does not yet exist - inline void safeIOWarning - ( - const Foam::IOstream& is, - const std::string& msg - ) - { - std::cerr - << "--> FOAM Warning :\n" - << " Reading \"" << is.name() << "\" at line " - << is.lineNumber() << '\n' - << " " << msg << std::endl; - } - -} // End anonymous namespace - - namespace Foam { @@ -158,8 +139,6 @@ static bool slurpUntilBalancedBrace(ISstream& is, std::string& str) str.append(buf, nChar); // Finalize pending content - safeIOWarning(is, "Premature end while reading expression - missing '}'?"); - is.fatalCheck(FUNCTION_NAME); return false; } @@ -252,7 +231,8 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate { InfoErr << "Empty #eval - line " - << is.lineNumber() << " in file " << parentDict.name() << nl; + << is.lineNumber() << " in file " + << parentDict.relativeName() << nl; return tokenList(); } @@ -268,7 +248,8 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate { InfoErr << "Failed #eval - line " - << is.lineNumber() << " in file " << parentDict.name() << nl; + << is.lineNumber() << " in file " + << parentDict.relativeName() << nl; return tokenList(); } @@ -296,7 +277,8 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate #ifdef FULLDEBUG DetailInfo << "Using #eval - line " - << is.lineNumber() << " in file " << parentDict.name() << nl; + << is.lineNumber() << " in file " + << parentDict.relativeName() << nl; #endif token tok(is); @@ -321,7 +303,14 @@ Foam::tokenList Foam::functionEntries::evalEntry::evaluate else if (tok.isPunctuation(token::BEGIN_BLOCK)) { // - #eval { expr } - slurpUntilBalancedBrace(dynamic_cast<ISstream&>(is), str); + if (!slurpUntilBalancedBrace(dynamic_cast<ISstream&>(is), str)) + { + reportReadWarning + ( + is, + "Premature end while reading expression - missing '}'?" + ); + } } else { diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C index 837221ad306..62664f00dfe 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -71,7 +72,7 @@ Foam::functionEntry::functionEntry : primitiveEntry ( - word(key+dict.name()+Foam::name(is.lineNumber())), + word(key + dict.name() + Foam::name(is.lineNumber())), readLine(key, is) ) {} @@ -106,9 +107,9 @@ bool Foam::functionEntry::execute { FatalErrorInFunction << "Unknown functionEntry '" << functionName - << "' in " << is.name() << " near line " << is.lineNumber() - << nl << nl - << "Valid functionEntries :" << endl + << "' in " << is.relativeName() + << " near line " << is.lineNumber() << nl << nl + << "Valid functionEntries :" << nl << executedictionaryIstreamMemberFunctionTablePtr_->sortedToc() << exit(FatalError); } @@ -148,9 +149,9 @@ bool Foam::functionEntry::execute { FatalErrorInFunction << "Unknown functionEntry '" << functionName - << "' in " << is.name() << " near line " << is.lineNumber() - << nl << nl - << "Valid functionEntries :" << endl + << "' in " << is.relativeName() + << " near line " << is.lineNumber() << nl << nl + << "Valid functionEntries :" << nl << executeprimitiveEntryIstreamMemberFunctionTablePtr_->sortedToc() << exit(FatalError); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H index 8eaca871562..9b796f3f60c 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,15 +49,15 @@ SourceFiles #ifndef functionEntry_H #define functionEntry_H -#include "word.H" -#include "memberFunctionSelectionTables.H" #include "primitiveEntry.H" +#include "memberFunctionSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward Declarations class dictionary; /*---------------------------------------------------------------------------*\ @@ -67,17 +68,10 @@ class functionEntry : public primitiveEntry { - // Private Member Functions - - //- No copy construct - functionEntry(const functionEntry&) = delete; - - //- No copy assignment - void operator=(const functionEntry&) = delete; - - protected: + // Protected Member Functions + //- Read line and return as a string token static token readLine(const word& key, Istream& is); @@ -86,6 +80,12 @@ protected: template<class StringType> static List<StringType> readStringList(Istream& is); + //- No copy construct + functionEntry(const functionEntry&) = delete; + + //- No copy assignment + void operator=(const functionEntry&) = delete; + public: // Constructors diff --git a/src/OpenFOAM/db/dictionary/functionEntries/ifeqEntry/ifeqEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/ifeqEntry/ifeqEntry.C index ab4979f5a93..5e77c6c68a9 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/ifeqEntry/ifeqEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/ifeqEntry/ifeqEntry.C @@ -391,8 +391,8 @@ bool Foam::functionEntries::ifeqEntry::execute if (ifEntry::isTrue(e.stream())) { - // Info<< "Using #elif " << doIf << " at line " << lineNo - // << " in file " << is.name() << endl; + // Info<< "Using #elif " << doIf << " - line " << lineNo + // << " in file " << is.relativeName() << endl; break; } } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index 6e7fd29ab8b..78620c7da3e 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -170,7 +170,7 @@ bool Foam::functionEntries::includeEntry::execute FatalIOErrorInFunction(is) << "Cannot open include file " << (ifs.name().size() ? ifs.name() : rawName) - << " while reading dictionary " << parentDict.name() + << " while reading dictionary " << parentDict.relativeName() << exit(FatalIOError); return false; @@ -222,7 +222,7 @@ bool Foam::functionEntries::includeEntry::execute FatalIOErrorInFunction(is) << "Cannot open include file " << (ifs.name().size() ? ifs.name() : rawName) - << " while reading dictionary " << parentDict.name() + << " while reading dictionary " << parentDict.relativeName() << exit(FatalIOError); return false; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C index 9431a57a922..9c55a6f0c92 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -138,7 +138,7 @@ bool Foam::functionEntries::includeEtcEntry::execute FatalIOErrorInFunction(is) << "Cannot open etc file " << (ifs.name().size() ? ifs.name() : rawName) - << " while reading dictionary " << parentDict.name() + << " while reading dictionary " << parentDict.relativeName() << exit(FatalIOError); return false; @@ -178,7 +178,7 @@ bool Foam::functionEntries::includeEtcEntry::execute FatalIOErrorInFunction(is) << "Cannot open etc file " << (ifs.name().size() ? ifs.name() : rawName) - << " while reading dictionary " << parentDict.name() + << " while reading dictionary " << parentDict.relativeName() << exit(FatalIOError); return false; diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index f05a9b19c65..14e0dfb5baa 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -155,6 +155,12 @@ public: return ITstream::name(); } + //- Return token stream name relative to the current case + virtual fileName relativeName() const + { + return ITstream::relativeName(); + } + //- Return line number of first token in dictionary virtual label startLineNumber() const; diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 5dccf2fb0ab..713351dc12a 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -30,27 +30,6 @@ License #include "functionEntry.H" #include "evalEntry.H" -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace -{ - // This is akin to a SafeIOWarning, which does not yet exist - inline void safeIOWarning - ( - const Foam::IOstream& is, - const std::string& msg - ) - { - std::cerr - << "--> FOAM Warning :\n" - << " Reading \"" << is.name() << "\" at line " - << is.lineNumber() << '\n' - << " " << msg << std::endl; - } - -} // End anonymous namespace - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // bool Foam::primitiveEntry::acceptToken @@ -182,7 +161,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) --depth; if (depth < 0) { - safeIOWarning + reportReadWarning ( is, "Too many closing ')' ... was a ';' forgotten?" @@ -191,7 +170,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) else if (depth < 61 && ((balanced >> depth) & 1u)) { // Bit was set, but expected it to be unset. - safeIOWarning(is, "Imbalanced '{' with ')'"); + reportReadWarning(is, "Imbalanced '{' with ')'"); } } break; @@ -201,7 +180,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) --depth; if (depth < 0) { - safeIOWarning + reportReadWarning ( is, "Too many closing '}' ... was a ';' forgotten?" @@ -210,7 +189,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) else if (depth < 61 && !((balanced >> depth) & 1u)) { // Bit was unset, but expected it to be set. - safeIOWarning(is, "Imbalanced '(' with '}'"); + reportReadWarning(is, "Imbalanced '(' with '}'"); } } break; @@ -230,7 +209,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) if (depth) { - safeIOWarning(is, "Imbalanced brackets"); + reportReadWarning(is, "Imbalanced brackets"); } is.fatalCheck(FUNCTION_NAME); diff --git a/src/OpenFOAM/db/error/IOerror.C b/src/OpenFOAM/db/error/IOerror.C index ec1c7836d2b..7f1084498dd 100644 --- a/src/OpenFOAM/db/error/IOerror.C +++ b/src/OpenFOAM/db/error/IOerror.C @@ -27,7 +27,6 @@ License \*---------------------------------------------------------------------------*/ #include "error.H" -#include "argList.H" #include "StringStream.H" #include "fileName.H" #include "dictionary.H" @@ -100,7 +99,7 @@ Foam::OSstream& Foam::IOerror::operator() functionName, sourceFileName, sourceFileLineNumber, - argList::envRelativePath(ioStream.name()), + ioStream.relativeName(), ioStream.lineNumber(), -1 // No known endLineNumber ); @@ -137,8 +136,8 @@ Foam::OSstream& Foam::IOerror::operator() ( where.c_str(), "", // No source file - 1, // Non-zero to ensure that 'where' is reported - argList::envRelativePath(ioStream.name()), + -1, // Non-zero to ensure 'where' is reported + ioStream.relativeName(), ioStream.lineNumber(), -1 // No known endLineNumber ); @@ -155,7 +154,7 @@ Foam::OSstream& Foam::IOerror::operator() ( where.c_str(), "", // No source file - 1, // Non-zero to ensure that 'where' is reported + -1, // Non-zero to ensure 'where' is reported dict.relativeName(), dict.startLineNumber(), dict.endLineNumber() @@ -188,7 +187,7 @@ void Foam::IOerror::SafeFatalIOError << nl << "--> FOAM FATAL IO ERROR:" << nl << msg << nl - << "file: " << ioStream.name() + << "file: " << ioStream.relativeName() << " at line " << ioStream.lineNumber() << '.' << nl << nl << " From " << functionName << nl << " in file " << sourceFileName @@ -253,7 +252,7 @@ void Foam::IOerror::abort() } -void Foam::IOerror::write(Ostream& os, const bool includeTitle) const +void Foam::IOerror::write(Ostream& os, const bool withTitle) const { if (os.bad()) { @@ -261,7 +260,7 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const } os << nl; - if (includeTitle && !title().empty()) + if (withTitle && !title().empty()) { os << title().c_str() << "(openfoam-" << foamVersion::api; diff --git a/src/OpenFOAM/db/error/error.C b/src/OpenFOAM/db/error/error.C index 50aebea8160..c3acb23a03d 100644 --- a/src/OpenFOAM/db/error/error.C +++ b/src/OpenFOAM/db/error/error.C @@ -38,6 +38,20 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +bool Foam::error::master(const label communicator) +{ + // Trap negative value for comm as 'default'. This avoids direct use + // of Pstream::worldComm which may not have been initialised + + return + ( + UPstream::parRun() + ? (communicator < 0 ? UPstream::master() : UPstream::master(communicator)) + : true + ); +} + + bool Foam::error::warnAboutAge(const int version) noexcept { // No warning for 0 (unversioned) or -ve values (silent versioning) @@ -245,20 +259,20 @@ void Foam::error::simpleExit(const int errNo, const bool isAbort) error::printStack(Perr); std::abort(); } - else if (Pstream::parRun()) + else if (UPstream::parRun()) { if (isAbort) { Perr<< nl << *this << nl << "\nFOAM parallel run aborting\n" << endl; error::printStack(Perr); - Pstream::abort(); + UPstream::abort(); } else { Perr<< nl << *this << nl << "\nFOAM parallel run exiting\n" << endl; - Pstream::exit(errNo); + UPstream::exit(errNo); } } else @@ -326,7 +340,7 @@ void Foam::error::abort() } -void Foam::error::write(Ostream& os, const bool includeTitle) const +void Foam::error::write(Ostream& os, const bool withTitle) const { if (os.bad()) { @@ -334,7 +348,7 @@ void Foam::error::write(Ostream& os, const bool includeTitle) const } os << nl; - if (includeTitle && !title().empty()) + if (withTitle && !title().empty()) { os << title().c_str() << "(openfoam-" << foamVersion::api; diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index 931896bf071..22fe3ad136a 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -119,6 +119,13 @@ public: // Static Functions + //- Like Pstream::master but with a Pstream::parRun guard in case + //- Pstream has not yet been initialised. + // + // \param communicator is the numbered MPI communicator. + // By default it uses UPstream::worldComm + static bool master(const label communicator = -1); + //- Test if an age warning should be emitted. // \param version is the old version (YYMM) for determining the // age in months compared to the current OpenFOAM version @@ -244,7 +251,7 @@ public: void abort(); //- Print error message - virtual void write(Ostream& os, const bool includeTitle = true) const; + virtual void write(Ostream& os, const bool withTitle = true) const; // Housekeeping @@ -405,7 +412,7 @@ public: void abort(); //- Print error message - virtual void write(Ostream& os, const bool includeTitle = true) const; + virtual void write(Ostream& os, const bool withTitle = true) const; }; diff --git a/src/OpenFOAM/db/error/messageStream.C b/src/OpenFOAM/db/error/messageStream.C index c0fdd7d6c7a..064a95ea879 100644 --- a/src/OpenFOAM/db/error/messageStream.C +++ b/src/OpenFOAM/db/error/messageStream.C @@ -80,10 +80,10 @@ Foam::OSstream& Foam::messageStream::stream(OSstream* alternative) || severity_ == INFO_STDERR || severity_ == WARNING ) - || !Pstream::parRun() + || !UPstream::parRun() ); - if (serialOnly && (Pstream::parRun() && !Pstream::master())) + if (serialOnly && (UPstream::parRun() && !UPstream::master())) { return Snull; // Non-serial, non-master: exit early } diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index ddeb11f77f7..8179f39dd28 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -571,6 +571,7 @@ Foam::word Foam::argList::optionCompat(const word& optName) { const auto& alt = fnd.val(); + // No error::master() guard - only called on master anyhow if (error::warnAboutAge(alt.second)) { std::cerr @@ -609,6 +610,7 @@ int Foam::argList::optionIgnore(const word& optName) // '-option ARG' or '-option' const int nskip = (alt.first ? 2 : 1); + // No error::master() guard - only called on master anyhow if (error::warnAboutAge(alt.second)) { std::cerr diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index 63a7a5a60c7..c544b1ad998 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -161,9 +161,7 @@ static void expandLeadingTilde(std::string& s) // Compat Warning const int version(1806); - // Single warning (on master) with guard to avoid Pstream::master() - // when Pstream has not yet been initialized - if (UPstream::parRun() ? UPstream::master() : true) + if (error::master()) { std::cerr << nl diff --git a/src/meshTools/coordinate/systems/coordinateSystemNew.C b/src/meshTools/coordinate/systems/coordinateSystemNew.C index 4db528d396e..834f1b4183c 100644 --- a/src/meshTools/coordinate/systems/coordinateSystemNew.C +++ b/src/meshTools/coordinate/systems/coordinateSystemNew.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,19 +56,21 @@ const Foam::dictionary* Foam::coordinateSystem::subDictCompat const word csName(finder.ref().stream()); // Deprecated, unsupported syntax - - std::cerr - << "--> FOAM IOWarning :" << nl - << " Ignoring 'coordinateSystem' as a keyword." - " Perhaps you meant this instead?" << nl - << '{' << nl - << " type " << coordSystem::indirect::typeName_() - << ';' << nl - << " name " << csName << ';' << nl - << '}' << nl - << std::endl; - - error::warnAboutAge("syntax change", 1806); + if (error::master()) + { + std::cerr + << "--> FOAM IOWarning :" << nl + << " Ignoring 'coordinateSystem' as a keyword." + " Perhaps you meant this instead?" << nl + << '{' << nl + << " type " << coordSystem::indirect::typeName_() + << ';' << nl + << " name " << csName << ';' << nl + << '}' << nl + << std::endl; + + error::warnAboutAge("syntax change", 1806); + } } } diff --git a/src/meshTools/coordinate/systems/coordinateSystems.C b/src/meshTools/coordinate/systems/coordinateSystems.C index ce9eb81152b..0581a897a93 100644 --- a/src/meshTools/coordinate/systems/coordinateSystems.C +++ b/src/meshTools/coordinate/systems/coordinateSystems.C @@ -60,12 +60,15 @@ void Foam::coordinateSystems::readFromStream(const bool valid) else if (headerClassName() == headerTypeCompat) { // Older (1806 and earlier) header name - std::cerr - << "--> FOAM IOWarning :" << nl - << " Found header class name '" << headerTypeCompat - << "' instead of '" << typeName << "'" << nl; - - error::warnAboutAge("header class", 1806); + if (error::master()) + { + std::cerr + << "--> FOAM IOWarning :" << nl + << " Found header class name '" << headerTypeCompat + << "' instead of '" << typeName << "'" << nl; + + error::warnAboutAge("header class", 1806); + } this->readIstream(is, coordinateSystem::iNew()); close(); diff --git a/src/meshTools/coordinate/systems/cylindricalCS.C b/src/meshTools/coordinate/systems/cylindricalCS.C index a4884af3e1f..6b75f35a90f 100644 --- a/src/meshTools/coordinate/systems/cylindricalCS.C +++ b/src/meshTools/coordinate/systems/cylindricalCS.C @@ -55,12 +55,12 @@ namespace Foam static inline void warnCompatDegrees(const Foam::dictionary& dict) { - if (Pstream::parRun() ? Pstream::master() : true) + if (error::master()) { std::cerr << "--> FOAM IOWarning :" << nl << " Found [v1806] 'degrees' keyword in dictionary \"" - << dict.name().c_str() << "\" Ignored, now radians only." << nl + << dict.relativeName() << "\" Ignored, now radians only." << nl << std::endl; } } -- GitLab