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 {
37 
39  (
42  decomposer
43  );
44 
46  (
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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Macros for easy insertion into run-time selection tables.
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:79
const TrackingData & data() const
Additional data to be passed into container.
Definition: FaceCellWave.H:308
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
static const List< label > & null()
Return a null List.
Definition: ListI.H:118
T * data()
Return a pointer to the first data element,.
Definition: UListI.H:149
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
Abstract base class for decomposition.
static autoPtr< decompositionMethod > NewDecomposer(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1307
Post-processing mesh subset tool. Given the original mesh and the list of selected cells,...
Definition: fvMeshSubset.H:74
const labelList & cellMap() const
Return cell map.
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:896
const fvMesh & subMesh() const
Return reference to subset mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
label nTotalCells() const
Return total number of cells in decomposed mesh.
Foam::polyBoundaryMesh.
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.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1563
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:280
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:313
label nCells() const
const vectorField & cellCentres() const
label nFaces() const
Decomposition by walking out decomposition of patch cells mesh.
structuredDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number. Use the.
For use with FaceCellWave. Determines topological distance to starting faces.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
const pointField & points
#define WarningInFunction
Report a warning using Foam::Warning.
bool valid(const PtrList< ModelType > &l)
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)