domainDecomposition.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) 2021 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::domainDecomposition
29 
30 Description
31  Automatic domain decomposition class for finite-volume meshes
32 
33 SourceFiles
34  domainDecomposition.C
35  domainDecompositionDistribute.C
36  domainDecompositionMesh.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef domainDecomposition_H
41 #define domainDecomposition_H
42 
43 #include "fvMesh.H"
44 #include "labelList.H"
45 #include "point.H"
46 #include "Time.H"
47 #include "volFields.H"
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 class decompositionModel;
54 
55 /*---------------------------------------------------------------------------*\
56  Class domainDecomposition Declaration
57 \*---------------------------------------------------------------------------*/
58 
60 :
61  public fvMesh
62 {
63  // Private Data
64 
65  //- Optional: points at the facesInstance
66  autoPtr<pointIOField> facesInstancePointsPtr_;
67 
68  //- Optional non-standard file for decomposeParDict
69  const fileName decompDictFile_;
70 
71  //- Number of processors in decomposition
72  label nProcs_;
73 
74  //- Is the decomposition data to be distributed for each processor
75  bool distributed_;
76 
77  //- Processor label for each cell
78  labelList cellToProc_;
79 
80  //- Labels of points for each processor
81  labelListList procPointAddressing_;
82 
83  //- Labels of faces for each processor
84  // Note: Face turning index is stored as the sign on addressing
85  // Only the processor boundary faces are affected: if the sign of the
86  // index is negative, the processor face is the reverse of the
87  // original face. In order to do this properly, all face
88  // indices will be incremented by 1 and the decremented as
89  // necessary to avoid the problem of face number zero having no
90  // sign.
91  List<DynamicList<label>> procFaceAddressing_;
92 
93  //- Labels of cells for each processor
94  labelListList procCellAddressing_;
95 
96  //- Sizes for processor mesh patches
97  // Excludes inter-processor boundaries
98  labelListList procPatchSize_;
99 
100  //- Start indices for processor patches
101  // Excludes inter-processor boundaries
102  labelListList procPatchStartIndex_;
103 
104 
105  // Per inter-processor patch information
106 
107  //- Neighbour processor ID for inter-processor boundaries
108  labelListList procNeighbourProcessors_;
109 
110  //- Sizes for inter-processor patches
111  labelListList procProcessorPatchSize_;
112 
113  //- Start indices (in procFaceAddressing_) for inter-processor patches
114  labelListList procProcessorPatchStartIndex_;
115 
116  //- Sub patch IDs for inter-processor patches
117  List<labelListList> procProcessorPatchSubPatchIDs_;
118 
119  //- Sub patch sizes for inter-processor patches
120  List<labelListList> procProcessorPatchSubPatchStarts_;
121 
122 
123  // Private Member Functions
124 
125  void distributeCells();
126 
127  //- Mark all elements with value or -2 if occur twice
128  static void mark
129  (
130  const labelList& zoneElems,
131  const label zoneI,
132  labelList& elementToZone
133  );
134 
135  //- Append single element to list
136  static void append(labelList&, const label);
137 
138  //- Add face to inter-processor patch
139  void addInterProcFace
140  (
141  const label facei,
142  const label ownerProc,
143  const label nbrProc,
144 
145  List<Map<label>>&,
147  ) const;
148 
149  //- Generate sub patch info for processor cyclics
150  template<class BinaryOp>
151  void processInterCyclics
152  (
153  const polyBoundaryMesh& patches,
154  List<DynamicList<DynamicList<label>>>& interPatchFaces,
155  List<Map<label>>& procNbrToInterPatch,
156  List<labelListList>& subPatchIDs,
157  List<labelListList>& subPatchStarts,
158  bool owner,
159  BinaryOp bop
160  ) const;
161 
162 
163 public:
164 
165  // Constructors
166 
167  //- Construct from components.
168  // \param io the IOobject for mesh
169  // \param decompDictFile optional non-standard location for the
170  // decomposeParDict file
171  explicit domainDecomposition
172  (
173  const IOobject& io,
174  const fileName& decompDictFile = ""
175  );
176 
177 
178  //- Destructor
179  ~domainDecomposition() = default;
180 
181 
182  // Member Functions
183 
184  //- The mesh
185  const fvMesh& mesh() const noexcept
186  {
187  return *this;
188  }
189 
190 
191  // Settings
192 
193  //- Number of processor in decomposition
194  label nProcs() const noexcept
195  {
196  return nProcs_;
197  }
198 
199  //- Is decomposition data to be distributed for each processor
200  bool distributed() const noexcept
201  {
202  return distributed_;
203  }
204 
205  //- Change distributed flag
206  bool distributed(const bool on) noexcept
207  {
208  bool old(distributed_);
209  distributed_ = on;
210  return old;
211  }
212 
213  //- Return decomposition model used
214  const decompositionModel& model() const;
215 
216  //- Update flags based on the decomposition model settings
217  // Sets "distributed"
218  void updateParameters(const dictionary& params);
219 
220 
221  // Mappings
222 
223  //- Cell-processor decomposition labels
224  const labelList& cellToProc() const noexcept
225  {
226  return cellToProc_;
227  }
228 
229 
230  // Decompose
231 
232  //- Decompose mesh
233  void decomposeMesh();
234 
235  //- Write decomposition
236  bool writeDecomposition(const bool decomposeSets);
237 
238 
239  // Write
240 
241  //- Write decomposition as volScalarField for visualization
242  void writeVolField(const word& timeName) const;
243 
244  //- Write cell distribution as VTU file (binary)
245  void writeVTK(const fileName& file) const;
246 };
247 
248 
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 
251 } // End namespace Foam
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 #ifdef NoRepository
257 #endif
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
volFields.H
Foam::domainDecomposition::writeVolField
void writeVolField(const word &timeName) const
Write decomposition as volScalarField for visualization.
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::domainDecomposition::domainDecomposition
domainDecomposition(const IOobject &io, const fileName &decompDictFile="")
Construct from components.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
point.H
Foam::domainDecomposition::nProcs
label nProcs() const noexcept
Number of processor in decomposition.
Definition: domainDecomposition.H:193
Foam::domainDecomposition::model
const decompositionModel & model() const
Return decomposition model used.
Foam::Map< label >
Foam::decompositionModel
MeshObject wrapper of decompositionMethod.
Definition: decompositionModel.H:57
labelList.H
Foam::domainDecomposition::writeDecomposition
bool writeDecomposition(const bool decomposeSets)
Write decomposition.
Foam::domainDecomposition::mesh
const fvMesh & mesh() const noexcept
The mesh.
Definition: domainDecomposition.H:184
Foam::domainDecomposition
Automatic domain decomposition class for finite-volume meshes.
Definition: domainDecomposition.H:58
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::domainDecomposition::updateParameters
void updateParameters(const dictionary &params)
Update flags based on the decomposition model settings.
Foam::fvMesh::owner
const labelUList & owner() const
Internal face owner. Note bypassing virtual mechanism so.
Definition: fvMesh.H:407
domainDecompositionTemplates.C
Foam::domainDecomposition::writeVTK
void writeVTK(const fileName &file) const
Write cell distribution as VTU file (binary)
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::domainDecomposition::cellToProc
const labelList & cellToProc() const noexcept
Cell-processor decomposition labels.
Definition: domainDecomposition.H:223
Foam::domainDecomposition::decomposeMesh
void decomposeMesh()
Decompose mesh.
Foam::domainDecomposition::distributed
bool distributed(const bool on) noexcept
Change distributed flag.
Definition: domainDecomposition.H:205
Foam::List< label >
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::domainDecomposition::~domainDecomposition
~domainDecomposition()=default
Destructor.
Foam::domainDecomposition::distributed
bool distributed() const noexcept
Is decomposition data to be distributed for each processor.
Definition: domainDecomposition.H:199