mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: centralized handling of -allRegions, -regions, -region (#2072)
Step 1.
include "addAllRegionOptions.H"
Adds the -allRegions, -regions and -region options to argList.
Step 2.
include "getAllRegionOptions.H"
Processes the options with -allRegions selecting everything
from the regionProperties.
OR use -regions to specify multiple regions (from
regionProperties), and can also contain regular expressions
OR use the -region option
Specifying a single -regions NAME (not a regular expresssion)
is the same as -region NAME and doesn't use regionProperties
Creates a `wordList regionNames`
Step 3.
Do something with the region names.
Either directly, or quite commonly with the following
include "createNamedMeshes.H"
Creates a `PtrList<fvMesh> meshes`
STYLE: add description to some central include files
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -67,7 +67,7 @@ if (doFiniteArea)
|
||||
pp,
|
||||
writeOpts,
|
||||
(
|
||||
outputDir/regionPrefix/"finite-area"
|
||||
outputDir/regionDir/"finite-area"
|
||||
/ "finiteArea" + timeDesc
|
||||
),
|
||||
Pstream::parRun()
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,7 +31,7 @@ Description
|
||||
|
||||
if (doLagrangian)
|
||||
{
|
||||
const fileName cloudPrefix = (regionPrefix/cloud::prefix);
|
||||
const fileName cloudPrefix = (regionDir/cloud::prefix);
|
||||
|
||||
wordList cloudNames = ListOps::create<word>
|
||||
(
|
||||
@ -89,7 +89,7 @@ if (doLagrangian)
|
||||
writeOpts,
|
||||
// Output name for the cloud
|
||||
(
|
||||
outputDir/regionPrefix/cloud::prefix
|
||||
outputDir/regionDir/cloud::prefix
|
||||
/ cloudName/cloudName + timeDesc
|
||||
),
|
||||
Pstream::parRun()
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -47,7 +47,7 @@ Description
|
||||
|
||||
fileName vtmOutputBase
|
||||
(
|
||||
outputDir/regionPrefix/vtkName + timeDesc
|
||||
outputDir/regionDir/vtkName + timeDesc
|
||||
);
|
||||
|
||||
// Naming
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -102,7 +102,7 @@ Description
|
||||
meshProxy.mesh(),
|
||||
writeOpts,
|
||||
(
|
||||
outputDir/regionPrefix
|
||||
outputDir/regionDir
|
||||
/ "surface-fields"/"surfaceFields" + timeDesc
|
||||
),
|
||||
Pstream::parRun()
|
||||
@ -205,7 +205,7 @@ Description
|
||||
pp,
|
||||
writeOpts,
|
||||
(
|
||||
outputDir/regionPrefix/fz.name()
|
||||
outputDir/regionDir/fz.name()
|
||||
/ (meshProxy.useSubMesh() ? meshProxy.name() : fz.name())
|
||||
+ timeDesc
|
||||
),
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,7 +39,7 @@ if (faceSetName.size())
|
||||
|
||||
fileName outputName
|
||||
(
|
||||
outputDir/regionPrefix/"face-set"
|
||||
outputDir/regionDir/"face-set"
|
||||
/ set.name()/set.name() + timeDesc
|
||||
);
|
||||
|
||||
@ -67,7 +67,7 @@ if (pointSetName.size())
|
||||
|
||||
fileName outputName
|
||||
(
|
||||
outputDir/regionPrefix/"point-set"
|
||||
outputDir/regionDir/"point-set"
|
||||
/ set.name()/set.name() + timeDesc
|
||||
);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -65,7 +65,7 @@ Description
|
||||
|
||||
fileName vtmOutputBase
|
||||
(
|
||||
outputDir/regionPrefix/vtkName + timeDesc
|
||||
outputDir/regionDir/vtkName + timeDesc
|
||||
);
|
||||
|
||||
// Combined internal + boundary in a vtm file
|
||||
@ -148,7 +148,7 @@ Description
|
||||
writeOpts.legacy()
|
||||
?
|
||||
(
|
||||
outputDir/regionPrefix/"boundary"
|
||||
outputDir/regionDir/"boundary"
|
||||
/ (meshProxy.useSubMesh() ? meshProxy.name() : "boundary")
|
||||
+ timeDesc
|
||||
)
|
||||
@ -203,7 +203,7 @@ Description
|
||||
writeOpts.legacy()
|
||||
?
|
||||
(
|
||||
outputDir/regionPrefix/pp.name()
|
||||
outputDir/regionDir/pp.name()
|
||||
/ (meshProxy.useSubMesh() ? meshProxy.name() : pp.name())
|
||||
+ timeDesc
|
||||
)
|
||||
@ -461,7 +461,7 @@ Description
|
||||
series.write(seriesName);
|
||||
|
||||
// Add to multi-region vtm
|
||||
vtmMultiRegion.add(regionName, regionPrefix, vtmWriter);
|
||||
vtmMultiRegion.add(regionName, regionDir, vtmWriter);
|
||||
}
|
||||
|
||||
if (vtmBoundaries.size())
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
|
||||
Description
|
||||
Additional mesh accounting (foamToVTK)
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
PtrList<fvMeshSubsetProxy> meshProxies(meshes.size());
|
||||
PtrList<vtk::vtuCells> vtuMappings(meshes.size());
|
||||
|
||||
{
|
||||
forAll(meshes, regioni)
|
||||
{
|
||||
// Mesh subsetting, or pass through
|
||||
meshProxies.set
|
||||
(
|
||||
regioni,
|
||||
new fvMeshSubsetProxy
|
||||
(
|
||||
meshes[regioni],
|
||||
cellSubsetType,
|
||||
cellSelectionName
|
||||
)
|
||||
);
|
||||
|
||||
// VTU sizing and decomposition information
|
||||
vtuMappings.set
|
||||
(
|
||||
regioni,
|
||||
new vtk::vtuCells(writeOpts, decomposePoly)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,58 +0,0 @@
|
||||
PtrList<fvMesh> meshes(regionNames.size());
|
||||
PtrList<fvMeshSubsetProxy> meshProxies(regionNames.size());
|
||||
PtrList<vtk::vtuCells> vtuMappings(regionNames.size());
|
||||
|
||||
forAll(regionNames, regioni)
|
||||
{
|
||||
const word& regionName = regionNames[regioni];
|
||||
|
||||
Info<< "Create mesh";
|
||||
|
||||
if (regionName != fvMesh::defaultRegion)
|
||||
{
|
||||
Info<< ' ' << regionName;
|
||||
}
|
||||
Info<< " for time = " << runTime.timeName() << nl << endl;
|
||||
|
||||
meshes.set
|
||||
(
|
||||
regioni,
|
||||
new fvMesh
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
regionName,
|
||||
runTime.timeName(),
|
||||
runTime,
|
||||
IOobject::MUST_READ
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Mesh subsetting, or pass through
|
||||
meshProxies.set
|
||||
(
|
||||
regioni,
|
||||
new fvMeshSubsetProxy
|
||||
(
|
||||
meshes[regioni],
|
||||
cellSubsetType,
|
||||
cellSelectionName
|
||||
)
|
||||
);
|
||||
|
||||
// VTU sizing and decomposition information
|
||||
vtuMappings.set
|
||||
(
|
||||
regioni,
|
||||
new vtk::vtuCells(writeOpts, decomposePoly)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Info<< "VTK mesh topology: "
|
||||
<< timer.cpuTimeIncrement() << " s, "
|
||||
<< mem.update().size() << " kB" << endl;
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -405,20 +405,7 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
argList::addOptionCompat("one-boundary", {"allPatches", 1806});
|
||||
|
||||
#include "addRegionOption.H"
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"regions",
|
||||
"wordRes",
|
||||
"Operate on selected regions from regionProperties.\n"
|
||||
"Eg, '( gas \"solid.*\" )'"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"allRegions",
|
||||
"Operate on all regions in regionProperties"
|
||||
);
|
||||
#include "addAllRegionOptions.H"
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
@ -473,7 +460,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
const bool oneBoundary = args.found("one-boundary") && doBoundary;
|
||||
const bool nearCellValue = args.found("nearCellValue") && doBoundary;
|
||||
const bool allRegions = args.found("allRegions");
|
||||
|
||||
const vtk::outputOptions writeOpts = getOutputOptions(args);
|
||||
|
||||
@ -563,80 +549,8 @@ int main(int argc, char *argv[])
|
||||
// Information for file series
|
||||
HashTable<vtk::seriesWriter, fileName> vtkSeries;
|
||||
|
||||
wordList regionNames;
|
||||
wordRes selectRegions;
|
||||
if (allRegions)
|
||||
{
|
||||
regionNames =
|
||||
regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
|
||||
|
||||
if (regionNames.empty())
|
||||
{
|
||||
Info<< "Warning: "
|
||||
<< "No regionProperties - assuming default region"
|
||||
<< nl << endl;
|
||||
|
||||
regionNames.resize(1);
|
||||
regionNames.first() = fvMesh::defaultRegion;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "Using all regions in regionProperties" << nl
|
||||
<< " "<< flatOutput(regionNames) << nl;
|
||||
}
|
||||
}
|
||||
else if (args.readListIfPresent<wordRe>("regions", selectRegions))
|
||||
{
|
||||
if (selectRegions.empty())
|
||||
{
|
||||
regionNames.resize(1);
|
||||
regionNames.first() = fvMesh::defaultRegion;
|
||||
}
|
||||
else if
|
||||
(
|
||||
selectRegions.size() == 1 && selectRegions.first().isLiteral()
|
||||
)
|
||||
{
|
||||
// Identical to -region NAME
|
||||
regionNames.resize(1);
|
||||
regionNames.first() = selectRegions.first();
|
||||
}
|
||||
else
|
||||
{
|
||||
regionNames =
|
||||
regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
|
||||
|
||||
if (regionNames.empty())
|
||||
{
|
||||
Info<< "Warning: "
|
||||
<< "No regionProperties - assuming default region"
|
||||
<< nl << endl;
|
||||
|
||||
regionNames.resize(1);
|
||||
regionNames.first() = fvMesh::defaultRegion;
|
||||
}
|
||||
else
|
||||
{
|
||||
inplaceSubsetStrings(selectRegions, regionNames);
|
||||
|
||||
if (regionNames.empty())
|
||||
{
|
||||
Info<< "No matching regions ... stopping" << nl << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Info<< "Using matching regions: "
|
||||
<< flatOutput(regionNames) << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
regionNames.resize(1);
|
||||
regionNames.first() =
|
||||
args.getOrDefault<word>("region", fvMesh::defaultRegion);
|
||||
}
|
||||
|
||||
// Handle -allRegions, -regions, -region
|
||||
#include "getAllRegionOptions.H"
|
||||
|
||||
// Names for sets and zones
|
||||
word cellSelectionName;
|
||||
@ -686,13 +600,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cpuTime timer;
|
||||
memInfo mem;
|
||||
Info<< "Initial memory " << mem.update().size() << " kB" << endl;
|
||||
|
||||
#include "createMeshes.H"
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Directory management
|
||||
|
||||
// Sub-directory for output
|
||||
@ -705,29 +613,39 @@ int main(int argc, char *argv[])
|
||||
// Overwrite or create the VTK/regionName directories.
|
||||
// For the default region, this is simply "VTK/"
|
||||
|
||||
fileName regionDir;
|
||||
for (const word& regionName : regionNames)
|
||||
{
|
||||
if (regionName != polyMesh::defaultRegion)
|
||||
{
|
||||
regionDir = outputDir / regionName;
|
||||
}
|
||||
else
|
||||
{
|
||||
regionDir = outputDir;
|
||||
}
|
||||
const word& regionDir =
|
||||
(
|
||||
regionName == polyMesh::defaultRegion ? word::null : regionName
|
||||
);
|
||||
|
||||
if (args.found("overwrite") && isDir(regionDir))
|
||||
fileName regionalDir(outputDir/regionDir);
|
||||
|
||||
if (args.found("overwrite") && Foam::isDir(regionalDir))
|
||||
{
|
||||
Info<< "Removing old directory "
|
||||
<< args.relativePath(regionDir)
|
||||
<< args.relativePath(regionalDir)
|
||||
<< nl << endl;
|
||||
rmDir(regionDir);
|
||||
Foam::rmDir(regionalDir);
|
||||
}
|
||||
mkDir(regionDir);
|
||||
Foam::mkDir(regionalDir);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
cpuTime timer;
|
||||
memInfo mem;
|
||||
Info<< "Initial memory " << mem.update().size() << " kB" << endl;
|
||||
|
||||
#include "createNamedMeshes.H"
|
||||
#include "createMeshAccounting.H"
|
||||
|
||||
Info<< "VTK mesh topology: "
|
||||
<< timer.cpuTimeIncrement() << " s, "
|
||||
<< mem.update().size() << " kB" << endl;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -749,11 +667,13 @@ int main(int argc, char *argv[])
|
||||
forAll(regionNames, regioni)
|
||||
{
|
||||
const word& regionName = regionNames[regioni];
|
||||
|
||||
fileName regionPrefix;
|
||||
if (regionName != polyMesh::defaultRegion)
|
||||
const word& regionDir =
|
||||
(
|
||||
regionName == polyMesh::defaultRegion ? word::null : regionName
|
||||
);
|
||||
if (regionNames.size() > 1 || !regionDir.empty())
|
||||
{
|
||||
regionPrefix = regionName;
|
||||
Info<< "region = " << regionName << nl;
|
||||
}
|
||||
|
||||
auto& meshProxy = meshProxies[regioni];
|
||||
|
||||
Reference in New Issue
Block a user