diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index 04e9dac79b58235e56c060bda1ae55c1b0499beb..099b2d7e30e9407168bc22bcd0c4a8c4adbd1c30 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 ac00d96cca4c98f5b71148a847f89f75a6b88b66..f91e5d83a939658281f9ad86ac7797a57b040360 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 a824586944c1021bc4e06ab8f44b5b5f555eb78a..66c6ff87f22fd3d822ecdd0d4eee50f9a3985f2b 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 2ac6ca0b8e8fdaf418bb7d34b2fed79503419cdf..415fd7d8625b202c7db9a5f1bfd63d40d22872eb 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 9ef4d995d68ecec758534bd9b70ff09bea6fd4f1..cef7f9ea244b738788d4b3bd39fea48a44f6bd86 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 c4668e57bf964f40e286ea87a4c1ce09b1fd9fd4..67fc7778667f7faec05b9e25340fe628abe0c405 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 21ed4be264ae7ce666094670b4a8d02db2a7a038..1380f427d672d8c54af7a5eb78d94e5b1cafed0d 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 3e5fe3387736447922267c1319c77e6b144608bc..a357421a7fd9a63fa9df27fc156e8723552a59a5 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 a180e93c236229cd14d2b6c2ec75df0a2c9f50c3..e91f8aaca10a41ddb6ae33b8266cedf7c1ac5d1b 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 48a0d9d83a6fa01f7376a92c4ae0b63dd3c4957d..886458d77f8224e66e1939370f4f31e999014fc9 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 94c128ef7d2333b166ae63eabaf9e018723c3ca4..cf3b0734de96e85b95667e0b2149fa9395f57e5c 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 78d33f45537f79ed20f81d345d058abc227c2bf6..2eedd92ce766f5ca002d0aa444fab17ff30c4454 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 efce884ea61a27597840de421b0426b93aca9937..89d153a31aee6f905e322022d25544ed97cda3c9 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 837221ad306a2cdafebd3135a01c411424a8d90b..62664f00dfe936ab532e03db99cb727f493ef9dd 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 8eaca87156285898fb39492b6b114fe58734103f..9b796f3f60ce4aee9cb2c2d344ea5c73eb555b3b 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 ab4979f5a93828776b224ca66073daaebdcf0275..5e77c6c68a9ca2ec840928d1a3e1554b8b380fda 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 6e7fd29ab8b503a447c6e8a36dadd8bfb0edaa6c..78620c7da3e689f34b7f644bb88a5827b2e94a88 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 9431a57a9229e9d0b1c2fd2a61ac0ab23e53f1da..9c55a6f0c92e18fc604d65f5860b750d94fd03de 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 f05a9b19c65fc145f11339ac03e0225ef90ec618..14e0dfb5baa6f279c812e48f23bbb87f17946fdb 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 5dccf2fb0ab50f762c0d0e6aacd3040e98ca4645..713351dc12a085c760d3e5ea9ed030dd89b65f02 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 ec1c7836d2ba0a740adfeb194be5bbc521dd9ebd..7f1084498dd7203a40cff71371864e14afab5924 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 50aebea81608a8035969ddd09b9f55674aa9707e..c3acb23a03dbc0c1c4e4d898ef5f7c78803d6c17 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 931896bf071be248d3af6356e0181e109b08a560..22fe3ad136a0d4538d85814a86369f06122f3480 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 c0fdd7d6c7a1ad0cb4998ddf97a58eb31570380b..064a95ea879c5a9fccfa2c025e4b17e8c25e452e 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 ddeb11f77f7e14752cfb4e81537b9eb400e47728..8179f39dd2819a8c00690a7635b5deee20457326 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 63a7a5a60c7a5aea373a9c13e8e3616b1db16f38..c544b1ad9980e789dcd1633d903acbf313667420 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 4db528d396e52064ff61ba0a65dbb71abde7ad30..834f1b4183c911202cfe2cd244184fd8a216e7a5 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 ce9eb81152bda82d45612dd34a7e4ca44f5f957b..0581a897a934c86d7ef61114bbeb72f2a93abdd1 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 a4884af3e1fdb5dc227b5bba2e34c061fc3d8f42..6b75f35a90f2984d753cd4bfd85a9258a4c817d7 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; } }