diff --git a/etc/controlDict b/etc/controlDict index c449984bdb267e3a84f6dbf630fe0f31411a87af..c3b4265142b35b50928ded1885f4e9cb010ee5b5 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -38,6 +38,7 @@ InfoSwitches writePrecision 6; writeJobInfo 0; writeDictionaries 0; + writeOptionalEntries 0; // Allow case-supplied C++ code (#codeStream, codedFixedValue) allowSystemOperations 1; diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index fbc567b3bddffe10c1ac2abba7ee08b1a7b1ff57..72a155bf6c323d34f8ff5ac895d6f76805904f12 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -34,8 +34,13 @@ License namespace Foam { -defineTypeNameAndDebug(dictionary, 0); -const dictionary dictionary::null; + defineTypeNameAndDebug(dictionary, 0); + const dictionary dictionary::null; + + bool dictionary::writeOptionalEntries + ( + debug::infoSwitch("writeOptionalEntries", 0) + ); } diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 3d4bdf1c633836df782fbaf320927bc71431b1b0..bbba527971e059c3456a4e491b09cfdb8e6ed226 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -142,6 +142,10 @@ class dictionary { // Private data + //- If true write optional keywords and values + // if not present in dictionary + static bool writeOptionalEntries; + //- HashTable of the entries held on the DL-list for quick lookup HashTable<entry*> hashedEntries_; diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C index b1b1c6fd4fa9d8321096fc202e053021e0bd6d3d..5211fc7bdac60116eee2186c5d210c4651c40706 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C +++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,6 +45,14 @@ T Foam::dictionary::lookupOrDefault } else { + if (writeOptionalEntries) + { + IOInfoIn("dictionary::lookupOrDefault", *this) + << "Optional entry '" << keyword << "' is not present," + << " returning the default value '" << deflt + << endl; + } + return deflt; } } @@ -67,6 +75,14 @@ T Foam::dictionary::lookupOrAddDefault } else { + if (writeOptionalEntries) + { + IOInfoIn("dictionary::lookupOrAddDefault", *this) + << "Optional entry '" << keyword << "' is not present," + << " adding and returning the default value '" << deflt + << endl; + } + add(new primitiveEntry(keyword, deflt)); return deflt; } @@ -76,13 +92,13 @@ T Foam::dictionary::lookupOrAddDefault template<class T> bool Foam::dictionary::readIfPresent ( - const word& k, + const word& keyword, T& val, bool recursive, bool patternMatch ) const { - const entry* entryPtr = lookupEntryPtr(k, recursive, patternMatch); + const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch); if (entryPtr) { @@ -91,6 +107,14 @@ bool Foam::dictionary::readIfPresent } else { + if (writeOptionalEntries) + { + IOInfoIn("dictionary::readIfPresent", *this) + << "Optional entry '" << keyword << "' is not present," + << " the default value '" << val << "' will be used." + << endl; + } + return false; } }