ENH: add optional agglomeration coefficent to random decomposition

- specifies the number of consecutive cells to assign to the same
  randomly chosen processor. Can be used to have a less extremely
  random distribution for testing possible breaking points.

Eg,
    method random;

    coeffs
    {
        agglom  4;
    }

- Add finiteArea cellID (actually face ids) / faceLabel and procID
  for foamToVTK with -write-ids. Useful when this type of information
  is needed.
This commit is contained in:
Mark Olesen
2022-05-03 17:37:12 +02:00
parent 8ee4efc64b
commit 0e01e530a8
3 changed files with 79 additions and 14 deletions

View File

@ -49,8 +49,10 @@ if (doFiniteArea)
faMeshPtr = faMesh::TryNew(meshProxy.baseMesh());
}
if (faMeshPtr && nAreaFields)
if (faMeshPtr && (nAreaFields || withMeshIds))
{
const faMesh& areaMesh = faMeshPtr();
reportFields::area(Info, objects);
const auto& pp = faMeshPtr->patch();
@ -66,17 +68,36 @@ if (doFiniteArea)
Pstream::parRun()
);
writer.beginFile(faMeshPtr->name());
writer.beginFile(areaMesh.name());
writer.writeTimeValue(timeValue);
writer.writeGeometry();
writer.beginCellData(nAreaFields);
// Optionally with (cellID, faceLabels, procID) fields
writer.beginCellData
(
(withMeshIds ? 2 + (writer.parallel() ? 1 : 0) : 0)
+ nAreaFields
);
if (withMeshIds)
{
const globalIndex procAddr(areaMesh.nFaces());
// Use global indexed values for the 'cell' ids
writer.writeCellData("cellID", identity(procAddr.range()));
// Use proc-local data for faceLabels
// (confusing enough already without renumbering)
writer.writeCellData("faceLabels", areaMesh.faceLabels());
writer.writeProcIDs(); // parallel only
}
writeAllAreaFields
(
writer,
*faMeshPtr,
areaMesh,
objects,
true // syncPar
);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,9 +51,29 @@ Foam::labelList Foam::randomDecomp::randomMap(const label nCells) const
labelList finalDecomp(nCells);
for (label& val : finalDecomp)
if (agglom_ > 1)
{
val = rndGen.position<label>(0, nDomains_ - 1);
label cached = 0;
label repeat = 0;
for (label& val : finalDecomp)
{
if (!repeat)
{
cached = rndGen.position<label>(0, nDomains_ - 1);
repeat = agglom_;
}
--repeat;
val = cached;
}
}
else
{
for (label& val : finalDecomp)
{
val = rndGen.position<label>(0, nDomains_ - 1);
}
}
return finalDecomp;
@ -65,11 +85,18 @@ Foam::labelList Foam::randomDecomp::randomMap(const label nCells) const
Foam::randomDecomp::randomDecomp
(
const dictionary& decompDict,
const word& regionName
const word& regionName,
int select
)
:
decompositionMethod(decompDict, regionName)
{}
decompositionMethod(decompDict, regionName),
agglom_(1)
{
const dictionary& coeffs = findCoeffsDict(typeName + "Coeffs", select);
// No sanity check needed here (done in randomMap routine)
coeffs.readIfPresent("agglom", agglom_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -27,15 +27,25 @@ Class
Foam::randomDecomp
Description
Decomposition according to pseudo-random number generator.
Decomposition according to pseudo-random number generator,
which is useful for development and stress testing implementations
but obviously sub-optimal for normal uses.
Can optionally specify the number of consecutive cells to assign
to the same processor (agglomeration).
Coefficients:
\table
Property | Description | Required | Default
agglom | Number of cells to agglomerate | no | 1
\endtable
SourceFiles
randomDecomp.C
\*---------------------------------------------------------------------------*/
#ifndef randomDecomp_H
#define randomDecomp_H
#ifndef Foam_randomDecomp_H
#define Foam_randomDecomp_H
#include "decompositionMethod.H"
@ -50,6 +60,12 @@ class randomDecomp
:
public decompositionMethod
{
// Private Data
//- Number of cells to agglomerate per random value (default: 1)
label agglom_;
// Private Member Functions
//- Random distribution on the 0-nCells interval
@ -74,7 +90,8 @@ public:
explicit randomDecomp
(
const dictionary& decompDict,
const word& regionName = ""
const word& regionName = "",
int select = selectionType::DEFAULT
);