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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2019 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::syncTools
29 
30 Description
31  Various tools to aid synchronizing lists across coupled patches. WIP.
32 
33  Require
34  - combineOperator (e.g. sumEqOp - not sumOp!) that is defined for the
35  type and combineReduce(UList<T>, combineOperator) should be defined.
36  - null value which gets overridden by any valid value.
37  - transform function
38 
39 SourceFiles
40  syncTools.C
41  syncToolsTemplates.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef syncTools_H
46 #define syncTools_H
47 
48 #include "Pstream.H"
49 #include "edgeHashes.H"
50 #include "bitSet.H"
51 #include "polyMesh.H"
52 #include "coupledPolyPatch.H"
53 #include "mapDistribute.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 // Forward declarations
61 class polyBoundaryMesh;
62 
63 /*---------------------------------------------------------------------------*\
64  Class syncTools Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class syncTools
68 {
69  // Private Member Functions
70 
71  //- Combine val with existing value in pointValues map at given index
72  template<class T, class CombineOp>
73  static void combine
74  (
75  Map<T>& pointValues,
76  const CombineOp& cop,
77  const label index,
78  const T& val
79  );
80 
81  //- Combine val with existing value in edgeValues at edge index
82  template<class T, class CombineOp>
83  static void combine
84  (
85  EdgeMap<T>& edgeValues,
86  const CombineOp& cop,
87  const edge& index,
88  const T& val
89  );
90 
91 
92 public:
93 
94  // Basic routines with user-supplied transformation.
95  // Preferably use specialisations below.
96 
97  //- Synchronize values on selected points.
98  template<class T, class CombineOp, class TransformOp>
99  static void syncPointMap
100  (
101  const polyMesh& mesh,
102  Map<T>& pointValues,
103  const CombineOp& cop,
104  const TransformOp& top
105  );
106 
107  //- Synchronize values on selected edges.
108  template<class T, class CombineOp, class TransformOp>
109  static void syncEdgeMap
110  (
111  const polyMesh& mesh,
112  EdgeMap<T>& edgeValues,
113  const CombineOp& cop,
114  const TransformOp& top
115  );
116 
117  //- Synchronize values on all mesh points.
118  template<class T, class CombineOp, class TransformOp>
119  static void syncPointList
120  (
121  const polyMesh& mesh,
122  List<T>& pointValues,
123  const CombineOp& cop,
124  const T& nullValue,
125  const TransformOp& top
126  );
127 
128  //- Synchronize values on selected mesh points.
129  template<class T, class CombineOp, class TransformOp>
130  static void syncPointList
131  (
132  const polyMesh& mesh,
133  const labelUList& meshPoints,
134  List<T>& pointValues,
135  const CombineOp& cop,
136  const T& nullValue,
137  const TransformOp& top
138  );
139 
140  //- Synchronize values on all mesh edges.
141  template<class T, class CombineOp, class TransformOp>
142  static void syncEdgeList
143  (
144  const polyMesh& mesh,
145  List<T>& edgeValues,
146  const CombineOp& cop,
147  const T& nullValue,
148  const TransformOp& top
149  );
150 
151  //- Synchronize values on selected mesh edges.
152  template<class T, class CombineOp, class TransformOp>
153  static void syncEdgeList
154  (
155  const polyMesh& mesh,
156  const labelList& meshEdges,
157  List<T>& edgeValues,
158  const CombineOp& cop,
159  const T& nullValue,
160  const TransformOp& top
161  );
162 
163  //- Synchronize values on boundary faces only.
164  template<class T, class CombineOp, class TransformOp>
165  static void syncBoundaryFaceList
166  (
167  const polyMesh& mesh,
168  UList<T>& faceValues,
169  const CombineOp& cop,
170  const TransformOp& top,
171  const bool parRun = Pstream::parRun()
172  );
173 
174 
175  // Synchronise point-wise data
176 
177  //- Synchronize values on all mesh points.
178  template<class T, class CombineOp>
179  static void syncPointList
180  (
181  const polyMesh& mesh,
182  List<T>& pointValues,
183  const CombineOp& cop,
184  const T& nullValue
185  )
186  {
188  (
189  mesh,
190  pointValues,
191  cop,
192  nullValue,
194  );
195  }
196 
197  //- Synchronize locations on all mesh points.
198  template<class CombineOp>
199  static void syncPointPositions
200  (
201  const polyMesh& mesh,
202  List<point>& positions,
203  const CombineOp& cop,
204  const point& nullValue
205  )
206  {
208  (
209  mesh,
210  positions,
211  cop,
212  nullValue,
214  );
215  }
216 
217  //- Synchronize values on selected mesh points.
218  template<class T, class CombineOp>
219  static void syncPointList
220  (
221  const polyMesh& mesh,
222  const labelList& meshPoints,
223  List<T>& pointValues,
224  const CombineOp& cop,
225  const T& nullValue
226  )
227  {
229  (
230  mesh,
231  meshPoints,
232  pointValues,
233  cop,
234  nullValue,
236  );
237  }
238 
239  //- Synchronize locations on selected mesh points.
240  template<class CombineOp>
241  static void syncPointPositions
242  (
243  const polyMesh& mesh,
244  const labelList& meshPoints,
245  List<point>& positions,
246  const CombineOp& cop,
247  const point& nullValue
248  )
249  {
251  (
252  mesh,
253  meshPoints,
254  positions,
255  cop,
256  nullValue,
258  );
259  }
260 
261 
262  // Synchronise edge-wise data
263 
264  //- Synchronize values on all mesh edges.
265  template<class T, class CombineOp>
266  static void syncEdgeList
267  (
268  const polyMesh& mesh,
269  List<T>& edgeValues,
270  const CombineOp& cop,
271  const T& nullValue
272  )
273  {
275  (
276  mesh,
277  edgeValues,
278  cop,
279  nullValue,
281  );
282  }
283 
284  //- Synchronize locations on all mesh edges.
285  template<class CombineOp>
286  static void syncEdgePositions
287  (
288  const polyMesh& mesh,
289  List<point>& positions,
290  const CombineOp& cop,
291  const point& nullValue
292  )
293  {
295  (
296  mesh,
297  positions,
298  cop,
299  nullValue,
301  );
302  }
303 
304  //- Synchronize values on selected mesh edges.
305  template<class T, class CombineOp>
306  static void syncEdgeList
307  (
308  const polyMesh& mesh,
309  const labelList& meshEdges,
310  List<T>& edgeValues,
311  const CombineOp& cop,
312  const T& nullValue
313  )
314  {
316  (
317  mesh,
318  meshEdges,
319  edgeValues,
320  cop,
321  nullValue,
323  );
324  }
325 
326  //- Synchronize locations on selected mesh edges.
327  template<class CombineOp>
328  static void syncEdgePositions
329  (
330  const polyMesh& mesh,
331  const labelList& meshEdges,
332  List<point>& positions,
333  const CombineOp& cop,
334  const point& nullValue
335  )
336  {
338  (
339  mesh,
340  meshEdges,
341  positions,
342  cop,
343  nullValue,
345  );
346  }
347 
348 
349 
350  // Synchronise face-wise data
351 
352  //- Synchronize values on boundary faces only.
353  template<class T, class CombineOp>
355  (
356  const polyMesh& mesh,
357  UList<T>& faceValues,
358  const CombineOp& cop
359  )
360  {
362  (
363  mesh,
364  faceValues,
365  cop,
367  );
368  }
369 
370  //- Synchronize locations on boundary faces only.
371  template<class CombineOp>
373  (
374  const polyMesh& mesh,
375  UList<point>& positions,
376  const CombineOp& cop
377  )
378  {
380  (
381  mesh,
382  positions,
383  cop,
385  );
386  }
387 
388  //- Synchronize values on all mesh faces.
389  template<class T, class CombineOp>
390  static void syncFaceList
391  (
392  const polyMesh& mesh,
393  UList<T>& faceValues,
394  const CombineOp& cop
395  )
396  {
397  SubList<T> bndValues
398  (
399  faceValues,
400  mesh.nBoundaryFaces(),
401  mesh.nInternalFaces()
402  );
403 
405  (
406  mesh,
407  bndValues,
408  cop,
410  );
411  }
412 
413  //- Synchronize locations on all mesh faces.
414  template<class CombineOp>
415  static void syncFacePositions
416  (
417  const polyMesh& mesh,
418  UList<point>& positions,
419  const CombineOp& cop
420  )
421  {
422  SubList<point> bndValues
423  (
424  positions,
425  mesh.nBoundaryFaces(),
426  mesh.nInternalFaces()
427  );
429  (
430  mesh,
431  bndValues,
432  cop,
434  );
435  }
436 
437  //- Swap coupled boundary face values. Uses eqOp
438  template<class T>
440  (
441  const polyMesh& mesh,
442  UList<T>& faceValues
443  )
444  {
446  (
447  mesh,
448  faceValues,
449  eqOp<T>(),
451  );
452  }
453 
454  //- Swap coupled positions. Uses eqOp
456  (
457  const polyMesh& mesh,
458  UList<point>& positions
459  )
460  {
462  (
463  mesh,
464  positions,
465  eqOp<point>(),
467  );
468  }
469 
470  //- Swap coupled face values. Uses eqOp
471  template<class T>
472  static void swapFaceList
473  (
474  const polyMesh& mesh,
475  UList<T>& faceValues
476  )
477  {
478  SubList<T> bndValues
479  (
480  faceValues,
481  mesh.nBoundaryFaces(),
482  mesh.nInternalFaces()
483  );
485  (
486  mesh,
487  bndValues,
488  eqOp<T>(),
490  );
491  }
492 
493  //- Swap to obtain neighbour cell values for all boundary faces
494  template<class T>
495  static void swapBoundaryCellList
496  (
497  const polyMesh& mesh,
498  const UList<T>& cellData,
499  List<T>& neighbourCellData
500  );
501 
502  //- Swap to obtain neighbour cell positions for all boundary faces
503  static void swapBoundaryCellPositions
504  (
505  const polyMesh& mesh,
506  const UList<point>& cellData,
507  List<point>& neighbourCellData
508  );
509 
510 
511  // Sparse versions
512 
513  //- Synchronize values on selected points.
514  template<class T, class CombineOp>
515  static void syncPointMap
516  (
517  const polyMesh& mesh,
518  Map<T>& pointValues,
519  const CombineOp& cop
520  )
521  {
523  (
524  mesh,
525  pointValues,
526  cop,
528  );
529  }
530 
531  //- Synchronize locations on selected points.
532  template<class CombineOp>
533  static void syncPointPositions
534  (
535  const polyMesh& mesh,
536  Map<point>& positions,
537  const CombineOp& cop
538  )
539  {
541  (
542  mesh,
543  positions,
544  cop,
546  );
547  }
548 
549  //- Synchronize values on selected edges. Edges are represented
550  // by the two vertices that make it up so global edges never get
551  // constructed.
552  template<class T, class CombineOp>
553  static void syncEdgeMap
554  (
555  const polyMesh& mesh,
556  EdgeMap<T>& edgeValues,
557  const CombineOp& cop
558  )
559  {
561  (
562  mesh,
563  edgeValues,
564  cop,
566  );
567  }
568 
569  //- Synchronize locations on selected edges.
570  template<class CombineOp>
571  static void syncEdgePositions
572  (
573  const polyMesh& mesh,
574  EdgeMap<point>& edgePositions,
575  const CombineOp& cop
576  )
577  {
579  (
580  mesh,
581  edgePositions,
582  cop,
584  );
585  }
586 
587 
588  // PackedList versions
589 
590  //- Synchronize face values from PackedList/bitSet
591  //
592  // \param mesh The mesh
593  // \param isBoundaryOnly True if faceValues are for the boundary
594  // only and not the entire mesh. This determines the face
595  // offset when accessing values.
596  // \param faceValues The face values to synchronize
597  // \param cop The combine operation
598  // \param parRun True if this is a parallel simulation
599  template<unsigned Width, class CombineOp>
600  static void syncFaceList
601  (
602  const polyMesh& mesh,
603  const bool isBoundaryOnly,
604  PackedList<Width>& faceValues,
605  const CombineOp& cop,
606  const bool parRun = Pstream::parRun()
607  );
608 
609  //- Synchronize mesh face values from PackedList/bitSet
610  template<unsigned Width, class CombineOp>
611  static void syncFaceList
612  (
613  const polyMesh& mesh,
614  PackedList<Width>& faceValues,
615  const CombineOp& cop,
616  const bool parRun = Pstream::parRun()
617  );
618 
619  //- Synchronize boundary face values from PackedList/bitSet
620  template<unsigned Width, class CombineOp>
621  static void syncBoundaryFaceList
622  (
623  const polyMesh& mesh,
624  PackedList<Width>& faceValues,
625  const CombineOp& cop,
626  const bool parRun = Pstream::parRun()
627  );
628 
629  //- Swap coupled face values. Uses eqOp
630  template<unsigned Width>
631  static void swapFaceList
632  (
633  const polyMesh& mesh,
634  PackedList<Width>& faceValues
635  );
636 
637  //- Swap coupled boundary face values. Uses eqOp
638  template<unsigned Width>
639  static void swapBoundaryFaceList
640  (
641  const polyMesh& mesh,
642  PackedList<Width>& faceValues
643  );
644 
645  template<unsigned Width, class CombineOp>
646  static void syncPointList
647  (
648  const polyMesh& mesh,
649  PackedList<Width>& pointValues,
650  const CombineOp& cop,
651  const unsigned int nullValue
652  );
653 
654  template<unsigned Width, class CombineOp>
655  static void syncEdgeList
656  (
657  const polyMesh& mesh,
658  PackedList<Width>& edgeValues,
659  const CombineOp& cop,
660  const unsigned int nullValue
661  );
662 
663 
664  // Other
665 
666  //- Get per point whether it is uncoupled or a master of a
667  //- coupled set of points
668  static bitSet getMasterPoints(const polyMesh& mesh);
669 
670  //- Get per edge whether it is uncoupled or a master of a
671  //- coupled set of edges
672  static bitSet getMasterEdges(const polyMesh& mesh);
673 
674  //- Get per face whether it is uncoupled or a master of a
675  //- coupled set of faces
676  static bitSet getMasterFaces(const polyMesh& mesh);
677 
678  //- Get per face whether it is internal or a master of a
679  //- coupled set of faces
681 
682  //- Get per face whether it is internal or coupled
684 };
685 
686 
687 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
688 
689 } // End namespace Foam
690 
691 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
692 
693 #ifdef NoRepository
694  #include "syncToolsTemplates.C"
695 #endif
696 
697 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
698 
699 #endif
700 
701 // ************************************************************************* //
Foam::syncTools::getInternalOrCoupledFaces
static bitSet getInternalOrCoupledFaces(const polyMesh &mesh)
Get per face whether it is internal or coupled.
Definition: syncTools.C:176
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::syncTools::syncPointMap
static void syncPointMap(const polyMesh &mesh, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
Definition: syncToolsTemplates.C:84
Foam::combine
Definition: FaceCellWave.C:57
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::syncTools::syncBoundaryFaceList
static void syncBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const TransformOp &top, const bool parRun=Pstream::parRun())
Synchronize values on boundary faces only.
Definition: syncToolsTemplates.C:904
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::syncTools::getMasterPoints
static bitSet getMasterPoints(const polyMesh &mesh)
Definition: syncTools.C:68
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::syncTools::swapBoundaryFaceList
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:439
Foam::syncTools::getMasterFaces
static bitSet getMasterFaces(const polyMesh &mesh)
Definition: syncTools.C:126
Foam::syncTools::syncPointPositions
static void syncPointPositions(const polyMesh &mesh, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh points.
Definition: syncTools.H:199
Foam::mapDistribute::transformPosition
Default transformation behaviour for position.
Definition: mapDistribute.H:262
polyMesh.H
bitSet.H
Foam::syncTools::syncFacePositions
static void syncFacePositions(const polyMesh &mesh, UList< point > &positions, const CombineOp &cop)
Synchronize locations on all mesh faces.
Definition: syncTools.H:415
Foam::syncTools
Various tools to aid synchronizing lists across coupled patches. WIP.
Definition: syncTools.H:66
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::syncTools::syncPointList
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
Definition: syncToolsTemplates.C:724
syncToolsTemplates.C
Foam::syncTools::syncFaceList
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:390
coupledPolyPatch.H
Foam::syncTools::swapBoundaryCellPositions
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:34
Foam::syncTools::syncEdgePositions
static void syncEdgePositions(const polyMesh &mesh, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh edges.
Definition: syncTools.H:286
Foam::syncTools::syncEdgeList
static void syncEdgeList(const polyMesh &mesh, List< T > &edgeValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh edges.
Definition: syncToolsTemplates.C:803
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::syncTools::swapBoundaryFacePositions
static void swapBoundaryFacePositions(const polyMesh &mesh, UList< point > &positions)
Swap coupled positions. Uses eqOp.
Definition: syncTools.H:455
Foam::syncTools::swapBoundaryCellList
static void swapBoundaryCellList(const polyMesh &mesh, const UList< T > &cellData, List< T > &neighbourCellData)
Swap to obtain neighbour cell values for all boundary faces.
Definition: syncToolsTemplates.C:1152
Foam::eqOp
Definition: ops.H:71
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Pstream.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::syncTools::getMasterEdges
static bitSet getMasterEdges(const polyMesh &mesh)
Definition: syncTools.C:97
Foam::mapDistribute::transform
Default transformation behaviour.
Definition: mapDistribute.H:209
Foam::EdgeMap
Map from edge (expressed as its endpoints) to value. For easier forward declaration it is currently i...
Definition: EdgeMap.H:51
edgeHashes.H
mapDistribute.H
Foam::syncTools::swapFaceList
static void swapFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled face values. Uses eqOp.
Definition: syncTools.H:472
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::PackedList
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
Definition: PackedList.H:108
Foam::syncTools::syncEdgeMap
static void syncEdgeMap(const polyMesh &mesh, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected edges.
Definition: syncToolsTemplates.C:367
Foam::UList< label >
Foam::syncTools::syncBoundaryFacePositions
static void syncBoundaryFacePositions(const polyMesh &mesh, UList< point > &positions, const CombineOp &cop)
Synchronize locations on boundary faces only.
Definition: syncTools.H:372
Foam::syncTools::getInternalOrMasterFaces
static bitSet getInternalOrMasterFaces(const polyMesh &mesh)
Definition: syncTools.C:148