mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: additional constructor and methods for regionProperties
- can now construct with READ_IF_PRESENT and use count() to determine if it was loaded. names() and sortedNames() for a collected overview.
This commit is contained in:
@ -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<word>("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;
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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<word>("region", fvMesh::defaultRegion);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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<wordList>
|
||||
regionProperties(runTime, IOobject::MUST_READ_IF_MODIFIED)
|
||||
{}
|
||||
|
||||
|
||||
Foam::regionProperties::regionProperties
|
||||
(
|
||||
const Time& runTime,
|
||||
IOobject::readOption rOpt
|
||||
)
|
||||
{
|
||||
HashTable<wordList>& 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<wordList>& 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<wordList>& 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<wordList>& props = *this;
|
||||
|
||||
forAllConstIters(props, iter)
|
||||
{
|
||||
for (const word& name : iter.object())
|
||||
{
|
||||
list[n] = name;
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
Foam::sort(list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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<wordList>
|
||||
{
|
||||
|
||||
//- 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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user