syncTools.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-2016 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::syncTools
26 
27 Description
28  Various tools to aid synchronizing lists across coupled patches. WIP.
29 
30  Require
31  - combineOperator (e.g. sumEqOp - not sumOp!) that is defined for the
32  type and combineReduce(UList<T>, combineOperator) should be defined.
33  - null value which gets overridden by any valid value.
34  - transform function
35 
36 SourceFiles
37  syncTools.C
38  syncToolsTemplates.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef syncTools_H
43 #define syncTools_H
44 
45 #include "Pstream.H"
46 #include "EdgeMap.H"
47 #include "PackedBoolList.H"
48 #include "polyMesh.H"
49 #include "coupledPolyPatch.H"
50 #include "mapDistribute.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 class polyBoundaryMesh;
58 
59 /*---------------------------------------------------------------------------*\
60  Class syncTools Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class syncTools
64 {
65  // Private Member Functions
66 
67  //- Combine value with existing value in map.
68  template<class T, class CombineOp>
69  static void combine
70  (
71  Map<T>& pointValues,
72  const CombineOp& cop,
73  const label index,
74  const T& val
75  );
76 
77  //- Combine val with existing value at (implicit index) e.
78  template<class T, class CombineOp>
79  static void combine
80  (
81  EdgeMap<T>& edgeValues,
82  const CombineOp& cop,
83  const edge& index,
84  const T& val
85  );
86 
87 
88 public:
89 
90 
91  // Basic routines with user-supplied transformation. Preferably
92  // use specialisations below.
93 
94  //- Synchronize values on selected points.
95  template<class T, class CombineOp, class TransformOp>
96  static void syncPointMap
97  (
98  const polyMesh&,
99  Map<T>& pointValues,
100  const CombineOp& cop,
101  const TransformOp& top
102  );
103 
104  //- Synchronize values on selected edges.
105  template<class T, class CombineOp, class TransformOp>
106  static void syncEdgeMap
107  (
108  const polyMesh&,
109  EdgeMap<T>& edgeValues,
110  const CombineOp& cop,
111  const TransformOp& top
112  );
113 
114  //- Synchronize values on all mesh points.
115  template<class T, class CombineOp, class TransformOp>
116  static void syncPointList
117  (
118  const polyMesh&,
119  List<T>&,
120  const CombineOp& cop,
121  const T& nullValue,
122  const TransformOp& top
123  );
124 
125  //- Synchronize values on selected mesh points.
126  template<class T, class CombineOp, class TransformOp>
127  static void syncPointList
128  (
129  const polyMesh&,
130  const labelList& meshPoints,
131  List<T>&,
132  const CombineOp& cop,
133  const T& nullValue,
134  const TransformOp& top
135  );
136 
137  //- Synchronize values on all mesh edges.
138  template<class T, class CombineOp, class TransformOp>
139  static void syncEdgeList
140  (
141  const polyMesh&,
142  List<T>&,
143  const CombineOp& cop,
144  const T& nullValue,
145  const TransformOp& top
146  );
147 
148  //- Synchronize values on selected mesh edges.
149  template<class T, class CombineOp, class TransformOp>
150  static void syncEdgeList
151  (
152  const polyMesh&,
153  const labelList& meshEdges,
154  List<T>&,
155  const CombineOp& cop,
156  const T& nullValue,
157  const TransformOp& top
158  );
159 
160  //- Synchronize values on boundary faces only.
161  template<class T, class CombineOp, class TransformOp>
162  static void syncBoundaryFaceList
163  (
164  const polyMesh&,
165  UList<T>&,
166  const CombineOp& cop,
167  const TransformOp& top,
168  const bool parRun = Pstream::parRun()
169  );
170 
171 
172  // Synchronise point-wise data
173 
174  //- Synchronize values on all mesh points.
175  template<class T, class CombineOp>
176  static void syncPointList
177  (
178  const polyMesh& mesh,
179  List<T>& l,
180  const CombineOp& cop,
181  const T& nullValue
182  )
183  {
185  (
186  mesh,
187  l,
188  cop,
189  nullValue,
191  );
192  }
193 
194  //- Synchronize locations on all mesh points.
195  template<class CombineOp>
196  static void syncPointPositions
197  (
198  const polyMesh& mesh,
199  List<point>& l,
200  const CombineOp& cop,
201  const point& nullValue
202  )
203  {
205  (
206  mesh,
207  l,
208  cop,
209  nullValue,
211  );
212  }
213 
214  //- Synchronize values on selected mesh points.
215  template<class T, class CombineOp>
216  static void syncPointList
217  (
218  const polyMesh& mesh,
219  const labelList& meshPoints,
220  List<T>& l,
221  const CombineOp& cop,
222  const T& nullValue
223  )
224  {
226  (
227  mesh,
228  meshPoints,
229  l,
230  cop,
231  nullValue,
233  );
234  }
235 
236  //- Synchronize locations on selected mesh points.
237  template<class CombineOp>
238  static void syncPointPositions
239  (
240  const polyMesh& mesh,
241  const labelList& meshPoints,
242  List<point>& l,
243  const CombineOp& cop,
244  const point& nullValue
245  )
246  {
248  (
249  mesh,
250  meshPoints,
251  l,
252  cop,
253  nullValue,
255  );
256  }
257 
258 
259  // Synchronise edge-wise data
260 
261  //- Synchronize values on all mesh edges.
262  template<class T, class CombineOp>
263  static void syncEdgeList
264  (
265  const polyMesh& mesh,
266  List<T>& l,
267  const CombineOp& cop,
268  const T& nullValue
269  )
270  {
272  (
273  mesh,
274  l,
275  cop,
276  nullValue,
278  );
279  }
280 
281  //- Synchronize locations on all mesh edges.
282  template<class CombineOp>
283  static void syncEdgePositions
284  (
285  const polyMesh& mesh,
286  List<point>& l,
287  const CombineOp& cop,
288  const point& nullValue
289  )
290  {
292  (
293  mesh,
294  l,
295  cop,
296  nullValue,
298  );
299  }
300 
301  //- Synchronize values on selected mesh edges.
302  template<class T, class CombineOp>
303  static void syncEdgeList
304  (
305  const polyMesh& mesh,
306  const labelList& meshEdges,
307  List<T>& l,
308  const CombineOp& cop,
309  const T& nullValue
310  )
311  {
313  (
314  mesh,
315  meshEdges,
316  l,
317  cop,
318  nullValue,
320  );
321  }
322 
323  //- Synchronize locations on selected mesh edges.
324  template<class CombineOp>
325  static void syncEdgePositions
326  (
327  const polyMesh& mesh,
328  const labelList& meshEdges,
329  List<point>& l,
330  const CombineOp& cop,
331  const point& nullValue
332  )
333  {
335  (
336  mesh,
337  meshEdges,
338  l,
339  cop,
340  nullValue,
342  );
343  }
344 
345 
346 
347  // Synchronise face-wise data
348 
349  //- Synchronize values on boundary faces only.
350  template<class T, class CombineOp>
352  (
353  const polyMesh& mesh,
354  UList<T>& l,
355  const CombineOp& cop
356  )
357  {
359  }
360 
361  //- Synchronize locations on boundary faces only.
362  template<class CombineOp>
364  (
365  const polyMesh& mesh,
366  UList<point>& l,
367  const CombineOp& cop
368  )
369  {
371  (
372  mesh,
373  l,
374  cop,
376  );
377  }
378 
379  //- Synchronize values on all mesh faces.
380  template<class T, class CombineOp>
381  static void syncFaceList
382  (
383  const polyMesh& mesh,
384  UList<T>& l,
385  const CombineOp& cop
386  )
387  {
388  SubList<T> bndValues
389  (
390  l,
391  mesh.nFaces()-mesh.nInternalFaces(),
392  mesh.nInternalFaces()
393  );
394 
396  (
397  mesh,
398  bndValues,
399  cop,
401  );
402  }
403 
404  //- Synchronize locations on all mesh faces.
405  template<class CombineOp>
406  static void syncFacePositions
407  (
408  const polyMesh& mesh,
409  UList<point>& l,
410  const CombineOp& cop
411  )
412  {
413  SubList<point> bndValues
414  (
415  l,
416  mesh.nFaces()-mesh.nInternalFaces(),
417  mesh.nInternalFaces()
418  );
420  (
421  mesh,
422  bndValues,
423  cop,
425  );
426  }
427 
428  //- Swap coupled boundary face values.
429  template<class T>
431  (
432  const polyMesh& mesh,
433  UList<T>& l
434  )
435  {
437  (
438  mesh,
439  l,
440  eqOp<T>(),
442  );
443  }
444 
445  //- Swap coupled positions.
447  (
448  const polyMesh& mesh,
449  UList<point>& l
450  )
451  {
453  (
454  mesh,
455  l,
456  eqOp<point>(),
458  );
459  }
460 
461  //- Swap coupled face values.
462  template<class T>
463  static void swapFaceList
464  (
465  const polyMesh& mesh,
466  UList<T>& l
467  )
468  {
469  SubList<T> bndValues
470  (
471  l,
472  mesh.nFaces()-mesh.nInternalFaces(),
473  mesh.nInternalFaces()
474  );
476  (
477  mesh,
478  bndValues,
479  eqOp<T>(),
481  );
482  }
483 
484  //- Swap to obtain neighbour cell values for all boundary faces
485  template<class T>
486  static void swapBoundaryCellList
487  (
488  const polyMesh& mesh,
489  const UList<T>& cellData,
490  List<T>& neighbourCellData
491  );
492 
493  //- Swap to obtain neighbour cell positions for all boundary faces
494  static void swapBoundaryCellPositions
495  (
496  const polyMesh& mesh,
497  const UList<point>& cellData,
498  List<point>& neighbourCellData
499  );
500 
501  // Sparse versions
502 
503  //- Synchronize values on selected points.
504  template<class T, class CombineOp>
505  static void syncPointMap
506  (
507  const polyMesh& mesh,
508  Map<T>& l,
509  const CombineOp& cop
510  )
511  {
512  syncPointMap(mesh, l, cop, mapDistribute::transform());
513  }
514 
515  //- Synchronize locations on selected points.
516  template<class CombineOp>
517  static void syncPointPositions
518  (
519  const polyMesh& mesh,
520  Map<point>& l,
521  const CombineOp& cop
522  )
523  {
525  }
526 
527  //- Synchronize values on selected edges. Edges are represented
528  // by the two vertices that make it up so global edges never get
529  // constructed.
530  template<class T, class CombineOp>
531  static void syncEdgeMap
532  (
533  const polyMesh& mesh,
534  EdgeMap<T>& l,
535  const CombineOp& cop
536  )
537  {
538  syncEdgeMap(mesh, l, cop, mapDistribute::transform());
539  }
540 
541  //- Synchronize locations on selected edges.
542  template<class CombineOp>
543  static void syncEdgePositions
544  (
545  const polyMesh& mesh,
546  EdgeMap<point>& l,
547  const CombineOp& cop
548  )
549  {
551  }
552 
553  // PackedList versions
554 
555  template<unsigned nBits, class CombineOp>
556  static void syncFaceList
557  (
558  const polyMesh& mesh,
559  PackedList<nBits>& faceValues,
560  const CombineOp& cop,
561  const bool parRun = Pstream::parRun()
562  );
563 
564  template<unsigned nBits>
565  static void swapFaceList
566  (
567  const polyMesh& mesh,
568  PackedList<nBits>& faceValues
569  );
570 
571  template<unsigned nBits, class CombineOp>
572  static void syncPointList
573  (
574  const polyMesh& mesh,
575  PackedList<nBits>& pointValues,
576  const CombineOp& cop,
577  const unsigned int nullValue
578  );
579 
580  template<unsigned nBits, class CombineOp>
581  static void syncEdgeList
582  (
583  const polyMesh& mesh,
584  PackedList<nBits>& edgeValues,
585  const CombineOp& cop,
586  const unsigned int nullValue
587  );
588 
589  // Other
590 
591  //- Get per point whether it is uncoupled or a master of a
592  // coupled set of points
593  static PackedBoolList getMasterPoints(const polyMesh&);
594 
595  //- Get per edge whether it is uncoupled or a master of a
596  // coupled set of edges
597  static PackedBoolList getMasterEdges(const polyMesh&);
598 
599  //- Get per face whether it is uncoupled or a master of a
600  // coupled set of faces
601  static PackedBoolList getMasterFaces(const polyMesh&);
602 
603  //- Get per face whether it is internal or a master of a
604  // coupled set of faces
606 
607  //- Get per face whether it is internal or coupled
609 
610 };
611 
612 
613 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
614 
615 } // End namespace Foam
616 
617 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
618 
619 #ifdef NoRepository
620  #include "syncToolsTemplates.C"
621 #endif
622 
623 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
624 
625 #endif
626 
627 // ************************************************************************* //
static void syncBoundaryFaceList(const polyMesh &, UList< T > &, const CombineOp &cop, const TransformOp &top, const bool parRun=Pstream::parRun())
Synchronize values on boundary faces only.
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 syncPointPositions(const polyMesh &mesh, List< point > &l, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh points.
Definition: syncTools.H:196
label nInternalFaces() const
static void swapBoundaryFacePositions(const polyMesh &mesh, UList< point > &l)
Swap coupled positions.
Definition: syncTools.H:446
static PackedBoolList getInternalOrCoupledFaces(const polyMesh &)
Get per face whether it is internal or coupled.
Definition: syncTools.C:217
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
label nFaces() const
Various tools to aid synchronizing lists across coupled patches. WIP.
Definition: syncTools.H:62
static void swapBoundaryCellPositions(const polyMesh &mesh, const UList< point > &cellData, List< point > &neighbourCellData)
Swap to obtain neighbour cell positions for all boundary faces.
Definition: syncTools.C:31
static void syncEdgePositions(const polyMesh &mesh, List< point > &l, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh edges.
Definition: syncTools.H:283
static PackedBoolList getMasterFaces(const polyMesh &)
Get per face whether it is uncoupled or a master of a.
Definition: syncTools.C:153
static PackedBoolList getInternalOrMasterFaces(const polyMesh &)
Get per face whether it is internal or a master of a.
Definition: syncTools.C:181
static PackedBoolList getMasterEdges(const polyMesh &)
Get per edge whether it is uncoupled or a master of a.
Definition: syncTools.C:109
A List obtained as a section of another List.
Definition: SubList.H:53
Default transformation behaviour.
Definition: ops.H:70
A dynamically allocatable list of packed unsigned integers.
Definition: PackedList.H:117
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
static void syncEdgeList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh edges.
static void swapFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled face values.
Definition: syncTools.H:463
static void syncPointMap(const polyMesh &, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
Default transformation behaviour for position.
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:61
Map from edge (expressed as its endpoints) to value.
Definition: EdgeMap.H:47
static PackedBoolList getMasterPoints(const polyMesh &)
Get per point whether it is uncoupled or a master of a.
Definition: syncTools.C:65
static void syncEdgeMap(const polyMesh &, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected edges.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static void swapBoundaryCellList(const polyMesh &mesh, const UList< T > &cellData, List< T > &neighbourCellData)
Swap to obtain neighbour cell values for all boundary faces.
static void syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:381
A bit-packed bool list.
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:394
static void syncBoundaryFacePositions(const polyMesh &mesh, UList< point > &l, const CombineOp &cop)
Synchronize locations on boundary faces only.
Definition: syncTools.H:363
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
static void syncFacePositions(const polyMesh &mesh, UList< point > &l, const CombineOp &cop)
Synchronize locations on all mesh faces.
Definition: syncTools.H:406
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:430
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49