diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 9a85725e381c17d83e7bda91caf23764b777b48f..df2357982a83e4cb1f0e94f159f46b5bbdc4931b 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -32,6 +32,8 @@ License #include "dictionaryEntry.H" #include "regExp.H" #include "OSHA1stream.H" +#include "argList.H" +#include "registerSwitch.H" /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ @@ -48,6 +50,31 @@ int Foam::dictionary::writeOptionalEntries ); +registerInfoSwitch +( + "writeOptionalEntries", + int, + Foam::dictionary::writeOptionalEntries +); + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::fileName Foam::dictionary::relativeName(const bool caseTag) const +{ + const fileName caseDir(argList::envGlobalPath()); + + if (!caseDir.empty() && name().isAbsolute()) + { + return name().relative(caseDir, caseTag); + } + else + { + return name(); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::dictionary::dictionary() diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 2dc09a2c14a40de6c530225f3d1ab984267dc1fd..9e0b7cf49860e7b20dd5e772916d040e38543555 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -284,11 +284,6 @@ private: // Private Data - //- Report optional keywords and values if not present in dictionary - // For value greater than 1: fatal. - // Set/unset via an InfoSwitch - static int writeOptionalEntries; - //- The dictionary name fileName name_; @@ -363,12 +358,29 @@ private: //- Emit IOError about bad input for the entry void raiseBadInput(const word& keyword) const; + //- The case-relative dictionary name. Uses FOAM_CASE + fileName relativeName(const bool caseTag=false) const; + + //- Report (on stderr) that the keyword default value was used + template<class T> + void reportDefault + ( + const word& keyword, + const T& deflt, + const bool added = false + ) const; + public: // Declare name of the class and its debug switch ClassName("dictionary"); + //- Report optional keywords and values if not present in dictionary + // For value greater than 1: fatal. + // Set/unset via an InfoSwitch + static int writeOptionalEntries; + //- An empty dictionary, which is also the parent for all dictionaries static const dictionary null; diff --git a/src/OpenFOAM/db/dictionary/dictionaryCompat.C b/src/OpenFOAM/db/dictionary/dictionaryCompat.C index ca4a9a7cbb8f2578377e50962a98df59f769c15a..b996d5583667d7c57890da8ac67138a658203a92 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryCompat.C +++ b/src/OpenFOAM/db/dictionary/dictionaryCompat.C @@ -65,9 +65,8 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat if (finder.good()) { - // Only want a single warning (on master), but guard with a - // parRun check to avoid Pstream::master() when Pstream has not - // yet been initialized + // Want single warning (on master), but guard with parRun to avoid + // Pstream::master() when Pstream has not yet been initialized if ( shouldWarnVersion(iter.second) diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C index 1ae164b5ecabc2d280ff2db87d7fb3a3f8d25e2b..cf386c1ed80effcc3946435a23e29090103eaf6b 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C +++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C @@ -28,6 +28,30 @@ License #include "dictionary.H" #include "primitiveEntry.H" +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template<class T> +void Foam::dictionary::reportDefault +( + const word& keyword, + const T& deflt, + const bool added +) const +{ + InfoErr + << "Dictionary: " << relativeName(true).c_str() + << " Entry: " << keyword; + + if (added) + { + InfoErr + << " Added"; + } + InfoErr + << " Default: " << deflt << nl; +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Compare> @@ -118,15 +142,13 @@ T Foam::dictionary::getOrDefault if (writeOptionalEntries > 1) { FatalIOErrorInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Default '" << deflt << "' ignored" << nl + << "No optional entry: " << keyword + << " Default: " << deflt << nl << exit(FatalIOError); } else { - IOInfoInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Using default '" << deflt << "'" << nl; + reportDefault(keyword, deflt); } } @@ -160,15 +182,13 @@ T Foam::dictionary::getOrAdd if (writeOptionalEntries > 1) { FatalIOErrorInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Default '" << deflt << "' ignored" << nl + << "No optional entry: " << keyword + << " Default: " << deflt << nl << exit(FatalIOError); } else { - IOInfoInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Adding default '" << deflt << "'" << nl; + reportDefault(keyword, deflt, true); } } @@ -218,15 +238,13 @@ T Foam::dictionary::getCheckOrDefault if (writeOptionalEntries > 1) { FatalIOErrorInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Default '" << deflt << "' ignored" << nl + << "No optional entry: " << keyword + << " Default: " << deflt << nl << exit(FatalIOError); } else { - IOInfoInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Using default '" << deflt << "'" << nl; + reportDefault(keyword, deflt); } } @@ -275,15 +293,13 @@ T Foam::dictionary::getCheckOrAdd if (writeOptionalEntries > 1) { FatalIOErrorInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Default '" << deflt << "' ignored" << nl + << "No optional entry: " << keyword + << " Default: " << deflt << nl << exit(FatalIOError); } else { - IOInfoInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Adding default '" << deflt << "'" << nl; + reportDefault(keyword, deflt, true); } } @@ -449,15 +465,13 @@ T Foam::dictionary::getOrDefaultCompat if (writeOptionalEntries > 1) { FatalIOErrorInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Default '" << deflt << "' ignored" << nl + << "No optional entry: " << keyword + << " Default: " << deflt << nl << exit(FatalIOError); } else { - IOInfoInFunction(*this) - << "Optional entry '" << keyword - << "' not found. Using default '" << deflt << "'" << nl; + reportDefault(keyword, deflt); } } diff --git a/src/OpenFOAM/global/debug/debug.C b/src/OpenFOAM/global/debug/debug.C index c37c503844f55ab8bb53808bffa84f1420c676dd..6e851b3f4974ba1c20694ce8c646277244f43293 100644 --- a/src/OpenFOAM/global/debug/debug.C +++ b/src/OpenFOAM/global/debug/debug.C @@ -62,13 +62,8 @@ simpleObjectRegistry* dimensionedConstantObjectsPtr_(nullptr); // To ensure controlDictPtr_ is deleted at the end of the run -class deleteControlDictPtr +struct deleteControlDictPtr { -public: - - deleteControlDictPtr() - {} - ~deleteControlDictPtr() { deleteDemandDrivenData(debugObjectsPtr_); @@ -92,6 +87,35 @@ deleteControlDictPtr deleteControlDictPtr_; } // End namespace Foam +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Like dictionary getOrAdd (default), but circumventing +// writeOptionalEntries to avoid extremely noisy output +template<class T> +static inline T getOrAdd +( + dictionary& dict, + const char* name, + const T deflt +) +{ + const entry* eptr = dict.findEntry(name, keyType::LITERAL); + + if (eptr) + { + return eptr->get<T>(); + } + + dict.add(new primitiveEntry(name, deflt)); + return deflt; +} + +} // End namespace Foam + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Foam::dictionary& Foam::debug::controlDict() @@ -142,7 +166,8 @@ Foam::dictionary& Foam::debug::switchSet if (!eptr || !eptr->isDict()) { - cerr<< "debug::switchSet(const char*, dictionary*&):\n" + std::cerr + << "debug::switchSet(const char*, dictionary*&):\n" << " Cannot find " << subDictName << " in dictionary " << controlDict().name().c_str() << std::endl << std::endl; @@ -175,43 +200,31 @@ Foam::dictionary& Foam::debug::optimisationSwitches() } -int Foam::debug::debugSwitch(const char* name, const int defaultValue) +int Foam::debug::debugSwitch(const char* name, const int deflt) { - return debugSwitches().lookupOrAddDefault - ( - name, defaultValue, keyType::LITERAL - ); + return getOrAdd(debugSwitches(), name, deflt); } -int Foam::debug::infoSwitch(const char* name, const int defaultValue) +int Foam::debug::infoSwitch(const char* name, const int deflt) { - return infoSwitches().lookupOrAddDefault - ( - name, defaultValue, keyType::LITERAL - ); + return getOrAdd(infoSwitches(), name, deflt); } -int Foam::debug::optimisationSwitch(const char* name, const int defaultValue) +int Foam::debug::optimisationSwitch(const char* name, const int deflt) { - return optimisationSwitches().lookupOrAddDefault - ( - name, defaultValue, keyType::LITERAL - ); + return getOrAdd(optimisationSwitches(), name, deflt); } float Foam::debug::floatOptimisationSwitch ( const char* name, - const float defaultValue + const float deflt ) { - return optimisationSwitches().lookupOrAddDefault - ( - name, defaultValue, keyType::LITERAL - ); + return getOrAdd(optimisationSwitches(), name, deflt); } @@ -393,7 +406,7 @@ Foam::simpleObjectRegistry& Foam::debug::dimensionedConstantObjects() namespace Foam { -void listSwitches +static void listSwitches ( const wordList& debugSwitches, const wordList& infoSwitches, @@ -431,26 +444,26 @@ void listSwitches wordHashSet hashset; hashset = debugSwitches; hashset -= controlDictDebug; - Info<< "Unset DebugSwitches" << hashset.sortedToc() << endl; + Info<< "Unset DebugSwitches" << hashset.sortedToc() << nl; hashset = infoSwitches; hashset -= controlDictInfo; - Info<< "Unset InfoSwitches" << hashset.sortedToc() << endl; + Info<< "Unset InfoSwitches" << hashset.sortedToc() << nl; hashset = optSwitches; hashset -= controlDictOpt; - Info<< "Unset OptimisationSwitches" << hashset.sortedToc() << endl; + Info<< "Unset OptimisationSwitches" << hashset.sortedToc() << nl; } else { IOobject::writeDivider(Info); - Info<< "DebugSwitches" << debugSwitches << endl; - Info<< "InfoSwitches" << infoSwitches << endl; - Info<< "OptimisationSwitches" << optSwitches << endl; + Info<< "DebugSwitches" << debugSwitches << nl + << "InfoSwitches" << infoSwitches << nl + << "OptimisationSwitches" << optSwitches << nl; } } -} +} // End namespace Foam void Foam::debug::listSwitches(const bool unset) diff --git a/src/OpenFOAM/global/debug/debug.H b/src/OpenFOAM/global/debug/debug.H index 5aa8f9744c8d659b403d62dc29276920ad6cb7d5..dc3bef6d280e15ebad4f3ff99ab8b941be6d8f28 100644 --- a/src/OpenFOAM/global/debug/debug.H +++ b/src/OpenFOAM/global/debug/debug.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -78,20 +78,16 @@ namespace debug dictionary& optimisationSwitches(); //- Lookup debug switch or add default value. - int debugSwitch(const char* name, const int defaultValue=0); + int debugSwitch(const char* name, const int deflt = 0); //- Lookup info switch or add default value. - int infoSwitch(const char* name, const int defaultValue=0); + int infoSwitch(const char* name, const int deflt = 0); //- Lookup optimisation switch or add default value. - int optimisationSwitch(const char* name, const int defaultValue=0); + int optimisationSwitch(const char* name, const int deflt = 0); //- Lookup optimisation switch or add default value. - float floatOptimisationSwitch - ( - const char* name, - const float defaultValue=0 - ); + float floatOptimisationSwitch(const char* name, const float deflt = 0); //- Internal function to lookup a sub-dictionary from controlDict. dictionary& switchSet(const char* subDictName, dictionary*& subDictPtr);