diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 699cdffeb8..851b9a9a46 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -368,9 +368,9 @@ const Foam::entry& Foam::dictionary::lookupEntry enum keyType::option matchOpt ) const { - const const_searcher finder(csearch(keyword, matchOpt)); + const entry* eptr = findEntry(keyword, matchOpt); - if (!finder.good()) + if (!eptr) { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " @@ -378,7 +378,7 @@ const Foam::entry& Foam::dictionary::lookupEntry << exit(FatalIOError); } - return finder.ref(); + return *eptr; } @@ -504,12 +504,12 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd { searcher finder(search(keyword, matchOpt)); - dictionary* ptr = finder.dictPtr(); + dictionary* dictPtr = finder.dictPtr(); - if (ptr) + if (dictPtr) { // Found and a sub-dictionary - return *ptr; + return *dictPtr; } if (finder.good()) @@ -521,9 +521,9 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd << exit(FatalIOError); } - ptr = this->set(keyword, dictionary())->dictPtr(); + dictPtr = this->set(keyword, dictionary())->dictPtr(); - if (!ptr) + if (!dictPtr) { FatalIOErrorInFunction(*this) << "Failed to insert sub-dictionary '" << keyword @@ -532,7 +532,7 @@ Foam::dictionary& Foam::dictionary::subDictOrAdd << exit(FatalIOError); } - return *ptr; + return *dictPtr; } @@ -545,10 +545,12 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict { const const_searcher finder(csearch(keyword, matchOpt)); - if (finder.isDict()) + const dictionary* dictPtr = finder.dictPtr(); + + if (dictPtr) { // Found and a sub-dictionary - return finder.dict(); + return *dictPtr; } if (mandatory) @@ -581,10 +583,12 @@ const Foam::dictionary& Foam::dictionary::optionalSubDict { const const_searcher finder(csearch(keyword, matchOpt)); - if (finder.isDict()) + const dictionary* dictPtr = finder.dictPtr(); + + if (dictPtr) { // Found and a sub-dictionary - return finder.dict(); + return *dictPtr; } if (finder.good()) @@ -787,10 +791,12 @@ Foam::entry* Foam::dictionary::set(entry* entryPtr) // Find non-recursive with patterns searcher finder(search(entryPtr->keyword(), keyType::REGEX)); + dictionary* dictPtr = finder.dictPtr(); + // Clear dictionary so merge acts like overwrite - if (finder.isDict()) + if (dictPtr) { - finder.dict().clear(); + dictPtr->clear(); } return add(entryPtr, true); diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index d8b75aae51..9b7b2ff50d 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -98,6 +98,7 @@ SeeAlso #include "wordList.H" #include "className.H" #include "refPtr.H" +#include "IOobjectOption.H" // Some common data types #include "label.H" @@ -175,14 +176,14 @@ public: //- Construct for the given dictionary context. // Allow implicit conversion - Searcher(dict_pointer dict) + Searcher(dict_pointer dict) noexcept : dict_(dict), eptr_(nullptr) {} //- Assign the entry - void set(pointer eptr) + void set(pointer eptr) noexcept { eptr_ = eptr; } @@ -191,7 +192,7 @@ public: public: //- Default construct - Searcher() + constexpr Searcher() noexcept : dict_(nullptr), eptr_(nullptr) @@ -199,34 +200,19 @@ public: //- True if entry was found - bool good() const noexcept - { - return eptr_; - } + bool good() const noexcept { return eptr_; } //- True if entry was found - bool found() const noexcept - { - return eptr_; - } + bool found() const noexcept { return eptr_; } //- The containing dictionary context - dict_reference context() const - { - return *dict_; - } + dict_reference context() const { return *dict_; } //- A pointer to the entry (nullptr if not found) - pointer ptr() const noexcept - { - return eptr_; - } + pointer ptr() const noexcept { return eptr_; } //- A reference to the entry (Error if not found) - reference ref() const - { - return *eptr_; - } + reference ref() const { return *eptr_; } //- True if found entry is a dictionary. bool isDict() const noexcept @@ -507,26 +493,26 @@ public: tokenList tokens() const; - // Search and lookup + // Searching - //- Search for an entry (const access) with the given keyword. + //- Find an entry (const access) with the given keyword. // // \param keyword the keyword to search for // \param matchOpt search mode (default: non-recursive with patterns) // - // \return True if entry was found - inline bool found + // \return pointer to the entry found or a nullptr. + inline const entry* findEntry ( const word& keyword, enum keyType::option matchOpt = keyType::REGEX ) const; - //- Find for an entry (non-const access) with the given keyword. + //- Find an entry (non-const access) with the given keyword. // // \param keyword the keyword to search for // \param matchOpt search mode (default: non-recursive with patterns) // - // \return the entry pointer found or a nullptr. + // \return pointer to the entry found or a nullptr. inline entry* findEntry ( const word& keyword, @@ -538,8 +524,8 @@ public: // \param keyword the keyword to search for // \param matchOpt search mode (default: non-recursive with patterns) // - // \return the entry pointer found or a nullptr. - inline const entry* findEntry + // \return True if entry was found + inline bool found ( const word& keyword, enum keyType::option matchOpt = keyType::REGEX @@ -553,7 +539,7 @@ public: // \param keyword the keyword to search for // \param matchOpt search mode (default: non-recursive with patterns) // - // \return the entry pointer found or a nullptr. + // \return pointer to the entry found or a nullptr. inline const entry* findScoped ( const word& keyword, @@ -561,7 +547,20 @@ public: ) const; //- Find and return a sub-dictionary pointer if present - // (and a sub-dictionary) otherwise return nullptr. + //- (and a sub-dictionary) otherwise return nullptr. + // + // \param keyword the keyword to search for + // \param matchOpt search mode (default: non-recursive with patterns) + // + // \return pointer to sub-dictionary found or a nullptr. + inline const dictionary* findDict + ( + const word& keyword, + enum keyType::option matchOpt = keyType::REGEX + ) const; + + //- Find and return a sub-dictionary pointer if present + //- (and a sub-dictionary) otherwise return nullptr. // // \param keyword the keyword to search for // \param matchOpt search mode (default: non-recursive with patterns) @@ -573,19 +572,21 @@ public: enum keyType::option matchOpt = keyType::REGEX ); - //- Find and return a sub-dictionary pointer if present - // (and a sub-dictionary) otherwise return nullptr. + //- Find a sub-dictionary. // // \param keyword the keyword to search for // \param matchOpt search mode (default: non-recursive with patterns) // - // \return pointer to sub-dictionary found or a nullptr. - inline const dictionary* findDict + // \return true if the sub-dictionary was found + inline bool isDict ( const word& keyword, enum keyType::option matchOpt = keyType::REGEX ) const; + + // Lookup + //- Search for an entry (const access) with the given keyword. // // \param keyword the keyword to search for @@ -659,16 +660,16 @@ public: // \param keyword the keyword to search for // \param val the value to read into // \param matchOpt search mode (default: non-recursive with patterns) - // \param mandatory the keyword is mandatory (default: true) + // \param readOpt the entry is required/optional (default: MUST_READ) // - // \return true if the entry was found. + // \return true if the entry was read template bool readEntry ( const word& keyword, T& val, enum keyType::option matchOpt = keyType::REGEX, - bool mandatory = true + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ ) const; //- Find an entry if present, and assign to T val. @@ -678,7 +679,7 @@ public: // \param val the value to read into // \param matchOpt search mode (default: non-recursive with patterns) // - // \return true if the entry was found. + // \return true if the entry was read template bool readIfPresent ( @@ -742,9 +743,9 @@ public: // \param val the value to read into // \param pred the value check predicate // \param matchOpt search mode (default: non-recursive with patterns) - // \param mandatory the keyword is mandatory (default: true) + // \param readOpt the entry is required/optional (default: MUST_READ) // - // \return true if the entry was found. + // \return true if the entry was read template bool readCheck ( @@ -752,7 +753,7 @@ public: T& val, const Predicate& pred, enum keyType::option matchOpt = keyType::REGEX, - bool mandatory = true + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ ) const; //- Find an entry if present, and assign to T val. @@ -763,7 +764,7 @@ public: // \param pred the value check predicate // \param matchOpt search mode (default: non-recursive with patterns) // - // \return true if the entry was found. + // \return true if the entry read template bool readCheckIfPresent ( @@ -773,18 +774,6 @@ public: enum keyType::option matchOpt = keyType::REGEX ) const; - //- Check if entry is found and is a sub-dictionary. - // - // \param keyword the keyword to search for - // \param matchOpt search mode (default: non-recursive with patterns) - // - // \return true if the entry was found. - inline bool isDict - ( - const word& keyword, - enum keyType::option matchOpt = keyType::REGEX - ) const; - //- Find and return a sub-dictionary. // Fatal if the entry does not exist or is not a sub-dictionary. // @@ -1120,19 +1109,6 @@ public: enum keyType::option matchOpt = keyType::REGEX ) const; - //- Search dictionary for given keyword and any compatibility names - // - // \param keyword the keyword to search for - // \param compat list of old compatibility keywords and the last - // OpenFOAM version for which they were used. - // \param matchOpt search mode (default: non-recursive with patterns) - bool foundCompat - ( - const word& keyword, - std::initializer_list> compat, - enum keyType::option matchOpt = keyType::REGEX - ) const; - //- Find and return an entry pointer if present, or return a nullptr, //- using any compatibility names if needed. // @@ -1147,6 +1123,19 @@ public: enum keyType::option matchOpt ) const; + //- Search dictionary for given keyword and any compatibility names + // + // \param keyword the keyword to search for + // \param compat list of old compatibility keywords and the last + // OpenFOAM version for which they were used. + // \param matchOpt search mode (default: non-recursive with patterns) + bool foundCompat + ( + const word& keyword, + std::initializer_list> compat, + enum keyType::option matchOpt = keyType::REGEX + ) const; + //- Find and return an entry if present, otherwise FatalIOError, //- using any compatibility names if needed. // @@ -1217,9 +1206,9 @@ public: // OpenFOAM version for which they were used. // \param val the value to read // \param matchOpt search mode (default: non-recursive with patterns) - // \param mandatory the keyword is mandatory (default: true) + // \param readOpt the entry is required/optional (default: MUST_READ) // - // \return true if the entry was found. + // \return true if the entry was read template bool readCompat ( @@ -1227,7 +1216,7 @@ public: std::initializer_list> compat, T& val, enum keyType::option matchOpt = keyType::REGEX, - bool mandatory = true + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ ) const; //- Find an entry if present, and assign to T val diff --git a/src/OpenFOAM/db/dictionary/dictionaryCompat.C b/src/OpenFOAM/db/dictionary/dictionaryCompat.C index 67fc777866..13ccb8adf8 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryCompat.C +++ b/src/OpenFOAM/db/dictionary/dictionaryCompat.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -71,17 +71,6 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat } -bool Foam::dictionary::foundCompat -( - const word& keyword, - std::initializer_list> compat, - enum keyType::option matchOpt -) const -{ - return csearchCompat(keyword, compat, matchOpt).good(); -} - - const Foam::entry* Foam::dictionary::findCompat ( const word& keyword, @@ -93,6 +82,17 @@ const Foam::entry* Foam::dictionary::findCompat } +bool Foam::dictionary::foundCompat +( + const word& keyword, + std::initializer_list> compat, + enum keyType::option matchOpt +) const +{ + return static_cast(findCompat(keyword, compat, matchOpt)); +} + + const Foam::entry& Foam::dictionary::lookupEntryCompat ( const word& keyword, @@ -100,9 +100,9 @@ const Foam::entry& Foam::dictionary::lookupEntryCompat enum keyType::option matchOpt ) const { - const const_searcher finder(csearchCompat(keyword, compat, matchOpt)); + const entry* eptr = findCompat(keyword, compat, matchOpt); - if (!finder.good()) + if (!eptr) { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " @@ -110,7 +110,7 @@ const Foam::entry& Foam::dictionary::lookupEntryCompat << exit(FatalIOError); } - return finder.ref(); + return *eptr; } diff --git a/src/OpenFOAM/db/dictionary/dictionaryI.H b/src/OpenFOAM/db/dictionary/dictionaryI.H index af4e791c96..ad7f29df04 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryI.H +++ b/src/OpenFOAM/db/dictionary/dictionaryI.H @@ -83,13 +83,13 @@ inline const Foam::dictionary& Foam::dictionary::parent() const noexcept } -inline bool Foam::dictionary::found +inline const Foam::entry* Foam::dictionary::findEntry ( const word& keyword, enum keyType::option matchOpt ) const { - return csearch(keyword, matchOpt).good(); + return csearch(keyword, matchOpt).ptr(); } @@ -99,17 +99,17 @@ inline Foam::entry* Foam::dictionary::findEntry enum keyType::option matchOpt ) { - return search(keyword, matchOpt).ptr(); + return const_cast(csearch(keyword, matchOpt).ptr()); } -inline const Foam::entry* Foam::dictionary::findEntry +inline bool Foam::dictionary::found ( const word& keyword, enum keyType::option matchOpt ) const { - return csearch(keyword, matchOpt).ptr(); + return static_cast(findEntry(keyword, matchOpt)); } @@ -123,16 +123,6 @@ inline const Foam::entry* Foam::dictionary::findScoped } -inline Foam::dictionary* Foam::dictionary::findDict -( - const word& keyword, - enum keyType::option matchOpt -) -{ - return search(keyword, matchOpt).dictPtr(); -} - - inline const Foam::dictionary* Foam::dictionary::findDict ( const word& keyword, @@ -143,13 +133,23 @@ inline const Foam::dictionary* Foam::dictionary::findDict } +inline Foam::dictionary* Foam::dictionary::findDict +( + const word& keyword, + enum keyType::option matchOpt +) +{ + return const_cast(csearch(keyword, matchOpt).dictPtr()); +} + + inline bool Foam::dictionary::isDict ( const word& keyword, enum keyType::option matchOpt ) const { - return csearch(keyword, matchOpt).isDict(); + return static_cast(findDict(keyword, matchOpt)); } diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C index 454100e2aa..7d97c858a0 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C +++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C @@ -151,13 +151,13 @@ T Foam::dictionary::getOrDefault enum keyType::option matchOpt ) const { - const const_searcher finder(csearch(keyword, matchOpt)); + const entry* eptr = csearch(keyword, matchOpt).ptr(); - if (finder.good()) + if (eptr) { T val; - ITstream& is = finder.ptr()->stream(); + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); @@ -181,13 +181,13 @@ T Foam::dictionary::getOrAdd enum keyType::option matchOpt ) { - const const_searcher finder(csearch(keyword, matchOpt)); + const entry* eptr = csearch(keyword, matchOpt).ptr(); - if (finder.good()) + if (eptr) { T val; - ITstream& is = finder.ptr()->stream(); + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); @@ -223,13 +223,13 @@ T Foam::dictionary::getCheckOrDefault } #endif - const const_searcher finder(csearch(keyword, matchOpt)); + const entry* eptr = csearch(keyword, matchOpt).ptr(); - if (finder.good()) + if (eptr) { T val; - ITstream& is = finder.ptr()->stream(); + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); @@ -269,13 +269,13 @@ T Foam::dictionary::getCheckOrAdd } #endif - const const_searcher finder(csearch(keyword, matchOpt)); + const entry* eptr = csearch(keyword, matchOpt).ptr(); - if (finder.good()) + if (eptr) { T val; - ITstream& is = finder.ptr()->stream(); + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); @@ -303,21 +303,26 @@ bool Foam::dictionary::readEntry const word& keyword, T& val, enum keyType::option matchOpt, - bool mandatory + IOobjectOption::readOption readOpt ) const { - const const_searcher finder(csearch(keyword, matchOpt)); - - if (finder.good()) + if (readOpt == IOobjectOption::NO_READ) { - ITstream& is = finder.ptr()->stream(); + return false; + } + + const entry* eptr = csearch(keyword, matchOpt).ptr(); + + if (eptr) + { + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); return true; } - else if (mandatory) + else if (IOobjectOption::isReadRequired(readOpt)) { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " @@ -336,14 +341,19 @@ bool Foam::dictionary::readCheck T& val, const Predicate& pred, enum keyType::option matchOpt, - bool mandatory + IOobjectOption::readOption readOpt ) const { - const const_searcher finder(csearch(keyword, matchOpt)); - - if (finder.good()) + if (readOpt == IOobjectOption::NO_READ) { - ITstream& is = finder.ptr()->stream(); + return false; + } + + const entry* eptr = csearch(keyword, matchOpt).ptr(); + + if (eptr) + { + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); @@ -355,7 +365,7 @@ bool Foam::dictionary::readCheck return true; } - else if (mandatory) + else if (IOobjectOption::isReadRequired(readOpt)) { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " @@ -374,21 +384,26 @@ bool Foam::dictionary::readCompat std::initializer_list> compat, T& val, enum keyType::option matchOpt, - bool mandatory + IOobjectOption::readOption readOpt ) const { - const const_searcher finder(csearchCompat(keyword, compat, matchOpt)); - - if (finder.good()) + if (readOpt == IOobjectOption::NO_READ) { - ITstream& is = finder.ptr()->stream(); + return false; + } + + const entry* eptr = csearchCompat(keyword, compat, matchOpt).ptr(); + + if (eptr) + { + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); return true; } - else if (mandatory) + else if (IOobjectOption::isReadRequired(readOpt)) { FatalIOErrorInFunction(*this) << "Entry '" << keyword << "' not found in dictionary " @@ -408,8 +423,14 @@ bool Foam::dictionary::readIfPresent enum keyType::option matchOpt ) const { - // Read is non-mandatory - return readEntry(keyword, val, matchOpt, false); + // Reading is optional + return readEntry + ( + keyword, + val, + matchOpt, + IOobjectOption::READ_IF_PRESENT + ); } @@ -422,8 +443,15 @@ bool Foam::dictionary::readCheckIfPresent enum keyType::option matchOpt ) const { - // Read is non-mandatory - return readCheck(keyword, val, pred, matchOpt, false); + // Reading is optional + return readCheck + ( + keyword, + val, + pred, + matchOpt, + IOobjectOption::READ_IF_PRESENT + ); } @@ -436,13 +464,13 @@ T Foam::dictionary::getOrDefaultCompat enum keyType::option matchOpt ) const { - const const_searcher finder(csearchCompat(keyword, compat, matchOpt)); + const entry* eptr = csearchCompat(keyword, compat, matchOpt).ptr(); - if (finder.good()) + if (eptr) { T val; - ITstream& is = finder.ptr()->stream(); + ITstream& is = eptr->stream(); is >> val; checkITstream(is, keyword); @@ -467,8 +495,15 @@ bool Foam::dictionary::readIfPresentCompat enum keyType::option matchOpt ) const { - // Read is non-mandatory - return readCompat(keyword, compat, val, matchOpt, false); + // Reading is optional + return readCompat + ( + keyword, + compat, + val, + matchOpt, + IOobjectOption::READ_IF_PRESENT + ); } diff --git a/src/OpenFOAM/expressions/exprString/exprString.C b/src/OpenFOAM/expressions/exprString/exprString.C index 7a156b30bd..7ffb0f4b36 100644 --- a/src/OpenFOAM/expressions/exprString/exprString.C +++ b/src/OpenFOAM/expressions/exprString/exprString.C @@ -74,10 +74,10 @@ bool Foam::expressions::exprString::readEntry ( const word& keyword, const dictionary& dict, - bool mandatory + IOobjectOption::readOption readOpt ) { - const bool ok = dict.readEntry(keyword, *this, keyType::LITERAL, mandatory); + const bool ok = dict.readEntry(keyword, *this, keyType::LITERAL, readOpt); if (ok && !empty()) { diff --git a/src/OpenFOAM/expressions/exprString/exprString.H b/src/OpenFOAM/expressions/exprString/exprString.H index 0fc172070c..49957be0e2 100644 --- a/src/OpenFOAM/expressions/exprString/exprString.H +++ b/src/OpenFOAM/expressions/exprString/exprString.H @@ -175,7 +175,7 @@ public: ( const word& keyword, //!< Lookup key. Uses LITERAL (not REGEX) const dictionary& dict, - bool mandatory = true + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ ); //- Read/expand optional entry with dictionary variables, diff --git a/src/OpenFOAM/expressions/exprString/exprStringI.H b/src/OpenFOAM/expressions/exprString/exprStringI.H index c0129e5b54..8218d709f6 100644 --- a/src/OpenFOAM/expressions/exprString/exprStringI.H +++ b/src/OpenFOAM/expressions/exprString/exprStringI.H @@ -195,7 +195,7 @@ inline bool Foam::expressions::exprString::readIfPresent const dictionary& dict ) { - return readEntry(key, dict, false); // non-mandatory + return readEntry(key, dict, IOobjectOption::READ_IF_PRESENT); } diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 4a766fe4e2..d4e53691aa 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -1373,12 +1373,17 @@ void Foam::argList::parse if (dictStream && dictStream->good()) { + // Get numberOfSubdomains if it exists. + // - mandatory when running with distributed roots + + IOobjectOption::readOption nDomainsReadOpt + = IOobjectOption::READ_IF_PRESENT; + dictionary decompDict(*dictStream); - bool nDomainsMandatory = false; if (decompDict.getOrDefault("distributed", false)) { - nDomainsMandatory = true; + nDomainsReadOpt = IOobjectOption::MUST_READ; runControl_.distributed(true); decompDict.readEntry("roots", roots); @@ -1390,14 +1395,12 @@ void Foam::argList::parse } } - // Get numberOfSubdomains if it exists. - // - mandatory when running with distributed roots decompDict.readEntry ( "numberOfSubdomains", dictNProcs, keyType::LITERAL, - nDomainsMandatory + nDomainsReadOpt ); } else diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C index 6b60839e00..b5be2d0a1e 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1New.C @@ -54,12 +54,16 @@ Foam::Function1::New << "For " << entryName << " with dictionary entries: " << flatOutput(coeffs->toc()) << nl; + // The "type" entry - mandatory if no redirectType provided coeffs->readEntry ( "type", modelType, keyType::LITERAL, - modelType.empty() // "type" entry is mandatory if no 'redirect' + ( + modelType.empty() + ? IOobjectOption::MUST_READ : IOobjectOption::READ_IF_PRESENT + ) ); // Fallthrough diff --git a/src/dynamicMesh/motionSmoother/motionSmootherAlgoTemplates.C b/src/dynamicMesh/motionSmoother/motionSmootherAlgoTemplates.C index 0bb71f9110..496bf281d1 100644 --- a/src/dynamicMesh/motionSmoother/motionSmootherAlgoTemplates.C +++ b/src/dynamicMesh/motionSmoother/motionSmootherAlgoTemplates.C @@ -300,18 +300,16 @@ Type Foam::motionSmootherAlgo::get const Type& defaultValue ) { + // If noExit, emit FatalIOError message without exiting + IOobjectOption::readOption readOpt + ( + noExit + ? IOobjectOption::READ_IF_PRESENT : IOobjectOption::MUST_READ + ); + Type val(defaultValue); - if - ( - !dict.readEntry - ( - keyword, - val, - matchOpt, - !noExit - ) - ) + if (!dict.readEntry(keyword, val, matchOpt, readOpt)) { FatalIOError << "Entry '" << keyword << "' not found in dictionary " diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethod.C b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethod.C index f656529c11..f3dcf1e85b 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethod.C +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/patchDistMethod/patchDistMethod.C @@ -62,12 +62,17 @@ Foam::patchDistMethod::New ) { word modelType(defaultPatchDistMethod); + + // The "method" entry - mandatory if no default was provided dict.readEntry ( "method", modelType, - keyType::REGEX, - modelType.empty() // Mandatory if no default was provided + keyType::LITERAL, + ( + modelType.empty() + ? IOobjectOption::MUST_READ : IOobjectOption::READ_IF_PRESENT + ) ); Info<< "Selecting patchDistMethod " << modelType << endl; diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index 5e422e52ef..11c1960245 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -1038,13 +1038,17 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read } } - // Mandatory if we didn't pick up a value from selectionNames_ + // The "name" entry + // - mandatory if we didn't pick up a value from selectionNames_ dict.readEntry ( "name", regionName_, keyType::LITERAL, - regionName_.empty() + ( + regionName_.empty() + ? IOobjectOption::MUST_READ : IOobjectOption::READ_IF_PRESENT + ) ); // Ensure there is always content for selectionNames_ diff --git a/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C b/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C index bda99d0c86..97e67f7553 100644 --- a/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C +++ b/src/mesh/snappyHexMesh/externalDisplacementMeshMover/medialAxisMeshMover.C @@ -148,26 +148,15 @@ void Foam::medialAxisMeshMover::update(const dictionary& coeffDict) ) ); - // Note: parameter name changed - // "minMedianAxisAngle" -> "minMedialAxisAngle" (DEC-2013) - // but not previously reported. - scalar minMedialAxisAngle(Zero); - if + const scalar minMedialAxisAngle ( - !coeffDict.readCompat + meshRefinement::get ( + coeffDict, "minMedialAxisAngle", - {{ "minMedianAxisAngle", 1712 }}, - minMedialAxisAngle, - keyType::REGEX, - !dryRun_ + dryRun_ ) - ) - { - FatalIOError - << "Entry '" << "minMedialAxisAngle" - << "' not found in dictionary " << coeffDict.name() << endl; - } + ); const scalar minMedialAxisAngleCos(Foam::cos(degToRad(minMedialAxisAngle))); diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index de014919c6..7e8ed9e187 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -3803,7 +3803,7 @@ const Foam::dictionary& Foam::meshRefinement::subDict auto& err = FatalIOErrorInFunction(dict); err << "Entry '" << keyword << "' not found in dictionary " - << dict.name() << nl; + << dict.relativeName() << nl; if (noExit) { @@ -3827,14 +3827,14 @@ Foam::ITstream& Foam::meshRefinement::lookup enum keyType::option matchOpt ) { - const auto finder(dict.csearch(keyword, matchOpt)); + const entry* eptr = dict.findEntry(keyword, matchOpt); - if (!finder.good()) + if (!eptr) { auto& err = FatalIOErrorInFunction(dict); err << "Entry '" << keyword << "' not found in dictionary " - << dict.name() << nl; + << dict.relativeName() << nl; if (noExit) { @@ -3847,7 +3847,7 @@ Foam::ITstream& Foam::meshRefinement::lookup } } - return finder.ref().stream(); + return eptr->stream(); } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C index 580effaa02..f28ba6d468 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C @@ -335,9 +335,16 @@ Type Foam::meshRefinement::get const Type& deflt ) { + // If noExit, emit FatalIOError message without exiting + IOobjectOption::readOption readOpt + ( + noExit + ? IOobjectOption::READ_IF_PRESENT : IOobjectOption::MUST_READ + ); + Type val(deflt); - if (!dict.readEntry(keyword, val, matchOpt, !noExit)) + if (!dict.readEntry(keyword, val, matchOpt, readOpt)) { FatalIOErrorInFunction(dict) << "Entry '" << keyword << "' not found in dictionary " diff --git a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C index f371329280..d664cd71ea 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C +++ b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C @@ -53,12 +53,13 @@ Foam::PatchFunction1::New << "For " << entryName << " with dictionary entries: " << flatOutput(coeffs->toc()) << nl; + // The "type" entry - mandatory, no fallback type provided coeffs->readEntry ( "type", modelType, - keyType::LITERAL - // "type" entry is mandatory, there is no 'redirect' + keyType::LITERAL, + IOobjectOption::MUST_READ ); } else if (eptr) diff --git a/src/meshTools/searchableSurfaces/searchableBox/searchableBox.C b/src/meshTools/searchableSurfaces/searchableBox/searchableBox.C index ec4045a731..015ce5d8a0 100644 --- a/src/meshTools/searchableSurfaces/searchableBox/searchableBox.C +++ b/src/meshTools/searchableSurfaces/searchableBox/searchableBox.C @@ -59,13 +59,17 @@ namespace Foam // Read min/max or min/span static void readBoxDim(const dictionary& dict, treeBoundBox& bb) { - dict.readEntry("min", bb.min()); + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ; - const bool hasSpan = dict.found("span"); - if (!dict.readEntry("max", bb.max(), keyType::REGEX, !hasSpan)) + dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt); + + if (dict.readIfPresent("span", bb.max(), keyType::LITERAL)) { - bb.max() = bb.min() + dict.get("span"); + bb.max() += bb.min(); + readOpt = IOobjectOption::READ_IF_PRESENT; } + + dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt); } } // End namespace Foam diff --git a/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.C b/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.C index 62d0228a8f..a3ca126907 100644 --- a/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.C +++ b/src/meshTools/topoSet/cellSources/boxToCell/boxToCell.C @@ -72,13 +72,17 @@ namespace Foam // Read min/max or min/span static void readBoxDim(const dictionary& dict, treeBoundBox& bb) { - dict.readEntry("min", bb.min()); + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ; - const bool hasSpan = dict.found("span"); - if (!dict.readEntry("max", bb.max(), keyType::REGEX, !hasSpan)) + dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt); + + if (dict.readIfPresent("span", bb.max(), keyType::LITERAL)) { - bb.max() = bb.min() + dict.get("span"); + bb.max() += bb.min(); + readOpt = IOobjectOption::READ_IF_PRESENT; } + + dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt); } } // End namespace Foam diff --git a/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.C b/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.C index 38feb4948a..91b633d13c 100644 --- a/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.C +++ b/src/meshTools/topoSet/faceSources/boxToFace/boxToFace.C @@ -72,13 +72,17 @@ namespace Foam // Read min/max or min/span static void readBoxDim(const dictionary& dict, treeBoundBox& bb) { - dict.readEntry("min", bb.min()); + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ; - const bool hasSpan = dict.found("span"); - if (!dict.readEntry("max", bb.max(), keyType::REGEX, !hasSpan)) + dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt); + + if (dict.readIfPresent("span", bb.max(), keyType::LITERAL)) { - bb.max() = bb.min() + dict.get("span"); + bb.max() += bb.min(); + readOpt = IOobjectOption::READ_IF_PRESENT; } + + dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt); } } // End namespace Foam diff --git a/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.C b/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.C index 6dcb58e141..9086bb4098 100644 --- a/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.C +++ b/src/meshTools/topoSet/pointSources/boxToPoint/boxToPoint.C @@ -72,13 +72,17 @@ namespace Foam // Read min/max or min/span static void readBoxDim(const dictionary& dict, treeBoundBox& bb) { - dict.readEntry("min", bb.min()); + IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ; - const bool hasSpan = dict.found("span"); - if (!dict.readEntry("max", bb.max(), keyType::REGEX, !hasSpan)) + dict.readEntry("min", bb.min(), keyType::LITERAL, readOpt); + + if (dict.readIfPresent("span", bb.max(), keyType::LITERAL)) { - bb.max() = bb.min() + dict.get("span"); + bb.max() += bb.min(); + readOpt = IOobjectOption::READ_IF_PRESENT; } + + dict.readEntry("max", bb.max(), keyType::LITERAL, readOpt); } } // End namespace Foam