fvMeshDistribute.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 | Copyright (C) 2011-2014 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::fvMeshDistribute
26 
27 Description
28  Sends/receives parts of mesh+fvfields to neighbouring processors.
29  Used in load balancing.
30 
31  Input is per local cell the processor it should move to. Moves meshes
32  and volFields/surfaceFields and returns map which can be used to
33  distribute other.
34 
35  Notes:
36  - does not handle cyclics. Will probably handle separated proc patches.
37  - if all cells move off processor also all its processor patches will
38  get deleted so comms might be screwed up (since e.g. globalMeshData
39  expects procPatches on all)
40  - initial mesh has to have procPatches last and all normal patches common
41  to all processors and in the same order. This is checked.
42  - faces are matched topologically but points on the faces are not. So
43  expect problems -on separated patches (cyclics?) -on zero sized processor
44  edges.
45 
46 SourceFiles
47  fvMeshDistribute.C
48  fvMeshDistributeTemplates.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef fvMeshDistribute_H
53 #define fvMeshDistribute_H
54 
55 #include "Field.H"
56 #include "fvMeshSubset.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 // Forward declaration of classes
64 class mapAddedPolyMesh;
65 class mapDistributePolyMesh;
66 
67 /*---------------------------------------------------------------------------*\
68  Class fvMeshDistribute Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 class fvMeshDistribute
72 {
73  // Private data
74 
75  //- Underlying fvMesh
76  fvMesh& mesh_;
77 
78  //- Absolute merging tolerance (constructing meshes gets done using
79  // geometric matching)
80  const scalar mergeTol_;
81 
82 
83  // Private Member Functions
84 
85  //- Find indices with value
86  static labelList select
87  (
88  const bool selectEqual,
89  const labelList& values,
90  const label value
91  );
92 
93  //- Check all procs have same names and in exactly same order.
94  static void checkEqualWordList(const string&, const wordList&);
95 
96  //- Merge wordlists over all processors
97  static wordList mergeWordList(const wordList&);
98 
99 
100  // Patch handling
101 
102  //- Find patch to put exposed faces into.
103  label findNonEmptyPatch() const;
104 
105  //- Save boundary fields
106  template<class T, class Mesh>
107  void saveBoundaryFields
108  (
110  ) const;
111 
112  //- Map boundary fields
113  template<class T, class Mesh>
114  void mapBoundaryFields
115  (
116  const mapPolyMesh& map,
117  const PtrList<FieldField<fvsPatchField, T> >& oldBflds
118  );
119 
120  //- Init patch fields of certain type
121  template<class GeoField, class PatchFieldType>
122  void initPatchFields
123  (
124  const typename GeoField::value_type& initVal
125  );
126 
127  //- Call correctBoundaryConditions on fields
128  template<class GeoField>
129  void correctBoundaryConditions();
130 
131  //- Delete all processor patches. Move any processor faces into
132  // patchI.
133  autoPtr<mapPolyMesh> deleteProcPatches(const label patchI);
134 
135  //- Repatch the mesh. This is only necessary for the proc
136  // boundary faces. newPatchID is over all boundary faces: -1 or
137  // new patchID. constructFaceMap is being adapted for the
138  // possible new face position (since proc faces get automatically
139  // matched)
140  autoPtr<mapPolyMesh> repatch
141  (
142  const labelList& newPatchID,
143  labelListList& constructFaceMap
144  );
145 
146  //- Merge any shared points that are geometrically shared. Needs
147  // parallel valid mesh - uses globalMeshData.
148  // constructPointMap is adapted for the new point labels.
149  autoPtr<mapPolyMesh> mergeSharedPoints
150  (
151  labelListList& constructPointMap
152  );
153 
154  // Coupling information
155 
156  //- Construct the local environment of all boundary faces.
157  void getNeighbourData
158  (
159  const labelList& distribution,
160  labelList& sourceFace,
161  labelList& sourceProc,
162  labelList& sourcePatch,
163  labelList& sourceNewProc
164  ) const;
165 
166  // Subset the neighbourCell/neighbourProc fields
167  static void subsetBoundaryData
168  (
169  const fvMesh& mesh,
170  const labelList& faceMap,
171  const labelList& cellMap,
172 
173  const labelList& oldDistribution,
174  const labelList& oldFaceOwner,
175  const labelList& oldFaceNeighbour,
176  const label oldInternalFaces,
177 
178  const labelList& sourceFace,
179  const labelList& sourceProc,
180  const labelList& sourcePatch,
181  const labelList& sourceNewProc,
182 
183  labelList& subFace,
184  labelList& subProc,
185  labelList& subPatch,
186  labelList& subNewProc
187  );
188 
189  //- Find cells on mesh whose faceID/procID match the neighbour
190  // cell/proc of domainMesh. Store the matching face.
191  static void findCouples
192  (
193  const primitiveMesh&,
194  const labelList& sourceFace,
195  const labelList& sourceProc,
196  const labelList& sourcePatch,
197 
198  const label domain,
199  const primitiveMesh& domainMesh,
200  const labelList& domainFace,
201  const labelList& domainProc,
202  const labelList& domainPatch,
203 
204  labelList& masterCoupledFaces,
205  labelList& slaveCoupledFaces
206  );
207 
208  //- Map data on boundary faces to new mesh (resulting from adding
209  // two meshes)
210  static labelList mapBoundaryData
211  (
212  const primitiveMesh& mesh, // mesh after adding
213  const mapAddedPolyMesh& map,
214  const labelList& boundaryData0, // mesh before adding
215  const label nInternalFaces1,
216  const labelList& boundaryData1 // added mesh
217  );
218 
219 
220  // Other
221 
222  //- Remove cells. Add all exposed faces to patch oldInternalPatchI
223  autoPtr<mapPolyMesh> doRemoveCells
224  (
225  const labelList& cellsToRemove,
226  const label oldInternalPatchI
227  );
228 
229  //- Add processor patches. Changes mesh and returns per neighbour
230  // proc the processor patchID.
231  void addProcPatches
232  (
233  const labelList&, // processor that neighbour is now on
234  const labelList&, // -1 or patch that face originated from
235  List<Map<label> >& procPatchID
236  );
237 
238  //- Get boundary faces to be repatched. Is -1 or new patchID
239  static labelList getBoundaryPatch
240  (
241  const labelList& neighbourNewProc, // new processor per b. face
242  const labelList& referPatchID, // -1 or original patch
243  const List<Map<label> >& procPatchID// patchID
244  );
245 
246  //- Send mesh and coupling data.
247  static void sendMesh
248  (
249  const label domain,
250  const fvMesh& mesh,
251  const wordList& pointZoneNames,
252  const wordList& facesZoneNames,
253  const wordList& cellZoneNames,
254  const labelList& sourceFace,
255  const labelList& sourceProc,
256  const labelList& sourcePatch,
257  const labelList& sourceNewProc,
258  Ostream& toDomain
259  );
260  //- Send subset of fields
261  template<class GeoField>
262  static void sendFields
263  (
264  const label domain,
265  const wordList& fieldNames,
266  const fvMeshSubset&,
267  Ostream& toNbr
268  );
269 
270  //- Receive mesh. Opposite of sendMesh
271  static autoPtr<fvMesh> receiveMesh
272  (
273  const label domain,
274  const wordList& pointZoneNames,
275  const wordList& facesZoneNames,
276  const wordList& cellZoneNames,
277  const Time& runTime,
278  labelList& domainSourceFace,
279  labelList& domainSourceProc,
280  labelList& domainSourcePatch,
281  labelList& domainSourceNewProc,
282  Istream& fromNbr
283  );
284 
285  //- Receive fields. Opposite of sendFields
286  template<class GeoField>
287  static void receiveFields
288  (
289  const label domain,
290  const wordList& fieldNames,
291  fvMesh&,
293  const dictionary& fieldDicts
294  );
295 
296  //- Disallow default bitwise copy construct
298 
299  //- Disallow default bitwise assignment
300  void operator=(const fvMeshDistribute&);
301 
302 public:
303 
304  ClassName("fvMeshDistribute");
305 
306 
307  // Constructors
308 
309  //- Construct from mesh and absolute merge tolerance
310  fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
311 
312 
313  // Member Functions
314 
315  //- Helper function: count cells per processor in wanted distribution
316  static labelList countCells(const labelList&);
317 
318  //- Send cells to neighbours according to distribution
319  // (for every cell the new proc)
321 
322  // Debugging
323 
324  //- Print some info on coupling data
325  static void printCoupleInfo
326  (
327  const primitiveMesh&,
328  const labelList&,
329  const labelList&,
330  const labelList&,
331  const labelList&
332  );
333 
334  //- Print some field info
335  template<class GeoField>
336  static void printFieldInfo(const fvMesh&);
337 
338  //- Print some info on mesh.
339  static void printMeshInfo(const fvMesh&);
340 };
341 
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 } // End namespace Foam
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #ifdef NoRepository
350 # include "fvMeshDistributeTemplates.C"
351 #endif
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #endif
356 
357 // ************************************************************************* //
static void printMeshInfo(const fvMesh &)
Print some info on mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Generic field type.
Definition: FieldField.H:51
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
static List< word > fieldNames
Definition: globalFoam.H:46
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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
static void printCoupleInfo(const primitiveMesh &, const labelList &, const labelList &, const labelList &, const labelList &)
Print some info on coupling data.
static void printFieldInfo(const fvMesh &)
Print some field info.
Accumulating histogram of values. Specified bin resolution automatic generation of bins...
Definition: distribution.H:51
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Namespace for OpenFOAM.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
autoPtr< mapDistributePolyMesh > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
ClassName("fvMeshDistribute")
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Post-processing mesh subset tool. Given the original mesh and the list of selected cells...
Definition: fvMeshSubset.H:71
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh (&#39;added m...