Files
openfoam/src/parallel/decompose/decompositionMethods/structuredDecomp/structuredDecomp.C
Mark Olesen dbe0db1d9a ENH: fvMeshSubset improvements (issue #951)
- what was previously termed 'setLargeCellSubset()' is now simply
  'setCellSubset()' and supports memory efficient interfaces.

  The new parameter ordering avoids ambiguities caused by default
  parameters.

  Old parameter order:

      setLargeCellSubset
      (
          const labelList& region,
          const label currentRegion,
          const label patchID = -1,
          const bool syncCouples = true
      );

  New parameter order:

      setCellSubset
      (
          const label regioni,
          const labelUList& regions,
          const label patchID = -1,
          const bool syncCouples = true
      );

   And without ambiguity:

      setCellSubset
      (
          const labelUList& selectedCells,
          const label patchID = -1,
          const bool syncCouples = true
      );

- support bitSet directly for specifying the selectedCells for
  memory efficiency and ease of use.

- Additional constructors to perform setCellSubset() immediately,
  which simplifies coding.

  For example,

      meshParts.set
      (
          zonei,
          new fvMeshSubset(mesh, selectedCells)
      );

  Or even

      return autoPtr<fvMeshSubset>::New(mesh, selectedCells);
2018-07-25 18:58:00 +02:00

183 lines
5.0 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 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/>.
\*---------------------------------------------------------------------------*/
#include "structuredDecomp.H"
#include "addToRunTimeSelectionTable.H"
#include "FaceCellWave.H"
#include "topoDistanceData.H"
#include "fvMeshSubset.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(structuredDecomp, 0);
addToRunTimeSelectionTable
(
decompositionMethod,
structuredDecomp,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::structuredDecomp::structuredDecomp(const dictionary& decompDict)
:
decompositionMethod(decompDict),
methodDict_(findCoeffsDict(typeName + "Coeffs", selectionType::MANDATORY)),
patches_(methodDict_.lookup("patches"))
{
methodDict_.set("numberOfSubdomains", nDomains());
method_ = decompositionMethod::New(methodDict_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::structuredDecomp::parallelAware() const
{
return method_().parallelAware();
}
Foam::labelList Foam::structuredDecomp::decompose
(
const polyMesh& mesh,
const pointField& cc,
const scalarField& cWeights
) const
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
const labelHashSet patchIDs(pbm.patchSet(patches_));
label nFaces = 0;
for (const label patchi : patchIDs)
{
nFaces += pbm[patchi].size();
}
// Extract a submesh.
labelHashSet patchCells(2*nFaces);
for (const label patchi : patchIDs)
{
patchCells.insert(pbm[patchi].faceCells());
}
// Subset the layer of cells next to the patch
fvMeshSubset subsetter
(
dynamic_cast<const fvMesh&>(mesh),
patchCells
);
const fvMesh& subMesh = subsetter.subMesh();
pointField subCc(cc, subsetter.cellMap());
scalarField subWeights(cWeights, subsetter.cellMap());
// Decompose the layer of cells
labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
// Transfer to final decomposition
labelList finalDecomp(cc.size(), -1);
forAll(subDecomp, i)
{
finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
}
// Field on cells and faces.
List<topoDistanceData> cellData(mesh.nCells());
List<topoDistanceData> faceData(mesh.nFaces());
// Start of changes
labelList patchFaces(nFaces);
List<topoDistanceData> patchData(nFaces);
nFaces = 0;
for (const label patchi : patchIDs)
{
const polyPatch& pp = pbm[patchi];
const labelUList& fc = pp.faceCells();
forAll(fc, i)
{
patchFaces[nFaces] = pp.start()+i;
patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
nFaces++;
}
}
// Propagate information inwards
FaceCellWave<topoDistanceData> deltaCalc
(
mesh,
patchFaces,
patchData,
faceData,
cellData,
mesh.globalData().nTotalCells()+1
);
// And extract
bool haveWarned = false;
forAll(finalDecomp, celli)
{
if (!cellData[celli].valid(deltaCalc.data()))
{
if (!haveWarned)
{
WarningInFunction
<< "Did not visit some cells, e.g. cell " << celli
<< " at " << mesh.cellCentres()[celli] << endl
<< "Assigning these cells to domain 0." << endl;
haveWarned = true;
}
finalDecomp[celli] = 0;
}
else
{
finalDecomp[celli] = cellData[celli].data();
}
}
return finalDecomp;
}
Foam::labelList Foam::structuredDecomp::decompose
(
const labelListList& globalCellCells,
const pointField& cc,
const scalarField& cWeights
) const
{
NotImplemented;
return labelList(0);
}
// ************************************************************************* //