structuredDecomp.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "structuredDecomp.H"
31 #include "FaceCellWave.H"
32 #include "topoDistanceData.H"
33 #include "fvMeshSubset.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(structuredDecomp, 0);
41  (
42  decompositionMethod,
43  structuredDecomp,
44  dictionary
45  );
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::structuredDecomp::structuredDecomp
52 (
53  const dictionary& decompDict,
54  const word& regionName
55 )
56 :
57  decompositionMethod(decompDict),
58  methodDict_(findCoeffsDict(typeName + "Coeffs", selectionType::MANDATORY)),
59  patches_(methodDict_.get<wordRes>("patches"))
60 {
61  methodDict_.set("numberOfSubdomains", nDomains());
62  method_ = decompositionMethod::New(methodDict_);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
69 {
70  return method_().parallelAware();
71 }
72 
73 
75 (
76  const polyMesh& mesh,
77  const pointField& cc,
78  const scalarField& cWeights
79 ) const
80 {
81  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
82  const labelHashSet patchIDs(pbm.patchSet(patches_));
83 
84  label nFaces = 0;
85  for (const label patchi : patchIDs)
86  {
87  nFaces += pbm[patchi].size();
88  }
89 
90  // Extract a submesh.
91  labelHashSet patchCells(2*nFaces);
92  for (const label patchi : patchIDs)
93  {
94  patchCells.insert(pbm[patchi].faceCells());
95  }
96 
97  // Subset the layer of cells next to the patch
98  fvMeshSubset subsetter
99  (
100  dynamic_cast<const fvMesh&>(mesh),
101  patchCells
102  );
103  const fvMesh& subMesh = subsetter.subMesh();
104  pointField subCc(cc, subsetter.cellMap());
105  scalarField subWeights(cWeights, subsetter.cellMap());
106 
107  // Decompose the layer of cells
108  labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
109 
110 
111  // Transfer to final decomposition
112  labelList finalDecomp(cc.size(), -1);
113  forAll(subDecomp, i)
114  {
115  finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
116  }
117 
118  // Field on cells and faces.
121 
122  // Start of changes
123  labelList patchFaces(nFaces);
124  List<topoDistanceData<label>> patchData(nFaces);
125  nFaces = 0;
126  for (const label patchi : patchIDs)
127  {
128  const polyPatch& pp = pbm[patchi];
129  const labelUList& fc = pp.faceCells();
130  forAll(fc, i)
131  {
132  patchFaces[nFaces] = pp.start()+i;
133  patchData[nFaces] = topoDistanceData<label>(0, finalDecomp[fc[i]]);
134  nFaces++;
135  }
136  }
137 
138  // Propagate information inwards
140  (
141  mesh,
142  patchFaces,
143  patchData,
144  faceData,
145  cellData,
147  );
148 
149  // And extract
150  bool haveWarned = false;
151  forAll(finalDecomp, celli)
152  {
153  if (!cellData[celli].valid(deltaCalc.data()))
154  {
155  if (!haveWarned)
156  {
158  << "Did not visit some cells, e.g. cell " << celli
159  << " at " << mesh.cellCentres()[celli] << nl
160  << "Assigning these cells to domain 0." << endl;
161  haveWarned = true;
162  }
163  finalDecomp[celli] = 0;
164  }
165  else
166  {
167  finalDecomp[celli] = cellData[celli].data();
168  }
169  }
170 
171  return finalDecomp;
172 }
173 
174 
175 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
topoDistanceData.H
Foam::topoDistanceData
For use with FaceCellWave. Determines topological distance to starting faces. Templated on passive tr...
Definition: topoDistanceData.H:53
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fvMeshSubset::cellMap
const labelList & cellMap() const
Return cell map.
Definition: fvMeshSubsetI.H:91
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
fvMeshSubset.H
Foam::FaceCellWave::data
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:348
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::HashSet< label, Hash< label > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Field< vector >
Foam::fvMeshSubset::subMesh
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::structuredDecomp::parallelAware
virtual bool parallelAware() const
Is method parallel aware.
Definition: structuredDecomp.C:68
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::decompositionMethod
Abstract base class for domain decomposition.
Definition: decompositionMethod.H:51
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:371
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:361
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::FaceCellWave
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:78
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
FaceCellWave.H
Foam::UList< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Definition: polyBoundaryMesh.C:864
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
Foam::globalMeshData::nTotalCells
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
Definition: globalMeshData.H:371
Foam::primitiveMesh::nFaces
label nFaces() const noexcept
Number of mesh faces.
Definition: primitiveMeshI.H:90
structuredDecomp.H
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1295
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56
Foam::structuredDecomp::decompose
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights) const
Return for every coordinate the wanted processor number.
Definition: structuredDecomp.C:75