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).
108  static const dictionary& findCoeffsDict
109  (
110  const dictionary& dict,
111  const word& coeffsName,
112  int select = selectionType::DEFAULT
113  );
114 
115 
116  //- Locate coeffsName dictionary or the fallback "coeffs" dictionary.
117  // Searches both the region-specific decomposition dictionary
118  // and the top-level decomposition dictionary.
119  //
120  // \param select choose to include "coeffs" in the search, make
121  // failure a FatalError, return dictionary::null instead on
122  // failure.
123  //
124  // \return the coefficients dictionary found. If nothing was found,
125  // return the top-level (non-region) dictionary or
126  // dictionary::null (depending on the select parameter).
128  (
129  const word& coeffsName,
130  int select = selectionType::DEFAULT
131  ) const;
132 
133 
134  // Constructors
135 
136  //- Construct with specified number of domains,
137  //- no coefficients or constraints
138  explicit decompositionMethod(const label numDomains);
139 
140 
141 public:
142 
143  // Generated Methods
144 
145  //- No copy construct
146  decompositionMethod(const decompositionMethod&) = delete;
147 
148  //- No copy assignment
149  void operator=(const decompositionMethod&) = delete;
150 
151 
152  //- Runtime type information
153  TypeName("decompositionMethod");
154 
155 
156  // Declare run-time constructor selection tables
157 
159  (
160  autoPtr,
162  dictionary,
163  (
164  const dictionary& decompDict,
165  const word& regionName
166  ),
167  (decompDict, regionName)
168  );
169 
170 
171  // Static Methods
172 
173  //- Return region-specific or top-level \c numberOfSubdomains entry.
174  // The region-specific version is found within the "regions"
175  // sub-dictionary.
176  static label nDomains
177  (
178  const dictionary& decompDict,
179  const word& regionName = ""
180  );
181 
182  //- Return an optional region-specific dictionary
183  //- from "regions" sub-dictionary, or dictionary::null on failure
184  static const dictionary& optionalRegionDict
185  (
186  const dictionary& decompDict,
187  const word& regionName
188  );
189 
190 
191  // Selectors
192 
193  //- Return a reference to the selected decomposition method,
194  //- optionally region-specific
196  (
197  const dictionary& decompDict,
198  const word& regionName = ""
199  );
200 
201 
202  // Constructors
203 
204  //- Construct given the decomposition dictionary,
205  //- optionally region-specific
206  explicit decompositionMethod
207  (
208  const dictionary& decompDict,
209  const word& regionName = ""
210  );
211 
212 
213  //- Destructor
214  virtual ~decompositionMethod() = default;
215 
216 
217  // Member Functions
218 
219  //- Number of domains
220  label nDomains() const noexcept
221  {
222  return nDomains_;
223  }
224 
225  //- True if the method is purely geometric,
226  //- often using cell centre points
227  virtual bool geometric() const { return false; }
228 
229  //- Is method parallel aware?
230  // (i.e. does it synchronize domains across proc boundaries)
231  virtual bool parallelAware() const = 0;
232 
233  // //- Is internally method parallel aware
234  // virtual bool parallelNative() const { return false; }
235 
236 
237  // No topology (implemented by geometric decomposers)
238 
239  //- Return the wanted processor number for every coordinate,
240  //- using uniform or specified point weights.
241  virtual labelList decompose
242  (
243  const pointField& points,
244  const scalarField& pointWeights = scalarField::null()
245  ) const;
246 
247 
248  // Topology provided by mesh
249 
250  //- Return for every coordinate the wanted processor number,
251  //- using uniform or specified point weights.
252  // Use the mesh connectivity (if needed)
253  virtual labelList decompose
254  (
255  const polyMesh& mesh,
256  const pointField& points,
257  const scalarField& pointWeights = scalarField::null()
258  ) const = 0;
259 
260  //- Return for every coordinate the wanted processor number.
261  // Gets passed agglomeration map (from fine to coarse cells)
262  // and coarse cell
263  // location. Can be overridden by decomposers that provide this
264  // functionality natively. Coarse cells are local to the processor
265  // (if in parallel). If you want to have coarse cells spanning
266  // processors use the globalCellCells instead.
268  (
269  const polyMesh& mesh,
270  const labelList& cellToRegion,
271  const pointField& regionPoints,
272  const scalarField& regionWeights = scalarField::null()
273  ) const;
274 
275 
276  // Topology provided explicitly
277 
278  //- Return for every coordinate the wanted processor number.
279  // The connectivity is equal to mesh.cellCells() except for
280  // - in parallel the cell numbers are global cell numbers
281  // (starting
282  // from 0 at processor0 and then incrementing all through the
283  // processors)
284  // - the connections are across coupled patches
285  virtual labelList decompose
286  (
287  const CompactListList<label>& globalCellCells,
288  const pointField& cc,
289  const scalarField& cWeights = scalarField::null()
290  ) const = 0;
291 
292  //- Return for every coordinate the wanted processor number.
293  // The connectivity is equal to mesh.cellCells() except for
294  // - in parallel the cell numbers are global cell numbers
295  // (starting
296  // from 0 at processor0 and then incrementing all through the
297  // processors)
298  // - the connections are across coupled patches
299  virtual labelList decompose
300  (
301  const labelListList& globalCellCells,
302  const pointField& cc,
303  const scalarField& cWeights = scalarField::null()
304  ) const = 0;
305 
306 
307  // Other
308 
309  //- Helper: extract constraints:
310  // blockedface: existing faces where owner and neighbour on same
311  // proc
312  // explicitConnections: sets of boundary faces ,, ,,
313  // specifiedProcessorFaces: groups of faces with all cells on
314  // same processor.
315  void setConstraints
316  (
317  const polyMesh& mesh,
318  boolList& blockedFace,
319  PtrList<labelList>& specifiedProcessorFaces,
320  labelList& specifiedProcessor,
321  List<labelPair>& explicitConnections
322  ) const;
323 
324  //- Helper: apply constraints to a decomposition.
325  // This gives constraints opportunity to modify decomposition in case
326  // the native decomposition method has not obeyed all constraints
327  void applyConstraints
328  (
329  const polyMesh& mesh,
330  const boolList& blockedFace,
331  const PtrList<labelList>& specifiedProcessorFaces,
332  const labelList& specifiedProcessor,
333  const List<labelPair>& explicitConnections,
334  labelList& finalDecomp
335  ) const;
336 
337  // Decompose a mesh with constraints:
338  // - blockedFace : whether owner and neighbour should be on same
339  // processor
340  // - specifiedProcessorFaces, specifiedProcessor : sets of faces
341  // that should go to same processor (as specified in
342  // specifiedProcessor, can be -1)
343  // - explicitConnections : connections between baffle faces
344  // (blockedFace should be false on these). Owner and
345  // neighbour on same processor.
346  // Set all to zero size to have unconstrained decomposition.
347  virtual labelList decompose
348  (
349  const polyMesh& mesh,
350  const scalarField& cellWeights,
351  const boolList& blockedFace,
352  const PtrList<labelList>& specifiedProcessorFaces,
353  const labelList& specifiedProcessor,
354  const List<labelPair>& explicitConnections
355  ) const;
356 
357 
358  //- Decompose a mesh.
359  // Apply all constraints from decomposeParDict
360  // ('preserveFaceZones' etc). Calls either
361  // - no constraints, empty weights:
362  // decompose(mesh, cellCentres())
363  // - no constraints, set weights:
364  // decompose(mesh, cellCentres(), cellWeights)
365  // - valid constraints:
366  // decompose(mesh, cellToRegion, regionPoints, regionWeights)
368  (
369  const polyMesh& mesh,
370  const scalarField& cWeights
371  ) const;
372 
373 
374  // Housekeeping
375 
376  //- Determine (local or global) cellCells from mesh agglomeration.
377  // Agglomeration is local to the processor.
378  // local : connections are in local indices. Coupled across
379  // cyclics but not processor patches.
380  // global : connections are in global indices. Coupled across
381  // cyclics and processor patches.
382  FOAM_DEPRECATED_STRICT(2023-11, "globalMeshData::calcCellCells()")
383  static void calcCellCells
384  (
385  const polyMesh& mesh,
386  const labelList& agglom,
387  const label nLocalCoarse,
388  const bool parallel,
389  CompactListList<label>& cellCells
390  );
391 
392  //- Determine (local or global) cellCells and face weights
393  //- from mesh agglomeration.
394  // Uses mag of faceArea as weights
396  static void calcCellCells
397  (
398  const polyMesh& mesh,
399  const labelList& agglom,
400  const label nLocalCoarse,
401  const bool parallel,
402  CompactListList<label>& cellCells,
403  CompactListList<scalar>& cellCellWeights
404  );
405 };
406 
407 
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 
410 } // End namespace Foam
411 
412 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
413 
414 #endif
415 
416 // ************************************************************************* //
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
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.
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:55
static 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: Scalar.H:258
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:55
static const Field< scalar > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
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:74
List< label > labelList
A List of labels.
Definition: List.H:62
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...