diff --git a/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C b/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C index 4729ac3bf3..27bbec71d7 100644 --- a/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C +++ b/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C @@ -60,18 +60,16 @@ int main(int argc, char *argv[]) ) ).subDict("volumetricBSplinesMotionSolverCoeffs") ); - // Read box names and allocate size - wordList controlBoxes(NURBSdict.toc()); - for (const word& boxName : controlBoxes) + for (const entry& dEntry : NURBSdict) { - if (NURBSdict.isDict(boxName)) + if (dEntry.isDict()) { // Creating an object writes the control points in the // constructor - NURBS3DVolume::New + (void) NURBS3DVolume::New ( - NURBSdict.subDict(boxName), + dEntry.dict(), mesh, false // do not compute parametric coordinates ); diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C index b3546c32e7..211809ea4e 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2021 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -373,6 +373,9 @@ int main(int argc, char *argv[]) } } + + const dictionary* subDictPtr = nullptr; + // // Extract features using the preferred extraction method // @@ -382,9 +385,9 @@ int main(int argc, char *argv[]) // ~~~~~~~~ // Option: "trimFeatures" (dictionary) - if (surfaceDict.isDict("trimFeatures")) + if ((subDictPtr = surfaceDict.findDict("trimFeatures")) != nullptr) { - const dictionary& trimDict = surfaceDict.subDict("trimFeatures"); + const dictionary& trimDict = *subDictPtr; const scalar minLen = trimDict.getOrDefault("minLen", 0); @@ -419,18 +422,15 @@ int main(int argc, char *argv[]) List edgeStat(features().toStatus()); // Option: "subsetFeatures" (dictionary) - if (surfaceDict.isDict("subsetFeatures")) + if ((subDictPtr = surfaceDict.findDict("subsetFeatures")) != nullptr) { - const dictionary& subsetDict = surfaceDict.subDict - ( - "subsetFeatures" - ); + const dictionary& subsetDict = *subDictPtr; + + treeBoundBox bb; // Suboption: "insideBox" - if (subsetDict.found("insideBox")) + if (subsetDict.readIfPresent("insideBox", bb)) { - treeBoundBox bb(subsetDict.lookup("insideBox")); - Info<< "Subset edges inside box " << bb << endl; features().subsetBox(edgeStat, bb); @@ -445,10 +445,8 @@ int main(int argc, char *argv[]) } } // Suboption: "outsideBox" - else if (subsetDict.found("outsideBox")) + else if (subsetDict.readIfPresent("outsideBox", bb)) { - treeBoundBox bb(subsetDict.lookup("outsideBox")); - Info<< "Exclude edges outside box " << bb << endl; features().excludeBox(edgeStat, bb); @@ -549,12 +547,11 @@ int main(int argc, char *argv[]) ); - if (surfaceDict.isDict("addFeatures")) + if ((subDictPtr = surfaceDict.findDict("addFeatures")) != nullptr) { - const word addFeName - ( - surfaceDict.subDict("addFeatures").get("name") - ); + const dictionary& addFeaturesDict = *subDictPtr; + + const word addFeName = addFeaturesDict.get("name"); Info<< "Adding (without merging) features from " << addFeName << nl << endl; diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 4080a77fb2..d8b75aae51 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -1278,6 +1278,30 @@ public: friend Ostream& operator<<(Ostream& os, const dictionary& dict); + // Shortcuts - when a templated classes also inherits from a dictionary + + #undef defineDictionaryGetter + #define defineDictionaryGetter(Func, Type) \ + /*! \brief Same as get\(const word&, keyType::option) */ \ + Type Func \ + ( \ + const word& keyword, \ + enum keyType::option matchOpt = keyType::REGEX \ + ) const \ + { \ + return get(keyword, matchOpt); \ + } + + defineDictionaryGetter(getBool, bool); + defineDictionaryGetter(getLabel, label); + defineDictionaryGetter(getScalar, scalar); + defineDictionaryGetter(getString, string); + defineDictionaryGetter(getWord, word); + defineDictionaryGetter(getFileName, fileName); + + #undef defineDictionaryGetter + + // Housekeeping //- Find and return a T, or return the given default value. @@ -1316,29 +1340,7 @@ public: return getOrAdd(keyword, deflt, matchOpt); } - //- Find and return a T, or return the given default value - //- using any compatibility names if needed. - // - // \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 deflt the default value to use - // \param matchOpt search mode (default: non-recursive with patterns) - template - FOAM_DEPRECATED_FOR(2019-05, "getOrDefaultCompat() method") - T lookupOrDefaultCompat - ( - const word& keyword, - std::initializer_list> compat, - const T& deflt, - enum keyType::option matchOpt = keyType::REGEX - ) const - { - return getOrDefaultCompat(keyword, compat, deflt, matchOpt); - } - - //- Deprecated(2018-07) find and return an entry data stream - // + //- Deprecated(2018-07) - use lookup() method // \deprecated(2018-07) - use lookup() method FOAM_DEPRECATED_FOR(2018-07, "lookup() method") ITstream& operator[](const word& keyword) const @@ -1360,7 +1362,7 @@ public: } //- Deprecated(2018-10) - // \deprecated(2018-10) - use keyType::option version + // \deprecated(2018-10) - use findEntry() method FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)") entry* lookupEntryPtr ( @@ -1373,7 +1375,7 @@ public: } //- Deprecated(2018-10) - // \deprecated(2018-10) - use keyType::option version + // \deprecated(2018-10) - use findEntry() method FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)") const entry* lookupEntryPtr ( @@ -1386,7 +1388,7 @@ public: } //- Deprecated(2018-10) - // \deprecated(2018-10) - use keyType::option version + // \deprecated(2018-10) - use findScoped() method FOAM_DEPRECATED_FOR(2018-10, "findScoped(keyType::option)") const entry* lookupScopedEntryPtr ( @@ -1527,30 +1529,6 @@ public: return get(keyword, matchOpt(recursive, patternMatch)); } #endif - - - // Shortcuts - when a templated classes also inherits from a dictionary - - #undef defineDictionaryGetter - #define defineDictionaryGetter(Func, Type) \ - /*! \brief Same as get\(const word&, keyType::option) */ \ - Type Func \ - ( \ - const word& keyword, \ - enum keyType::option matchOpt = keyType::REGEX \ - ) const \ - { \ - return get(keyword, matchOpt); \ - } - - defineDictionaryGetter(getBool, bool); - defineDictionaryGetter(getLabel, label); - defineDictionaryGetter(getScalar, scalar); - defineDictionaryGetter(getString, string); - defineDictionaryGetter(getWord, word); - defineDictionaryGetter(getFileName, fileName); - - #undef defineDictionaryGetter }; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectProperties/functionObjectProperties.C b/src/OpenFOAM/db/functionObjects/functionObjectProperties/functionObjectProperties.C index d5bf49751c..ca09ac1a27 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectProperties/functionObjectProperties.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectProperties/functionObjectProperties.C @@ -137,10 +137,11 @@ bool Foam::functionObjects::properties::getObjectDict if (found(objectName)) { const dictionary& baseDict = subDict(objectName); + const dictionary* subDictPtr = baseDict.findDict(objectName); - if (baseDict.found(entryName) && baseDict.isDict(entryName)) + if (subDictPtr) { - dict = baseDict.subDict(entryName); + dict = *subDictPtr; return true; } } diff --git a/src/conversion/ccm/reader/ccmReader.C b/src/conversion/ccm/reader/ccmReader.C index baa5b19b7c..2cb8e4f47a 100644 --- a/src/conversion/ccm/reader/ccmReader.C +++ b/src/conversion/ccm/reader/ccmReader.C @@ -625,18 +625,19 @@ bool Foam::ccm::reader::remapMeshInfo return false; } + const dictionary* subDictPtr = nullptr; // Merge specified cellTable entries together - if (remapDict.isDict("cellTable")) + if ((subDictPtr = remapDict.findDict("cellTable")) != nullptr) { - cellTable_.combine(remapDict.subDict("cellTable"), cellTableId_); + cellTable_.combine(*subDictPtr, cellTableId_); ok = true; } // Rename boundaries - if (remapDict.isDict("boundaryRegion")) + if ((subDictPtr = remapDict.findDict("boundaryRegion")) != nullptr) { - boundaryRegion_.rename(remapDict.subDict("boundaryRegion")); + boundaryRegion_.rename(*subDictPtr); ok = true; } diff --git a/src/conversion/ccm/writer/ccmWriterSolution.C b/src/conversion/ccm/writer/ccmWriterSolution.C index accfa07a6b..a64e470592 100644 --- a/src/conversion/ccm/writer/ccmWriterSolution.C +++ b/src/conversion/ccm/writer/ccmWriterSolution.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -76,12 +76,14 @@ bool Foam::ccm::writer::newFieldNode ccmID& fieldNode ) const { - if (!nameMapping.found(fieldName) || !nameMapping.isDict(fieldName)) + const dictionary* subDictPtr = nameMapping.findDict(fieldName); + + if (!subDictPtr) { return false; } - const dictionary& dict = nameMapping.subDict(fieldName); + const dictionary& dict = *subDictPtr; word shortName; if (!dict.readIfPresent("name", shortName)) @@ -165,9 +167,11 @@ void Foam::ccm::writer::writeSolution dictionary nameMapping(defaultNameMapping); // Merge without overwrite - if (remapDict.isDict("fields")) + const dictionary* subDictPtr = remapDict.findDict("fields"); + + if (subDictPtr) { - nameMapping |= remapDict.subDict("fields"); + nameMapping |= *subDictPtr; } diff --git a/src/functionObjects/solvers/energyTransport/energyTransport.C b/src/functionObjects/solvers/energyTransport/energyTransport.C index 2c49df5a12..3335c6994d 100644 --- a/src/functionObjects/solvers/energyTransport/energyTransport.C +++ b/src/functionObjects/solvers/energyTransport/energyTransport.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. @@ -252,7 +252,9 @@ Foam::functionObjects::energyTransport::energyTransport { const word& key = iter().keyword(); - if (!multiphaseThermo_.isDict(key)) + const dictionary* subDictPtr = multiphaseThermo_.findDict(key); + + if (!subDictPtr) { FatalErrorInFunction << "Found non-dictionary entry " << iter() @@ -260,7 +262,7 @@ Foam::functionObjects::energyTransport::energyTransport << exit(FatalError); } - const dictionary& dict = multiphaseThermo_.subDict(key); + const dictionary& dict = *subDictPtr; phaseNames_[phasei] = key; diff --git a/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/volBSplinesBase/volBSplinesBase.C b/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/volBSplinesBase/volBSplinesBase.C index a60cd802d0..c73b7835ad 100644 --- a/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/volBSplinesBase/volBSplinesBase.C +++ b/src/optimisation/adjointOptimisation/adjoint/parameterization/NURBS/NURBS3DVolume/volBSplinesBase/volBSplinesBase.C @@ -64,31 +64,26 @@ volBSplinesBase::volBSplinesBase ) ).subDict("volumetricBSplinesMotionSolverCoeffs") ); - // Read box names and allocate size - wordList controlBoxes(NURBSdict.toc()); - volume_.setSize(controlBoxes.size()); // Populate NURBS volumes + volume_.resize(NURBSdict.size()); + label iBox(0); - for (const word& boxName : controlBoxes) + + for (const entry& dEntry : NURBSdict) { - if (NURBSdict.isDict(boxName)) + if (dEntry.isDict()) { volume_.set ( iBox, - NURBS3DVolume::New - ( - NURBSdict.subDict(boxName), - mesh, - true - ) + NURBS3DVolume::New(dEntry.dict(), mesh, true) ); volume_[iBox].writeParamCoordinates(); iBox++; } } - volume_.setSize(iBox); + volume_.resize(iBox); // Determine active design variables activeDesignVariables_.setSize(3*getTotalControlPointsNumber(), -1); diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C index f312d86240..954d41d1d0 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -50,7 +50,9 @@ Foam::autoPtr Foam::basicChemistryModel::New ) ); - if (!chemistryDict.isDict("chemistryType")) + const dictionary* subDictPtr = chemistryDict.findDict("chemistryType"); + + if (!subDictPtr) { FatalErrorInFunction << "Template parameter based chemistry solver selection is no " @@ -64,8 +66,7 @@ Foam::autoPtr Foam::basicChemistryModel::New << endl << " }" << exit(FatalError); } - const dictionary& chemistryTypeDict = - chemistryDict.subDict("chemistryType"); + const dictionary& chemistryTypeDict = *subDictPtr; const word solverName ( diff --git a/src/thermophysicalModels/radiation/submodels/boundaryRadiationProperties/boundaryRadiationProperties.C b/src/thermophysicalModels/radiation/submodels/boundaryRadiationProperties/boundaryRadiationProperties.C index 3e25ef3d8f..c409ec2467 100644 --- a/src/thermophysicalModels/radiation/submodels/boundaryRadiationProperties/boundaryRadiationProperties.C +++ b/src/thermophysicalModels/radiation/submodels/boundaryRadiationProperties/boundaryRadiationProperties.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -81,9 +81,11 @@ Foam::radiation::boundaryRadiationProperties::boundaryRadiationProperties { const polyPatch& pp = mesh.boundaryMesh()[patchi]; - if (radiationDict.isDict(pp.name())) + const dictionary* subDictPtr = radiationDict.findDict(pp.name()); + + if (subDictPtr) { - const dictionary& dict = radiationDict.subDict(pp.name()); + const dictionary& dict = *subDictPtr; radBoundaryPropertiesPtrList_[patchi].reset ( diff --git a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C index 51952aeab5..f76654914e 100644 --- a/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C +++ b/src/thermophysicalModels/thermophysicalProperties/liquidProperties/liquidMixtureProperties/liquidMixtureProperties.C @@ -50,12 +50,16 @@ Foam::liquidMixtureProperties::liquidMixtureProperties forAll(components_, i) { - if (dict.isDict(components_[i])) + // Handle sub-dictionary or primitive entry + + const dictionary* subDictPtr = dict.findDict(components_[i]); + + if (subDictPtr) { properties_.set ( i, - liquidProperties::New(dict.subDict(components_[i])) + liquidProperties::New(*subDictPtr) ); } else diff --git a/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C b/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C index b8d5e06675..f948f7ad3b 100644 --- a/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C +++ b/src/thermophysicalModels/thermophysicalProperties/solidProperties/solidMixtureProperties/solidMixtureProperties.C @@ -40,12 +40,16 @@ Foam::solidMixtureProperties::solidMixtureProperties(const dictionary& dict) forAll(components_, i) { - if (dict.isDict(components_[i])) + // Handle sub-dictionary or primitive entry + + const dictionary* subDictPtr = dict.findDict(components_[i]); + + if (subDictPtr) { properties_.set ( i, - solidProperties::New(dict.subDict(components_[i])) + solidProperties::New(*subDictPtr) ); } else diff --git a/src/thermophysicalModels/thermophysicalProperties/thermophysicalPropertiesSelector/thermophysicalPropertiesSelector.C b/src/thermophysicalModels/thermophysicalProperties/thermophysicalPropertiesSelector/thermophysicalPropertiesSelector.C index 365d4f6b6e..4010b429c4 100644 --- a/src/thermophysicalModels/thermophysicalProperties/thermophysicalPropertiesSelector/thermophysicalPropertiesSelector.C +++ b/src/thermophysicalModels/thermophysicalProperties/thermophysicalPropertiesSelector/thermophysicalPropertiesSelector.C @@ -49,9 +49,13 @@ thermophysicalPropertiesSelector { const word name(dict.first()->keyword()); - if (dict.isDict(name)) + // Handle sub-dictionary or primitive entry + + const dictionary* subDictPtr = dict.findDict(name); + + if (subDictPtr) { - propertiesPtr_ = ThermophysicalProperties::New(dict.subDict(name)); + propertiesPtr_ = ThermophysicalProperties::New(*subDictPtr); } else { diff --git a/src/transportModels/interfaceProperties/surfaceTensionModels/constant/constantSurfaceTension.C b/src/transportModels/interfaceProperties/surfaceTensionModels/constant/constantSurfaceTension.C index eb601293b8..df3c4aecbe 100644 --- a/src/transportModels/interfaceProperties/surfaceTensionModels/constant/constantSurfaceTension.C +++ b/src/transportModels/interfaceProperties/surfaceTensionModels/constant/constantSurfaceTension.C @@ -85,9 +85,12 @@ Foam::surfaceTensionModels::constant::sigma() const bool Foam::surfaceTensionModels::constant::readDict(const dictionary& dict) { // Handle sub-dictionary format as a special case - if (dict.isDict("sigma")) + + const dictionary* subDictPtr = dict.findDict("sigma"); + + if (subDictPtr) { - dict.subDict("sigma").readEntry("sigma", sigma_); + subDictPtr->readEntry("sigma", sigma_); } else {