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  const dictionary& methodDict
63 )
64 :
65  decompositionMethod(decompositionDict)
66 {
67  methodDict.lookup("patches") >> patches_;
68 
69  dictionary methodDict_(methodDict);
70  methodDict_.set("numberOfSubdomains", nDomains());
71  method_ = decompositionMethod::NewDecomposer(methodDict_);
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
78 (
79  const polyMesh& mesh,
80  const pointField& cellCentres,
81  const scalarField& cellWeights
82 )
83 {
84  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
85  const labelHashSet patchIDs(pbm.patchSet(patches_));
86 
87  label nFaces = 0;
88  forAllConstIter(labelHashSet, patchIDs, iter)
89  {
90  nFaces += pbm[iter.key()].size();
91  }
92 
93  // Extract a submesh.
94  labelHashSet patchCells(2*nFaces);
95  forAllConstIter(labelHashSet, patchIDs, iter)
96  {
97  const labelUList& fc = pbm[iter.key()].faceCells();
98  forAll(fc, i)
99  {
100  patchCells.insert(fc[i]);
101  }
102  }
103 
104  // Subset the layer of cells next to the patch
105  fvMeshSubset subsetter(dynamic_cast<const fvMesh&>(mesh));
106  subsetter.setLargeCellSubset(patchCells);
107  const fvMesh& subMesh = subsetter.subMesh();
108  pointField subCc(cellCentres, subsetter.cellMap());
109  scalarField subWeights(cellWeights, subsetter.cellMap());
110 
111  // Decompose the layer of cells
112  labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
113 
114 
115  // Transfer to final decomposition
116  labelList finalDecomp(cellCentres.size(), -1);
117  forAll(subDecomp, i)
118  {
119  finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
120  }
121 
122  // Field on cells and faces.
123  List<topoDistanceData> cellData(mesh.nCells());
125 
126  // Start of changes
127  labelList patchFaces(nFaces);
128  List<topoDistanceData> patchData(nFaces);
129  nFaces = 0;
130  forAllConstIter(labelHashSet, patchIDs, iter)
131  {
132  const polyPatch& pp = pbm[iter.key()];
133  const labelUList& fc = pp.faceCells();
134  forAll(fc, i)
135  {
136  patchFaces[nFaces] = pp.start()+i;
137  patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
138  nFaces++;
139  }
140  }
141 
142  // Propagate information inwards
144  (
145  mesh,
146  patchFaces,
147  patchData,
148  faceData,
149  cellData,
151  );
152 
153  // And extract
154  bool haveWarned = false;
155  forAll(finalDecomp, celli)
156  {
157  if (!cellData[celli].valid(deltaCalc.data()))
158  {
159  if (!haveWarned)
160  {
162  << "Did not visit some cells, e.g. cell " << celli
163  << " at " << mesh.cellCentres()[celli] << endl
164  << "Assigning these cells to domain 0." << endl;
165  haveWarned = true;
166  }
167  finalDecomp[celli] = 0;
168  }
169  else
170  {
171  finalDecomp[celli] = cellData[celli].data();
172  }
173  }
174 
175  return finalDecomp;
176 }
177 
178 
180 (
181  const labelListList& globalPointPoints,
182  const pointField& points,
183  const scalarField& pointWeights
184 )
185 {
187 
188  return labelList::null();
189 }
190 
191 
192 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
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, const dictionary &methodDict)
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:78
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
Base class for classes which manage incomplete sets of face data.
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:917
const fvMesh & subMesh() const
Return reference to subset mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
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 patch set 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:1521
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:401
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
const vectorField & cellCentres() const
label nCells() const
label nFaces() const
For use with FaceCellWave. Determines topological distance to starting faces.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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:258