ENH: align meshRefinement dictionary wrapper with dictionary code

COMP: do not rely on implicit conversion to PtrList from Istream
This commit is contained in:
Mark Olesen 2020-05-26 00:09:04 +02:00
parent 997c9a232c
commit 03c2373d2c
4 changed files with 51 additions and 60 deletions

View File

@ -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<dictionary>
(
meshRefinement::lookup(refineDict, "features", dryRun)
),
dryRun
);
Info<< "Read features in = "

View File

@ -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();
}

View File

@ -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
);
};

View File

@ -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<class T> void Foam::meshRefinement::updateList
template<class T>
void Foam::meshRefinement::updateList
(
const labelList& newToOld,
const T& nullValue,
@ -45,7 +45,7 @@ template<class T> 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;
}