decompositionMethod.H
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 Class
25  Foam::decompositionMethod
26 
27 Description
28  Abstract base class for decomposition
29 
30 SourceFiles
31  decompositionMethod.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef decompositionMethod_H
36 #define decompositionMethod_H
37 
38 #include "polyMesh.H"
39 #include "CompactListList.H"
41 #include "IOdictionary.H"
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class decompositionMethod Declaration
48 \*---------------------------------------------------------------------------*/
49 
51 {
52 protected:
53 
54  // Protected data
55 
57 
59 
60  //- Optional constraints
62 
63 
64  // Protected member functions
65 
66  //- Return the number of weights per point
68  (
69  const pointField& points,
70  const scalarField& pointWeights
71  ) const;
72 
73  //- Check the weights against the points
74  // and return the number of weights per point
76  (
77  const pointField& points,
78  const scalarField& pointWeights
79  ) const;
80 
81 
82 public:
83 
84  //- Runtime type information
85  TypeName("decompositionMethod");
86 
87 
88  // Declare run-time constructor selection tables
89 
91  (
92  autoPtr,
94  decomposer,
95  (
96  const dictionary& decompositionDict
97  ),
98  (decompositionDict)
99  );
100 
102  (
103  autoPtr,
105  distributor,
106  (
107  const dictionary& decompositionDict
108  ),
109  (decompositionDict)
110  );
111 
112 
113  // Constructors
114 
115  //- Construct given the decomposition dictionary
116  decompositionMethod(const dictionary& decompositionDict);
117 
118  //- Disallow default bitwise copy construction
119  decompositionMethod(const decompositionMethod&) = delete;
120 
121 
122  // Selectors
123 
124  //- Return a reference to the selected decomposition method
126  (
127  const dictionary& decompositionDict
128  );
129 
130  //- Return a reference to the selected decomposition method
132  (
133  const dictionary& decompositionDict
134  );
135 
136 
137  //- Destructor
138  virtual ~decompositionMethod()
139  {}
140 
141 
142  // Member Functions
143 
144  label nDomains() const
145  {
146  return nProcessors_;
147  }
148 
149  //- Read and return the decomposeParDict
150  static IOdictionary decomposeParDict(const Time& time);
151 
152 
153  // No topology (implemented by geometric decomposers)
154 
155  //- Return for every coordinate the wanted processor number.
156  virtual labelList decompose
157  (
158  const pointField& points,
159  const scalarField& pointWeights
160  )
161  {
163  return labelList(0);
164  }
165 
166  //- Like decompose but with uniform weights on the points
167  virtual labelList decompose(const pointField&)
168  {
170  return labelList(0);
171  }
172 
173 
174  // Topology provided by mesh
175 
176  //- Return for every coordinate the wanted processor number. Use the
177  // mesh connectivity (if needed)
178  virtual labelList decompose
179  (
180  const polyMesh& mesh,
181  const pointField& points,
182  const scalarField& pointWeights
183  ) = 0;
184 
185  //- Like decompose but with uniform weights on the points
186  virtual labelList decompose(const polyMesh&, const pointField&);
187 
188  //- Return for every coordinate the wanted processor number. Gets
189  // passed agglomeration map (from fine to coarse cells) and coarse
190  // cell location. Can be overridden by decomposers that provide
191  // this functionality natively. Coarse cells are local to the
192  // processor (if in parallel). If you want to have coarse cells
193  // spanning processors use the globalCellCells instead.
194  virtual labelList decompose
195  (
196  const polyMesh& mesh,
197  const labelList& cellToRegion,
198  const pointField& regionPoints,
199  const scalarField& regionWeights
200  );
201 
202  //- Like decompose but with uniform weights on the regions
203  virtual labelList decompose
204  (
205  const polyMesh& mesh,
206  const labelList& cellToRegion,
207  const pointField& regionPoints
208  );
209 
210 
211  // Topology provided explicitly addressing
212 
213  //- Return for every coordinate the wanted processor number.
214  // The connectivity is equal to mesh.cellCells() except for
215  // - in parallel the cell numbers are global cell numbers
216  // (starting
217  // from 0 at processor0 and then incrementing all through the
218  // processors)
219  // - the connections are across coupled patches
220  virtual labelList decompose
221  (
222  const labelListList& globalCellCells,
223  const pointField& cellCentres,
224  const scalarField& cellWeights
225  ) = 0;
226 
227  //- Like decompose but with uniform weights on the cells
228  virtual labelList decompose
229  (
230  const labelListList& globalCellCells,
231  const pointField& cellCentres
232  );
233 
234 
235  // Other
236 
237  //- Convert the given scalar weights to labels
238  // in the range 0-labelMax/2
239  // Removes 0 weights and updates nWeights accordingly
240  static labelList scaleWeights
241  (
242  const scalarField& weights,
243  label& nWeights,
244  const bool distributed = true
245  );
246 
247  //- Helper: determine (local or global) cellCells from mesh
248  // agglomeration. Agglomeration is local to the processor.
249  // local : connections are in local indices. Coupled across
250  // cyclics but not processor patches.
251  // global : connections are in global indices. Coupled across
252  // cyclics and processor patches.
253  static void calcCellCells
254  (
255  const polyMesh& mesh,
256  const labelList& agglom,
257  const label nLocalCoarse,
258  const bool global,
259  CompactListList<label>& cellCells
260  );
261 
262  //- Helper: determine (local or global) cellCells and face weights
263  // from mesh agglomeration.
264  // Uses mag of faceArea as weights
265  static void calcCellCells
266  (
267  const polyMesh& mesh,
268  const labelList& agglom,
269  const label nLocalCoarse,
270  const bool parallel,
271  CompactListList<label>& cellCells,
272  CompactListList<scalar>& cellCellWeights
273  );
274 
275  //- Helper: extract constraints:
276  // blockedface: existing faces where owner and neighbour on same
277  // proc
278  // explicitConnections: sets of boundary faces ,, ,,
279  // specifiedProcessorFaces: groups of faces with all cells on
280  // same processor.
281  void setConstraints
282  (
283  const polyMesh& mesh,
284  boolList& blockedFace,
285  PtrList<labelList>& specifiedProcessorFaces,
286  labelList& specifiedProcessor,
287  List<labelPair>& explicitConnections
288  );
289 
290  //- Helper: apply constraints to a decomposition. This gives
291  // constraints opportunity to modify decomposition in case
292  // the native decomposition method has not obeyed all constraints
293  void applyConstraints
294  (
295  const polyMesh& mesh,
296  const boolList& blockedFace,
297  const PtrList<labelList>& specifiedProcessorFaces,
298  const labelList& specifiedProcessor,
299  const List<labelPair>& explicitConnections,
300  labelList& finalDecomp
301  );
302 
303  //- Decompose a mesh with constraints
304  // Constraints:
305  // - blockedFace : whether owner and neighbour should be on same
306  // processor
307  // - specifiedProcessorFaces, specifiedProcessor : sets of faces
308  // that should go to same processor (as specified in
309  // specifiedProcessor, can be -1)
310  // - explicitConnections : connections between baffle faces
311  // (blockedFace should be false on these). Owner and
312  // neighbour on same processor.
313  // Set all to zero size to have unconstrained decomposition.
314  virtual labelList decompose
315  (
316  const polyMesh& mesh,
317  const scalarField& cellWeights,
318  const boolList& blockedFace,
319  const PtrList<labelList>& specifiedProcessorFaces,
320  const labelList& specifiedProcessor,
321  const List<labelPair>& explicitConnections
322  );
323 
324  //- Decompose a mesh. Apply all constraints from decomposeParDict
325  // ('preserveFaceZones' etc). Calls either
326  // - no constraints, empty weights:
327  // decompose(mesh, cellCentres())
328  // - no constraints, set weights:
329  // decompose(mesh, cellCentres(), cellWeights)
330  // - valid constraints:
331  // decompose(mesh, cellToRegion, regionPoints, regionWeights)
333  (
334  const polyMesh& mesh,
335  const scalarField& cellWeights
336  );
337 
338 
339  // Member Operators
340 
341  //- Disallow default bitwise assignment
342  void operator=(const decompositionMethod&) = delete;
343 };
344 
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 } // End namespace Foam
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 #endif
353 
354 // ************************************************************************* //
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Abstract base class for decomposition.
decompositionMethod(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
static IOdictionary decomposeParDict(const Time &time)
Read and return the decomposeParDict.
PtrList< decompositionConstraint > constraints_
Optional constraints.
label nWeights(const pointField &points, const scalarField &pointWeights) const
Return the number of weights per point.
virtual labelList decompose(const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number.
void operator=(const decompositionMethod &)=delete
Disallow default bitwise assignment.
void setConstraints(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections)
Helper: extract constraints:
TypeName("decompositionMethod")
Runtime type information.
virtual ~decompositionMethod()
Destructor.
label checkWeights(const pointField &points, const scalarField &pointWeights) const
Check the weights against the points.
static void calcCellCells(const polyMesh &mesh, const labelList &agglom, const label nLocalCoarse, const bool global, CompactListList< label > &cellCells)
Helper: determine (local or global) cellCells from mesh.
static autoPtr< decompositionMethod > NewDistributor(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
declareRunTimeSelectionTable(autoPtr, decompositionMethod, decomposer,(const dictionary &decompositionDict),(decompositionDict))
static labelList scaleWeights(const scalarField &weights, label &nWeights, const bool distributed=true)
Convert the given scalar weights to labels.
void applyConstraints(const polyMesh &mesh, const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &finalDecomp)
Helper: apply constraints to a decomposition. This gives.
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:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
const pointField & points
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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