structured.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-2024 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 "structured.H"
28 #include "FaceCellWave.H"
29 #include "topoDistanceData.H"
30 #include "fvMeshSubset.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace decompositionMethods
37 {
39 
41  (
43  structured,
44  decomposer
45  );
46 
48  (
50  structured,
51  distributor
52  );
53 }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const dictionary& decompositionDict
62 )
63 :
64  decompositionMethod(decompositionDict),
65  methodDict_(decompositionDict_.optionalSubDict(typeName + "Coeffs")),
66  patches_(methodDict_.lookup("patches"))
67 {
68  methodDict_.set("numberOfSubdomains", nDomains());
69  method_ = decompositionMethod::NewDecomposer(methodDict_);
70 }
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
76 (
77  const polyMesh& mesh,
78  const pointField& cellCentres,
79  const scalarField& cellWeights
80 )
81 {
82  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
83  const labelHashSet patchIDs(pbm.patchSet(patches_));
84 
85  label nFaces = 0;
86  forAllConstIter(labelHashSet, patchIDs, iter)
87  {
88  nFaces += pbm[iter.key()].size();
89  }
90 
91  // Extract a submesh.
92  labelHashSet patchCells(2*nFaces);
93  forAllConstIter(labelHashSet, patchIDs, iter)
94  {
95  const labelUList& fc = pbm[iter.key()].faceCells();
96  forAll(fc, i)
97  {
98  patchCells.insert(fc[i]);
99  }
100  }
101 
102  // Subset the layer of cells next to the patch
103  fvMeshSubset subsetter(dynamic_cast<const fvMesh&>(mesh));
104  subsetter.setLargeCellSubset(patchCells);
105  const fvMesh& subMesh = subsetter.subMesh();
106  pointField subCc(cellCentres, subsetter.cellMap());
107  scalarField subWeights(cellWeights, subsetter.cellMap());
108 
109  // Decompose the layer of cells
110  labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
111 
112 
113  // Transfer to final decomposition
114  labelList finalDecomp(cellCentres.size(), -1);
115  forAll(subDecomp, i)
116  {
117  finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
118  }
119 
120  // Field on cells and faces.
121  List<topoDistanceData> cellData(mesh.nCells());
122  List<topoDistanceData> faceData(mesh.nFaces());
123 
124  // Start of changes
125  labelList patchFaces(nFaces);
126  List<topoDistanceData> patchData(nFaces);
127  nFaces = 0;
128  forAllConstIter(labelHashSet, patchIDs, iter)
129  {
130  const polyPatch& pp = pbm[iter.key()];
131  const labelUList& fc = pp.faceCells();
132  forAll(fc, i)
133  {
134  patchFaces[nFaces] = pp.start()+i;
135  patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
136  nFaces++;
137  }
138  }
139 
140  // Propagate information inwards
142  (
143  mesh,
144  patchFaces,
145  patchData,
146  faceData,
147  cellData,
148  mesh.globalData().nTotalCells()+1
149  );
150 
151  // And extract
152  bool haveWarned = false;
153  forAll(finalDecomp, celli)
154  {
155  if (!cellData[celli].valid(deltaCalc.data()))
156  {
157  if (!haveWarned)
158  {
160  << "Did not visit some cells, e.g. cell " << celli
161  << " at " << mesh.cellCentres()[celli] << endl
162  << "Assigning these cells to domain 0." << endl;
163  haveWarned = true;
164  }
165  finalDecomp[celli] = 0;
166  }
167  else
168  {
169  finalDecomp[celli] = cellData[celli].data();
170  }
171  }
172 
173  return finalDecomp;
174 }
175 
176 
178 (
179  const labelListList& globalPointPoints,
180  const pointField& points,
181  const scalarField& pointWeights
182 )
183 {
185 
186  return labelList::null();
187 }
188 
189 
190 // ************************************************************************* //
#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:109
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.
Decomposition by walking out decomposition of patch cells mesh.
Definition: structured.H:51
structured(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
Definition: structured.C:60
virtual labelList decompose(const polyMesh &mesh, const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number. Use the.
Definition: structured.C:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1152
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:893
const fvMesh & subMesh() const
Return reference to subset mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
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 indices 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:1515
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
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
For use with FaceCellWave. Determines topological distance to starting faces.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
const pointField & points
#define WarningInFunction
Report a warning using Foam::Warning.
bool valid(const PtrList< ModelType > &l)
addToRunTimeSelectionTable(decompositionMethod, metis, decomposer)
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:257