diff --git a/applications/test/decomposePar/Test-decomposePar.C b/applications/test/decomposePar/Test-decomposePar.C index 30445a26b7..26673bf6b1 100644 --- a/applications/test/decomposePar/Test-decomposePar.C +++ b/applications/test/decomposePar/Test-decomposePar.C @@ -121,41 +121,27 @@ int main(int argc, char *argv[]) fileName decompDictFile; args.readIfPresent("decomposeParDict", decompDictFile); + // Get all region names wordList regionNames; - wordList regionDirs; if (allRegions) { - Info<< "Decomposing all regions in regionProperties" << nl << endl; - regionProperties rp(runTime); - forAllConstIters(rp, iter) - { - const wordList& regions = iter(); - forAll(regions, i) - { - if (!regionNames.found(regions[i])) - { - regionNames.append(regions[i]); - } - } - } - regionDirs = regionNames; + regionNames = regionProperties(runTime).names(); + + Info<< "Decomposing all regions in regionProperties" << nl + << " " << flatOutput(regionNames) << nl << endl; } else { - regionNames.resize(1, fvMesh::defaultRegion); - regionDirs.resize(1, word::null); - - if (args.readIfPresent("region", regionNames.first())) - { - regionDirs.first() = regionNames.first(); - } + regionNames.resize(1); + regionNames.first() = + args.lookupOrDefault("region", fvMesh::defaultRegion); } - forAll(regionNames, regioni) { const word& regionName = regionNames[regioni]; - const word& regionDir = regionDirs[regioni]; + const word& regionDir = + (regionName == fvMesh::defaultRegion ? word::null : regionName); Info<< "\n\nDecomposing mesh " << regionName << nl << endl; Info<< "Create mesh..." << flush; diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C index f11942fba9..e061325c84 100644 --- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C +++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C @@ -330,19 +330,14 @@ int main(int argc, char *argv[]) fileName decompDictFile; args.readIfPresent("decomposeParDict", decompDictFile); + // Get all region names wordList regionNames; if (allRegions) { - Info<< "Decomposing all regions in regionProperties" << nl << nl; - regionProperties rp(runTime); + regionNames = regionProperties(runTime).names(); - wordHashSet names; - forAllConstIters(rp, iter) - { - names.insert(iter.object()); - } - - regionNames = names.sortedToc(); + Info<< "Decomposing all regions in regionProperties" << nl + << " " << flatOutput(regionNames) << nl << endl; } else { diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 7645b9c91f..37e179440d 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -180,17 +180,11 @@ int main(int argc, char *argv[]) wordList regionDirs; if (allRegions) { - Info<< "Reconstructing all regions in regionProperties" << nl << endl; - regionProperties rp(runTime); - - wordHashSet names; - forAllConstIters(rp, iter) - { - names.insert(iter.object()); - } - - regionNames = names.sortedToc(); + regionNames = regionProperties(runTime).names(); regionDirs = regionNames; + + Info<< "Reconstructing all regions in regionProperties" << nl + << " " << flatOutput(regionNames) << nl << endl; } else { diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 664ba34078..b7ae617422 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -2499,21 +2499,16 @@ int main(int argc, char *argv[]) wordList regionNames; if (args.found("allRegions")) { - Info<< "Decomposing all regions in regionProperties" << nl << endl; - regionProperties rp(runTime); + regionNames = regionProperties(runTime).names(); - wordHashSet names; - forAllConstIters(rp, iter) - { - names.insert(iter.object()); - } - - regionNames = names.sortedToc(); + Info<< "Decomposing all regions in regionProperties" << nl + << " " << flatOutput(regionNames) << nl << endl; } else { - regionNames = {fvMesh::defaultRegion}; - args.readIfPresent("region", regionNames[0]); + regionNames.resize(1); + regionNames.first() = + args.lookupOrDefault("region", fvMesh::defaultRegion); } diff --git a/src/regionModels/regionModel/regionProperties/regionProperties.C b/src/regionModels/regionModel/regionProperties/regionProperties.C index 7a7d6a646e..6d91d2bf34 100644 --- a/src/regionModels/regionModel/regionProperties/regionProperties.C +++ b/src/regionModels/regionModel/regionProperties/regionProperties.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,32 +25,106 @@ License #include "regionProperties.H" #include "IOdictionary.H" +#include "Time.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::regionProperties::regionProperties(const Time& runTime) : - HashTable + regionProperties(runTime, IOobject::MUST_READ_IF_MODIFIED) +{} + + +Foam::regionProperties::regionProperties +( + const Time& runTime, + IOobject::readOption rOpt +) +{ + HashTable& props = *this; + + IOdictionary iodict ( - IOdictionary + IOobject ( - IOobject - ( - "regionProperties", - runTime.time().constant(), - runTime.db(), - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ).lookup("regions") + "regionProperties", + runTime.time().constant(), + runTime.db(), + rOpt, + IOobject::NO_WRITE + ) + ); + + if + ( + (rOpt == IOobject::MUST_READ || rOpt == IOobject::MUST_READ_IF_MODIFIED) + || iodict.size() ) -{} + { + iodict.readEntry("regions", props); + } +} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::regionProperties::~regionProperties() -{} +Foam::label Foam::regionProperties::count() const +{ + label n = 0; + + const HashTable& props = *this; + + forAllConstIters(props, iter) + { + n += iter.object().size(); + } + + return n; +} + + +Foam::wordList Foam::regionProperties::names() const +{ + wordList list(this->count()); + + label n = 0; + + const HashTable& props = *this; + + for (const word& grp : props.sortedToc()) + { + for (const word& name : props[grp]) + { + list[n] = name; + ++n; + } + } + + return list; +} + + +Foam::wordList Foam::regionProperties::sortedNames() const +{ + wordList list(this->count()); + + label n = 0; + + const HashTable& props = *this; + + forAllConstIters(props, iter) + { + for (const word& name : iter.object()) + { + list[n] = name; + ++n; + } + } + + Foam::sort(list); + + return list; +} // ************************************************************************* // diff --git a/src/regionModels/regionModel/regionProperties/regionProperties.H b/src/regionModels/regionModel/regionProperties/regionProperties.H index 579a8a0e1f..28640822b7 100644 --- a/src/regionModels/regionModel/regionProperties/regionProperties.H +++ b/src/regionModels/regionModel/regionProperties/regionProperties.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,14 +39,18 @@ SourceFiles #ifndef regionProperties_H #define regionProperties_H -#include "Time.H" #include "HashTable.H" +#include "wordList.H" +#include "IOobject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward Declarations +class Time; + /*---------------------------------------------------------------------------*\ Class regionProperties Declaration \*---------------------------------------------------------------------------*/ @@ -55,23 +59,35 @@ class regionProperties : public HashTable { - - //- No copy construct - regionProperties(const regionProperties&) = delete; - - //- No copy assignment - void operator=(const regionProperties&) = delete; - public: // Constructors - //- Construct from components - regionProperties(const Time& runTime); + //- Construct from Time + explicit regionProperties(const Time& runTime); + + //- Construct from Time with specified read options + regionProperties + ( + const Time& runTime, + IOobject::readOption rOpt + ); //- Destructor - ~regionProperties(); + ~regionProperties() = default; + + + // Member Functions + + //- Total count of all region names. + label count() const; + + //- The region names. Sorted by region type. + wordList names() const; + + //- The region names in sorted order. + wordList sortedNames() const; };