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.
119  List<topoDistanceData<label>> cellData(mesh.nCells());
120  List<topoDistanceData<label>> faceData(mesh.nFaces());
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
139  FaceCellWave<topoDistanceData<label>> deltaCalc
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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:584
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights) const
Return for every coordinate the wanted processor number.
label nFaces() const noexcept
Number of mesh faces.
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
Foam::word regionName(Foam::polyMesh::defaultRegion)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:99
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1293
Abstract base class for domain decomposition.
const vectorField & cellCentres() const
label nDomains() const noexcept
Number of domains.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
virtual bool parallelAware() const
Is method parallel aware.
defineTypeNameAndDebug(combustionModel, 0)
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
static autoPtr< decompositionMethod > New(const dictionary &decompDict, const word &regionName="")
Return a reference to the selected decomposition method, optionally region-specific.
#define WarningInFunction
Report a warning using Foam::Warning.
label nCells() const noexcept
Number of mesh cells.
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.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:777
List< label > labelList
A List of labels.
Definition: List.H:62
Namespace for OpenFOAM.