decompositionMethod.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::decompositionMethod
29 
30 Description
31  Abstract base class for domain decomposition
32 
33 SourceFiles
34  decompositionMethod.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_decompositionMethod_H
39 #define Foam_decompositionMethod_H
40 
41 #include "polyMesh.H"
42 #include "CompactListList.H"
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class decompositionMethod Declaration
50 \*---------------------------------------------------------------------------*/
51 
53 {
54  // Private Member Functions
55 
56  //- Check (and warn) about existence of old constraint syntax.
57  // The syntax changed MAY-2014.
58  //
59  // \return true if this model name was found in the decompDict_
60  // but not previously added with the newer syntax.
61  bool constraintCompat(const word& modelType) const;
62 
63  //- Set PtrList of constraints by reading decompDict_.
64  void readConstraints();
65 
66 
67 protected:
68 
69  //- Selection type when handling the coefficients dictionary.
70  // To be used as a bit-mask for findCoeffsDict
71  enum selectionType
72  {
73  DEFAULT = 0,
74  EXACT = 1,
75  MANDATORY = 2,
76  NULL_DICT = 4,
77  };
79 
80 
81  // Protected Data
82 
83  //- Top-level decomposition dictionary (eg, decomposeParDict)
84  const dictionary& decompDict_;
85 
86  //- Region-specific decomposition dictionary information
88 
89  //- Number of domains for the decomposition
90  label nDomains_;
91 
92  //- Optional constraints
94 
95 
96  // Protected Member Functions
97 
98  //- Locate coeffsName dictionary or the fallback "coeffs" dictionary
99  //- within an enclosing dictionary.
100  //
101  // \param select choose to include "coeffs" in the search, make
102  // failure a FatalError, return dictionary::null instead on
103  // failure.
104  //
105  // \return the coefficients dictionary found. If nothing was found,
106  // return the enclosing dictionary or
107  // dictionary::null (depending on the select parameter).
109  static const dictionary& findCoeffsDict
110  (
111  const dictionary& dict,
112  const word& coeffsName,
113  int select = selectionType::DEFAULT
114  );
115 
116 
117  //- Locate coeffsName dictionary or the fallback "coeffs" dictionary.
118  // Searches both the region-specific decomposition dictionary
119  // and the top-level decomposition dictionary.
120  //
121  // \param select choose to include "coeffs" in the search, make
122  // failure a FatalError, return dictionary::null instead on
123  // failure.
124  //
125  // \return the coefficients dictionary found. If nothing was found,
126  // return the top-level (non-region) dictionary or
127  // dictionary::null (depending on the select parameter).
130  (
131  const word& coeffsName,
132  int select = selectionType::DEFAULT
133  ) const;
134 
135 
136  // Constructors
137 
138  //- Construct with specified number of domains,
139  //- no coefficients or constraints
140  explicit decompositionMethod(const label numDomains);
141 
142 
143 public:
144 
145  // Generated Methods
146 
147  //- No copy construct
148  decompositionMethod(const decompositionMethod&) = delete;
149 
150  //- No copy assignment
151  void operator=(const decompositionMethod&) = delete;
152 
153 
154  //- Runtime type information
155  TypeName("decompositionMethod");
156 
157 
158  // Declare run-time constructor selection tables
159 
161  (
162  autoPtr,
164  dictionary,
165  (
166  const dictionary& decompDict,
167  const word& regionName
168  ),
169  (decompDict, regionName)
170  );
171 
172 
173  // Static Methods
174 
175  //- Return region-specific or top-level \c numberOfSubdomains entry.
176  // The region-specific version is found within the "regions"
177  // sub-dictionary.
178  static label nDomains
179  (
180  const dictionary& decompDict,
181  const word& regionName = ""
182  );
183 
184  //- Return an optional region-specific dictionary
185  //- from "regions" sub-dictionary, or dictionary::null on failure
186  static const dictionary& optionalRegionDict
187  (
188  const dictionary& decompDict,
189  const word& regionName
190  );
191 
192 
193  // Selectors
194 
195  //- Return a reference to the selected decomposition method,
196  //- optionally region-specific
198  (
199  const dictionary& decompDict,
200  const word& regionName = ""
201  );
202 
203 
204  // Constructors
205 
206  //- Construct given the decomposition dictionary,
207  //- optionally region-specific
208  explicit decompositionMethod
209  (
210  const dictionary& decompDict,
211  const word& regionName = ""
212  );
213 
214 
215  //- Destructor
216  virtual ~decompositionMethod() = default;
217 
218 
219  // Member Functions
220 
221  //- Number of domains
222  label nDomains() const noexcept
223  {
224  return nDomains_;
225  }
226 
227  //- True if the method is purely geometric,
228  //- often using cell centre points
229  virtual bool geometric() const { return false; }
230 
231  //- Is method parallel aware?
232  // (i.e. does it synchronize domains across proc boundaries)
233  virtual bool parallelAware() const = 0;
234 
235  // //- Is internally method parallel aware
236  // virtual bool parallelNative() const { return false; }
237 
238 
239  // No topology (implemented by geometric decomposers)
240 
241  //- Return the wanted processor number for every coordinate,
242  //- using uniform or specified point weights.
243  virtual labelList decompose
244  (
245  const pointField& points,
246  const scalarField& pointWeights = scalarField::null()
247  ) const;
248 
249 
250  // Topology provided by mesh
251 
252  //- Return for every coordinate the wanted processor number,
253  //- using uniform or specified point weights.
254  // Use the mesh connectivity (if needed)
255  virtual labelList decompose
256  (
257  const polyMesh& mesh,
258  const pointField& points,
259  const scalarField& pointWeights = scalarField::null()
260  ) const = 0;
261 
262  //- Return for every coordinate the wanted processor number.
263  // Gets passed agglomeration map (from fine to coarse cells)
264  // and coarse cell
265  // location. Can be overridden by decomposers that provide this
266  // functionality natively. Coarse cells are local to the processor
267  // (if in parallel). If you want to have coarse cells spanning
268  // processors use the globalCellCells instead.
270  (
271  const polyMesh& mesh,
272  const labelList& cellToRegion,
273  const pointField& regionPoints,
274  const scalarField& regionWeights = scalarField::null()
275  ) const;
276 
277 
278  // Topology provided explicitly
279 
280  //- Return for every coordinate the wanted processor number.
281  // The connectivity is equal to mesh.cellCells() except for
282  // - in parallel the cell numbers are global cell numbers
283  // (starting
284  // from 0 at processor0 and then incrementing all through the
285  // processors)
286  // - the connections are across coupled patches
287  virtual labelList decompose
288  (
289  const CompactListList<label>& globalCellCells,
290  const pointField& cc,
291  const scalarField& cWeights = scalarField::null()
292  ) const = 0;
293 
294  //- Return for every coordinate the wanted processor number.
295  // The connectivity is equal to mesh.cellCells() except for
296  // - in parallel the cell numbers are global cell numbers
297  // (starting
298  // from 0 at processor0 and then incrementing all through the
299  // processors)
300  // - the connections are across coupled patches
301  virtual labelList decompose
302  (
303  const labelListList& globalCellCells,
304  const pointField& cc,
305  const scalarField& cWeights = scalarField::null()
306  ) const = 0;
307 
308 
309  // Other
310 
311  //- Helper: extract constraints:
312  // blockedface: existing faces where owner and neighbour on same
313  // proc
314  // explicitConnections: sets of boundary faces ,, ,,
315  // specifiedProcessorFaces: groups of faces with all cells on
316  // same processor.
317  void setConstraints
318  (
319  const polyMesh& mesh,
320  boolList& blockedFace,
321  PtrList<labelList>& specifiedProcessorFaces,
322  labelList& specifiedProcessor,
323  List<labelPair>& explicitConnections
324  ) const;
325 
326  //- Helper: apply constraints to a decomposition.
327  // This gives constraints opportunity to modify decomposition in case
328  // the native decomposition method has not obeyed all constraints
329  void applyConstraints
330  (
331  const polyMesh& mesh,
332  const boolList& blockedFace,
333  const PtrList<labelList>& specifiedProcessorFaces,
334  const labelList& specifiedProcessor,
335  const List<labelPair>& explicitConnections,
336  labelList& finalDecomp
337  ) const;
338 
339  // Decompose a mesh with constraints:
340  // - blockedFace : whether owner and neighbour should be on same
341  // processor
342  // - specifiedProcessorFaces, specifiedProcessor : sets of faces
343  // that should go to same processor (as specified in
344  // specifiedProcessor, can be -1)
345  // - explicitConnections : connections between baffle faces
346  // (blockedFace should be false on these). Owner and
347  // neighbour on same processor.
348  // Set all to zero size to have unconstrained decomposition.
349  virtual labelList decompose
350  (
351  const polyMesh& mesh,
352  const scalarField& cellWeights,
353  const boolList& blockedFace,
354  const PtrList<labelList>& specifiedProcessorFaces,
355  const labelList& specifiedProcessor,
356  const List<labelPair>& explicitConnections
357  ) const;
358 
359 
360  //- Decompose a mesh.
361  // Apply all constraints from decomposeParDict
362  // ('preserveFaceZones' etc). Calls either
363  // - no constraints, empty weights:
364  // decompose(mesh, cellCentres())
365  // - no constraints, set weights:
366  // decompose(mesh, cellCentres(), cellWeights)
367  // - valid constraints:
368  // decompose(mesh, cellToRegion, regionPoints, regionWeights)
370  (
371  const polyMesh& mesh,
372  const scalarField& cWeights
373  ) const;
374 
375 
376  // Housekeeping
377 
378  //- Determine (local or global) cellCells from mesh agglomeration.
379  // Agglomeration is local to the processor.
380  // local : connections are in local indices. Coupled across
381  // cyclics but not processor patches.
382  // global : connections are in global indices. Coupled across
383  // cyclics and processor patches.
384  FOAM_DEPRECATED_STRICT(2023-11, "globalMeshData::calcCellCells()")
385  static void calcCellCells
386  (
387  const polyMesh& mesh,
388  const labelList& agglom,
389  const label nLocalCoarse,
390  const bool parallel,
391  CompactListList<label>& cellCells
392  );
393 
394  //- Determine (local or global) cellCells and face weights
395  //- from mesh agglomeration.
396  // Uses mag of faceArea as weights
398  static void calcCellCells
399  (
400  const polyMesh& mesh,
401  const labelList& agglom,
402  const label nLocalCoarse,
403  const bool parallel,
404  CompactListList<label>& cellCells,
405  CompactListList<scalar>& cellCellWeights
406  );
407 };
408 
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 } // End namespace Foam
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 #endif
417 
418 // ************************************************************************* //
selectionType
Selection type when handling the coefficients dictionary.
dictionary dict
declareRunTimeSelectionTable(autoPtr, decompositionMethod, dictionary,(const dictionary &decompDict, const word &regionName),(decompDict, regionName))
virtual bool parallelAware() const =0
Is method parallel aware?
static void calcCellCells(const polyMesh &mesh, const labelList &agglom, const label nLocalCoarse, const bool parallel, CompactListList< label > &cellCells)
Determine (local or global) cellCells from mesh agglomeration.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label nDomains_
Number of domains for the decomposition.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
static const Field< scalar > & null() noexcept
Return a null Field (reference to a nullObject). Behaves like an empty Field.
Definition: Field.H:186
void setConstraints(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Helper: extract constraints:
virtual bool geometric() const
True if the method is purely geometric, often using cell centre points.
PtrList< decompositionConstraint > constraints_
Optional constraints.
#define FOAM_NO_DANGLING_REFERENCE
Definition: stdFoam.H:80
void applyConstraints(const polyMesh &mesh, const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &finalDecomp) const
Helper: apply constraints to a decomposition.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
const dictionary & decompRegionDict_
Region-specific decomposition dictionary information.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
TypeName("decompositionMethod")
Runtime type information.
Abstract base class for domain decomposition.
#define FOAM_DEPRECATED_STRICT(since, replacement)
Definition: stdFoam.H:53
static FOAM_NO_DANGLING_REFERENCE const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Locate coeffsName dictionary or the fallback "coeffs" dictionary within an enclosing dictionary...
label nDomains() const noexcept
Number of domains.
void operator=(const decompositionMethod &)=delete
No copy assignment.
A packed storage of objects of type <T> using an offset table for access.
const direction noexcept
Definition: scalarImpl.H:255
Fatal if dictionary could not be found.
decompositionMethod(const label numDomains)
Construct with specified number of domains, no coefficients or constraints.
static autoPtr< decompositionMethod > New(const dictionary &decompDict, const word &regionName="")
Return a reference to the selected decomposition method, optionally region-specific.
virtual ~decompositionMethod()=default
Destructor.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
static const dictionary & optionalRegionDict(const dictionary &decompDict, const word &regionName)
Return an optional region-specific dictionary from "regions" sub-dictionary, or dictionary::null on f...
const dictionary & decompDict_
Top-level decomposition dictionary (eg, decomposeParDict)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:61
No fallback to "coeffs" if main name not found.
Namespace for OpenFOAM.
virtual labelList decompose(const pointField &points, const scalarField &pointWeights=scalarField::null()) const
Return the wanted processor number for every coordinate, using uniform or specified point weights...