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;
|
fileName decompDictFile;
|
||||||
args.readIfPresent("decomposeParDict", decompDictFile);
|
args.readIfPresent("decomposeParDict", decompDictFile);
|
||||||
|
|
||||||
|
// Get all region names
|
||||||
wordList regionNames;
|
wordList regionNames;
|
||||||
wordList regionDirs;
|
|
||||||
if (allRegions)
|
if (allRegions)
|
||||||
{
|
{
|
||||||
Info<< "Decomposing all regions in regionProperties" << nl << endl;
|
regionNames = regionProperties(runTime).names();
|
||||||
regionProperties rp(runTime);
|
|
||||||
forAllConstIters(rp, iter)
|
Info<< "Decomposing all regions in regionProperties" << nl
|
||||||
{
|
<< " " << flatOutput(regionNames) << nl << endl;
|
||||||
const wordList& regions = iter();
|
|
||||||
forAll(regions, i)
|
|
||||||
{
|
|
||||||
if (!regionNames.found(regions[i]))
|
|
||||||
{
|
|
||||||
regionNames.append(regions[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
regionDirs = regionNames;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
regionNames.resize(1, fvMesh::defaultRegion);
|
regionNames.resize(1);
|
||||||
regionDirs.resize(1, word::null);
|
regionNames.first() =
|
||||||
|
args.lookupOrDefault<word>("region", fvMesh::defaultRegion);
|
||||||
if (args.readIfPresent("region", regionNames.first()))
|
|
||||||
{
|
|
||||||
regionDirs.first() = regionNames.first();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
forAll(regionNames, regioni)
|
forAll(regionNames, regioni)
|
||||||
{
|
{
|
||||||
const word& regionName = 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<< "\n\nDecomposing mesh " << regionName << nl << endl;
|
||||||
Info<< "Create mesh..." << flush;
|
Info<< "Create mesh..." << flush;
|
||||||
|
|||||||
@ -330,19 +330,14 @@ int main(int argc, char *argv[])
|
|||||||
fileName decompDictFile;
|
fileName decompDictFile;
|
||||||
args.readIfPresent("decomposeParDict", decompDictFile);
|
args.readIfPresent("decomposeParDict", decompDictFile);
|
||||||
|
|
||||||
|
// Get all region names
|
||||||
wordList regionNames;
|
wordList regionNames;
|
||||||
if (allRegions)
|
if (allRegions)
|
||||||
{
|
{
|
||||||
Info<< "Decomposing all regions in regionProperties" << nl << nl;
|
regionNames = regionProperties(runTime).names();
|
||||||
regionProperties rp(runTime);
|
|
||||||
|
|
||||||
wordHashSet names;
|
Info<< "Decomposing all regions in regionProperties" << nl
|
||||||
forAllConstIters(rp, iter)
|
<< " " << flatOutput(regionNames) << nl << endl;
|
||||||
{
|
|
||||||
names.insert(iter.object());
|
|
||||||
}
|
|
||||||
|
|
||||||
regionNames = names.sortedToc();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -180,17 +180,11 @@ int main(int argc, char *argv[])
|
|||||||
wordList regionDirs;
|
wordList regionDirs;
|
||||||
if (allRegions)
|
if (allRegions)
|
||||||
{
|
{
|
||||||
Info<< "Reconstructing all regions in regionProperties" << nl << endl;
|
regionNames = regionProperties(runTime).names();
|
||||||
regionProperties rp(runTime);
|
|
||||||
|
|
||||||
wordHashSet names;
|
|
||||||
forAllConstIters(rp, iter)
|
|
||||||
{
|
|
||||||
names.insert(iter.object());
|
|
||||||
}
|
|
||||||
|
|
||||||
regionNames = names.sortedToc();
|
|
||||||
regionDirs = regionNames;
|
regionDirs = regionNames;
|
||||||
|
|
||||||
|
Info<< "Reconstructing all regions in regionProperties" << nl
|
||||||
|
<< " " << flatOutput(regionNames) << nl << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2499,21 +2499,16 @@ int main(int argc, char *argv[])
|
|||||||
wordList regionNames;
|
wordList regionNames;
|
||||||
if (args.found("allRegions"))
|
if (args.found("allRegions"))
|
||||||
{
|
{
|
||||||
Info<< "Decomposing all regions in regionProperties" << nl << endl;
|
regionNames = regionProperties(runTime).names();
|
||||||
regionProperties rp(runTime);
|
|
||||||
|
|
||||||
wordHashSet names;
|
Info<< "Decomposing all regions in regionProperties" << nl
|
||||||
forAllConstIters(rp, iter)
|
<< " " << flatOutput(regionNames) << nl << endl;
|
||||||
{
|
|
||||||
names.insert(iter.object());
|
|
||||||
}
|
|
||||||
|
|
||||||
regionNames = names.sortedToc();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
regionNames = {fvMesh::defaultRegion};
|
regionNames.resize(1);
|
||||||
args.readIfPresent("region", regionNames[0]);
|
regionNames.first() =
|
||||||
|
args.lookupOrDefault<word>("region", fvMesh::defaultRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,32 +25,106 @@ License
|
|||||||
|
|
||||||
#include "regionProperties.H"
|
#include "regionProperties.H"
|
||||||
#include "IOdictionary.H"
|
#include "IOdictionary.H"
|
||||||
|
#include "Time.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::regionProperties::regionProperties(const Time& runTime)
|
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(),
|
||||||
"regionProperties",
|
runTime.db(),
|
||||||
runTime.time().constant(),
|
rOpt,
|
||||||
runTime.db(),
|
IOobject::NO_WRITE
|
||||||
IOobject::MUST_READ_IF_MODIFIED,
|
)
|
||||||
IOobject::NO_WRITE
|
);
|
||||||
)
|
|
||||||
).lookup("regions")
|
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
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -39,14 +39,18 @@ SourceFiles
|
|||||||
#ifndef regionProperties_H
|
#ifndef regionProperties_H
|
||||||
#define regionProperties_H
|
#define regionProperties_H
|
||||||
|
|
||||||
#include "Time.H"
|
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
|
#include "wordList.H"
|
||||||
|
#include "IOobject.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
|
class Time;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class regionProperties Declaration
|
Class regionProperties Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -55,23 +59,35 @@ class regionProperties
|
|||||||
:
|
:
|
||||||
public HashTable<wordList>
|
public HashTable<wordList>
|
||||||
{
|
{
|
||||||
|
|
||||||
//- No copy construct
|
|
||||||
regionProperties(const regionProperties&) = delete;
|
|
||||||
|
|
||||||
//- No copy assignment
|
|
||||||
void operator=(const regionProperties&) = delete;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from Time
|
||||||
regionProperties(const Time& runTime);
|
explicit regionProperties(const Time& runTime);
|
||||||
|
|
||||||
|
//- Construct from Time with specified read options
|
||||||
|
regionProperties
|
||||||
|
(
|
||||||
|
const Time& runTime,
|
||||||
|
IOobject::readOption rOpt
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- 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