From 03c2373d2c9e83b51fd098395df5248fa029a1d8 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 26 May 2020 00:09:04 +0200 Subject: [PATCH] ENH: align meshRefinement dictionary wrapper with dictionary code COMP: do not rely on implicit conversion to PtrList from Istream --- .../generation/snappyHexMesh/snappyHexMesh.C | 7 ++- .../meshRefinement/meshRefinement.C | 57 +++++++++---------- .../meshRefinement/meshRefinement.H | 19 ++++--- .../meshRefinement/meshRefinementTemplates.C | 28 ++++----- 4 files changed, 51 insertions(+), 60 deletions(-) diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index 3998d13538..7714baec17 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1259,7 +1259,10 @@ int main(int argc, char *argv[]) refinementFeatures features ( mesh, - meshRefinement::lookup(refineDict, "features", dryRun), + PtrList + ( + meshRefinement::lookup(refineDict, "features", dryRun) + ), dryRun ); Info<< "Read features in = " diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index cde1f3a3a5..6b99d7ac69 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -3465,35 +3465,30 @@ const Foam::dictionary& Foam::meshRefinement::subDict ( const dictionary& dict, const word& keyword, - const bool noExit + const bool noExit, + enum keyType::option matchOpt ) { - if (noExit) - { - // Find non-recursive with patterns - const dictionary::const_searcher finder - ( - dict.csearch - ( - keyword, - keyType::REGEX - ) - ); + const auto finder(dict.csearch(keyword, matchOpt)); - if (!finder.found()) + if (!finder.good()) + { + auto& err = FatalIOErrorInFunction(dict); + + err << "Entry '" << keyword << "' not found in dictionary " + << dict.name() << nl; + + if (noExit) { - FatalIOErrorInFunction(dict) - << "Entry '" << keyword << "' not found in dictionary " - << dict.name(); return dictionary::null; } else { - return finder.dict(); + err << exit(FatalIOError); } } - return dict.subDict(keyword); + return finder.dict(); } @@ -3501,31 +3496,31 @@ Foam::ITstream& Foam::meshRefinement::lookup ( const dictionary& dict, const word& keyword, - const bool noExit + const bool noExit, + enum keyType::option matchOpt ) { - if (noExit) - { - const dictionary::const_searcher finder - ( - dict.csearch(keyword, keyType::REGEX) - ); + const auto finder(dict.csearch(keyword, matchOpt)); - if (!finder.found()) + if (!finder.good()) + { + auto& err = FatalIOErrorInFunction(dict); + + err << "Entry '" << keyword << "' not found in dictionary " + << dict.name() << nl; + + if (noExit) { - FatalIOErrorInFunction(dict) - << "Entry '" << keyword << "' not found in dictionary " - << dict.name(); // Fake entry return dict.first()->stream(); } else { - return finder.ref().stream(); + err << exit(FatalIOError); } } - return dict.lookup(keyword); + return finder.ref().stream(); } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H index 4bf5205315..69916ef29e 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,7 +66,7 @@ SourceFiles namespace Foam { -// Class forward declarations +// Forward Declarations class fvMesh; class mapDistributePolyMesh; class decompositionMethod; @@ -79,7 +79,6 @@ class removePoints; class localPointRegion; class snapParameters; - /*---------------------------------------------------------------------------*\ Class meshRefinement Declaration \*---------------------------------------------------------------------------*/ @@ -88,7 +87,7 @@ class meshRefinement { public: - // Public data types + // Public Data Types //- Enumeration for what to debug. Used as a bit-pattern. enum debugType @@ -143,7 +142,7 @@ public: private: - // Static data members + // Static Data Members //- Control of writing level static writeType writeLevel_; @@ -152,7 +151,7 @@ private: //static outputType outputLevel_; - // Private data + // Private Data //- Reference to mesh fvMesh& mesh_; @@ -1701,7 +1700,7 @@ public: const word& keyword, const bool noExit, enum keyType::option matchOpt = keyType::REGEX, - const Type& defaultValue = Zero + const Type& deflt = Zero ); //- Wrapper around dictionary::subDict which does not exit @@ -1709,7 +1708,8 @@ public: ( const dictionary& dict, const word& keyword, - const bool noExit + const bool noExit, + enum keyType::option matchOpt = keyType::REGEX ); //- Wrapper around dictionary::lookup which does not exit @@ -1717,7 +1717,8 @@ public: ( const dictionary& dict, const word& keyword, - const bool noExit + const bool noExit, + enum keyType::option matchOpt = keyType::REGEX ); }; diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C index 4449de6251..580effaa02 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,8 +33,8 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Add a T entry -template void Foam::meshRefinement::updateList +template +void Foam::meshRefinement::updateList ( const labelList& newToOld, const T& nullValue, @@ -45,7 +45,7 @@ template void Foam::meshRefinement::updateList forAll(newElems, i) { - label oldI = newToOld[i]; + const label oldI = newToOld[i]; if (oldI >= 0) { @@ -332,26 +332,18 @@ Type Foam::meshRefinement::get const word& keyword, const bool noExit, enum keyType::option matchOpt, - const Type& defaultValue + const Type& deflt ) { - Type val(defaultValue); + Type val(deflt); - if - ( - !dict.readEntry - ( - keyword, - val, - matchOpt, - !noExit - ) - ) + if (!dict.readEntry(keyword, val, matchOpt, !noExit)) { - FatalIOError + FatalIOErrorInFunction(dict) << "Entry '" << keyword << "' not found in dictionary " - << dict.name() << endl; + << dict.name() << nl; } + return val; }