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  static void inplaceRenumberWithFlip
86  (
87  const labelUList& oldToNew,
88  const bool oldToNewHasFlip,
89  const bool lstHasFlip,
90  labelUList& lst
91  );
92 
93  //- Find indices with value
94  static labelList select
95  (
96  const bool selectEqual,
97  const labelList& values,
98  const label value
99  );
100 
101  //- Check all procs have same names and in exactly same order.
102  static void checkEqualWordList(const string&, const wordList&);
103 
104  //- Merge wordlists over all processors
105  static wordList mergeWordList(const wordList&);
106 
107 
108  // Patch handling
109 
110  //- Find patch to put exposed faces into.
111  label findNonEmptyPatch() const;
112 
113  //- Save boundary fields
114  template<class T, class Mesh>
115  void saveBoundaryFields
116  (
118  ) const;
119 
120  //- Map boundary fields
121  template<class T, class Mesh>
122  void mapBoundaryFields
123  (
124  const mapPolyMesh& map,
125  const PtrList<FieldField<fvsPatchField, T> >& oldBflds
126  );
127 
128  //- Save internal fields of surfaceFields
129  template<class T>
130  void saveInternalFields
131  (
132  PtrList<Field<T> >& iflds
133  ) const;
134 
135  //- Set value of patch faces resulting from internal faces
136  template<class T>
137  void mapExposedFaces
138  (
139  const mapPolyMesh& map,
140  const PtrList<Field<T> >& oldFlds
141  );
142 
143  //- Init patch fields of certain type
144  template<class GeoField, class PatchFieldType>
145  void initPatchFields
146  (
147  const typename GeoField::value_type& initVal
148  );
149 
150  //- Call correctBoundaryConditions on fields
151  template<class GeoField>
153 
154  //- Delete all processor patches. Move any processor faces into
155  // patchI.
157 
158  //- Repatch the mesh. This is only necessary for the proc
159  // boundary faces. newPatchID is over all boundary faces: -1 or
160  // new patchID. constructFaceMap is being adapted for the
161  // possible new face position (since proc faces get automatically
162  // matched)
164  (
165  const labelList& newPatchID,
166  labelListList& constructFaceMap
167  );
168 
169  //- Merge any shared points that are geometrically shared. Needs
170  // parallel valid mesh - uses globalMeshData.
171  // constructPointMap is adapted for the new point labels.
173  (
174  labelListList& constructPointMap
175  );
176 
177  // Coupling information
178 
179  //- Construct the local environment of all boundary faces.
180  void getNeighbourData
181  (
182  const labelList& distribution,
183  labelList& sourceFace,
184  labelList& sourceProc,
185  labelList& sourcePatch,
186  labelList& sourceNewProc
187  ) const;
188 
189  // Subset the neighbourCell/neighbourProc fields
190  static void subsetBoundaryData
191  (
192  const fvMesh& mesh,
193  const labelList& faceMap,
194  const labelList& cellMap,
195 
196  const labelList& oldDistribution,
197  const labelList& oldFaceOwner,
198  const labelList& oldFaceNeighbour,
199  const label oldInternalFaces,
200 
201  const labelList& sourceFace,
202  const labelList& sourceProc,
203  const labelList& sourcePatch,
204  const labelList& sourceNewProc,
205 
206  labelList& subFace,
207  labelList& subProc,
208  labelList& subPatch,
209  labelList& subNewProc
210  );
211 
212  //- Find cells on mesh whose faceID/procID match the neighbour
213  // cell/proc of domainMesh. Store the matching face.
214  static void findCouples
215  (
216  const primitiveMesh&,
217  const labelList& sourceFace,
218  const labelList& sourceProc,
219  const labelList& sourcePatch,
220 
221  const label domain,
222  const primitiveMesh& domainMesh,
223  const labelList& domainFace,
224  const labelList& domainProc,
225  const labelList& domainPatch,
226 
227  labelList& masterCoupledFaces,
228  labelList& slaveCoupledFaces
229  );
230 
231  //- Map data on boundary faces to new mesh (resulting from adding
232  // two meshes)
234  (
235  const primitiveMesh& mesh, // mesh after adding
236  const mapAddedPolyMesh& map,
237  const labelList& boundaryData0, // mesh before adding
238  const label nInternalFaces1,
239  const labelList& boundaryData1 // added mesh
240  );
241 
242 
243  // Other
244 
245  //- Remove cells. Add all exposed faces to patch oldInternalPatchI
247  (
248  const labelList& cellsToRemove,
249  const label oldInternalPatchI
250  );
251 
252  //- Add processor patches. Changes mesh and returns per neighbour
253  // proc the processor patchID.
254  void addProcPatches
255  (
256  const labelList&, // processor that neighbour is now on
257  const labelList&, // -1 or patch that face originated from
258  List<Map<label> >& procPatchID
259  );
260 
261  //- Get boundary faces to be repatched. Is -1 or new patchID
263  (
264  const labelList& neighbourNewProc, // new processor per b. face
265  const labelList& referPatchID, // -1 or original patch
266  const List<Map<label> >& procPatchID// patchID
267  );
268 
269  //- Send mesh and coupling data.
270  static void sendMesh
271  (
272  const label domain,
273  const fvMesh& mesh,
274  const wordList& pointZoneNames,
275  const wordList& facesZoneNames,
276  const wordList& cellZoneNames,
277  const labelList& sourceFace,
278  const labelList& sourceProc,
279  const labelList& sourcePatch,
280  const labelList& sourceNewProc,
281  Ostream& toDomain
282  );
283  //- Send subset of fields
284  template<class GeoField>
285  static void sendFields
286  (
287  const label domain,
288  const wordList& fieldNames,
289  const fvMeshSubset&,
290  Ostream& toNbr
291  );
292 
293  //- Receive mesh. Opposite of sendMesh
295  (
296  const label domain,
297  const wordList& pointZoneNames,
298  const wordList& facesZoneNames,
299  const wordList& cellZoneNames,
300  const Time& runTime,
301  labelList& domainSourceFace,
302  labelList& domainSourceProc,
303  labelList& domainSourcePatch,
304  labelList& domainSourceNewProc,
305  Istream& fromNbr
306  );
307 
308  //- Receive fields. Opposite of sendFields
309  template<class GeoField>
310  static void receiveFields
311  (
312  const label domain,
313  const wordList& fieldNames,
314  fvMesh&,
316  const dictionary& fieldDicts
317  );
318 
319  //- Disallow default bitwise copy construct
321 
322  //- Disallow default bitwise assignment
323  void operator=(const fvMeshDistribute&);
324 
325 public:
326 
327  ClassName("fvMeshDistribute");
328 
329 
330  // Constructors
331 
332  //- Construct from mesh and absolute merge tolerance
333  fvMeshDistribute(fvMesh& mesh, const scalar mergeTol);
334 
335 
336  // Member Functions
337 
338  //- Helper function: count cells per processor in wanted distribution
339  static labelList countCells(const labelList&);
340 
341  //- Send cells to neighbours according to distribution
342  // (for every cell the new proc)
344 
345  // Debugging
346 
347  //- Print some info on coupling data
348  static void printCoupleInfo
349  (
350  const primitiveMesh&,
351  const labelList&,
352  const labelList&,
353  const labelList&,
354  const labelList&
355  );
356 
357  //- Print some field info
358  template<class GeoField>
359  static void printFieldInfo(const fvMesh&);
360 
361  //- Print some info on mesh.
362  static void printMeshInfo(const fvMesh&);
363 
364  //- Generate a test field on faces
366 
367  //- Check whether field consistent with face orientation
368  static void testField(const surfaceScalarField&);
369 };
370 
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 } // End namespace Foam
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 #ifdef NoRepository
379 # include "fvMeshDistributeTemplates.C"
380 #endif
381 
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 
384 #endif
385 
386 // ************************************************************************* //
fvMeshDistributeTemplates.C
Foam::fvMeshDistribute::countCells
static labelList countCells(const labelList &)
Helper function: count cells per processor in wanted distribution.
Definition: fvMeshDistribute.C:1589
Foam::fvMeshDistribute::receiveFields
static void receiveFields(const label domain, const wordList &fieldNames, fvMesh &, PtrList< GeoField > &, const dictionary &fieldDicts)
Receive fields. Opposite of sendFields.
Definition: fvMeshDistributeTemplates.C:338
Foam::distribution
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:51
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::fvMeshDistribute::saveBoundaryFields
void saveBoundaryFields(PtrList< FieldField< fvsPatchField, T > > &bflds) const
Save boundary fields.
Definition: fvMeshDistributeTemplates.C:61
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
Foam::fvMeshDistribute::mapBoundaryFields
void mapBoundaryFields(const mapPolyMesh &map, const PtrList< FieldField< fvsPatchField, T > > &oldBflds)
Map boundary fields.
Definition: fvMeshDistributeTemplates.C:90
Foam::fvMeshDistribute::getBoundaryPatch
static labelList getBoundaryPatch(const labelList &neighbourNewProc, const labelList &referPatchID, const List< Map< label > > &procPatchID)
Get boundary faces to be repatched. Is -1 or new patchID.
Definition: fvMeshDistribute.C:1275
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::fvMeshSubset
Post-processing mesh subset tool. Given the original mesh and the list of selected cells,...
Definition: fvMeshSubset.H:73
fvMeshSubset.H
Foam::fvMeshDistribute::printFieldInfo
static void printFieldInfo(const fvMesh &)
Print some field info.
Definition: fvMeshDistributeTemplates.C:31
Foam::fvMeshDistribute::findNonEmptyPatch
label findNonEmptyPatch() const
Find patch to put exposed faces into.
Definition: fvMeshDistribute.C:327
Foam::Map< label >
Foam::fvMeshDistribute::findCouples
static void findCouples(const primitiveMesh &, const labelList &sourceFace, const labelList &sourceProc, const labelList &sourcePatch, const label domain, const primitiveMesh &domainMesh, const labelList &domainFace, const labelList &domainProc, const labelList &domainPatch, labelList &masterCoupledFaces, labelList &slaveCoupledFaces)
Find cells on mesh whose faceID/procID match the neighbour.
Definition: fvMeshDistribute.C:965
Foam::fvMeshDistribute::getNeighbourData
void getNeighbourData(const labelList &distribution, labelList &sourceFace, labelList &sourceProc, labelList &sourcePatch, labelList &sourceNewProc) const
Construct the local environment of all boundary faces.
Definition: fvMeshDistribute.C:750
Foam::fvMeshDistribute::receiveMesh
static autoPtr< fvMesh > receiveMesh(const label domain, const wordList &pointZoneNames, const wordList &facesZoneNames, const wordList &cellZoneNames, const Time &runTime, labelList &domainSourceFace, labelList &domainSourceProc, labelList &domainSourcePatch, labelList &domainSourceNewProc, Istream &fromNbr)
Receive mesh. Opposite of sendMesh.
Definition: fvMeshDistribute.C:1467
Foam::fvMeshDistribute::inplaceRenumberWithFlip
static void inplaceRenumberWithFlip(const labelUList &oldToNew, const bool oldToNewHasFlip, const bool lstHasFlip, labelUList &lst)
Definition: fvMeshDistribute.C:89
Foam::fvMeshDistribute::doRemoveCells
autoPtr< mapPolyMesh > doRemoveCells(const labelList &cellsToRemove, const label oldInternalPatchI)
Remove cells. Add all exposed faces to patch oldInternalPatchI.
Definition: fvMeshDistribute.C:1079
Foam::fvMeshDistribute::ClassName
ClassName("fvMeshDistribute")
Foam::fvMeshDistribute::generateTestField
static tmp< surfaceScalarField > generateTestField(const fvMesh &)
Generate a test field on faces.
Definition: fvMeshDistribute.C:389
Foam::fvMeshDistribute::mapBoundaryData
static labelList mapBoundaryData(const primitiveMesh &mesh, const mapAddedPolyMesh &map, const labelList &boundaryData0, const label nInternalFaces1, const labelList &boundaryData1)
Map data on boundary faces to new mesh (resulting from adding.
Definition: fvMeshDistribute.C:1040
Foam::fvMeshDistribute::sendFields
static void sendFields(const label domain, const wordList &fieldNames, const fvMeshSubset &, Ostream &toNbr)
Send subset of fields.
Definition: fvMeshDistributeTemplates.C:303
Foam::fvMeshDistribute::checkEqualWordList
static void checkEqualWordList(const string &, const wordList &)
Check all procs have same names and in exactly same order.
Definition: fvMeshDistribute.C:195
Foam::fvMeshDistribute::repatch
autoPtr< mapPolyMesh > repatch(const labelList &newPatchID, labelListList &constructFaceMap)
Repatch the mesh. This is only necessary for the proc.
Definition: fvMeshDistribute.C:567
Foam::label
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
Foam::Field< T >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Field.H
Foam::PtrList
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
Foam::fvMeshDistribute::operator=
void operator=(const fvMeshDistribute &)
Disallow default bitwise assignment.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMeshDistribute::fvMeshDistribute
fvMeshDistribute(const fvMeshDistribute &)
Disallow default bitwise copy construct.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::fvMeshDistribute::saveInternalFields
void saveInternalFields(PtrList< Field< T > > &iflds) const
Save internal fields of surfaceFields.
Definition: fvMeshDistributeTemplates.C:149
Foam::fvMeshDistribute::mergeWordList
static wordList mergeWordList(const wordList &)
Merge wordlists over all processors.
Definition: fvMeshDistribute.C:220
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::fvMeshDistribute::printMeshInfo
static void printMeshInfo(const fvMesh &)
Print some info on mesh.
Definition: fvMeshDistribute.C:240
Foam::fvMeshDistribute::addProcPatches
void addProcPatches(const labelList &, const labelList &, List< Map< label > > &procPatchID)
Add processor patches. Changes mesh and returns per neighbour.
Definition: fvMeshDistribute.C:1157
Foam::fvMeshDistribute::correctBoundaryConditions
void correctBoundaryConditions()
Call correctBoundaryConditions on fields.
Definition: fvMeshDistributeTemplates.C:268
Foam::fvMeshDistribute::mesh_
fvMesh & mesh_
Underlying fvMesh.
Definition: fvMeshDistribute.H:75
Foam::fvMeshDistribute::mergeTol_
const scalar mergeTol_
Absolute merging tolerance (constructing meshes gets done using.
Definition: fvMeshDistribute.H:79
Foam::fieldNames
wordList fieldNames(const IOobjectList &objects, const bool syncPar)
Get sorted names of fields of type. If syncPar and running in parallel.
Definition: ReadFields.C:36
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::fvMeshDistribute::printCoupleInfo
static void printCoupleInfo(const primitiveMesh &, const labelList &, const labelList &, const labelList &, const labelList &)
Print some info on coupling data.
Definition: fvMeshDistribute.C:300
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::fvMeshDistribute::initPatchFields
void initPatchFields(const typename GeoField::value_type &initVal)
Init patch fields of certain type.
Definition: fvMeshDistributeTemplates.C:239
Foam::fvMeshDistribute::testField
static void testField(const surfaceScalarField &)
Check whether field consistent with face orientation.
Definition: fvMeshDistribute.C:436
Foam::fvMeshDistribute::distribute
autoPtr< mapDistributePolyMesh > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
Definition: fvMeshDistribute.C:1613
Foam::fvMeshDistribute::deleteProcPatches
autoPtr< mapPolyMesh > deleteProcPatches(const label patchI)
Delete all processor patches. Move any processor faces into.
Definition: fvMeshDistribute.C:495
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::fvMeshDistribute::mapExposedFaces
void mapExposedFaces(const mapPolyMesh &map, const PtrList< Field< T > > &oldFlds)
Set value of patch faces resulting from internal faces.
Definition: fvMeshDistributeTemplates.C:178
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::fvMeshDistribute::mergeSharedPoints
autoPtr< mapPolyMesh > mergeSharedPoints(labelListList &constructPointMap)
Merge any shared points that are geometrically shared. Needs.
Definition: fvMeshDistribute.C:687
Foam::fvMeshDistribute::subsetBoundaryData
static void subsetBoundaryData(const fvMesh &mesh, const labelList &faceMap, const labelList &cellMap, const labelList &oldDistribution, const labelList &oldFaceOwner, const labelList &oldFaceNeighbour, const label oldInternalFaces, const labelList &sourceFace, const labelList &sourceProc, const labelList &sourcePatch, const labelList &sourceNewProc, labelList &subFace, labelList &subProc, labelList &subPatch, labelList &subNewProc)
Definition: fvMeshDistribute.C:895
Foam::mapAddedPolyMesh
Class containing mesh-to-mesh mapping information after a mesh addition where we add a mesh ('added m...
Definition: mapAddedPolyMesh.H:56
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::fvMeshDistribute::sendMesh
static void sendMesh(const label domain, const fvMesh &mesh, const wordList &pointZoneNames, const wordList &facesZoneNames, const wordList &cellZoneNames, const labelList &sourceFace, const labelList &sourceProc, const labelList &sourcePatch, const labelList &sourceNewProc, Ostream &toDomain)
Send mesh and coupling data.
Definition: fvMeshDistribute.C:1306
Foam::fvMeshDistribute::select
static labelList select(const bool selectEqual, const labelList &values, const label value)
Find indices with value.
Definition: fvMeshDistribute.C:163
Foam::fvMeshDistribute
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Definition: fvMeshDistribute.H:70
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79