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-2024 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 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 Foam_syncTools_H
46 #define Foam_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  // No communication
73  template<class T, class CombineOp>
74  static void combine
75  (
76  Map<T>& pointValues,
77  const CombineOp& cop,
78  const label index,
79  const T& val
80  );
81 
82  //- Combine val with existing value in edgeValues at edge index
83  // No communication
84  template<class T, class CombineOp>
85  static void combine
86  (
87  EdgeMap<T>& edgeValues,
88  const CombineOp& cop,
89  const edge& index,
90  const T& val
91  );
92 
93 
94 public:
95 
96  // Basic routines with user-supplied transformation.
97  // Preferably use specialisations below.
98 
99  //- Synchronize values on selected points.
100  // Communication if UPstream::parRun() == true.
101  template<class T, class CombineOp, class TransformOp>
102  static void syncPointMap
103  (
104  const polyMesh& mesh,
105  Map<T>& pointValues,
106  const CombineOp& cop,
107  const TransformOp& top
108  );
109 
110  //- Synchronize values on selected edges.
111  // Communication if UPstream::parRun() == true.
112  template<class T, class CombineOp, class TransformOp>
113  static void syncEdgeMap
114  (
115  const polyMesh& mesh,
116  EdgeMap<T>& edgeValues,
117  const CombineOp& cop,
118  const TransformOp& top
119  );
120 
121  //- Synchronize values on all mesh points.
122  // Communication if UPstream::parRun() == true.
123  template<class T, class CombineOp, class TransformOp>
124  static void syncPointList
125  (
126  const polyMesh& mesh,
127  List<T>& pointValues,
128  const CombineOp& cop,
129  const T& nullValue,
130  const TransformOp& top
131  );
132 
133  //- Synchronize values on selected mesh points.
134  // Communication if UPstream::parRun() == true.
135  template<class T, class CombineOp, class TransformOp>
136  static void syncPointList
137  (
138  const polyMesh& mesh,
139  const labelUList& meshPoints,
140  List<T>& pointValues,
141  const CombineOp& cop,
142  const T& nullValue,
143  const TransformOp& top
144  );
145 
146  //- Synchronize values on all mesh edges.
147  // Communication if UPstream::parRun() == true.
148  template<class T, class CombineOp, class TransformOp, class FlipOp>
149  static void syncEdgeList
150  (
151  const polyMesh& mesh,
152  List<T>& edgeValues,
153  const CombineOp& cop,
154  const T& nullValue,
155  const TransformOp& top,
156  const FlipOp& fop
157  );
158 
159  //- Synchronize values on selected mesh edges.
160  // Communication if UPstream::parRun() == true.
161  template<class T, class CombineOp, class TransformOp, class FlipOp>
162  static void syncEdgeList
163  (
164  const polyMesh& mesh,
165  const labelUList& meshEdges,
166  List<T>& edgeValues,
167  const CombineOp& cop,
168  const T& nullValue,
169  const TransformOp& top,
170  const FlipOp& fop
171  );
172 
173  //- Synchronize values on boundary faces only.
174  template<class T, class CombineOp, class TransformOp>
175  static void syncBoundaryFaceList
176  (
177  const polyMesh& mesh,
178  UList<T>& faceValues,
179  const CombineOp& cop,
180  const TransformOp& top,
182  const bool parRun = UPstream::parRun()
183  );
184 
185 
186  // Synchronise point-wise data
187 
188  //- Synchronize values on all mesh points.
189  // Communication if UPstream::parRun() == true.
190  template<class T, class CombineOp>
191  static void syncPointList
192  (
193  const polyMesh& mesh,
194  List<T>& pointValues,
195  const CombineOp& cop,
196  const T& nullValue
197  )
198  {
200  (
201  mesh,
202  pointValues,
203  cop,
204  nullValue,
206  );
207  }
208 
209  //- Synchronize locations on all mesh points.
210  // Communication if UPstream::parRun() == true.
211  template<class CombineOp>
212  static void syncPointPositions
213  (
214  const polyMesh& mesh,
215  List<point>& positions,
216  const CombineOp& cop,
217  const point& nullValue
218  )
219  {
221  (
222  mesh,
223  positions,
224  cop,
225  nullValue,
227  );
228  }
229 
230  //- Synchronize values on selected mesh points.
231  // Communication if UPstream::parRun() == true.
232  template<class T, class CombineOp>
233  static void syncPointList
234  (
235  const polyMesh& mesh,
236  const labelUList& meshPoints,
237  List<T>& pointValues,
238  const CombineOp& cop,
239  const T& nullValue
240  )
241  {
243  (
244  mesh,
245  meshPoints,
246  pointValues,
247  cop,
248  nullValue,
250  );
251  }
252 
253  //- Synchronize locations on selected mesh points.
254  // Communication if UPstream::parRun() == true.
255  template<class CombineOp>
256  static void syncPointPositions
257  (
258  const polyMesh& mesh,
259  const labelUList& meshPoints,
260  List<point>& positions,
261  const CombineOp& cop,
262  const point& nullValue
263  )
264  {
266  (
267  mesh,
268  meshPoints,
269  positions,
270  cop,
271  nullValue,
273  );
274  }
275 
276 
277  // Synchronise edge-wise data
278 
279  //- Synchronize values on all mesh edges.
280  // Communication if UPstream::parRun() == true.
281  template<class T, class CombineOp>
282  static void syncEdgeList
283  (
284  const polyMesh& mesh,
285  List<T>& edgeValues,
286  const CombineOp& cop,
287  const T& nullValue
288  )
289  {
291  (
292  mesh,
293  edgeValues,
294  cop,
295  nullValue,
297  identityOp() // No flipping
298  );
299  }
300 
301  //- Synchronize locations on all mesh edges.
302  // Communication if UPstream::parRun() == true.
303  template<class CombineOp>
304  static void syncEdgePositions
305  (
306  const polyMesh& mesh,
307  List<point>& positions,
308  const CombineOp& cop,
309  const point& nullValue
310  )
311  {
313  (
314  mesh,
315  positions,
316  cop,
317  nullValue,
319  identityOp() // No flipping
320  );
321  }
322 
323  //- Synchronize values on selected mesh edges.
324  // Communication if UPstream::parRun() == true.
325  template<class T, class CombineOp>
326  static void syncEdgeList
327  (
328  const polyMesh& mesh,
329  const labelUList& meshEdges,
330  List<T>& edgeValues,
331  const CombineOp& cop,
332  const T& nullValue
333  )
334  {
336  (
337  mesh,
338  meshEdges,
339  edgeValues,
340  cop,
341  nullValue,
343  identityOp() // No flipping
344  );
345  }
346 
347  //- Synchronize locations on selected mesh edges.
348  // Communication if UPstream::parRun() == true.
349  template<class CombineOp>
350  static void syncEdgePositions
351  (
352  const polyMesh& mesh,
353  const labelUList& meshEdges,
354  List<point>& positions,
355  const CombineOp& cop,
356  const point& nullValue
357  )
358  {
360  (
361  mesh,
362  meshEdges,
363  positions,
364  cop,
365  nullValue,
367  identityOp() // No flipping
368  );
369  }
370 
371 
372 
373  // Synchronise face-wise data
374 
375  //- Synchronize values on boundary faces only.
376  template<class T, class CombineOp>
377  static void syncBoundaryFaceList
378  (
379  const polyMesh& mesh,
380  UList<T>& faceValues,
381  const CombineOp& cop
382  )
383  {
385  (
386  mesh,
387  faceValues,
388  cop,
390  );
391  }
392 
393  //- Synchronize locations on boundary faces only.
394  template<class CombineOp>
395  static void syncBoundaryFacePositions
396  (
397  const polyMesh& mesh,
398  UList<point>& positions,
399  const CombineOp& cop
400  )
401  {
403  (
404  mesh,
405  positions,
406  cop,
408  );
409  }
410 
411  //- Synchronize values on all mesh faces.
412  template<class T, class CombineOp>
413  static void syncFaceList
414  (
415  const polyMesh& mesh,
416  UList<T>& faceValues,
417  const CombineOp& cop,
419  const bool parRun = UPstream::parRun()
420  )
421  {
422  SubList<T> bndValues
423  (
424  faceValues,
425  mesh.nBoundaryFaces(),
426  mesh.nInternalFaces()
427  );
428 
430  (
431  mesh,
432  bndValues,
433  cop,
435  parRun
436  );
437  }
438 
439  //- Synchronize locations on all mesh faces.
440  template<class CombineOp>
441  static void syncFacePositions
442  (
443  const polyMesh& mesh,
444  UList<point>& positions,
445  const CombineOp& cop,
447  const bool parRun = UPstream::parRun()
448  )
449  {
450  SubList<point> bndValues
451  (
452  positions,
453  mesh.nBoundaryFaces(),
454  mesh.nInternalFaces()
455  );
457  (
458  mesh,
459  bndValues,
460  cop,
462  parRun
463  );
464  }
466  //- Swap coupled boundary face values. Uses eqOp
467  template<class T>
468  static void swapBoundaryFaceList
469  (
470  const polyMesh& mesh,
471  UList<T>& faceValues,
473  const bool parRun = UPstream::parRun()
474  )
475  {
477  (
478  mesh,
479  faceValues,
480  eqOp<T>(),
482  parRun
483  );
484  }
485 
486  //- Swap coupled positions. Uses eqOp
487  static void swapBoundaryFacePositions
488  (
489  const polyMesh& mesh,
490  UList<point>& positions,
492  const bool parRun = UPstream::parRun()
493  )
494  {
496  (
497  mesh,
498  positions,
499  eqOp<point>(),
501  parRun
502  );
503  }
504 
505  //- Swap coupled face values. Uses eqOp
506  template<class T>
507  static void swapFaceList
508  (
509  const polyMesh& mesh,
510  UList<T>& faceValues,
512  const bool parRun = UPstream::parRun()
513  )
514  {
515  SubList<T> bndValues
516  (
517  faceValues,
518  mesh.nBoundaryFaces(),
519  mesh.nInternalFaces()
520  );
522  (
523  mesh,
524  bndValues,
525  eqOp<T>(),
527  parRun
528  );
529  }
530 
531  //- Extract and swap to obtain neighbour cell values
532  //- for all boundary faces
533  template<class T>
534  static void swapBoundaryCellList
535  (
536  const polyMesh& mesh,
537  const UList<T>& cellData,
538  List<T>& neighbourCellData,
540  const bool parRun = UPstream::parRun()
541  );
542 
543  //- Extract and swap to obtain neighbour cell positions
544  //- for all boundary faces
546  (
547  const polyMesh& mesh,
548  const UList<point>& cellData,
549  List<point>& neighbourCellData,
551  const bool parRun = UPstream::parRun()
552  );
553 
554 
555  //- Return neighbour cell values for all boundary faces
556  //- by swapping via boundary faces
557  template<class T>
559  (
560  const polyMesh& mesh,
561  const UList<T>& cellData,
563  const bool parRun = UPstream::parRun()
564  )
565  {
566  List<T> nbrCellData;
567  swapBoundaryCellList(mesh, cellData, nbrCellData, parRun);
568  return nbrCellData;
569  }
570 
571  //- Return neighbour cell positions for all boundary faces
572  //- by swapping via boundary faces
574  (
575  const polyMesh& mesh,
576  const UList<point>& cellData,
578  const bool parRun = UPstream::parRun()
579  )
580  {
581  List<point> nbrCellData;
582  swapBoundaryCellPositions(mesh, cellData, nbrCellData, parRun);
583  return nbrCellData;
584  }
585 
586 
587  // Sparse versions
588 
589  //- Synchronize values on selected points.
590  // Communication if UPstream::parRun() == true.
591  template<class T, class CombineOp>
592  static void syncPointMap
593  (
594  const polyMesh& mesh,
595  Map<T>& pointValues,
596  const CombineOp& cop
597  )
598  {
600  (
601  mesh,
602  pointValues,
603  cop,
605  );
606  }
607 
608  //- Synchronize locations on selected points.
609  // Communication if UPstream::parRun() == true.
610  template<class CombineOp>
611  static void syncPointPositions
612  (
613  const polyMesh& mesh,
614  Map<point>& positions,
615  const CombineOp& cop
616  )
617  {
619  (
620  mesh,
621  positions,
622  cop,
623  mapDistribute::transformPosition()
624  );
625  }
626 
627  //- Synchronize values on selected edges.
628  //- Edges are represented by the two vertices that make it up
629  //- so global edges never get constructed.
630  // Communication if UPstream::parRun() == true.
631  template<class T, class CombineOp>
632  static void syncEdgeMap
633  (
634  const polyMesh& mesh,
635  EdgeMap<T>& edgeValues,
636  const CombineOp& cop
637  )
638  {
640  (
642  edgeValues,
643  cop,
645  );
646  }
647 
648  //- Synchronize locations on selected edges.
649  // Communication if UPstream::parRun() == true.
650  template<class CombineOp>
651  static void syncEdgePositions
652  (
653  const polyMesh& mesh,
654  EdgeMap<point>& edgePositions,
655  const CombineOp& cop
656  )
657  {
659  (
660  mesh,
661  edgePositions,
662  cop,
664  );
665  }
666 
667 
668  // PackedList versions
669 
670  //- Synchronize face values from PackedList/bitSet
671  //
672  // \param mesh The mesh
673  // \param isBoundaryOnly True if faceValues are for the boundary
674  // only and not the entire mesh. This determines the face
675  // offset when accessing values.
676  // \param faceValues The face values to synchronize
677  // \param cop The combine operation
678  // \param parRun Allow parallel communication
679  template<unsigned Width, class CombineOp>
680  static void syncFaceList
681  (
682  const polyMesh& mesh,
683  const bool isBoundaryOnly,
684  PackedList<Width>& faceValues,
685  const CombineOp& cop,
686  const bool parRun = UPstream::parRun()
687  );
688 
689  //- Synchronize mesh face values from PackedList/bitSet
690  template<unsigned Width, class CombineOp>
691  static void syncFaceList
692  (
693  const polyMesh& mesh,
694  PackedList<Width>& faceValues,
695  const CombineOp& cop,
697  const bool parRun = UPstream::parRun()
698  );
699 
700  //- Synchronize boundary face values from PackedList/bitSet
701  template<unsigned Width, class CombineOp>
702  static void syncBoundaryFaceList
703  (
704  const polyMesh& mesh,
705  PackedList<Width>& faceValues,
706  const CombineOp& cop,
708  const bool parRun = UPstream::parRun()
709  );
710 
711  //- Swap coupled face values. Uses eqOp
712  template<unsigned Width>
713  static void swapFaceList
714  (
715  const polyMesh& mesh,
716  PackedList<Width>& faceValues,
718  const bool parRun = UPstream::parRun()
719  );
720 
721  //- Swap coupled boundary face values. Uses eqOp
722  template<unsigned Width>
723  static void swapBoundaryFaceList
724  (
725  const polyMesh& mesh,
726  PackedList<Width>& faceValues,
728  const bool parRun = UPstream::parRun()
729  );
730 
731  template<unsigned Width, class CombineOp>
732  static void syncPointList
733  (
734  const polyMesh& mesh,
735  PackedList<Width>& pointValues,
736  const CombineOp& cop,
737  const unsigned int nullValue
738  );
739 
740  template<unsigned Width, class CombineOp>
741  static void syncEdgeList
742  (
743  const polyMesh& mesh,
744  PackedList<Width>& edgeValues,
745  const CombineOp& cop,
746  const unsigned int nullValue
747  );
748 
749 
750  // Other
751 
752  //- Get per point whether it is uncoupled or a master of a
753  //- coupled set of points
754  static bitSet getMasterPoints(const polyMesh& mesh);
755 
756  //- Get per edge whether it is uncoupled or a master of a
757  //- coupled set of edges
758  static bitSet getMasterEdges(const polyMesh& mesh);
759 
760  //- Get per face whether it is uncoupled or a master of a
761  //- coupled set of faces
762  static bitSet getMasterFaces(const polyMesh& mesh);
763 
764  //- Get per face whether it is internal or a master of a
765  //- coupled set of faces
767 
768  //- Get per face whether it is internal or coupled
770 };
771 
772 
773 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
774 
775 } // End namespace Foam
776 
777 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
778 
779 #ifdef NoRepository
780  #include "syncToolsTemplates.C"
781 #endif
782 
783 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
784 
785 #endif
786 
787 // ************************************************************************* //
static void swapFaceList(const polyMesh &mesh, UList< T > &faceValues, const bool parRun=UPstream::parRun())
Swap coupled face values. Uses eqOp.
Definition: syncTools.H:567
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const bool parRun=UPstream::parRun())
Synchronize values on all mesh faces.
Definition: syncTools.H:465
Definition: ops.H:67
static void syncBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const TransformOp &top, const bool parRun=UPstream::parRun())
Synchronize values on boundary faces only.
#define FOAM_NODISCARD
Definition: stdFoam.H:63
static bitSet getMasterFaces(const polyMesh &mesh)
Get per face whether it is uncoupled or a master of a coupled set of faces.
Definition: syncTools.C:119
static void syncPointPositions(const polyMesh &mesh, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh points.
Definition: syncTools.H:240
static void swapBoundaryCellList(const polyMesh &mesh, const UList< T > &cellData, List< T > &neighbourCellData, const bool parRun=UPstream::parRun())
Extract and swap to obtain neighbour cell values for all boundary faces.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
static void syncBoundaryFacePositions(const polyMesh &mesh, UList< point > &positions, const CombineOp &cop)
Synchronize locations on boundary faces only.
Definition: syncTools.H:445
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const bool parRun=UPstream::parRun())
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:524
Various tools to aid synchronizing lists across coupled patches. WIP.
Definition: syncTools.H:62
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1061
static bitSet getInternalOrCoupledFaces(const polyMesh &mesh)
Get per face whether it is internal or coupled.
Definition: syncTools.C:165
A List obtained as a section of another List.
Definition: SubList.H:50
static void syncFacePositions(const polyMesh &mesh, UList< point > &positions, const CombineOp &cop, const bool parRun=UPstream::parRun())
Synchronize locations on all mesh faces.
Definition: syncTools.H:495
dynamicFvMesh & mesh
Default transformation behaviour.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
Definition: PackedList.H:105
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition: edge.H:59
static bitSet getMasterPoints(const polyMesh &mesh)
Get per point whether it is uncoupled or a master of a coupled set of points.
Definition: syncTools.C:61
static bitSet getMasterEdges(const polyMesh &mesh)
Get per edge whether it is uncoupled or a master of a coupled set of edges.
Definition: syncTools.C:90
static void swapBoundaryCellPositions(const polyMesh &mesh, const UList< point > &cellData, List< point > &neighbourCellData, const bool parRun=UPstream::parRun())
Extract and swap to obtain neighbour cell positions for all boundary faces.
Definition: syncTools.C:27
static void swapBoundaryFacePositions(const polyMesh &mesh, UList< point > &positions, const bool parRun=UPstream::parRun())
Swap coupled positions. Uses eqOp.
Definition: syncTools.H:545
Default transformation behaviour for position.
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
A functor that returns its argument unchanged (cf. C++20 std::identity) Should never be specialized...
Definition: stdFoam.H:90
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Map from edge (expressed as its endpoints) to value. Hashing (and ==) on an edge is symmetric...
Definition: edgeHashes.H:56
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static void syncEdgePositions(const polyMesh &mesh, List< point > &positions, const CombineOp &cop, const point &nullValue)
Synchronize locations on all mesh edges.
Definition: syncTools.H:344
static bitSet getInternalOrMasterFaces(const polyMesh &mesh)
Get per face whether it is internal or a master of a coupled set of faces.
Definition: syncTools.C:139
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
static void syncEdgeList(const polyMesh &mesh, List< T > &edgeValues, const CombineOp &cop, const T &nullValue, const TransformOp &top, const FlipOp &fop)
Synchronize values on all mesh edges.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
static void syncEdgeMap(const polyMesh &mesh, EdgeMap< T > &edgeValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected edges.
static void syncPointMap(const polyMesh &mesh, Map< T > &pointValues, const CombineOp &cop, const TransformOp &top)
Synchronize values on selected points.
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.