Files
openfoam/applications/test/decomposePar/Test-decomposePar.C
Mark Olesen c410edf928 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
2021-05-07 09:46:33 +02:00

309 lines
8.1 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-decomposePar
Group
grpParallelUtilities
Description
Like decomposePar -dry-run, but with additional options
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include "fvCFD.H"
#include "cpuTime.H"
#include "volFields.H"
#include "IOobjectList.H"
#include "regionProperties.H"
#include "decompositionInformation.H"
#include "decompositionModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote
(
"Special-purpose version of decomposePar with additional"
" -domain and -method options."
" The '-dry-run' and '-cellDist' are implicit.\n"
"NB: The -domain/-method overrides may not work very well with regions"
);
argList::noParallel();
argList::addOption
(
"decomposeParDict",
"file",
"Use specified file for decomposePar dictionary"
);
#include "addAllRegionOptions.H"
argList::addBoolOption
(
"verbose",
"Additional verbosity"
);
argList::addOption
(
"domains",
"N",
"Override numberOfSubdomains"
);
argList::addOption
(
"method",
"name",
"Override decomposition method"
);
// These are implicit so just ignore them
argList::ignoreOptionCompat({"dry-run", 0}, false);
argList::addBoolOption
(
"cellDist",
"Write cell distribution as volScalarField for visualization"
);
argList::addBoolOption
(
"cellDist-internal",
"Write cell distribution (internal field) for visualization"
);
// Include explicit constant options, have zero from time range
timeSelector::addOptions(true, false);
#include "setRootCase.H"
const bool optRegion = args.found("region");
const bool verbose = args.found("verbose");
const label numSubdomains = args.getOrDefault<label>("domains", 0);
const word methodName = args.getOrDefault<word>("method", word::null);
// Set time from database
#include "createTime.H"
// Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args);
// Allow override of decomposeParDict location
const fileName decompDictFile =
args.getOrDefault<fileName>("decomposeParDict", "");
// Get region names
#include "getAllRegionOptions.H"
Info<< "Decomposing regions: "
<< flatOutput(regionNames) << nl << endl;
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
const word& regionDir =
(
regionName == polyMesh::defaultRegion ? word::null : regionName
);
Info<< "\n\nDecomposing mesh " << regionName << nl << endl;
Info<< "Create mesh..." << flush;
fvMesh mesh
(
IOobject
(
regionName,
runTime.timeName(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
Info<< " nCells = " << mesh.nCells() << endl;
Info<< "\nCalculating distribution of cells" << endl;
cpuTime decompositionTime;
const decompositionModel& model = decompositionModel::New
(
mesh,
decompDictFile
);
// Allow command-line override for quick testing
dictionary& modelDict = const_cast<decompositionModel&>(model);
if (numSubdomains)
{
modelDict.add
(
word("numberOfSubdomains"),
numSubdomains,
true
);
}
if (!methodName.empty())
{
modelDict.add
(
word("method"),
methodName,
true
);
}
scalarField cellWeights;
word weightName;
if (model.readIfPresent("weightField", weightName))
{
volScalarField weights
(
IOobject
(
weightName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
cellWeights = weights.primitiveField();
}
decompositionMethod& method = model.decomposer();
CompactListList<label> cellCells;
decompositionMethod::calcCellCells
(
mesh,
identity(mesh.nCells()),
mesh.nCells(),
false,
cellCells
);
labelList cellToProc = method.decompose(mesh, cellWeights);
Info<< "\nFinished decomposition into "
<< method.nDomains() << " domains in "
<< decompositionTime.elapsedCpuTime()
<< " s" << nl << endl;
decompositionInformation info
(
cellCells,
cellToProc,
method.nDomains()
);
if (verbose)
{
info.printDetails(Info);
Info<< nl;
}
info.printSummary(Info);
if (args.found("cellDist-internal"))
{
volScalarField::Internal cellDist
(
IOobject
(
"cellDist",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("cellDist", dimless, -1)
);
forAll(cellToProc, celli)
{
cellDist[celli] = cellToProc[celli];
}
cellDist.write();
Info<< nl << "Wrote decomposition as volScalarField::Internal to "
<< cellDist.name() << " for visualization."
<< endl;
fileHandler().flush();
}
else if (args.found("cellDist"))
{
volScalarField cellDist
(
IOobject
(
"cellDist",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("cellDist", dimless, -1),
zeroGradientFvPatchScalarField::typeName
);
forAll(cellToProc, celli)
{
cellDist[celli] = cellToProc[celli];
}
cellDist.correctBoundaryConditions();
cellDist.write();
Info<< nl << "Wrote decomposition as volScalarField to "
<< cellDist.name() << " for visualization."
<< endl;
fileHandler().flush();
}
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //