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-2018 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 decompositionMethod_H
39 #define 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  //- No copy construct
68 
69  //- No copy assignment
70  void operator=(const decompositionMethod&) = delete;
71 
72 
73 protected:
74 
75  //- Selection type when handling the coefficients dictionary.
76  // To be used as a bit-mask for findCoeffsDict
77  enum selectionType
78  {
79  DEFAULT = 0,
80  EXACT = 1,
81  MANDATORY = 2,
82  NULL_DICT = 4,
83  };
85 
86 
87  // Protected data
88 
89  //- Top-level decomposition dictionary (eg, decomposeParDict)
90  const dictionary& decompDict_;
91 
92  //- Region-specific decomposition dictionary information
94 
95  //- Number of domains for the decomposition
96  label nDomains_;
97 
98  //- Optional constraints
100 
101 
102  // Protected Member Functions
103 
104  //- Locate coeffsName dictionary or the fallback "coeffs" dictionary
105  //- within an enclosing dictionary.
106  //
107  // \param select choose to include "coeffs" in the search, make
108  // failure a FatalError, return dictionary::null instead on
109  // failure.
110  //
111  // \return the coefficients dictionary found. If nothing was found,
112  // return the enclosing dictionary or
113  // dictionary::null (depending on the select parameter).
114  static const dictionary& findCoeffsDict
115  (
116  const dictionary& dict,
117  const word& coeffsName,
118  int select = selectionType::DEFAULT
119  );
120 
121 
122  //- Locate coeffsName dictionary or the fallback "coeffs" dictionary.
123  // Searches both the region-specific decomposition dictionary
124  // and the top-level decomposition dictionary.
125  //
126  // \param select choose to include "coeffs" in the search, make
127  // failure a FatalError, return dictionary::null instead on
128  // failure.
129  //
130  // \return the coefficients dictionary found. If nothing was found,
131  // return the top-level (non-region) dictionary or
132  // dictionary::null (depending on the select parameter).
134  (
135  const word& coeffsName,
136  int select = selectionType::DEFAULT
137  ) const;
138 
139 
140 public:
141 
142  //- Runtime type information
143  TypeName("decompositionMethod");
144 
145 
146  // Declare run-time constructor selection tables
147 
149  (
150  autoPtr,
152  dictionary,
153  (
154  const dictionary& decompDict
155  ),
156  (decompDict)
157  );
158 
160  (
161  autoPtr,
163  dictionaryRegion,
164  (
165  const dictionary& decompDict,
166  const word& regionName
167  ),
168  (decompDict, regionName)
169  );
170 
171 
172  // Static Methods
173 
174  //- Return the \c numberOfSubdomains entry from the dictionary
175  static label nDomains(const dictionary& decompDict);
176 
177  //- Return the \c numberOfSubdomains from a region within the
178  // "regions" sub-dictionary
179  static label nDomains
180  (
181  const dictionary& decompDict,
182  const word& regionName
183  );
184 
185  //- Return an optional region dictionary from "regions" sub-dictionary
186  // or dictionary::null on failure.
187  static const dictionary& optionalRegionDict
188  (
189  const dictionary& decompDict,
190  const word& regionName
191  );
192 
193 
194  // Selectors
195 
196  //- Return a reference to the selected decomposition method
198  (
199  const dictionary& decompDict
200  );
201 
202  //- Return a reference to the selected decomposition method,
203  //- with region specification
205  (
206  const dictionary& decompDict,
207  const word& regionName
208  );
209 
210 
211  // Constructors
212 
213  //- Construct given the decomposition dictionary
214  decompositionMethod(const dictionary& decompDict);
215 
216  //- Construct given the decomposition dictionary for specific region
218  (
219  const dictionary& decompDict,
220  const word& regionName
221  );
222 
223 
224  //- Destructor
225  virtual ~decompositionMethod() = default;
226 
227 
228  // Member Functions
229 
230  //- Number of domains
231  inline label nDomains() const
232  {
233  return nDomains_;
234  }
235 
236  //- Is method parallel aware?
237  // (i.e. does it synchronize domains across proc boundaries)
238  virtual bool parallelAware() const = 0;
239 
240 
241  // No topology (implemented by geometric decomposers)
242 
243  //- Return for every coordinate the wanted processor number.
245  (
246  const pointField& points,
247  const scalarField& pointWeights
248  ) const
249  {
251  return labelList();
252  }
253 
254  //- Decompose with uniform weights on the points
255  virtual labelList decompose(const pointField& points) const
256  {
258  return labelList();
259  }
260 
261 
262  // Topology provided by mesh
263 
264  //- Return for every coordinate the wanted processor number.
265  // Use the mesh connectivity (if needed)
266  virtual labelList decompose
267  (
268  const polyMesh& mesh,
269  const pointField& points,
270  const scalarField& pointWeights
271  ) const = 0;
272 
273  //- Decompose with uniform weights on the points
274  virtual labelList decompose
275  (
276  const polyMesh& mesh,
277  const pointField& points
278  ) const;
279 
280 
281  //- Return for every coordinate the wanted processor number. Gets
282  // passed agglomeration map (from fine to coarse cells) and coarse
283  // cell
284  // location. Can be overridden by decomposers that provide this
285  // functionality natively. Coarse cells are local to the processor
286  // (if in parallel). If you want to have coarse cells spanning
287  // processors use the globalCellCells instead.
288  virtual labelList decompose
289  (
290  const polyMesh& mesh,
291  const labelList& cellToRegion,
292  const pointField& regionPoints,
293  const scalarField& regionWeights
294  ) const;
295 
296  //- Like decompose but with uniform weights on the regions
297  virtual labelList decompose
298  (
299  const polyMesh& mesh,
300  const labelList& cellToRegion,
301  const pointField& regionPoints
302  ) const;
303 
304 
305  // Topology provided explicitly addressing
306 
307  //- Return for every coordinate the wanted processor number.
308  // The connectivity is equal to mesh.cellCells() except for
309  // - in parallel the cell numbers are global cell numbers
310  // (starting
311  // from 0 at processor0 and then incrementing all through the
312  // processors)
313  // - the connections are across coupled patches
314  virtual labelList decompose
315  (
316  const labelListList& globalCellCells,
317  const pointField& cc,
318  const scalarField& cWeights
319  ) const = 0;
320 
321  //- Like decompose but with uniform weights on the cells
322  virtual labelList decompose
323  (
324  const labelListList& globalCellCells,
325  const pointField& cc
326  ) const;
327 
328 
329  // Other
330 
331  //- Helper: determine (local or global) cellCells from mesh
332  // agglomeration. Agglomeration is local to the processor.
333  // local : connections are in local indices. Coupled across
334  // cyclics but not processor patches.
335  // global : connections are in global indices. Coupled across
336  // cyclics and processor patches.
337  static void calcCellCells
338  (
339  const polyMesh& mesh,
340  const labelList& agglom,
341  const label nLocalCoarse,
342  const bool global,
343  CompactListList<label>& cellCells
344  );
345 
346  //- Helper: determine (local or global) cellCells and face weights
347  // from mesh agglomeration.
348  // Uses mag of faceArea as weights
349  static void calcCellCells
350  (
351  const polyMesh& mesh,
352  const labelList& agglom,
353  const label nLocalCoarse,
354  const bool parallel,
355  CompactListList<label>& cellCells,
356  CompactListList<scalar>& cellCellWeights
357  );
358 
359  //- Helper: extract constraints:
360  // blockedface: existing faces where owner and neighbour on same
361  // proc
362  // explicitConnections: sets of boundary faces ,, ,,
363  // specifiedProcessorFaces: groups of faces with all cells on
364  // same processor.
365  void setConstraints
366  (
367  const polyMesh& mesh,
368  boolList& blockedFace,
369  PtrList<labelList>& specifiedProcessorFaces,
370  labelList& specifiedProcessor,
371  List<labelPair>& explicitConnections
372  ) const;
373 
374  //- Helper: apply constraints to a decomposition.
375  // This gives constraints opportunity to modify decomposition in case
376  // the native decomposition method has not obeyed all constraints
377  void applyConstraints
378  (
379  const polyMesh& mesh,
380  const boolList& blockedFace,
381  const PtrList<labelList>& specifiedProcessorFaces,
382  const labelList& specifiedProcessor,
383  const List<labelPair>& explicitConnections,
384  labelList& finalDecomp
385  ) const;
386 
387  // Decompose a mesh with constraints:
388  // - blockedFace : whether owner and neighbour should be on same
389  // processor
390  // - specifiedProcessorFaces, specifiedProcessor : sets of faces
391  // that should go to same processor (as specified in
392  // specifiedProcessor, can be -1)
393  // - explicitConnections : connections between baffle faces
394  // (blockedFace should be false on these). Owner and
395  // neighbour on same processor.
396  // Set all to zero size to have unconstrained decomposition.
397  virtual labelList decompose
398  (
399  const polyMesh& mesh,
400  const scalarField& cellWeights,
401  const boolList& blockedFace,
402  const PtrList<labelList>& specifiedProcessorFaces,
403  const labelList& specifiedProcessor,
404  const List<labelPair>& explicitConnections
405  ) const;
406 
407 
408  //- Decompose a mesh.
409  // Apply all constraints from decomposeParDict
410  // ('preserveFaceZones' etc). Calls either
411  // - no constraints, empty weights:
412  // decompose(mesh, cellCentres())
413  // - no constraints, set weights:
414  // decompose(mesh, cellCentres(), cellWeights)
415  // - valid constraints:
416  // decompose(mesh, cellToRegion, regionPoints, regionWeights)
418  (
419  const polyMesh& mesh,
420  const scalarField& cWeights
421  ) const;
422 
423 };
424 
425 
426 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
427 
428 } // End namespace Foam
429 
430 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
431 
432 #endif
433 
434 // ************************************************************************* //
Foam::decompositionMethod::nDomains_
label nDomains_
Number of domains for the decomposition.
Definition: decompositionMethod.H:95
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::decompositionMethod::calcCellCells
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.
Definition: decompositionMethod.C:517
Foam::decompositionMethod::decompDict_
const dictionary & decompDict_
Top-level decomposition dictionary (eg, decomposeParDict)
Definition: decompositionMethod.H:89
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::decompositionMethod::EXACT
No fallback to "coeffs" if main name not found.
Definition: decompositionMethod.H:79
Foam::decompositionMethod::optionalRegionDict
static const dictionary & optionalRegionDict(const dictionary &decompDict, const word &regionName)
Return an optional region dictionary from "regions" sub-dictionary.
Definition: decompositionMethod.C:98
Foam::decompositionMethod::decompRegionDict_
const dictionary & decompRegionDict_
Region-specific decomposition dictionary information.
Definition: decompositionMethod.H:92
decompositionConstraint.H
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:93
Foam::decompositionMethod::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, decompositionMethod, dictionary,(const dictionary &decompDict),(decompDict))
Foam::decompositionMethod::setConstraints
void setConstraints(const polyMesh &mesh, boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Helper: extract constraints:
Definition: decompositionMethod.C:1266
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:436
Foam::decompositionMethod::selectionType
selectionType
Selection type when handling the coefficients dictionary.
Definition: decompositionMethod.H:76
Foam::decompositionMethod::parallelAware
virtual bool parallelAware() const =0
Is method parallel aware?
Foam::decompositionMethod::MANDATORY
Fatal if dictionary could not be found.
Definition: decompositionMethod.H:80
Foam::Field< vector >
Foam::decompositionMethod::DEFAULT
Default request.
Definition: decompositionMethod.H:78
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::decompositionMethod::decompose
virtual labelList decompose(const pointField &points) const
Decompose with uniform weights on the points.
Definition: decompositionMethod.H:254
Foam::decompositionMethod::NULL_DICT
Definition: decompositionMethod.H:81
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::decompositionMethod::nDomains
label nDomains() const
Number of domains.
Definition: decompositionMethod.H:230
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::decompositionMethod
Abstract base class for domain decomposition.
Definition: decompositionMethod.H:51
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decompositionMethod::~decompositionMethod
virtual ~decompositionMethod()=default
Destructor.
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::List< label >
Foam::decompositionMethod::decompose
virtual labelList decompose(const pointField &points, const scalarField &pointWeights) const
Return for every coordinate the wanted processor number.
Definition: decompositionMethod.H:244
points
const pointField & points
Definition: gmvOutputHeader.H:1
CompactListList.H
Foam::decompositionMethod::TypeName
TypeName("decompositionMethod")
Runtime type information.
Foam::decompositionMethod::applyConstraints
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.
Definition: decompositionMethod.C:1295
Foam::decompositionMethod::findCoeffsDict
static const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Definition: decompositionMethod.C:229
Foam::decompositionMethod::constraints_
PtrList< decompositionConstraint > constraints_
Optional constraints.
Definition: decompositionMethod.H:98
Foam::decompositionMethod::New
static autoPtr< decompositionMethod > New(const dictionary &decompDict)
Return a reference to the selected decomposition method.
Definition: decompositionMethod.C:359