structuredDecomp.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "structuredDecomp.H"
28 #include "FaceCellWave.H"
29 #include "topoDistanceData.H"
30 #include "fvMeshSubset.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(structuredDecomp, 0);
37 
39  (
40  decompositionMethod,
41  structuredDecomp,
42  decomposer
43  );
44 
46  (
47  decompositionMethod,
48  structuredDecomp,
49  distributor
50  );
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 :
58  decompositionMethod(decompositionDict),
59  methodDict_(decompositionDict_.optionalSubDict(typeName + "Coeffs")),
60  patches_(methodDict_.lookup("patches"))
61 {
62  methodDict_.set("numberOfSubdomains", nDomains());
63  method_ = decompositionMethod::NewDecomposer(methodDict_);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 (
71  const polyMesh& mesh,
72  const pointField& cc,
73  const scalarField& cWeights
74 )
75 {
76  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
77  const labelHashSet patchIDs(pbm.patchSet(patches_));
78 
79  label nFaces = 0;
80  forAllConstIter(labelHashSet, patchIDs, iter)
81  {
82  nFaces += pbm[iter.key()].size();
83  }
84 
85  // Extract a submesh.
86  labelHashSet patchCells(2*nFaces);
87  forAllConstIter(labelHashSet, patchIDs, iter)
88  {
89  const labelUList& fc = pbm[iter.key()].faceCells();
90  forAll(fc, i)
91  {
92  patchCells.insert(fc[i]);
93  }
94  }
95 
96  // Subset the layer of cells next to the patch
97  fvMeshSubset subsetter(dynamic_cast<const fvMesh&>(mesh));
98  subsetter.setLargeCellSubset(patchCells);
99  const fvMesh& subMesh = subsetter.subMesh();
100  pointField subCc(cc, subsetter.cellMap());
101  scalarField subWeights(cWeights, subsetter.cellMap());
102 
103  // Decompose the layer of cells
104  labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
105 
106 
107  // Transfer to final decomposition
108  labelList finalDecomp(cc.size(), -1);
109  forAll(subDecomp, i)
110  {
111  finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
112  }
113 
114  // Field on cells and faces.
115  List<topoDistanceData> cellData(mesh.nCells());
116  List<topoDistanceData> faceData(mesh.nFaces());
117 
118  // Start of changes
119  labelList patchFaces(nFaces);
120  List<topoDistanceData> patchData(nFaces);
121  nFaces = 0;
122  forAllConstIter(labelHashSet, patchIDs, iter)
123  {
124  const polyPatch& pp = pbm[iter.key()];
125  const labelUList& fc = pp.faceCells();
126  forAll(fc, i)
127  {
128  patchFaces[nFaces] = pp.start()+i;
129  patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
130  nFaces++;
131  }
132  }
133 
134  // Propagate information inwards
136  (
137  mesh,
138  patchFaces,
139  patchData,
140  faceData,
141  cellData,
142  mesh.globalData().nTotalCells()+1
143  );
144 
145  // And extract
146  bool haveWarned = false;
147  forAll(finalDecomp, celli)
148  {
149  if (!cellData[celli].valid(deltaCalc.data()))
150  {
151  if (!haveWarned)
152  {
154  << "Did not visit some cells, e.g. cell " << celli
155  << " at " << mesh.cellCentres()[celli] << endl
156  << "Assigning these cells to domain 0." << endl;
157  haveWarned = true;
158  }
159  finalDecomp[celli] = 0;
160  }
161  else
162  {
163  finalDecomp[celli] = cellData[celli].data();
164  }
165  }
166 
167  return finalDecomp;
168 }
169 
170 
172 (
173  const labelListList& globalPointPoints,
174  const pointField& points,
175  const scalarField& pointWeights
176 )
177 {
179 
180  return labelList::null();
181 }
182 
183 
184 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:453
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
label nFaces() const
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:76
label nTotalCells() const
Return total number of cells in decomposed mesh.
static const List< label > & null()
Return a null List.
Definition: ListI.H:118
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
Macros for easy insertion into run-time selection tables.
const fvMesh & subMesh() const
Return reference to subset mesh.
stressControl lookup("compactNormalStress") >> compactNormalStress
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:340
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number. Use the.
static autoPtr< decompositionMethod > NewDecomposer(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1435
Abstract base class for decomposition.
const labelList & cellMap() const
Return cell map.
const vectorField & cellCentres() const
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::polyBoundaryMesh.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Post-processing mesh subset tool. Given the original mesh and the list of selected cells...
Definition: fvMeshSubset.H:73
structuredDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
#define WarningInFunction
Report a warning using Foam::Warning.
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:315
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:306
For use with FaceCellWave. Determines topological distance to starting faces.
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1291
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
void setLargeCellSubset(const labelList &region, const label currentRegion, const label patchID=-1, const bool syncCouples=true)
Set the subset from all cells with region == currentRegion.
Definition: fvMeshSubset.C:895
Namespace for OpenFOAM.